//
you're reading...
Android Apps

Send HTML Alert Mails

This article describes the plugin that send Nagios HTML Alert Emails with Performance Graphs.

This is the Version 3 of the popular ‘Send HTML Alert Email’. Nagios Alert eMails now contain formatted Text & Performance Graphs which is much smaller saving you bandwidth. Tested with Nagios v3 & 4. This may not work with Nagios v1 (As it requires the use of MACROS)…

Contains Useful Features:

  • Performance Graphs
  • Total Downtime of the Service upon Recovery
  • 4 Colour Coordinated Alerts
  • Group & Email Information.
  • Low bandwidth usage when downloading hundreds/thousands of Alerts Emails.
  • Takes less than 10 minutes to setup.

screenshot1

Requires less than 10 minutes to fully setup.

  1. Download the three .php files from the github repository, to the nagios/libexec/ folder and give them execution permission..
    $>  chmod 665 /usr/local/nagios/libexec/
  2. Open the three php files and check if the 1st line path/to/php and .ini files are correct
  3. In the three .php files, change the $from email variable to a real name(Else your Email Server might Reject it / or SPAM it).
  4. In the three .php files, change the $f_domain to your nagios webserver domain name.
  5. In the “graph_auth.php“, change the $login and $password to your nagios username & password.
  6. Create a new folder “/usr/local/nagios/cms” and move the “graph_auth.php” and “a_11.png” file to the “/usr/local/nagios/cms/

[Note: Do not put the graph_auth.php or a_11.png in the /usr/local/nagios/share/ as this folder requires the username/passwd when viewing]

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.php "$NOTIFICATIONTYPE$" "$HOSTNAME$" "$HOSTALIAS$" "$HOSTSTATE$" "$HOSTADDRESS$" "$SERVICEOUTPUT$" "$SHORTDATETIME$" "$SERVICEDESC$" "$SERVICESTATE$" "$CONTACTEMAIL$" "$SERVICEDURATIONSEC$" "$SERVICEEXECUTIONTIME$" "$TOTALSERVICESWARNING$" "$TOTALSERVICESCRITICAL$" "$TOTALSERVICESUNKNOWN$" "$NOTIFICATIONRECIPIENTS$" "$TOTALSERVICESOK$" "$SERVICENOTIFICATIONNUMBER$" "$SERVICEACKCOMMENT$" "$HOSTGROUPNAME$" "$SERVICEPERFDATA$"
}

Also replace the [notify-host-by-email] code block with the following block.

define command{
  command_name notify-host-by-email
  command_line /usr/local/nagios/libexec/nagios_host_mail.php "$NOTIFICATIONTYPE$" "$HOSTNAME$" "$HOSTALIAS$" "$HOSTSTATE$" "$HOSTADDRESS$" "$HOSTOUTPUT$" "$SHORTDATETIME$" "$SERVICEDESC$" "$SERVICESTATE$" "$CONTACTEMAIL$" "$TOTALHOSTSUP$" "$TOTALHOSTSDOWN$" "$HOSTGROUPNAME$" "$SERVICEPERFDATA$"
}

Check your nagios/libexec folder paths are accurate and save the “command.cfg” file.
In order to get the graph to render, we need to configure the Apache “httpd.conf” file. Go ahead and open the “/etc/httpd/conf/httpd.conf” and add an extra VirtualHost as follows.. (The ServerName & ServerAlias should be your nagios domain name)

<VirtualHost *:80>
  ServerAdmin operations@mycompany.com 
  ServerName nagios.mycompany.com 
  ServerAlias nagios.mycompany.com 
  DocumentRoot "/usr/local/nagios/cms" 
  ErrorLog logs/nagios-error_log 
</VirtualHost>

The emails are sent using the PHP mail() function. A set of temporary 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.
————————————————————————–

screenshot2

[Optional Bonus]:

If you have CMSimple “Content Management” 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 CMSimple and create headings with Identical Names as the Service Name in Nagios. The dummy domain nagios.cmsnagios.com was used as the Nagios WebSite. The CMSimple 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 Email plugins.. Would love to hear from you..

https://github.com/shawnbrito/nagios/

About Shawn Brito

I'm guy searching for amazing new things to do, adventures to go on. Travelling across Sri Lanka and Video Blogging.

Discussion

10 thoughts on “Send HTML Alert Mails

  1. not showing the graph in alert email

    Posted by Satish Singh | December 7, 2017, 5:31 pm
  2. Graph_auth.php seems not working properly, getting blank page with no error, did I missing something here ?

    Posted by Dan | November 17, 2020, 5:09 am
  3. No error log indicated the this issue, suspected it could be your php call may not working with newer php7 or above, but I could be wrong…

    Posted by Dan | November 17, 2020, 6:49 pm

Leave a comment