SlideShare a Scribd company logo
Configuring e-Mail Notifications in Nagios
Core…
by Andy Grogan on February 24, 2012 · 9 comments

in Exchange 2010 (General), Linux, Linux with Exchange, Monitoring, Nagios, Ubuntu

Linked to my multi part series on using Nagios Core with Exchange server, I would like to explain how
you can configure mail notifications to recipients when status changes occur within the Nagios
monitoring environment.

If you are just joining us here, I recommend that you have a look at the series in its entirety before
reading any further, as there are a few concepts used in this article which were covered in-depth within
previous four parts. You can view them here:

       In Part 1
       I covered how you can install Nagios Core 3.3.1 onto an existing Ubuntu 11.10 server within
       your environment
       In Part 2
       I covered how you can setup basic monitoring on your first Windows Server – making use of the
       NSClient++, I also covered how you could setup a basic “check_nt” monitoring service
       In Part 3
       I covered how you can install the NRPE daemon onto your Nagios Server – and then use the
       NSClient to execute a basic Powershell script and report the output back into the Nagios
       interface
       In Part 4
       I covered how you can build some custom PowerShell scripts to monitor you Exchange
       environment

Making Sure that you DNS Configuration is correct
Before you begin to setup the tools which will enable mail notifications to be sent from Nagios, you
should ensure that you destination mail domain can be resolved from your Ubuntu server. I have
assumed that you will be sending notifications to a mailbox within your Exchange infrastructure which
naturally is separate to the Nagios implementation.

In my example, my destination domain is “prepad.com” – therefore in order to check if the Nagios
server can lookup the MX record for that domain you can use the “dig” command like so:

dig prepad.com mx

If everything is ok, you should receive an output to the command similar to that below:
Installing POSTFIX
Postfix is a free MTA for Linux which is designed to be easier to setup and configure than the more
traditional SendMail offering. Combined with Heirloom-MailX (see next section) Nagios can be
configured to use the two products to send e-mail notifications to a designated set of contacts in the
event of an alert being generated.

From the perspective of using Postfix to send e-mail from Nagios – the setup is very simple (e.g. I am
not going to go into huge amounts of detail on how you can configure Postfix).

In order to install Postfix open an SSH session to your Nagios Ubuntu Server using PuTTY and type in
the following command:

sudo apt-get install postfix




You will then be presented with a two step setup Wizard – the first page will ask you what type of
POSTFIX SMTP Server you would like to use – ensure that you have selected the “Internet Site”
option, when done navigate (using TAB) to the “OK” button – see below
You will then be asked to supply a Domain Name which the source e-mails will be sent from – in my
example I have used “nagios.notify” – when you are done tab to the “OK” button – see below




This will then complete the configuration of Postfix.

Installing Heirloom-MailX
Heirloom-MailX is a small binary program that is used by Nagios to send mail to the Postfix mail server
– it is very easy to install.
From the SSH console, type in the following command:

sudo apt-get install heirloom-mailx




Configuring Exchange to accept messages from your Nagios
Server
There are better ways to do this, however if you want to ensure that your Exchange Hub transport
servers are accepting mail from your Nagios server, you should ensure that the Default Receive
Connector on your HT is configured to accept anonymous connections – you can do this by opening up
the Exchange Management Console and navigating to [ Microsoft Exchange On-Premises –> Server
Configuration –> Hub Transport ], then select your HT and then from the low pane (Receive
Connectors) right click on the “Default <Your HT>” – from the context menu that appears choose
“Properties” – see below




From the properties box that appears, click on the “Permission Groups” tab, and then tick the
“Anonymous Users” tick box, and then click on the “OK” button – see below
In the real world, you should probably consider creating a dedicated Receive Connector for the Nagios
instance.

Configuring Nagios to Send Mail Notifications
Now that you have installed the required components to enabled Nagios to send mail notifications, you
will need to download two configurations files from your Nagios Server (using FileZilla and edit them
using Notepad++ – if you need to understand how to do this, please review part 2 of my installing
Nagios for Exchange series).

These files are:

   1. commands.cfg
   2. contacts.cfg

Which are located in:

/usr/local/nagios/etc/objects

Open the commands.cfg file in Notepad++ and modify the following two lines:

