[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to set email notification in Nagios?

Posted on 2010-11-25
6
Medium Priority
?
999 Views
Last Modified: 2012-06-27
I have setup Nagios on Centos 5. Added all my Linux Server and windows Server. Everything seems to be fine except Email Notification.

Please suggest me how to set Email Notification?

Already i have a Mail Server running on another system that is based on RHEL 5.
0
Comment
Question by:aloknet21
6 Comments
 
LVL 18

Expert Comment

by:Sanga Collins
ID: 34212588
In yours commands.cfg what is your send notification command ?
0
 
LVL 1

Expert Comment

by:fracassa79
ID: 34213123
I have installed ssmtp: it's a simple tool to configure your smtp account and so be able to send mail from linux command line with /usr/bin/mail command

http://www.linux.com/archive/feature/132006

my config:
cat /etc/ssmtp/ssmtp.conf
#
# Config file for sSMTP sendmail
#
# The person who gets all mail for userids < 1000
# Make this empty to disable rewriting.
root=postmaster

# The place where the mail goes. The actual machine name is required no
# MX records are consulted. Commonly mailhosts are named mail.domain.com

mailhub=<smtpserver-ip-address>:25
AuthUser=<mailaccount>
AuthPass=<mailaccountpassword>
STARTSSL=YES

rewriteDomain=<yourdomain>

# The full hostname
hostname=<hostnameofnagiosserver>

# Are users allowed to set their own From: address?
# YES - Allow the user to specify their own From: address
# NO - Use the system generated From: address


Then configure mail command in command.cfg
# '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\nDate/Time: $LONGDATETIME$\n" | /usr/bin/mail -s "NAGIOS $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\nAdditional Info:\n$SERVICEOUTPUT$\n\nLong Additional Info:\n$LONGSERVICEOUTPUT$\n\nDate/Time: $LONGDATETIME$\n\nDate/Time: $LONGDATETIME$" | /usr/bin/mail -s "NAGIOS $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
#      }



0
 
LVL 14

Accepted Solution

by:
Deepak Kosaraju earned 2000 total points
ID: 34213430
Make sure you have postfix setup on your server and let it relay the email to your email server on other redhat server.
Then if you follow the documented procedure of setting email you are good to go.

If you want to receive email notifications for Nagios alerts, you need to install the mailx (Postfix) package.


sudo yum install mailx

sudo yum install postfix

You'll have to edit the Nagios email notification commands found in /etc/nagios/commands.cfg and change any '/bin/mail' references to '/usr/bin/mail'. Once you do that you'll need to restart Nagios to make the configuration changes live.
Make sure you have these correct inside commands.cfg
# '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/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$" | /usr/bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
}

sudo /etc/init.d/nagios restart
0
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 
LVL 18

Expert Comment

by:Sanga Collins
ID: 34214138
kosarajudeepak comment is exactly how i did it as well. quite simple :)
0
 
LVL 1

Author Comment

by:aloknet21
ID: 34221544
thanks kosarajudeepak. it is working now.

Now i need to monitor My Firewall and Switches also. please suggest the steps for this.
0
 
LVL 2

Expert Comment

by:koffu
ID: 34238359
in /etc/nagios3/commands.cfg
be sure you have defined
define command{
        command_name    notify-host-by-email
......
}

define command{
        command_name    notify-service-by-email
.....
}

Open in new window

in /etc/nagios3/conf.d/contacts.cfg
define contactgroup{
        contactgroup_name       admins
        alias                   Nagios Administrators
        members                 it
            }

define contact{
    contact_name                    it
    alias                           it
    service_notification_period     24x7
    host_notification_period        hostmonitoringhours
    host_notification_options       d
    service_notification_options    n
    service_notification_commands   notify-service-by-email
    host_notification_commands      notify-host-by-email
    email                           user@domain
host_notifications_enabled              1
service_notifications_enabled           1
}

Open in new window

in /etc/nagios3/conf.d/generic-host_nagios2.cfg
define host{
        name                            generic-host    ; The name of this host template
        notifications_enabled           0       ; Host notifications are enabled

Open in new window


in /etc/nagios3/conf.d/generic-host_nagios2.cfg
define service{
        name                            generic-service ; The 'name' of this service template
        notifications_enabled           1       ; Service notifications are enabled

Open in new window





I'm using postfix with relayhost=[xxx.xxx.xxx.xxx] option, pointed directly to my server. This solution have outgoing queue, so you not loose your notification if connection hang or you can setup mail routing for multiple destiantions.
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Network ports are the threads that hold network communication together. They are an essential part of networking that can be easily ignore or misunderstood, my goals is to show those who don't have a strong network foundation how network ports opera…
Often times it's very very easy to extend a volume on a Linux instance in AWS, but impossible to shrink it. I wanted to contribute to the experts-exchange community a way of providing a procedure that works on an AWS instance. It can also be used on…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
Suggested Courses
Course of the Month19 days, 18 hours left to enroll

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question