1 Introduction
If you already used standart email notification, you'll find it cool but not really sexy. That's why a project has been initiated and called "Flexible Notifications for Nagios".
I will explain here how to use it easily. The goal is to have this kind of HTML email instead of plain text :
You also can do others stuff like adding image, carbon copy, different languages... but I'll explain here only what I need.
2 Installation
Very simple, create a scripts folder and put the 2 required scripts in it :
Also we'll need to install perl dependancies :
aptitude
|
aptitude install libmail-sendmail-perl librrds-perl
|
3 Configuration
3.1 commands.cfg
Here is the file containing default email commands. You just have to comment the one commented here and add the new lines :
/etc/nagios3/commands.cfg
|
###############################################################################
# COMMANDS.CFG - SAMPLE COMMAND DEFINITIONS FOR NAGIOS
################################################################################
################################################################################
# NOTIFICATION COMMANDS
################################################################################
# 'notify-service-by-email' command definition
define command{
command_name notify-host-by-email
command_line /bin/sleep 1
}
# 'notify-host-by-email' command definition
#define command{
# command_name notify-host-by-email
# command_line /usr/bin/printf "%b" "***** INTERNAL Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /usr/bin/mail -s "** Internal $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
# }
# sends HTML e-mails for hosts
define command{
command_name host-notify-by-email
command_line /etc/nagios3/scripts/nagios_send_service_mail.pl -c "$CONTACTADDRESS1$" -f html -u -p "Deimos.fr Monitoring Tool"
}
# 'notify-host-by-email' command definition
#define command{
# command_name host-notify-by-email
# command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n$HOSTACKAUTHOR$: $NOTIFICATIONCOMMENT$\n\n$HOSTNOTES$\n" | /usr/bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
# }
# sends HTML e-mails for services
define command{
command_name notify-service-by-email
command_line /etc/nagios3/scripts/nagios_send_service_mail.pl -c "$CONTACTADDRESS1$" -f html -u -p "Deimos.fr Monitoring Tool"
}
# 'notify-service-by-email' command definition
#define command{
# command_name notify-service-by-email
# command_line /usr/bin/printf "%b" "***** INTERNAL Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$" | /usr/bin/mail -s "** $Internal NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
# }
|
3.2 nagios_send_host_mail.pl and nagios_send_service_mail.pl
We now need to modify little things like URL, names etc... so let's open files and set custom fields :
|
...
my $mail_sender = "Nagios Monitoring <deimos\@deimos.fr>";
my $nagios_cgiurl = "http://nagios/nagios3/cgi-bin";
my $o_smtphost = "127.0.0.1";
...
|
Those fiels are corresponding to :
- $mail_sender : Email sender name
- $nagios_cgiurl : The CGI URL to nagios server. It's needed for links in the mail
- $o_smtphost : The SMTP server
That's all. Reload your Nagios now