# 'notify-host-by-email' command definition
define command{
command_name    notify-host-by-email
command_line    /usr/bin/printf "%b" "***** Nagios *****nnNotification Type:
$NOTIFICATIONTYPE$nHost: $HOSTNAME$nState: $HOSTSTATE$nAddress:
$HOSTADDRESS$nInfo: $HOSTOUTPUT$nnDate/Time: $LONGDATETIME$n" | /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 *****nnNotification Type:
$NOTIFICATIONTYPE$nnService: $SERVICEDESC$nHost: $HOSTALIAS$nAddress:
$HOSTADDRESS$nState: $SERVICESTATE$nnDate/Time: $LONGDATETIME$nnAdditional
Info:nn$SERVICEOUTPUT$n" | /bin/mailx -s "** $NOTIFICATIONTYPE$ Service Alert:
$HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
    }

To look like the following:

# 'notify-host-by-email' command definition
define command{
command_name    notify-host-by-email
command_line    /usr/bin/printf "%b" "***** Nagios *****nnNotification Type:
$NOTIFICATIONTYPE$nHost: $HOSTNAME$nState: $HOSTSTATE$nAddress:
$HOSTADDRESS$nInfo: $HOSTOUTPUT$nnDate/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 *****nnNotification Type:
$NOTIFICATIONTYPE$nnService: $SERVICEDESC$nHost: $HOSTALIAS$nAddress:
$HOSTADDRESS$nState: $SERVICESTATE$nnDate/Time: $LONGDATETIME$nnAdditional
Info:nn$SERVICEOUTPUT$n" | /usr/bin/mailx -s "** $NOTIFICATIONTYPE$ Service
Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
    }

In essence you are changing the /bin/mail part of each command to /usr/bin/mailx

When you are done, save the file and then using FileZilla upload it back to your Nagios Server.

Next open the contacts.cfg file and change the “email” property to that of the account where you would
like the notifications to be sent – see below

define contact{
contact_namenagiosadmin        ; Short name of user
use                                generic-contact                      ; Inherit default values
from generic-contact template (defined above)
aliasNagios Admin        ; Full name of user
email                           administrator@prepad.com                   ; <<***** CHANGE THIS
TO YOUR EMAIL ADDRESS ******
        }

When you are done, save the file, and upload it back to your Nagios server.

To finish up the configuration, from a PuTTY session type in the following command:

sudo /etc/init.d/nagios restart

For the configuration changes to take effect.

When there is now a problem with either a service or a host, the chosen recipient should receive a mail
notification like the following:
Configuring e mail notificationin nagios core

More Related Content

ODP
Tutorial: Install Nagios in Fedora
PDF
Step by step_linux_guide
DOCX
Build your own secure mail server on the cloud using Amazon Web Services
PDF
How to configure Nagios in Fedora ?
DOC
gcis-zenworks7.2
PDF
Dns server slide(h.m_merajul_hasan)
PDF
Debugging Network Issues
PDF
NATS + Docker meetup talk Oct - 2016
Tutorial: Install Nagios in Fedora
Step by step_linux_guide
Build your own secure mail server on the cloud using Amazon Web Services
How to configure Nagios in Fedora ?
gcis-zenworks7.2
Dns server slide(h.m_merajul_hasan)
Debugging Network Issues
NATS + Docker meetup talk Oct - 2016

What's hot (20)

PPT
How To Deploy A Cloud Based Webserver in 5 minutes - LAMP
PDF
PPTX
Dns server setup on ubuntu vps (master+slave)
PDF
GopherFest 2017 - Adding Context to NATS
PDF
Linux Day2
PPTX
Ubuntu vps setup
PDF
Mail server
PDF
The Zen of High Performance Messaging with NATS (Strange Loop 2016)
PPTX
Hadoop presentation
DOCX
AWS | Nat instance Configuration
PDF
Mail server
PDF
DSpace Manual for BALID Trainee
DOC
Modul quick debserver
PDF
Email server design(h.m merajul_hasan)
PDF
Deploying an open source private cloud on a shoe string budget presentation
ODP
Ubuntu For Intranet Services
PDF
Intro KaKao MRTE (MySQL Realtime Traffic Emulator)
DOCX
เครื่องแม่ข่าย
PDF
NATS: Simple, Secure and Scalable Messaging For the Cloud Native Era
PPTX
DNN Upgrades Made Simple (DNN Summit 2019)
How To Deploy A Cloud Based Webserver in 5 minutes - LAMP
Dns server setup on ubuntu vps (master+slave)
GopherFest 2017 - Adding Context to NATS
Linux Day2
Ubuntu vps setup
Mail server
The Zen of High Performance Messaging with NATS (Strange Loop 2016)
Hadoop presentation
AWS | Nat instance Configuration
Mail server
DSpace Manual for BALID Trainee
Modul quick debserver
Email server design(h.m merajul_hasan)
Deploying an open source private cloud on a shoe string budget presentation
Ubuntu For Intranet Services
Intro KaKao MRTE (MySQL Realtime Traffic Emulator)
เครื่องแม่ข่าย
NATS: Simple, Secure and Scalable Messaging For the Cloud Native Era
DNN Upgrades Made Simple (DNN Summit 2019)
Ad

