Page 2 of 2
Re: Writing Custom Plugin with String output
Posted: Wed Dec 07, 2016 5:26 pm
by chrisbooth
I realized it wasn't the best idea to run a check within another check so i removed the check_by_ssh and just used ssh itself
Code: Select all
if ssh admin@"$HOSTNAME" /usr/local/aw/bin/nsdchat -s 'awsock:/admin:Operation8@localhost:9001 -c Job failed 90' | grep -v empty > /dev/tty; then
#if ./check_by_ssh -H "$HOSTNAME" -l admin -C '/usr/local/aw/bin/nsdchat -s awsock:/admin:Operation8@localhost:9001 -c Job failed 90' | grep -v empty > /dev/tty; then
echo "Syncs Failed"
exit 2
else
echo "OK"
exit 0
fi
I've just realized no matter what i put in the host when i run a service check it responds with OK
Screen Shot 2016-12-07 at 22.27.56.png
other checks do fail so i'm obviously an issue specific to my plugin
Screen Shot 2016-12-07 at 22.31.48.png
Re: Writing Custom Plugin with String output
Posted: Wed Dec 07, 2016 5:38 pm
by gormank
For some reason my last post never got posted :(
Is the if reacting to the return value of the command, or to the text in the command?
You can make a test script that returns the value you tell it and figure things out before trying in real life. Call w/ 1/2/3/255
test.sh n
echo "Return value: $1"
exit $1
Something like the above...
Is " -c Job failed 90" part of the current check or an arg to the check_ plugin.
I'd think interms of the return value of the underlying command executed since it should theoretically be meaningful. Maybe not.
Re: Writing Custom Plugin with String output
Posted: Wed Dec 07, 2016 5:43 pm
by chrisbooth
ok i think i've found the issue
Code: Select all
if ssh admin@"$HOSTNAME" /usr/local/aw/bin/nsdchat -s 'awsock:/admin:Operation8@localhost:9001 -c Job failed 90' | grep -v empty > /dev/tty; then
changed it from /dev/tty; to /dev/null;
/dev/tty; was my way of getting the output of /usr/local/aw/bin/nsdchat -s 'awsock:/admin:Operation8@localhost:9001 -c Job failed 90' and not just passing it onto the if statement
changed to:
Code: Select all
if ssh admin@"$HOSTNAME /usr/local/aw/bin/nsdchat -s 'awsock:/admin:Operation8@localhost:9001 -c Job failed 90' | grep -v empty > /dev/null; then
the only reason i had /dev/tty; is becuase that way i get the codes of the failed jobs.
i'm not sure how i can use /dev/null; but also get that output
Re: Writing Custom Plugin with String output
Posted: Wed Dec 07, 2016 5:46 pm
by gormank
> /dev/null: redirect all output to nowhere. Not good.
2>&1: redirect STDERR to STDOUT
2>&1 > /dev/null: redirect STDERR to nowhere
Maybe the return status isn't meaningful, but it seems you're trying to react to return text rather than status. Why not try using the status in $?
Re: Writing Custom Plugin with String output
Posted: Wed Dec 07, 2016 5:50 pm
by dwhitfield
@gormank thanks again for your help!
@chrisbooth, I know this was already mentioned, but you might find quicker responses for the output/scripting questions at
https://unix.stackexchange.com/.
Re: Writing Custom Plugin with String output
Posted: Wed Dec 07, 2016 5:53 pm
by chrisbooth
thanks for your help. i only posted here as i wasn't sure if it was a script issue or a nagios issue.
thanks again for your generous help.
Re: Writing Custom Plugin with String output
Posted: Wed Dec 07, 2016 6:00 pm
by rkennedy
Did you have any further questions about this?
Re: Writing Custom Plugin with String output
Posted: Wed Dec 14, 2016 8:08 am
by chrisbooth
thanks so much. all this information helped
Re: Writing Custom Plugin with String output
Posted: Wed Dec 14, 2016 12:45 pm
by tmcdonald
I'll be closing this thread now, but feel free to open another if you need anything in the future!