Nagios Notifications dont work

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.
Rook
Posts: 12
Joined: Tue Feb 19, 2019 4:50 am

Nagios Notifications dont work

Post 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 xxx@xxx.com ; <<***** 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,
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Nagios Notifications dont work

Post 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$
}
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
Rook
Posts: 12
Joined: Tue Feb 19, 2019 4:50 am

Re: Nagios Notifications dont work

Post 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
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Nagios Notifications dont work

Post by scottwilkerson »

Please post your current commands
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
Rook
Posts: 12
Joined: Tue Feb 19, 2019 4:50 am

Re: Nagios Notifications dont work

Post 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
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Nagios Notifications dont work

Post 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
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
Rook
Posts: 12
Joined: Tue Feb 19, 2019 4:50 am

Re: Nagios Notifications dont work

Post by Rook »

Running the command

Code: Select all

which mail
is giving me 0 results.

I did freshly installed postfix yesterday.
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Nagios Notifications dont work

Post by scottwilkerson »

try

Code: Select all

which mailx
If you still don't get results let me know what OS and version this is
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
Rook
Posts: 12
Joined: Tue Feb 19, 2019 4:50 am

Re: Nagios Notifications dont work

Post by Rook »

Still no result with which mailx.

This machine has Ubuntu 18.04.1 LTS installed with Nagios Core 4.4.3.
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Nagios Notifications dont work

Post by scottwilkerson »

I think you don't have it installed

Lets run

Code: Select all

sudo apt-get install mailutils
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
Locked