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.
#!/bin/sh
# write a command to the Nagios command file to cause
# it to process a service check result
echocmd="/bin/echo"
CommandFile="/app/monitor/MASTER1/var/rw/nagios.cmd"
# get the current date/time in seconds sine UNIX epoch
datetime=`date +%s`
# create the command line to add to the command file
cmdline="[$datetime] PROCESS_SERVICE_CHECK_RESULT;$1;$2;$3;$4"
# append the command to the end of the command file
`$echocmd $cmdline >> $CommandFile`
Example of a service definition, defined on slaves:
@paolo974, Have you taken a look inside the /app/monitor/MASTER1/var/rw/nagios.cmd file to see if the number 8 gets written out instead of the epoch stamp? The script looks fine at a first glance.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
@npolovenko, Yes, the number 8 gets written out instead of the epoch stamp in /app/monitor/MASTER1/var/rw/nagios.cmd file
In /app/monitor/MASTER1/var/nagios.log, the number 8 gets written out too,
and if I put an echo $cmdline >> /tmp/debug before `$echocmd $cmdline >> $CommandFile` in event handler script, the number 8 gets written out too in /tmp/debug file.
As a workaround, I change the line `$echocmd $cmdline >> $CommandFile` by `echo $cmdline | sed -e 's/^8 /\['$(date +%s)'\] /' >> $CommandFile`, it works but I still don't know why the number 8 gets written
I'm with @mcapra on this one, I couldn't reproduce the issue on Debian or CentOS. I did notice that /bin/sh --help did not work on Debian, so running ls -l /bin/sh might be needed to tell us where it is symlinking to.
GNU bash, version 4.1.2(1)-release-(x86_64-redhat-linux-gnu)
Usage: /bin/sh [GNU long option] [option] ...
/bin/sh [GNU long option] [option] script-file ...
GNU long options:
--debug
--debugger
--dump-po-strings
--dump-strings
--help
--init-file
--login
--noediting
--noprofile
--norc
--posix
--protected
--rcfile
--rpm-requires
--restricted
--verbose
--version
Shell options:
-irsD or -c command or -O shopt_option (invocation only)
-abefhkmnptuvxBCHP or -o option
Type `/bin/sh -c "help set"' for more information about shell options.
Type `/bin/sh -c help' for more information about shell builtin commands.
# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 6.9 (Santiago)
# ls -l /bin/sh
lrwxrwxrwx 1 root root 4 Nov 23 06:36 /bin/sh -> bash
Using following one-liner works
/bin/echo "[$(date +%s)] PROCESS_SERVICE_CHECK_RESULT;$1;$2;$3;$4" >> /app/monitor/MASTER1/var/rw/nagios.cmd
if I use following code for my event handler, it works but from time to time I still see number 8 getting written in /tmp/debug
What version of Core is this? We can't really come up with any reason why this might be happening, but at least if we have a version on which we can test we can see if we can reproduce.