Search Exchange
Search All Sites
Nagios Live Webinars
Let our experts show you how Nagios can help your organization.Login
Directory Tree
Send HTML Alert Email v2
- Nagios 3.x
- Nagios XI
File | Description |
---|---|
nagios_service_mail | This php file sends HTML Service Related Alerts |
nagios_host_mail | This php file sends HTML Host Related Alerts |
a_11.png | The Thumbnail Image in the Alert eMail |
Meet The New Nagios Core Services Platform
Built on over 25 years of monitoring experience, the Nagios Core Services Platform provides insightful monitoring dashboards, time-saving monitoring wizards, and unmatched ease of use. Use it for free indefinitely.
Monitoring Made Magically Better
- Nagios Core on Overdrive
- Powerful Monitoring Dashboards
- Time-Saving Configuration Wizards
- Open Source Powered Monitoring On Steroids
- And So Much More!
Contains Useful Features Like ---
1) Duration of the Problem Alert
2) Total Downtime of the Service upon Recovery
3) 4 Colored Coordinated Alerts
4) A thumbnail image in the Alert eMail to spice things up.
Requires less than 5 minutes to fully setup...
Now edit the nagios/etc/objects/command.cfg and replace the [notify-service-by-email] block with the following Block...
define command{
command_name notify-service-by-email
command_line /usr/local/nagios/libexec/nagios_service_mail "$NOTIFICATIONTYPE$" "$HOSTNAME$" "$HOSTALIAS$" "$HOSTSTATE$" "$HOSTADDRESS$" "$SERVICEOUTPUT$" "$SHORTDATETIME$" "$SERVICEDESC$" "$SERVICESTATE$" "$CONTACTEMAIL$" "$SERVICEDURATIONSEC$" "$SERVICEEXECUTIONTIME$" "$TOTALSERVICESWARNING$" "$TOTALSERVICESCRITICAL$" "$TOTALSERVICESUNKNOWN$" "$LASTSERVICEOK$" "$LASTSERVICEWARNING$" "$SERVICENOTIFICATIONNUMBER$"
}
Also replace the [notify-host-by-email] code block with this block below...
define command{
command_name notify-host-by-email
command_line /usr/local/nagios/libexec/nagios_host_mail "$NOTIFICATIONTYPE$" "$HOSTNAME$" "$HOSTALIAS$" "$HOSTSTATE$" "$HOSTADDRESS$" "$HOSTOUTPUT$" "$SHORTDATETIME$" "$SERVICEDESC$" "$SERVICESTATE$" "$CONTACTEMAIL$" "$TOTALHOSTSUP$" "$TOTALHOSTSDOWN$"
}
(Check if the nagios/libexec folder paths are accurate before restarting)...
Save the command.cfg file and restart the Nagios Service... The emails are sent using the PHP mail() function... A set oftemporary files are written to the root level /tmp folder in order to determine the Total Downtime upon Service Recovery... Many MACROS are used in order to boost the Usable Data, hence I am not sure if it will work on Older Nagios v2.0...
[Optional Bonus]: If you have SimpleCMS installed, you can create a custom link which Network Staff can click and get the details of every single Service Type and Description... In order to do this, you will need to install the simplecms and create headings with Identical Names as the Service Name in Nagios.. The dummy domain kdog.cmsnagios.com was used as the Nagios WebSite.. The SimpleCMS was used to compliment the New Network Staff...
For example: In Nagios/ Server Win32 DOG7 has a service name cpu_load (which describes the CPU), create a CMS heading cpu_load and write a detailed description about it..
You may email me for further descriptions on CMS Manipulations...
Let me know if you have any queries regarding the 2 Email plugins... Would love to hear from you...
$d = floor ($f_duration / 1440);
$h = floor (($f_duration - $d * 1440) / 60);
$m = round($f_duration - ($d * 1440) - ($h * 60));
and changed this line
#$body .= "State Duration:$f_duration mins.
";
to something like this
$body .= "State Duration:$d days $h hours $m minutes
";
anyway good job!
Then I saw this.
Less than 2 minutes to setup everything and worked at first try!
Great job ;)
Only things I want to note:
1. I use Nagios to read the log of lots of scripts of mine, I use performance data here because I can have more details BUT for these group of services I do not process them (process_perfdata 0).
I find it useful to have them in the email, so I added:
"$SERVICEPERFDATA$"
at the end of notify-service-by-email.
Modified the php:
$extra_info= array_shift($argv); /*19*/
and added this row just below "Additional info":
$body .= "Extra Info:$extra_info\r\n";
2. I changed shebang to #!/usr/bin/env php not really a reason here, if not that I do not have /etc/php.ini but
/etc/php5/apache2/php.ini
/etc/php5/cli/php.ini
What's important is that it works very very well!
Wow! Really appreciate it! Thanks for the extra information.. This was really helpful in sprucing things up.
Could you tell me how i use this to send trough sendmail?
Thanks for trying this out. Very much appreciated. As of now, its only written for php mailer. I'm pretty sure it could be done in sendmail as I have seen it been done. We just need to send the email content-type as html.
Thanks for trying this out.. Very much appreciated! If you have any suggestions and recommendations, please let me know.
Hi walkeong...
Its currently using the PHP mail() function which in-turn invokes the sendmail Linux command. You may need to configure the sendmail SMTP properties in order to send mails directly from PHP.. I will need to do a bit of reading on the sendmail application...
Just realized a teeny mistake in my CMS related section.. Note: Its not SimpleCMS, but rather CMSimple(http://www.cmsimple.org/). CMSimple is free and ONLY required PHP to work (no MySQL).. In CMSimple, the URL contains the name of the Article Header - which means, you can set up Article Heading with the identical name as the Service Name in Nagios(No space allowed).. A special MACRO($SERVICESTATE$) in Nagios assigns the description of the Service..
All you need to do is change the URL of the CMS so it reflects the actual CMS URL on your system (possibly apache :-).