Similar to Configuring e mail notificationin nagios core (20)

PDF
Mail server on Ubuntu Server 12.04 (Postfix, Courier, SSL, SpamAssassin, Clam...
PPS
Linux10 sendmail
PPTX
Nagios Conference 2014 - James Clark - Nagios Cool Tips and Tricks
PPTX
Nagios Conference 2014 - Rob Hassing - How To Maintain Over 20 Monitoring App...
PDF
Linux instalação e-conf postfix - pop3 eimap
PDF
Postfix, Imap e Pop3
PDF
Exchange overview and popularization
PDF
OSMC 2009 | mail2eventdb - An agent to process mailbased alerts with NETWAYS ...
PPT
Unix Administration 5
PPT
Linux corporate-training-in-mumbai
PDF
Dedicated Email Servers
PDF
Dedicated Email Servers
PDF
Dedicated Email Servers
PDF
Fighting Spam With A Perimeter Mail System 20071108 Sasag
PPT
Electronic Mail on Solaris 2 Configuration
PDF
NT341 Mail Server Integration
PDF
Mail
PPT
pop3-imap.ppt
PPT
pop3-imap.ppt
PDF
Nagios Conference 2011 - Mike Weber - Training: Monitoring Linux Mail Servers...
Mail server on Ubuntu Server 12.04 (Postfix, Courier, SSL, SpamAssassin, Clam...
Linux10 sendmail
Nagios Conference 2014 - James Clark - Nagios Cool Tips and Tricks
Nagios Conference 2014 - Rob Hassing - How To Maintain Over 20 Monitoring App...
Linux instalação e-conf postfix - pop3 eimap
Postfix, Imap e Pop3
Exchange overview and popularization
OSMC 2009 | mail2eventdb - An agent to process mailbased alerts with NETWAYS ...
Unix Administration 5
Linux corporate-training-in-mumbai
Dedicated Email Servers
Dedicated Email Servers
Dedicated Email Servers
Fighting Spam With A Perimeter Mail System 20071108 Sasag
Electronic Mail on Solaris 2 Configuration
NT341 Mail Server Integration
Mail
pop3-imap.ppt
pop3-imap.ppt
Nagios Conference 2011 - Mike Weber - Training: Monitoring Linux Mail Servers...
Ad

Configuring e mail notificationin nagios core

  • 1. Configuring e-Mail Notifications in Nagios Core… by Andy Grogan on February 24, 2012 · 9 comments in Exchange 2010 (General), Linux, Linux with Exchange, Monitoring, Nagios, Ubuntu Linked to my multi part series on using Nagios Core with Exchange server, I would like to explain how you can configure mail notifications to recipients when status changes occur within the Nagios monitoring environment. If you are just joining us here, I recommend that you have a look at the series in its entirety before reading any further, as there are a few concepts used in this article which were covered in-depth within previous four parts. You can view them here: In Part 1 I covered how you can install Nagios Core 3.3.1 onto an existing Ubuntu 11.10 server within your environment In Part 2 I covered how you can setup basic monitoring on your first Windows Server – making use of the NSClient++, I also covered how you could setup a basic “check_nt” monitoring service In Part 3 I covered how you can install the NRPE daemon onto your Nagios Server – and then use the NSClient to execute a basic Powershell script and report the output back into the Nagios interface In Part 4 I covered how you can build some custom PowerShell scripts to monitor you Exchange environment Making Sure that you DNS Configuration is correct Before you begin to setup the tools which will enable mail notifications to be sent from Nagios, you should ensure that you destination mail domain can be resolved from your Ubuntu server. I have assumed that you will be sending notifications to a mailbox within your Exchange infrastructure which naturally is separate to the Nagios implementation. In my example, my destination domain is “prepad.com” – therefore in order to check if the Nagios server can lookup the MX record for that domain you can use the “dig” command like so: dig prepad.com mx If everything is ok, you should receive an output to the command similar to that below:
  • 2. Installing POSTFIX Postfix is a free MTA for Linux which is designed to be easier to setup and configure than the more traditional SendMail offering. Combined with Heirloom-MailX (see next section) Nagios can be configured to use the two products to send e-mail notifications to a designated set of contacts in the event of an alert being generated. From the perspective of using Postfix to send e-mail from Nagios – the setup is very simple (e.g. I am not going to go into huge amounts of detail on how you can configure Postfix). In order to install Postfix open an SSH session to your Nagios Ubuntu Server using PuTTY and type in the following command: sudo apt-get install postfix You will then be presented with a two step setup Wizard – the first page will ask you what type of POSTFIX SMTP Server you would like to use – ensure that you have selected the “Internet Site” option, when done navigate (using TAB) to the “OK” button – see below
  • 3. You will then be asked to supply a Domain Name which the source e-mails will be sent from – in my example I have used “nagios.notify” – when you are done tab to the “OK” button – see below This will then complete the configuration of Postfix. Installing Heirloom-MailX
  • 4. Heirloom-MailX is a small binary program that is used by Nagios to send mail to the Postfix mail server – it is very easy to install. From the SSH console, type in the following command: sudo apt-get install heirloom-mailx Configuring Exchange to accept messages from your Nagios Server There are better ways to do this, however if you want to ensure that your Exchange Hub transport servers are accepting mail from your Nagios server, you should ensure that the Default Receive Connector on your HT is configured to accept anonymous connections – you can do this by opening up the Exchange Management Console and navigating to [ Microsoft Exchange On-Premises –> Server Configuration –> Hub Transport ], then select your HT and then from the low pane (Receive Connectors) right click on the “Default <Your HT>” – from the context menu that appears choose “Properties” – see below From the properties box that appears, click on the “Permission Groups” tab, and then tick the “Anonymous Users” tick box, and then click on the “OK” button – see below
  • 5. In the real world, you should probably consider creating a dedicated Receive Connector for the Nagios instance. Configuring Nagios to Send Mail Notifications Now that you have installed the required components to enabled Nagios to send mail notifications, you will need to download two configurations files from your Nagios Server (using FileZilla and edit them using Notepad++ – if you need to understand how to do this, please review part 2 of my installing Nagios for Exchange series). These files are: 1. commands.cfg 2. contacts.cfg Which are located in: /usr/local/nagios/etc/objects Open the commands.cfg file in Notepad++ and modify the following two lines: # 'notify-host-by-email' command definition define command{ command_name notify-host-by-email command_line /usr/bin/printf "%b" "***** Nagios *****nnNotification Type: $NOTIFICATIONTYPE$nHost: $HOSTNAME$nState: $HOSTSTATE$nAddress: $HOSTADDRESS$nInfo: $HOSTOUTPUT$nnDate/Time: $LONGDATETIME$n" | /bin/mailx -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$ } # 'notify-service-by-email' command definition
  • 6. define command{ command_name notify-service-by-email command_line /usr/bin/printf "%b" "***** Nagios *****nnNotification Type: $NOTIFICATIONTYPE$nnService: $SERVICEDESC$nHost: $HOSTALIAS$nAddress: $HOSTADDRESS$nState: $SERVICESTATE$nnDate/Time: $LONGDATETIME$nnAdditional Info:nn$SERVICEOUTPUT$n" | /bin/mailx -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$ } To look like the following: # 'notify-host-by-email' command definition define command{ command_name notify-host-by-email command_line /usr/bin/printf "%b" "***** Nagios *****nnNotification Type: $NOTIFICATIONTYPE$nHost: $HOSTNAME$nState: $HOSTSTATE$nAddress: $HOSTADDRESS$nInfo: $HOSTOUTPUT$nnDate/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 *****nnNotification Type: $NOTIFICATIONTYPE$nnService: $SERVICEDESC$nHost: $HOSTALIAS$nAddress: $HOSTADDRESS$nState: $SERVICESTATE$nnDate/Time: $LONGDATETIME$nnAdditional Info:nn$SERVICEOUTPUT$n" | /usr/bin/mailx -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$ } In essence you are changing the /bin/mail part of each command to /usr/bin/mailx When you are done, save the file and then using FileZilla upload it back to your Nagios Server. Next open the contacts.cfg file and change the “email” property to that of the account where you would like the notifications to be sent – see below define contact{ contact_namenagiosadmin ; Short name of user use generic-contact ; Inherit default values from generic-contact template (defined above) aliasNagios Admin ; Full name of user email administrator@prepad.com ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ****** } When you are done, save the file, and upload it back to your Nagios server. To finish up the configuration, from a PuTTY session type in the following command: sudo /etc/init.d/nagios restart For the configuration changes to take effect. When there is now a problem with either a service or a host, the chosen recipient should receive a mail notification like the following: