External Command

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.
Locked
grafton
Posts: 7
Joined: Wed Jun 12, 2013 8:33 pm

External Command

Post 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
sreinhardt
-fno-stack-protector
Posts: 4366
Joined: Mon Nov 19, 2012 12:10 pm

Re: External Command

Post 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.
Nagios-Plugins maintainer exclusively, unless you have other C language bugs with open-source nagios projects, then I am happy to help! Please pm or use other communication to alert me to issues as I no longer track the forum.
grafton
Posts: 7
Joined: Wed Jun 12, 2013 8:33 pm

Re: External Command

Post 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
Locked