Nagios 4.4.10 Notification Command returns stderr line 01: /bin/sh: 1: Syntax error: redirection unexpected
Posted: Thu Sep 05, 2024 6:12 pm
I have created a new Python 3.10 script that takes notification arguments and triggers an email and at the same time forwards the notification to another service using and API.
When I try to send a "Custom host notification" to test my notification script I get a and of course the notification is not sent and my script is not executed. I have tried to redirect stdout to a file and stderr to stdout, and it still is not working.
Any idea what may be wrong. Looks like nagios is trying to start /bin/sh and launch the command. The path of Python is correct so as the path to the Python script. I'm starting to believe that it could be the quotes I'm using to wrap each parameter.
/usr/local/nagios/etc/objects/commands.cfg
/usr/local/nagios/var/nagios.log
/usr/local/nagios/var/nagios.debug
When I try to send a "Custom host notification" to test my notification script I get a
Code: Select all
stderr line 01: /bin/sh: 1: Syntax error: redirection unexpectedAny idea what may be wrong. Looks like nagios is trying to start /bin/sh and launch the command. The path of Python is correct so as the path to the Python script. I'm starting to believe that it could be the quotes I'm using to wrap each parameter.
/usr/local/nagios/etc/objects/commands.cfg
Code: Select all
...
define command{
command_name notify-host-by-email-normal
command_line /usr/bin/python3 /usr/local/neo/nagios/notify/notify.py -u "$USER20$" -n "$NOTIFICATIONTYPE$" -d "$HOSTNAME$" -D "$HOSTSTATE$" -i "$HOSTADDRESS$" -o "$HOSTOUTPUT$" -c "$NOTIFICATIONCOMMENT$" -t "$LONGDATETIME$" "$CONTACTEMAIL$" >> /usr/local/neo/nagios/notify/logs/notify.log 2>&1
}
...
Code: Select all
...
[1725576091] EXTERNAL COMMAND: SEND_CUSTOM_HOST_NOTIFICATION;17KNK9K3CS11;3;Network Engineering NEO;custom 3
[1725576091] HOST NOTIFICATION: monitoring-normal;********;CUSTOM (UP);notify-host-by-email-normal;PING OK - Packet loss = 0%, RTA = 2.42 ms;Network Engineering NEO;custom 3
[1725576091] HOST NOTIFICATION: networke-normal;********;CUSTOM (UP);notify-host-by-email-normal;PING OK - Packet loss = 0%, RTA = 2.42 ms;Network Engineering NEO;custom 3
[1725576091] wproc: NOTIFY job 0 from worker Core Worker 557827 is a non-check helper but exited with return code 2
[1725576091] wproc: host=********; service=(none); contact=network-normal
[1725576091] wproc: early_timeout=0; exited_ok=1; wait_status=512; error_code=0;
[1725576091] wproc: stderr line 01: /bin/sh: 1: Syntax error: redirection unexpected
[1725576091] wproc: NOTIFY job 0 from worker Core Worker 557828 is a non-check helper but exited with return code 2
[1725576091] wproc: host=********; service=(none); contact=monitoring-normal
[1725576091] wproc: early_timeout=0; exited_ok=1; wait_status=512; error_code=0;
[1725576091] wproc: stderr line 01: /bin/sh: 1: Syntax error: redirection unexpected
...
Code: Select all
...
[1725576091.501592] [256.1] [pid=47302] Read raw external command '[1725576091] SEND_CUSTOM_HOST_NOTIFICATION;********;3;Network Engineering NEO;custom 3'
[1725576091.502759] [032.0] [pid=47302] ** Host Notification Attempt ** Host: '********', Type: CUSTOM, Options: 3, Current State: 0, Last Notification: Thu Jan 1 00:00:00 1970
[1725576091.502918] [032.1] [pid=47302] This is a forced host notification, so we'll send it out.
[1725576091.503030] [032.0] [pid=47302] Notification viability test passed.
[1725576091.503163] [032.1] [pid=47302] Current notification number: 0 (unchanged)
[1725576091.503272] [032.1] [pid=47302] Host notification will NOT be escalated.
[1725576091.503374] [032.1] [pid=47302] This notification will be BROADCAST to all (escalated and normal) contacts...
[1725576091.503490] [032.1] [pid=47302] Adding contacts from host escalation(s) to notification list.
[1725576091.503595] [032.1] [pid=47302] Adding normal contacts for host to notification list.
[1725576091.504688] [032.0] [pid=47302] 2 contacts were notified.
...