Page 1 of 1

External Command

Posted: Fri Jul 18, 2014 4:55 pm
by grafton
Hola,

I'm trying to write a simple script that, tied to a cron job, will net me recurring scheduled downtime. I pulled the following:

Code: Select all

#!/bin/sh
# This is a sample shell script showing how you can submit the SCHEDULE_HOST_DOWNTIME command
# to Nagios.  Adjust variables to fit your environment as necessary.

now=`date +%s`
commandfile='/usr/local/nagios/var/rw/nagios.cmd'

/bin/printf "[%lu] SCHEDULE_HOST_DOWNTIME;host1;1110741500;1110748700;0;0;7200;Some One;Some Downtime Comment\n" $now > $commandfile
From http://old.nagios.org/developerinfo/ext ... and_id=118

But I only see this in nagiosinstallation/var/nagios.log

Code: Select all

[1405720261] EXTERNAL COMMAND: SCHEDULE_HOST_DOWNTIME;nagios.domain.com;1406678400;1406764800;0;0;0;Test User;Test Downtime Comment
[1405720261] Error: External command failed -> SCHEDULE_HOST_DOWNTIME;nagios.domain.com;1406678400;1406764800;0;0;0;Test User;Test Downtime Comment
[1405720261] External command error: Command failed
nagios.debug doesn't say much else...

My actual downtime.sh script is:

Code: Select all

#!/bin/sh
# This is a sample shell script showing how you can submit the SCHEDULE_HOST_DOWNTIME command
# to Nagios.  Adjust variables to fit your environment as necessary.

now=`date +%s`
commandfile='/usr/local/nagios/var/rw/nagios.cmd'

/usr/bin/printf "[%lu] SCHEDULE_HOST_DOWNTIME;nagios.domain.com;1406678400;1406764800;0;0;0;Test User;Test Downtime Comment\n" $now > $commandfile

if [ $? -ne 1 ]; then
                echo "Works....";
fi

It outputs "Works..." when it definitely does not. :\

Any idea why this would be failing?

Thanks!

Best,

G

Re: External Command

Posted: Mon Jul 21, 2014 4:20 pm
by sreinhardt
Do you have:
A host "nagios.domain.com"
A user "Test User"

The issue with your current command provided everything else exists in your configs, is that duration is set to 0 and needs to be a valid positive number. The particular item is highlighted, note this value is in seconds.
SCHEDULE_HOST_DOWNTIME;nagios.domain.com;1406678400;1406764800;0;0;0;Test User;Test Downtime Comment

Also just so you are aware, the test to see if it works, is simply checking if printf passed or failed. Unless you put something obviously malicious in there, printf is not going to fail very often. That said, I do agree that it is not a good test at all.

Re: External Command

Posted: Thu Aug 07, 2014 10:19 am
by grafton
Hey sreinhardt,

Sorry for not replying earlier. Side-tracked. :P

It looks like I didn't have this set to fixed window - simple oversight on my end. thanks for pointing this out to me! :)

Best,

Joel