Nagios Notifications dont work
Nagios Notifications dont work
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,
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,
-
- DevOps Engineer
- Posts: 19396
- Joined: Tue Nov 15, 2011 3:11 pm
- Location: Nagios Enterprises
- Contact:
Re: Nagios Notifications dont work
Your commands aren't piping the printf to the mail command..
Here is what the defaults look like
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
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
[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
-
- DevOps Engineer
- Posts: 19396
- Joined: Tue Nov 15, 2011 3:11 pm
- Location: Nagios Enterprises
- Contact:
Re: Nagios Notifications dont work
Please post your current commands
Re: Nagios Notifications dont work
Forget the last comment, not everything was copied correctly:
The code in commands.cfg, the rest is standard.
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
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$
}
[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
-
- DevOps Engineer
- Posts: 19396
- Joined: Tue Nov 15, 2011 3:11 pm
- Location: Nagios Enterprises
- Contact:
Re: Nagios Notifications dont work
It looks like your system doesn't have /bin/mail
You can find the correct path by running
and then replace that in the commands
You can find the correct path by running
Code: Select all
which mail
Re: Nagios Notifications dont work
Running the command
is giving me 0 results.
I did freshly installed postfix yesterday.
Code: Select all
which mail
I did freshly installed postfix yesterday.
-
- DevOps Engineer
- Posts: 19396
- Joined: Tue Nov 15, 2011 3:11 pm
- Location: Nagios Enterprises
- Contact:
Re: Nagios Notifications dont work
try
If you still don't get results let me know what OS and version this is
Code: Select all
which mailx
Re: Nagios Notifications dont work
Still no result with which mailx.
This machine has Ubuntu 18.04.1 LTS installed with Nagios Core 4.4.3.
This machine has Ubuntu 18.04.1 LTS installed with Nagios Core 4.4.3.
-
- DevOps Engineer
- Posts: 19396
- Joined: Tue Nov 15, 2011 3:11 pm
- Location: Nagios Enterprises
- Contact: