Your SlideShare is downloading. ×
Configuring e mail notificationin nagios core
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Configuring e mail notificationin nagios core

1,847

Published on

Documentation about nagios

Documentation about nagios

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,847
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
21
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Configuring e-Mail Notifications in NagiosCore…by Andy Grogan on February 24, 2012 · 9 commentsin Exchange 2010 (General), Linux, Linux with Exchange, Monitoring, Nagios, UbuntuLinked to my multi part series on using Nagios Core with Exchange server, I would like to explain howyou can configure mail notifications to recipients when status changes occur within the Nagiosmonitoring environment.If you are just joining us here, I recommend that you have a look at the series in its entirety beforereading any further, as there are a few concepts used in this article which were covered in-depth withinprevious 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 environmentMaking Sure that you DNS Configuration is correctBefore you begin to setup the tools which will enable mail notifications to be sent from Nagios, youshould ensure that you destination mail domain can be resolved from your Ubuntu server. I haveassumed that you will be sending notifications to a mailbox within your Exchange infrastructure whichnaturally is separate to the Nagios implementation.In my example, my destination domain is “prepad.com” – therefore in order to check if the Nagiosserver can lookup the MX record for that domain you can use the “dig” command like so:dig prepad.com mxIf everything is ok, you should receive an output to the command similar to that below:
  • 2. Installing POSTFIXPostfix is a free MTA for Linux which is designed to be easier to setup and configure than the moretraditional SendMail offering. Combined with Heirloom-MailX (see next section) Nagios can beconfigured to use the two products to send e-mail notifications to a designated set of contacts in theevent 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 amnot 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 inthe following command:sudo apt-get install postfixYou will then be presented with a two step setup Wizard – the first page will ask you what type ofPOSTFIX 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 myexample I have used “nagios.notify” – when you are done tab to the “OK” button – see belowThis 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-mailxConfiguring Exchange to accept messages from your NagiosServerThere are better ways to do this, however if you want to ensure that your Exchange Hub transportservers are accepting mail from your Nagios server, you should ensure that the Default ReceiveConnector on your HT is configured to accept anonymous connections – you can do this by opening upthe Exchange Management Console and navigating to [ Microsoft Exchange On-Premises –> ServerConfiguration –> Hub Transport ], then select your HT and then from the low pane (ReceiveConnectors) right click on the “Default <Your HT>” – from the context menu that appears choose“Properties” – see belowFrom 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 Nagiosinstance.Configuring Nagios to Send Mail NotificationsNow that you have installed the required components to enabled Nagios to send mail notifications, youwill need to download two configurations files from your Nagios Server (using FileZilla and edit themusing Notepad++ – if you need to understand how to do this, please review part 2 of my installingNagios for Exchange series).These files are: 1. commands.cfg 2. contacts.cfgWhich are located in:/usr/local/nagios/etc/objectsOpen the commands.cfg file in Notepad++ and modify the following two lines:# notify-host-by-email command definitiondefine command{command_name notify-host-by-emailcommand_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-emailcommand_line /usr/bin/printf "%b" "***** Nagios *****nnNotification Type:$NOTIFICATIONTYPE$nnService: $SERVICEDESC$nHost: $HOSTALIAS$nAddress:$HOSTADDRESS$nState: $SERVICESTATE$nnDate/Time: $LONGDATETIME$nnAdditionalInfo:nn$SERVICEOUTPUT$n" | /bin/mailx -s "** $NOTIFICATIONTYPE$ Service Alert:$HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$ }To look like the following:# notify-host-by-email command definitiondefine command{command_name notify-host-by-emailcommand_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 definitiondefine command{command_name notify-service-by-emailcommand_line /usr/bin/printf "%b" "***** Nagios *****nnNotification Type:$NOTIFICATIONTYPE$nnService: $SERVICEDESC$nHost: $HOSTALIAS$nAddress:$HOSTADDRESS$nState: $SERVICESTATE$nnDate/Time: $LONGDATETIME$nnAdditionalInfo:nn$SERVICEOUTPUT$n" | /usr/bin/mailx -s "** $NOTIFICATIONTYPE$ ServiceAlert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$ }In essence you are changing the /bin/mail part of each command to /usr/bin/mailxWhen 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 wouldlike the notifications to be sent – see belowdefine contact{contact_namenagiosadmin ; Short name of useruse generic-contact ; Inherit default valuesfrom generic-contact template (defined above)aliasNagios Admin ; Full name of useremail administrator@prepad.com ; <<***** CHANGE THISTO 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 restartFor 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 mailnotification like the following:

×