Installing Mail Server on Nagios
Postfix Server Installation
First you need to install postfix;
1 |
apt-get install postfix |
When prompted, choose internet site, then enter the @ part where you wish the mail to be sent from, e.g nagios.notify. This will mean that emails received from nagios will be @nagios.notify.
Mailx Server Installation
Now install Nagios’s part of the mail server;
1 |
apt-get install heirloom-mailx |
Configuring Nagios Mail Command
You need to edit the commands.cfg folder to take into account the new paths;
1 |
vi /usr/local/nagios/etc/objects/commands.cfg |
Replace;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# 'notify-host-by-email' command definition define command{ command_name notify-host-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" | /bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$ } # 'notify-service-by-email' command definition define command{ command_name notify-service-by-email command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$ } |
With;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# 'notify-host-by-email' command definition define command{ command_name notify-host-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" | /usr/bin/mailx -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$ } # 'notify-service-by-email' command definition define command{ command_name notify-service-by-email command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n" | /usr/bin/mailx -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$ } |
Note that the change is ‘/bin/mail’ to ‘/usr/bin/mailx’.
Now restart Nagios;
1 |
service nagios restart |
You should now receive email notifications of services/host states.
Enabling and Disabling Notifications for a Service
To disable notifications follows the steps below.
- Access the web interface;
1 |
http://<nagiosip>/nagios |
- Choose Hosts or Services from the side menu (depending on which you wish to change).
- Select a service or host you wish to disable notifications for (note that HTTP and SSH notifications are disabled by default on localhost).
- On the page which opens, from the right hand section select the option ‘Disable Notifications’.
- This should open a page asking to confirm the host or host and service you wish to disable notifications for. Select ‘Commit’ to continue;
- From this page it will now show a page verifying that it has been complete. Make sure to select the option ‘Done';
This will return you to the homepage. Navigate back to the host/service (from 4.) and you will see at the bottom it shows Notifications in red and as ‘DISABLED’. Also the right hand menu has changed to give the option to ‘Enable’ notifications as they are currently disabled.
Tags: monitoring, nagios, sysadmin