Page 1 of 2

Nagios Notifications dont work

Posted: Wed Feb 20, 2019 4:13 pm
by Rook
Evening,

I'm trying to get nagios notifications to work, but it seems something is still going wrong.

First my contacts.cfg:

define contact {

contact_name nagiosadmin
use generic-contact
alias Nagios Admin
service_notification_period 24x7
host_notification_period 24x7
service_notification_options w,u,c,r
host_notification_options d,r
service_notification_commands notify-service-by-email
host_notification_commands notify-host-by-email
email [email protected] ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
}


In the command.conf i changed the 2 notify rules to:

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: $LONG$
}


and 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/T$
}


Freshly installed Postfix for this.

When i test this by sending an custom service notification, it all goes well and the output of nagios.log shows:

[1550697140] EXTERNAL COMMAND: SEND_CUSTOM_SVC_NOTIFICATION;Host;PING;0;Nagios Admin;q
[1550697140] SERVICE NOTIFICATION: nagiosadmin;Host;PING;CUSTOM (CRITICAL);notify-service-by-email;PING CRITICAL - Packet loss = 100%;Nagios Admin;q


But I'm not getting an email in my inbox.

Is there anything that I'm missing?

Thanks in advance.

Kind regards,

Re: Nagios Notifications dont work

Posted: Thu Feb 21, 2019 11:33 am
by scottwilkerson
Your commands aren't piping the printf to the mail command..

Here is what the defaults look like

Code: Select all

define command {
    command_name    notify-host-by-email
    command_line    /usr/bin/printf "%b" "***** Nagios Monitor XI Alert *****\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 Monitor XI Alert *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$" | /bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
}

Re: Nagios Notifications dont work

Posted: Thu Feb 21, 2019 1:30 pm
by Rook
The changes i made to commands.cfg resulted in the following error down below when sending an test notification:

[1550773706] wproc: NOTIFY job 66 from worker Core Worker 52406 is a non-check helper but exited with return code 2
[1550773706] wproc: host=XXX; service=Free Space VolGroup-lv_root; contact=nagiosadmin
[1550773706] wproc: early_timeout=0; exited_ok=1; wait_status=512; error_code=0;
[1550773706] wproc: stderr line 01: /bin/sh: 1: Syntax error: Unterminated quoted string

Re: Nagios Notifications dont work

Posted: Thu Feb 21, 2019 1:37 pm
by scottwilkerson
Please post your current commands

Re: Nagios Notifications dont work

Posted: Thu Feb 21, 2019 1:55 pm
by Rook
Forget the last comment, not everything was copied correctly:

The code in commands.cfg, the rest is standard.

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$" | /bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
}
The correct output is:

[1550775195] wproc: NOTIFY job 1 from worker Core Worker 57662 is a non-check helper but exited with return code 127
[1550775195] wproc: host=XXX; service=Free Space VolGroup-lv_root; contact=nagiosadmin
[1550775195] wproc: early_timeout=0; exited_ok=1; wait_status=32512; error_code=0;
[1550775195] wproc: stderr line 01: /bin/sh: 1: /bin/mail: not found
[1550775195] wproc: stderr line 02: /usr/bin/printf: write error: Broken pipe

Re: Nagios Notifications dont work

Posted: Thu Feb 21, 2019 2:22 pm
by scottwilkerson
It looks like your system doesn't have /bin/mail

You can find the correct path by running

Code: Select all

which mail
and then replace that in the commands

Re: Nagios Notifications dont work

Posted: Thu Feb 21, 2019 2:44 pm
by Rook
Running the command

Code: Select all

which mail
is giving me 0 results.

I did freshly installed postfix yesterday.

Re: Nagios Notifications dont work

Posted: Thu Feb 21, 2019 2:58 pm
by scottwilkerson
try

Code: Select all

which mailx
If you still don't get results let me know what OS and version this is

Re: Nagios Notifications dont work

Posted: Thu Feb 21, 2019 3:04 pm
by Rook
Still no result with which mailx.

This machine has Ubuntu 18.04.1 LTS installed with Nagios Core 4.4.3.

Re: Nagios Notifications dont work

Posted: Thu Feb 21, 2019 3:16 pm
by scottwilkerson
I think you don't have it installed

Lets run

Code: Select all

sudo apt-get install mailutils