Mail Notifications

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
orani
Posts: 169
Joined: Wed May 06, 2015 3:33 pm

Mail Notifications

Post by orani »

How can i set up mail notifications?
User avatar
Box293
Too Basu
Posts: 5126
Joined: Sun Feb 07, 2010 10:55 pm
Location: Deniliquin, Australia
Contact:

Re: Mail Notifications

Post by Box293 »

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
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
orani
Posts: 169
Joined: Wed May 06, 2015 3:33 pm

Re: Mail Notifications

Post by orani »

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??
User avatar
Box293
Too Basu
Posts: 5126
Joined: Sun Feb 07, 2010 10:55 pm
Location: Deniliquin, Australia
Contact:

Re: Mail Notifications

Post by Box293 »

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
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
orani
Posts: 169
Joined: Wed May 06, 2015 3:33 pm

Re: Mail Notifications

Post by orani »

close this thread please. it is solved
Locked