Writing Custom Plugin with String output

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
chrisbooth
Posts: 43
Joined: Thu Dec 01, 2016 10:09 am

Re: Writing Custom Plugin with String output

Post 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
You do not have the required permissions to view the files attached to this post.
gormank
Posts: 1114
Joined: Tue Dec 02, 2014 12:00 pm

Re: Writing Custom Plugin with String output

Post 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.
Last edited by gormank on Wed Dec 07, 2016 5:43 pm, edited 1 time in total.
chrisbooth
Posts: 43
Joined: Thu Dec 01, 2016 10:09 am

Re: Writing Custom Plugin with String output

Post 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
gormank
Posts: 1114
Joined: Tue Dec 02, 2014 12:00 pm

Re: Writing Custom Plugin with String output

Post 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 $?
Last edited by gormank on Wed Dec 07, 2016 5:51 pm, edited 1 time in total.
dwhitfield
Former Nagios Staff
Posts: 4583
Joined: Wed Sep 21, 2016 10:29 am
Location: NoLo, Minneapolis, MN
Contact:

Re: Writing Custom Plugin with String output

Post 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/.
chrisbooth
Posts: 43
Joined: Thu Dec 01, 2016 10:09 am

Re: Writing Custom Plugin with String output

Post 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.
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Writing Custom Plugin with String output

Post by rkennedy »

Did you have any further questions about this?
Former Nagios Employee
chrisbooth
Posts: 43
Joined: Thu Dec 01, 2016 10:09 am

Re: Writing Custom Plugin with String output

Post by chrisbooth »

thanks so much. all this information helped
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: Writing Custom Plugin with String output

Post by tmcdonald »

I'll be closing this thread now, but feel free to open another if you need anything in the future!
Former Nagios employee
Locked