Page 1 of 1

Email configuration for nagios

Posted: Tue Jun 30, 2015 3:31 pm
by yunushaikh
Hello Experts,

I have configured contacts and contact group in Nagios.
I have 2 questions regarding the email.
1. What command does Nagios run for sending the email and where can I find the logs if the email fails? I have postfix enabled on the Nagios server.
2. How can I setup the below scenarios
Suppose I need email every 6 hours if it is warning
or I need email every hour when it is critical

It will be very helpful for me
Thanks

Re: Email configuration for nagios

Posted: Tue Jun 30, 2015 10:04 pm
by Box293
yunushaikh wrote:1. What command does Nagios run for sending the email and where can I find the logs if the email fails? I have postfix enabled on the Nagios server.
This is defined per contact. In a default Core installation they are defined in the generic-contact template.

/usr/local/nagios/etc/objects/templates.cfg

Extract:

Code: Select all

        name                            generic-contact         ; The name of this contact template
        service_notification_commands   notify-service-by-email ; send service notifications via email
        host_notification_commands      notify-host-by-email    ; send host notifications via email
And those commands are defined in /usr/local/nagios/etc/objects/commands.cfg

Code: Select all

# '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" | /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$\n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
        }
I think the logs will be in /var/log/mail.log
yunushaikh wrote:2. How can I setup the below scenarios
Suppose I need email every 6 hours if it is warning
or I need email every hour when it is critical
There's no real way to have a different notification interval for a warning state and a critical state.

Re: Email configuration for nagios

Posted: Wed Jul 01, 2015 5:00 am
by yunushaikh
If there is no real way to differentiate the notification, then how often will we get emails for warning ( or we dont get email for warning?) and how often we get email for critical.

Re: Email configuration for nagios

Posted: Wed Jul 01, 2015 10:02 am
by jdalrymple
You could do this in some different ways:

1) Have 2 services, one that only notifies on WARNING and one that notifies on CRITICAL
2) Wrap your notification scripts with a time/logic script. You can grab the service state out of the macros and then add your own timing logic.
3) Use 2 contacts/contactgroups and escalations, one contact group only gets the notifications every 6 notification_intervals and that group only receives warning...

None of these fixes are amazing or clean, but there is no built-in way to do what you want.

Re: Email configuration for nagios

Posted: Wed Jul 01, 2015 10:13 am
by yunushaikh
ok Thanks for you nice suggesstion.

If I configure this way then services will keep on increasing. Will 2 services accept the same command? Nagios should build some option to get this thing with single service. Isnt it?

Re: Email configuration for nagios

Posted: Wed Jul 01, 2015 10:22 am
by jdalrymple
yunushaikh wrote:Nagios should build some option to get this thing with single service. Isnt it?
We add features based upon community interest and the amount of time we have at our disposal. One thing worth noting - it's a community project, the source is open and you're welcome to change the program to fit your needs.

To put in a feature request visit http://tracker.nagios.org
yunushaikh wrote:If I configure this way then services will keep on increasing. Will 2 services accept the same command?
As I mentioned, it's not a clean solution. You can however have duplicate commands. The only parameter that needs to be unique is service_description.

Re: Email configuration for nagios

Posted: Wed Jul 01, 2015 10:43 am
by yunushaikh
Ok thank you Sir for your help.
It was very helpful.