1. #!/bin/sh
  2.  
  3. # notify-html-email.sh v1.7
  4. # by mgothard
  5. # www.NagiosExchange.org
  6. VERSION="1.7"
  7.  
  8. # Requires the following shell commands/programs (in reference order):
  9. # sendmail - or other command-line mail tool; called to actually handle sending of message
  10. # printf - interpret escape characters before passing to mail system
  11. # date - used to generate unique Content-ID and MIME boundary; also to convert Nagios Unix epoch timestamps to human readable
  12. # hostname - used to generate unique Content-ID and MIME boundary
  13. # uuencode - generates Base64 encodes of Nagios graphics
  14. # head - used to cleanup uuencode output
  15. # tail - used to cleanup uuencode output
  16. # python - manipulate strings
  17.  
  18. # ChangeLog
  19. # ---------
  20. # 1.7 - Added Nagios 3.x compatibility
  21. # - Changed HTML to reflect Nagios 3.x format changes
  22. # - More Outlook 2007 rendering fixes
  23. # - Added checks for critical supporting programs
  24. # - Modified error messages to be more helpful
  25. # 1.6 - Fixed MIME boundary problem
  26. # - Fixed capitalization problems with "text-transform" on some browsers
  27. # - Fixed compatibility issues with Microsoft Outlook 2007 (with a loss of HTML 4.01 Strict compliance)
  28. # 1.5 - New format looks and acts more like Nagios itself
  29. # - HTML 4.01 Strict compliant; all tags in lower case and all parameters quoted in prep for XHTML 1.0
  30. # - Multipart MIME added with embedded graphics and alternate text
  31. # - Single HTML form modified with variables for ease in editing
  32. # - Lots of code changes/cleanup
  33. # - Corrected some timezone related bugs
  34. # - Added tons of comments
  35. # 1.0 - Original HTML message generation; text/html MIME type only
  36. # - CSS 2.0 compliant
  37.  
  38. # Known Bugs
  39. # ---------
  40. # 1. May be some bash specific syntax in here. Please report this if you find it.
  41.  
  42. # ****************************************
  43. # Modify the following variables as needed
  44. # ****************************************
  45.  
  46. # Full path to your mail program
  47. MAILER=/usr/sbin/sendmail
  48.  
  49. # Any options necessary to read the FROM: and TO: fields, etc. from the input
  50. MAILOPTS="-t"
  51.  
  52. # Full path to printf
  53. PRINTF=/usr/bin/printf
  54.  
  55. # Full path to Nagios images directory. Do NOT include a trailing backslash character! ('/')
  56. IMAGES=/srv/nagios/share/images
  57.  
  58. # Text name for your reply-to address. E-mail address is gleaned from Nagios config
  59. REPLYNAME="Southern Union Networks"
  60. REPLYADDRESS="$REPLYNAME <$NAGIOS_ADMINEMAIL>"
  61.  
  62. # Full URL to Nagios front-end. Do NOT include a trailing backslash character! ('/')
  63. URLPATH="http://$HOSTNAME/nagios"
  64.  
  65. # Full URL to Nagios cgi-bin directory. Do NOT include a trailing backslash character! ('/')
  66. URLCGIBIN="$URLPATH/cgi-bin"
  67.  
  68. # Date command formating parameters used in HTML message. Can be null, or include options, or both
  69. # ex: "--rfc-3389=seconds", "+%x %X"
  70. DATEFORMAT="+%m/%d/%Y %l:%M:%S%P %Z"
  71.  
  72. # Generate unique MIME Content-ID base for multipart message
  73. CONTENTIDBASE="`date +%s`@`hostname --fqdn`"
  74.  
  75. # MIME boundary string
  76. MIMEBOUNDARY1="=_NextPart_`date +%s`_`hostname`_1"
  77. MIMEBOUNDARY2="=_NextPart_`date +%s`_`hostname`_2"
  78.  
  79. # *************END MODIFY*****************
  80.  
  81. # Check for proper usage
  82. [ $1 ] || {
  83. echo -e "notify-html-email.sh $VERISON\n\nHTML 4.0 notification for Nagios 3.x and 2.x\n\nUsage: notify-html-email <notification_type>\n\nOptions:"
  84. echo -e " notification_type\n Must be 'host' or 'service' indicating the type of notification\n"
  85. echo -e "This script should be called by a Nagios e-mail notification command\nfrom /usr/local/nagios/etc/misccommands.cfg"
  86. echo -e "It uses the NAGIOS_* environmental variables to generate and send an HTML\nmessage to the recipient. The format of the e-mail is customizable by\nediting this script.\n"
  87. exit -1
  88. }
  89.  
  90. # Be sure minimum necessary variables are present
  91. [ $NAGIOS_HOSTNAME ] || {
  92. echo -e "ERROR: Hostname not found.\n\nMaybe this script was not called from Nagios?\nDo not try to execute this script manually.\nType $0 for more info"
  93. exit -1
  94. }
  95. [ $NAGIOS_CONTACTEMAIL ] || {
  96. echo -e "ERROR: E-mail address not found.\n\nMaybe this script was not called from Nagios?\nDo not try to execute this script manually.\nType $0 for more info"
  97. exit -1
  98. }
  99. [ $NAGIOS_ADMINEMAIL ] || {
  100. echo -e "ERROR: Reply-To e-mail address not found.\n\nMaybe this script was not called from Nagios?\nDo not try to execute this script manually.\nType $0 for more info"
  101. exit -1
  102. }
  103.  
  104. # For future functionaliy
  105. #[ $NAGIOS_MAINCONFIGFILE ] || {
  106. # echo "ERROR: Unable to locate the main Nagios config file. Not called from Nagios?"
  107. # exit -1
  108. #}
  109.  
  110. # Check all necessary programs are present
  111. [ -f $MAILER ] || {
  112. echo -e "ERROR: E-mail program $MAILER could not be found!\n\nPlease edit this script and change the MAILER variable accordingly"
  113. exit -1
  114. }
  115. [ -f $PRINTF ] || {
  116. echo -e "ERROR: Print formatting function $PRINTF could not be found!\n\nPlease edit this script and change the PRINTF variable accordingly"
  117. exit -1
  118. }
  119. [ -d $IMAGES ] || {
  120. echo -e "ERROR: Images directory $IMAGES could not be found!\n\nPlease edit this script and change the IMAGES variable accordingly"
  121. exit -1
  122. }
  123.  
  124. # Generate Base64 encodings for inline graphics
  125. UUIMGSTATUS3=`uuencode --base64 $IMAGES/status3.gif status3.gif | tail --lines=+2 | head --lines=-1`
  126. UUIMGDISABLED=`uuencode --base64 $IMAGES/disabled.gif disabled.gif | tail --lines=+2 | head --lines=-1`
  127. UUIMGDELAY=`uuencode --base64 $IMAGES/delay.gif delay.gif | tail --lines=+2 | head --lines=-1`
  128. UUIMGACK=`uuencode --base64 $IMAGES/ack.gif ack.gif | tail --lines=+2 | head --lines=-1`
  129. UUIMGDOWNTIME=`uuencode --base64 $IMAGES/downtime.gif downtime.gif | tail --lines=+2 | head --lines=-1`
  130. UUIMGENABLED=`uuencode --base64 $IMAGES/enabled.gif enabled.gif | tail --lines=+2 | head --lines=-1`
  131. UUIMGCOMMENT=`uuencode --base64 $IMAGES/comment.gif comment.gif | tail --lines=+2 | head --lines=-1`
  132.  
  133. # Graphics that may not be used (depends on notification type)
  134. MIMEGRAPHICACK="--$MIMEBOUNDARY2
  135. Content-Type: image/gif
  136. Content-Transfer-Encoding: base64
  137. Content-Description: Inline graphic
  138. Content-ID: <ack.gif$CONTENTIDBASE>
  139. Content-Location: $URLPATH/images/ack.gif
  140. Content-Disposition: inline
  141.  
  142. $UUIMGACK"
  143. MIMEGRAPHIC1="--$MIMEBOUNDARY2
  144. Content-Type: image/gif
  145. Content-Transfer-Encoding: base64
  146. Content-Description: Inline graphic
  147. Content-ID: <status3.gif$CONTENTIDBASE>
  148. Content-Location: $URLPATH/images/status3.gif
  149. Content-Disposition: inline
  150.  
  151. $UUIMGSTATUS3"
  152. MIMEGRAPHIC2="--$MIMEBOUNDARY2
  153. Content-Type: image/gif
  154. Content-Transfer-Encoding: base64
  155. Content-Description: Inline graphic
  156. Content-ID: <enabled.gif$CONTENTIDBASE>
  157. Content-Location: $URLPATH/images/enabled.gif
  158. Content-Disposition: inline
  159.  
  160. $UUIMGENABLED"
  161.  
  162. # Initialize variables
  163. FLAPPING="NO"
  164. FLAPPINGCLASS="notflapping"
  165.  
  166. case $NAGIOS_NOTIFICATIONTYPE
  167. in
  168. PROBLEM) BKCLR="F83838" ;
  169. case $NAGIOS_SERVICESTATE
  170. in
  171. WARNING) BKCLR="FFFF00" ;;
  172. UNKNOWN) BKCLR="FF9900" ;;
  173. esac ;;
  174. RECOVERY) BKCLR="33FF00" ;
  175. MIMEGRAPHICACK="" ;;
  176. ACKNOWLEDGEMENT) BKCLR="0099FF" ;
  177. R_SUBJECT="has been acknowledged by" ;
  178. STATUSACK="(Has been acknowledged)&nbsp;&nbsp;" ;
  179. MIMEGRAPHICACK="" ;;
  180. FLAPPINGSTART) BKCLR="F83838" ;
  181. R_SUBJECT="has started flapping" ;
  182. FLAPPING="YES" ;
  183. FLAPPINGCLASS="flapping" ;;
  184. FLAPPINGSTOP) BKCLR="33FF00" ;
  185. R_SUBJECT="is no longer flapping" ;
  186. MIMEGRAPHICACK="" ;;
  187. FLAPPINGDISABLED) BKCLR="0099FF" ;
  188. R_SUBJECT="was flapping and had flapping notifications disabled";
  189. FLAPPING="DISABLED" ;
  190. FLAPPINGCLASS="flapping" ;
  191. MIMEGRAPHICACK="" ;;
  192. DOWNTIMESTART) BKCLR="0099FF" ;
  193. R_SUBJECT="has entered scheduled downtime" ;
  194. MIMEGRAPHICACK="" ;;
  195. DOWNTIMEEND) BKCLR="0099FF" ;
  196. R_SUBJECT="has exited scheduled downtime" ;
  197. MIMEGRAPHICACK="" ;;
  198. DOWNTIMECANCELLED) BKCLR="0099FF" ;
  199. R_SUBJECT="had scheduled downtime cancelled" ;
  200. MIMEGRAPHICACK="" ;;
  201. TEST) BKCLR="FF66FF" ;
  202. MIMEGRAPHICACK="" ;;
  203. *) BKCLR="FF66FF" ;;
  204. esac
  205.  
  206. # Host message prep
  207. if [[ $1 == 'host' ]] ;
  208. then {
  209.  
  210. # ---Section only used for alternative text message---
  211. LASTHOSTDOWNTIME=`date --universal --date="1970-01-01 UTC $NAGIOS_LASTHOSTDOWN seconds"`
  212. LASTHOSTUPTIME=`date --universal --date="1970-01-01 UTC $NAGIOS_LASTHOSTUP seconds"`
  213. LASTHOSTUNREACHABLETIME=`date --universal --date="1970-01-01 UTC $NAGIOS_LASTHOSTUNREACHABLE seconds"`
  214.  
  215. if [[ $LASTHOSTDOWNTIME == "Thu Jan 1 00:00:00 UTC 1970" ]] ; then LASTHOSTDOWNTIME="never" ; fi
  216. if [[ $LASTHOSTUPTIME == "Thu Jan 1 00:00:00 UTC 1970" ]] ; then LASTHOSTUPTIME="never" ; fi
  217. if [[ $LASTHOSTUNREACHABLETIME == "Thu Jan 1 00:00:00 UTC 1970" ]] ; then LASTHOSTUNREACHABLETIME="never" ; fi
  218.  
  219. case $NAGIOS_HOSTSTATE
  220. in
  221. UP) R_TIMES="Last time this host was down: $LASTHOSTDOWNTIME
  222. Last time this host was unreachable: $LASTHOSTUNREACHABLETIME" ;;
  223. DOWN | UNREACHABLE) R_TIMES="Last time this host was up: $LASTHOSTUPTIME" ;;
  224. *) R_TIMES="Error: Unknown host state" ;;
  225. esac
  226. # ---END SECTION---
  227.  
  228. # Catch for Nagios 2.x variable difference
  229. if [[ $NAGIOS_HOSTNOTIFICATIONNUMBER == "" && $NAGIOS_NOTIFICATIONNUMBER != "" ]] ;
  230. then {
  231. NAGIOS_HOSTNOTIFICATIONNUMBER=$NAGIOS_NOTIFICATIONNUMBER
  232. };
  233. fi
  234.  
  235. if [[ $R_SUBJECT == "" ]] ;
  236. then {
  237. R_SUBJECT="is $NAGIOS_HOSTSTATE ($NAGIOS_HOSTNOTIFICATIONNUMBER)"
  238. };
  239. fi
  240.  
  241. if [[ $NAGIOS_NOTIFICATIONTYPE == "ACKNOWLEDGEMENT" ]] ;
  242. then {
  243. R_SUBJECT="$R_SUBJECT $NAGIOS_HOSTACKAUTHOR"
  244. R_ACKADD="<tr class='commentOdd'>
  245. <td class='commentOdd'>$NAGIOS_HOSTACKAUTHOR</td>
  246. <td class='commentOdd'>$NAGIOS_HOSTACKCOMMENT</td>
  247. </tr>"
  248. };
  249. elif [[ $NAGIOS_NOTIFICATIONTYPE == "PROBLEM" || $NAGIOS_NOTIFICATIONTYPE == "FLAPPINGSTART" ]] ;
  250. then {
  251. R_ACKCOMMAND="<tr class='command'>
  252. <td><img src='cid:ack.gif$CONTENTIDBASE' class='icon' alt='Acknowledge'></td>
  253. <td class='command'><a href='$URLCGIBIN/cmd.cgi?cmd_typ=33&amp;host=$NAGIOS_HOSTNAME'>Acknowledge this host problem</a></td>
  254. </tr>"
  255. };
  256. fi
  257.  
  258. R_SUBJECT="Nagios Host Alert - $NAGIOS_HOSTNAME $R_SUBJECT"
  259. R_NUMBER=$NAGIOS_HOSTNOTIFICATIONNUMBER
  260. R_DESCRIPTION=$NAGIOS_HOSTALIAS
  261. R_NOTES=$NAGIOS_HOSTNOTES
  262. R_STATE=$NAGIOS_HOSTSTATE
  263. R_OUTPUT=$NAGIOS_HOSTOUTPUT
  264. R_ATTEMPT=$NAGIOS_HOSTATTEMPT
  265. R_PERFDATA=$NAGIOS_HOSTPERFDATA
  266. R_DURATION=$NAGIOS_HOSTDURATION
  267. R_LATENCY=$NAGIOS_HOSTLATENCY
  268. R_EXECUTION=$NAGIOS_HOSTEXECUTIONTIME
  269. R_PERCENT=$NAGIOS_HOSTPERCENTCHANGE
  270. R_LASTCHECK=`date --date="1970-01-01 UTC $NAGIOS_LASTHOSTCHECK seconds" "$DATEFORMAT"`
  271. R_LASTSTATECHANGE=`date --date="1970-01-01 UTC $NAGIOS_LASTHOSTSTATECHANGE seconds" "$DATEFORMAT"`
  272. R_COMMANDTAIL="&amp;host=$NAGIOS_HOSTNAME"
  273. R_COMMANDADD1="<tr class='command'>
  274. <td><img src='cid:status3.gif$CONTENTIDBASE' class='icon' alt='map'></td>
  275. <td class='command'><a href='$URLCGIBIN/statusmap.cgi?host=$NAGIOS_HOSTNAME'>Locate host on map</a></td>
  276. </tr>"
  277. R_COMMANDADD2="48"
  278. R_COMMANDADD3="96"
  279. R_COMMANDADD4="25"
  280. R_COMMANDADD5="10"
  281. R_COMMANDADD6="55"
  282. R_COMMANDADD7="<tr class='command'>
  283. <td><img src='cid:enabled.gif$CONTENTIDBASE' class='icon' alt='enabled'></td>
  284. <td class='command'><a href='$URLCGIBIN/cmd.cgi?cmd_typ=28$R_COMMANDTAIL'>Enable notifications for all services on this host</a></td>
  285. </tr>
  286. <tr class='command'>
  287. <td><img src='cid:delay.gif$CONTENTIDBASE' class='icon' alt='delay'></td>
  288. <td class='command'><a href='$URLCGIBIN/cmd.cgi?cmd_typ=17$R_COMMANDTAIL'>Schedule a check of all services on this host</a></td>
  289. </tr>
  290. <tr class='command'>
  291. <td><img src='cid:disabled.gif$CONTENTIDBASE' class='icon' alt='disabled'></td>
  292. <td class='command'><a href='$URLCGIBIN/cmd.cgi?cmd_typ=16$R_COMMANDTAIL'>Disable checks of all services on this host</a></td>
  293. </tr>
  294. <tr class='command'>
  295. <td><img src='cid:enabled.gif$CONTENTIDBASE' class='icon' alt='enabled'></td>
  296. <td class='command'><a href='$URLCGIBIN/cmd.cgi?cmd_typ=15$R_COMMANDTAIL'>Enable checks of all services on this host</a></td>
  297. </tr>"
  298. R_COMMANDADD8="58"
  299. R_COMMANDADD9="1"
  300. };
  301.  
  302. # Service message prep
  303. elif [[ $1 == 'service' ]] ;
  304. then {
  305.  
  306. # ---Section only used for alterative text message---
  307. LASTSERVICECRITICALTIME=`date --universal --date="1970-01-01 UTC $NAGIOS_LASTSERVICECRITICAL seconds"`
  308. LASTSERVICEWARNINGTIME=`date --universal --date="1970-01-01 UTC $NAGIOS_LASTSERVICEWARNING seconds"`
  309. LASTSERVICEOKTIME=`date --universal --date="1970-01-01 UTC $NAGIOS_LASTSERVICEOK seconds"`
  310. LASTSERVICEUNKNOWNTIME=`date --universal --date="1970-01-01 UTC $NAGIOS_LASTSERVICEUNKNOWN seconds"`
  311.  
  312. if [[ $LASTSERVICECRITICALTIME == "Thu Jan 1 00:00:00 UTC 1970" ]] ; then LASTSERVICECRITICALTIME="never" ; fi
  313. if [[ $LASTSERVICEWARNINGTIME == "Thu Jan 1 00:00:00 UTC 1970" ]] ; then LASTSERVICEWARNINGTIME="never" ; fi
  314. if [[ $LASTSERVICEOKTIME == "Thu Jan 1 00:00:00 UTC 1970" ]] ; then LASTSERVICEOKTIME="never" ; fi
  315. if [[ $LASTSERVICEUNKNOWNTIME == "Thu Jan 1 00:00:00 UTC 1970" ]] ; then LASTSERVICEUNKNOWNTIME="never" ; fi
  316.  
  317. case $NAGIOS_SERVICESTATE
  318. in
  319. OK) R_TIMES="Last time this service was critical: $LASTSERVICECRITICALTIME
  320. Last time this service was warning: $LASTSERVICEWARNINGTIME
  321. Last time this service was unknown: $LASTSERVICEUNKNOWNTIME" ;;
  322. WARNING | UNKNOWN | CRITICAL) R_TIMES="Last time this service was ok: $LASTSERVICEOKTIME" ;;
  323. *) R_TIMES="Error: Unknown service state" ;;
  324. esac
  325. # ---END SECTION---
  326.  
  327. # Catch for Nagios 2.x variable difference
  328. if [[ $NAGIOS_SERVICENOTIFICATIONNUMBER == "" && $NAGIOS_NOTIFICATIONNUMBER != "" ]] ;
  329. then {
  330. NAGIOS_SERVICENOTIFICATIONNUMBER=$NAGIOS_NOTIFICATIONNUMBER
  331. };
  332. fi
  333.  
  334. if [[ $R_SUBJECT == "" ]] ;
  335. then {
  336. R_SUBJECT="is $NAGIOS_SERVICESTATE ($NAGIOS_SERVICENOTIFICATIONNUMBER)"
  337. };
  338. fi
  339.  
  340. if [[ $NAGIOS_NOTIFICATIONTYPE == "ACKNOWLEDGEMENT" ]] ;
  341. then {
  342. R_SUBJECT="$R_SUBJECT $NAGIOS_SERVICEACKAUTHOR"
  343. R_ACKADD="<tr class='commentOdd'>
  344. <td class='commentOdd'>$NAGIOS_SERVICEACKAUTHOR</td>
  345. <td class='commentOdd'>$NAGIOS_SERVICEACKCOMMENT</td>
  346. </tr>"
  347. };
  348. elif [[ $NAGIOS_NOTIFICATIONTYPE == "PROBLEM" || $NAGIOS_NOTIFICATIONTYPE == "FLAPPINGSTART" ]] ;
  349. then {
  350. R_ACKCOMMAND="<tr class='command'>
  351. <td><img src='cid:ack.gif$CONTENTIDBASE' class='icon' alt='acknowledge'></td>
  352. <td class='command'><a href='$URLCGIBIN/cmd.cgi?cmd_typ=34&amp;host=$NAGIOS_HOSTNAME&amp;service=$NAGIOS_SERVICEDESC'>Acknowledge this service problem</a></td>
  353. </tr>"
  354. };
  355. fi
  356.  
  357. R_SUBJECT="Nagios Service Alert - $NAGIOS_SERVICEDESC on $NAGIOS_HOSTNAME $R_SUBJECT"
  358. R_NUMBER=$NAGIOS_SERVICENOTIFICATIONNUMBER
  359. R_DESCRIPTION=$NAGIOS_SERVICEDESC
  360. R_STATE=$NAGIOS_SERVICESTATE
  361. R_OUTPUT=$NAGIOS_SERVICEOUTPUT
  362. R_ATTEMPT=$NAGIOS_SERVICEATTEMPT
  363. R_LINKBOX_ADD="<a href='$URLCGIBIN/extinfo.cgi?type=1&amp;host=$NAGIOS_HOSTNAME'>View Information For This Host</a><br>"
  364. R_LINKBOXLINK_ADD="&amp;service=$NAGIOS_SERVICEDESC"
  365. R_TITLE_ADD="<div class='data'>On Host</div><div class='dataTitle'>$NAGIOS_HOSTALIAS</div>"
  366. R_NOTES=$NAGIOS_SERVICENOTES
  367. R_PERFDATA=$NAGIOS_SERVICEPERFDATA
  368. R_DURATION=$NAGIOS_SERVICEDURATION
  369. R_LATENCY=$NAGIOS_SERVICELATENCY
  370. R_EXECUTION=$NAGIOS_SERVICEEXECUTIONTIME
  371. R_PERCENT=$NAGIOS_SERVICEPERCENTCHANGE
  372. R_LASTCHECK=`date --date="1970-01-01 UTC $NAGIOS_LASTSERVICECHECK seconds" "$DATEFORMAT"`
  373. R_LASTSTATECHANGE=`date --date="1970-01-01 UTC $NAGIOS_LASTSERVICESTATECHANGE seconds" "$DATEFORMAT"`
  374. R_COMMANDTAIL="&amp;host=$NAGIOS_HOSTNAME&amp;service=$NAGIOS_SERVICEDESC"
  375. R_COMMANDADD2="6"
  376. R_COMMANDADD3="7"
  377. R_COMMANDADD4="23"
  378. R_COMMANDADD5="9"
  379. R_COMMANDADD6="56"
  380. R_COMMANDADD8="60"
  381. R_COMMANDADD9="3"
  382. MIMEGRAPHIC1=""
  383. MIMEGRAPHIC2=""
  384. };
  385.  
  386. # Catch for bad argument
  387. else {
  388. echo "ERROR: Invalid argument. Must be 'host' or 'service'"
  389. exit -1
  390. };
  391. fi
  392.  
  393. # Included for browser compatability problems with CSS text-transform: capitalize
  394. NAGIOS_NOTIFICATIONTYPE=`echo $NAGIOS_NOTIFICATIONTYPE | python -c "print raw_input().capitalize()"`
  395. set -- `echo $1 | python -c "print raw_input().capitalize()"`
  396.  
  397. # Message generation
  398. # NOTE: All of the "R_" variables change when either 'host' or 'service' is selected
  399. MSG=`echo "From: $REPLYADDRESS
  400. Reply-To: $REPLYADDRESS
  401. To: $NAGIOS_CONTACTALIAS <$NAGIOS_CONTACTEMAIL>
  402. Subject: $R_SUBJECT
  403. MIME-Version: 1.0
  404. Content-Type: multipart/alternative; boundary=$MIMEBOUNDARY1
  405.  
  406. --$MIMEBOUNDARY1
  407. Content-Type: text/plain; charset=us-ascii
  408.  
  409. $R_DESCRIPTION ($NAGIOS_HOSTNAME @ $NAGIOS_HOSTADDRESS) is $R_STATE,
  410. Nagios reports: $R_OUTPUT,
  411. This $1 has been $R_STATE for $R_ATTEMPT consecutive attempts,
  412. $R_TIMES
  413.  
  414. --$MIMEBOUNDARY1
  415. Content-Type: multipart/related; boundary=$MIMEBOUNDARY2; type=text/html
  416.  
  417. --$MIMEBOUNDARY2
  418. Content-Type: text/html; charset=us-ascii
  419. Content-Description: HTML message
  420. Content-ID: <html$CONTENTIDBASE>
  421.  
  422. <!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\"
  423. \"http://www.w3.org/TR/html4/strict.dtd\">
  424. <html>
  425. <head>
  426. <title>Nagios Notification</title>
  427. <meta http-equiv='Content-Type' content='text/html; charset=us-ascii'>
  428. <style type='text/css'>
  429.  
  430. /* Modified styles from Nagios extinfo.css style sheet */
  431. BODY { font-family: arial,sans-serif; background-color: white; color: black; font-size: 10pt; }
  432. .linkBox { font-size: 8pt; background-color: #DBDBDB; padding: 1px; }
  433. DIV.dataTitle { text-align: center; font-weight: bold; font-size: 12pt; }
  434. DIV.data { text-align: center; font-size: 12pt; }
  435. TABLE.data { font-size: 10pt; background-color: white; padding: 2px; }
  436. TH.data { font-size: 10pt; background-color: white; text-align: left; background-color: #999797; color: #DCE5C1; }
  437. .commandTitle { text-align: center; font-weight: bold; font-size: 12pt; }
  438. TABLE.command { font-size: 10pt; background-color: #DBDBDB; padding: 2px; }
  439. .command { font-size: 10pt; text-align: left; }
  440. .commentTitle { text-align: center; font-weight: bold; font-size: 12pt; }
  441. TABLE.comment { font-size: 10pt; background-color: white; padding: 2px; }
  442. TH.comment { font-size: 10pt; background-color: white; text-align: left; background-color: #999797; color: #DCE5C1; }
  443. .commentOdd { font-size: 9pt; background-color: #DBDBDB; }
  444. .commentEven { font-size: 9pt; background-color: #C4C2C2; }
  445. DIV.comment,A.comment { font-size: 10pt; background-color: white; text-align: center; }
  446. .notflapping { font-size: 10pt; text-align: left; background-color: #33FF00; font-weight: bold; float: left; }
  447. .flapping { font-size: 10pt; text-align: left; background-color: #F83838; font-weight: bold; float: left; }
  448. .HostUP { font-size: 10pt; text-align: left; background-color: #33FF00; font-weight: bold; float: left; }
  449. .HostDOWN { font-size: 10pt; text-align: left; background-color: #F83838; font-weight: bold; float: left; }
  450. .HostUNREACHABLE { font-size: 10pt; text-align: left; background-color: #F83838; font-weight: bold; float: left; }
  451. .ServiceOK { font-size: 10pt; text-align: left; background-color: #33FF00; font-weight: bold; float: left; }
  452. .ServiceWARNING { font-size: 10pt; text-align: left; background-color: #FFFF00; font-weight: bold; float: left; }
  453. .ServiceUNKNOWN { font-size: 10pt; text-align: left; background-color: #FF9900; font-weight: bold; float: left; }
  454. .ServiceCRITICAL { font-size: 10pt; text-align: left; background-color: #F83838; font-weight: bold; float: left; }
  455. .commandPanel { background-color: white; text-align: center; vertical-align: top; }
  456. .commentPanel { background-color: white; text-align: center; vertical-align: top; }
  457. .stateInfoPanel { background-color: white; vertical-align: top; }
  458. .stateInfoTable1 { font-size: 10pt; background-color: #DBDBDB; text-align: left; }
  459. .dataVar { font-size: 10pt; }
  460. .dataVal { font-size: 10pt; }
  461. /* End Copy */
  462.  
  463. /* a { text-decoration: none; }
  464. a:hover { text-decoration: underline; } */
  465. h1 { font-family: Garamond,'Times New Roman',serif; text-align: center; vertical-align: bottom; text-transform: capitalize; }
  466. span.caps { text-transform: capitalize; }
  467. .notif { background-color: #$BKCLR; }
  468. .address { font-size: 10.0pt; font-style: italic; }
  469. table.center { margin-left: auto; margin-right: auto; }
  470. .fullwidth { width: 100%; }
  471. .border { border-style: ridge; border-width: 2px; }
  472. .border-thick { border-style: ridge; border-width: 3px; }
  473. .noborder { border-style: none; }
  474. .nopad { border-spacing: 0px; padding: 0px; }
  475. td.onethirdl { text-align: left; vertical-align: top; width: 33%; }
  476. td.onethirdc { text-align: center; vertical-align: middle; width: 33%; }
  477. td.onethirdr { text-align: right; vertical-align: bottom; width: 33%; }
  478. td.rightpanel { text-align: center; vertical-align: top; }
  479. td.vcenter { vertical-align: middle; }
  480. img.icon { border-style: none; border-width: 0px; height: 20px; width: 20px; }
  481.  
  482. </style>
  483. </head>
  484. <body>
  485. <table class='center noborder' align='center'>
  486. <tr>
  487. <td class='notif'>
  488. &nbsp;
  489. </td>
  490. </tr>
  491. <tr>
  492. <td>
  493. <h1><a href='$URLPATH'>Nagios</a> $NAGIOS_NOTIFICATIONTYPE Notification</h1>
  494. </td>
  495. </tr>
  496. <tr>
  497. <td class='notif'>
  498. &nbsp;
  499. </td>
  500. </tr>
  501. </table>
  502. <!--$NAGIOS_LONGDATETIME-->
  503. <table class='fullwidth noborder' align='center'>
  504. <tr>
  505. <td class='onethirdl'>
  506. <table cellspacing='0' class='linkBox nopad border' border='2'>
  507. <tr>
  508. <td class='linkBox'>
  509. $R_LINKBOX_ADD
  510. <a href='$URLCGIBIN/status.cgi?host=$NAGIOS_HOSTNAME$R_LINKBOXLINK_ADD'>View Status Detail For This Host</a><br>
  511. <a href='$URLCGIBIN/history.cgi?host=$NAGIOS_HOSTNAME$R_LINKBOXLINK_ADD'>View Alert History For This <span class='caps'>$1</span></a><br>
  512. <a href='$URLCGIBIN/trends.cgi?host=$NAGIOS_HOSTNAME$R_LINKBOXLINK_ADD'>View Trends For This <span class='caps'>$1</span></a><br>
  513. <a href='$URLCGIBIN/histogram.cgi?host=$NAGIOS_HOSTNAME$R_LINKBOXLINK_ADD'>View Alert Histogram For This <span class='caps'>$1</span></a><br>
  514. <a href='$URLCGIBIN/avail.cgi?host=$NAGIOS_HOSTNAME$R_LINKBOXLINK_ADD&amp;show_log_entries'>View Availability Report For This <span class='caps'>$1</span></a><br>
  515. <a href='$URLCGIBIN/notifications.cgi?host=$NAGIOS_HOSTNAME$R_LINKBOXLINK_ADD'>View Notifications This <span class='caps'>$1</span></a>
  516. </td>
  517. </tr>
  518. </table>
  519. <td class='onethirdc'>
  520. <div class='data'>
  521. <span class='caps'>$1</span>
  522. </div>
  523. <div class='dataTitle'>
  524. $R_DESCRIPTION
  525. </div>
  526. $R_TITLE_ADD
  527. <div class='dataTitle'>
  528. (<a href='$URLCGIBIN/status.cgi?host=$NAGIOS_HOSTNAME'>$NAGIOS_HOSTNAME</a>)
  529. </div><br>
  530. <div class='data'>
  531. <a href='$NAGIOS_HOSTACTIONURL'>$NAGIOS_HOSTADDRESS</a>
  532. </div>
  533. <p>$R_NOTES</p>
  534. </td>
  535. <td class='onethirdr'>
  536. </td>
  537. </tr>
  538. </table>
  539. <table class='center fullwidth nopad noborder' align='center' width='100%'>
  540. <tr>
  541. <td class='stateInfoPanel'>
  542. <div class='dataTitle'>
  543. <span class='caps'>$1</span> State Information
  544. </div>
  545. <table class='center noborder' align='center'>
  546. <tr>
  547. <td>
  548. <table cellspacing='0' class='center nopad border' border='2' align='center'>
  549. <tr>
  550. <td class='stateInfoTable1'>
  551. <table class='noborder' align='center'>
  552. <tr>
  553. <td class='dataVar'>Current Status:</td>
  554. <td class='dataVal'>
  555. <span class='$1$R_STATE'>
  556. &nbsp;&nbsp;$R_STATE&nbsp;&nbsp;$STATUSACK
  557. </span>
  558. &nbsp;(for $R_DURATION)
  559. </td>
  560. </tr>
  561. <tr>
  562. <td class='dataVar'>Status Information:</td>
  563. <td class='dataVal'>$R_OUTPUT</td>
  564. </tr>
  565. <!--<tr>
  566. <td class='dataVar'>Performance Data:</td>
  567. <td class='dataVal'>$R_PERFDATA</td>
  568. </tr>-->
  569. <tr>
  570. <td class='dataVar'>Check attempts:</td>
  571. <td class='dataVal'>$R_ATTEMPT</td>
  572. </tr>
  573. <tr>
  574. <td class='dataVar'>Last Check Time:</td>
  575. <td class='dataVal' nowrap='nowrap'>$R_LASTCHECK</td>
  576. </tr>
  577. <tr>
  578. <td class='dataVar' nowrap='nowrap'>Check Latency / Duration:</td>
  579. <td class='dataVal' nowrap='nowrap'>$R_LATENCY&nbsp;/&nbsp;$R_EXECUTION seconds</td>
  580. </tr>
  581. <tr>
  582. <td class='dataVar'>Last State Change:</td>
  583. <td class='dataVal' nowrap='nowrap'>$R_LASTSTATECHANGE</td>
  584. </tr>
  585. <tr>
  586. <td class='dataVar'>Current Notification Number:</td>
  587. <td class='dataVal'>$R_NUMBER</td>
  588. </tr>
  589. <tr>
  590. <td class='dataVar'>Is This <span class='caps'>$1</span> Flapping?</td>
  591. <td class='dataVal'>
  592. <span class='$FLAPPINGCLASS'>
  593. &nbsp;&nbsp;$FLAPPING&nbsp;&nbsp;
  594. </span>
  595. &nbsp;($R_PERCENT% state change)
  596. </td>
  597. </tr>
  598. </table>
  599. </td>
  600. </tr>
  601. </table>
  602. </td>
  603. </tr>
  604. </table>
  605. </td>
  606. <td class='rightpanel'>
  607. <table cellspacing='0' class='nopad noborder' align='center'>
  608. <tr>
  609. <td class='commandPanel'>
  610. <div class='commandTitle'>
  611. <span class='caps'>$1</span> Commands
  612. </div>
  613. <table cellspacing='0' class='command nopad border' border='2' align='center'>
  614. <tr>
  615. <td>
  616. <table cellspacing='0' class='command nopad noborder' align='center'>
  617. $R_COMMANDADD1
  618. <tr class='command'>
  619. <td><img src='cid:disabled.gif$CONTENTIDBASE' class='icon' alt='disabled'></td>
  620. <td class='command'><a href='$URLCGIBIN/cmd.cgi?cmd_typ=$R_COMMANDADD2$R_COMMANDTAIL'>Disable active checks of this $1</a></td>
  621. </tr>
  622. <tr class='data'>
  623. <td><img src='cid:delay.gif$CONTENTIDBASE' class='icon' alt='delay'></td>
  624. <td class='command'><a href='$URLCGIBIN/cmd.cgi?cmd_typ=$R_COMMANDADD3$R_COMMANDTAIL'>Re-schedule the next check of this $1</a></td>
  625. </tr>
  626. $R_ACKCOMMAND
  627. <tr class='command'>
  628. <td><img src='cid:disabled.gif$CONTENTIDBASE' class='icon' alt='disabled'></td>
  629. <td class='command'><a href='$URLCGIBIN/cmd.cgi?cmd_typ=$R_COMMANDADD4$R_COMMANDTAIL'>Disable notifications for this $1</a></td>
  630. </tr>
  631. <tr class='command'>
  632. <td><img src='cid:delay.gif$CONTENTIDBASE' class='icon' alt='delay'></td>
  633. <td class='command'><a href='$URLCGIBIN/cmd.cgi?cmd_typ=$R_COMMANDADD5$R_COMMANDTAIL'>Delay next $1 notification</a></td>
  634. </tr>
  635. <tr class='command'>
  636. <td><img src='cid:downtime.gif$CONTENTIDBASE' class='icon' alt='downtime'></td>
  637. <td class='command'><a href='$URLCGIBIN/cmd.cgi?cmd_typ=$R_COMMANDADD6$R_COMMANDTAIL'>Schedule downtime for this $1</a></td>
  638. </tr>
  639. $R_COMMANDADD7
  640. <tr class='command'>
  641. <td><img src='cid:disabled.gif$CONTENTIDBASE' class='icon' alt='disabled'></td>
  642. <td class='command'><a href='$URLCGIBIN/cmd.cgi?cmd_typ=$R_COMMANDADD8$R_COMMANDTAIL'>Disable flap detection for this $1</a></td>
  643. </tr>
  644. </table>
  645. </td>
  646. </tr>
  647. </table>
  648. </td>
  649. </tr>
  650. </table>
  651. </td>
  652. </tr>
  653. </table>
  654. <table class='center' align='center'>
  655. <tr>
  656. <td colspan='2' class='commentPanel'>
  657. <div class='commentTitle'>
  658. <span class='caps'>$1</span> Comments
  659. </div>
  660. <table>
  661. <tr>
  662. <td class='vcenter'><img src='cid:comment.gif$CONTENTIDBASE' class='icon' alt='comment'></td>
  663. <td class='comment'><a href='$URLCGIBIN/cmd.cgi?cmd_typ=$R_COMMANDADD9$R_COMMANDTAIL' class='comment'>Add a new comment</a></td>
  664. </tr>
  665. </table>
  666. <table class='comment border-thick' border='3'>
  667. <tr class='comment'>
  668. <th class='comment'>Author</th>
  669. <th class='comment'>Comment</th>
  670. </tr>
  671. $R_ACKADD
  672. </table>
  673. </td>
  674. </tr>
  675. </table>
  676. <p class='address'>All information is the property of <a href='mailto:$REPLYADDRESS'>$REPLYNAME</a><br>
  677. and should be treated as confidential</p>
  678. </body>
  679. </html>
  680.  
  681. --$MIMEBOUNDARY2
  682. Content-Type: image/gif
  683. Content-Transfer-Encoding: base64
  684. Content-Description: Inline graphic
  685. Content-ID: <disabled.gif$CONTENTIDBASE>
  686. Content-Location: $URLPATH/images/disabled.gif
  687. Content-Disposition: inline
  688.  
  689. $UUIMGDISABLED
  690.  
  691. --$MIMEBOUNDARY2
  692. Content-Type: image/gif
  693. Content-Transfer-Encoding: base64
  694. Content-Description: Inline graphic
  695. Content-ID: <delay.gif$CONTENTIDBASE>
  696. Content-Location: $URLPATH/images/delay.gif
  697. Content-Disposition: inline
  698.  
  699. $UUIMGDELAY
  700.  
  701. --$MIMEBOUNDARY2
  702. Content-Type: image/gif
  703. Content-Transfer-Encoding: base64
  704. Content-Description: Inline graphic
  705. Content-ID: <downtime.gif$CONTENTIDBASE>
  706. Content-Location: $URLPATH/images/downtime.gif
  707. Content-Disposition: inline
  708.  
  709. $UUIMGDOWNTIME
  710.  
  711. --$MIMEBOUNDARY2
  712. Content-Type: image/gif
  713. Content-Transfer-Encoding: base64
  714. Content-Description: Inline graphic
  715. Content-ID: <comment.gif$CONTENTIDBASE>
  716. Content-Location: $URLPATH/images/comment.gif
  717. Content-Disposition: inline
  718.  
  719. $UUIMGCOMMENT
  720.  
  721. $MIMEGRAPHIC1
  722. $MIMEGRAPHIC2
  723. $MIMEGRAPHICACK
  724. --$MIMEBOUNDARY2--
  725.  
  726. --$MIMEBOUNDARY1--"`
  727.  
  728. [ "$MSG" ] || {
  729. echo "Error generating e-mail message."
  730. exit -1
  731. }
  732.  
  733. # Send the damn e-mail already!
  734. $PRINTF "%b" "$MSG" | $MAILER $MAILOPTS
  735.  
  736. exit
  737.