Mail Notifications

An open discussion forum for obtaining help with Nagios Core. Nagios Core users of all experience levels are welcome here. Subforum have been created for the discussion of Nagios Core and Nagios Plugin development.

NOTE: The SourceForge.net mailing lists have been deprecated in favor of this forum in order to expedite support and provide additional features not available on the old mailing list.

Mail Notifications

Postby orani » Sat Jun 18, 2016 4:05 pm

How can i set up mail notifications?
orani
 
Posts: 125
Joined: Wed May 06, 2015 3:33 pm

Re: Mail Notifications

Postby Box293 » Sun Jun 19, 2016 10:24 pm

Notifications are sent to contacts when a host or service enters a hard state.

This article explains the logic:

https://support.nagios.com/kb/article.php?id=371
User avatar
Box293
Too Basu
 
Posts: 4735
Joined: Sun Feb 07, 2010 10:55 pm
Location: Deniliquin, Australia

Re: Mail Notifications

Postby orani » Wed Jun 22, 2016 6:50 pm

Yes but how can i setup this up?

I have replaced the mail (root@localhost) at contacts with my personal (gmail.com)

What else i have to set up??
orani
 
Posts: 125
Joined: Wed May 06, 2015 3:33 pm

Re: Mail Notifications

Postby Box293 » Wed Jun 22, 2016 7:34 pm

You contacts have notification commands that are used to send the emails.

In a default core implementation the nagiosadmin contact is using a template that has these defined.

Code: Select all
define contact{
        name                            generic-contact         ; The name of this contact template
        service_notification_period     24x7                    ; service notifications can be sent anytime
        host_notification_period        24x7                    ; host notifications can be sent anytime
        service_notification_options    w,u,c,r,f,s             ; send notifications for all service states, flapping events, and scheduled downtime events
        host_notification_options       d,u,r,f,s               ; send notifications for all host states, flapping events, and scheduled downtime events
        service_notification_commands   notify-service-by-email ; send service notifications via email
        host_notification_commands      notify-host-by-email    ; send host notifications via email
        register                        0                       ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL CONTACT, JUST A TEMPLATE!
        }


These two lines are what I am talking about:

Code: Select all
        service_notification_commands   notify-service-by-email ; send service notifications via email
        host_notification_commands      notify-host-by-email    ; send host notifications via email


These commands are:

Code: Select all
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$
        }

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$


Basically it uses printf to output the message body and pipe it to the /bin/mail command

So it's the /bin/mail command that is responsible for sending notifications. You can change this to sendmail or any other command that can send the message.

There isn't much official documentation on this as it starts to get into setting up a sendmail server which is way out of the scope of the Nagios product. An internet search should yield some results on making this work.

https://www.google.com/?q=nagios+sendmail+configuration
User avatar
Box293
Too Basu
 
Posts: 4735
Joined: Sun Feb 07, 2010 10:55 pm
Location: Deniliquin, Australia

Re: Mail Notifications

Postby orani » Thu Jan 12, 2017 3:43 am

close this thread please. it is solved
orani
 
Posts: 125
Joined: Wed May 06, 2015 3:33 pm


Return to Nagios Core

Who is online

Users browsing this forum: Google [Bot] and 18 guests