Handling alerts from date returned from external app?

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.
jriker1
Posts: 115
Joined: Tue Dec 15, 2015 8:40 pm

Handling alerts from date returned from external app?

Post by jriker1 »

I have an app that all it returns is a date in this format: 8/26/2016 11:59:00 PM. I can manage the date format for reference. This date determines the error condition but want it configurable. Basically this date tells me the last set of data that was successfully loaded in an encrypted datastore. If there are less than say 8 days I want a warning. If there are less than 3 days of data I want it to go critical. How would I wrap this program's return value into reporting in Nagios? Note this is a windows console application and I have NSClient++ running successfully for other things.

Also for reference, it takes about 30 seconds for this check to run if timeout factors into responses.

Thanks.

JR
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Handling alerts from date returned from external app?

Post by rkennedy »

It really depends on the language everything is written in, but you would need to write if conditional statements to do so. For example (this won't work, just for reference) -

Code: Select all

$vardate = get.date.from.app
$curdate = date
$diff = date - vardate

if $diff < 3 then
echo CRITICAL
exit 2
elif $diff < 8 then
echo WARNING
exit 1
else
echo OK
exit 0
You would need to tighten your if statements to match multiple criteria (so that it can only be labeled one of the exit codes). I didn't use any specific language here, but hopefully that helps. You'll just need to compare the amount of days difference, and then write something that exits accordingly. Nagios depends on the exit codes to use as a judgement for which state a host / service is in. For reference, exit 2 = critical, 1 = warning, and 0 = ok.
Former Nagios Employee
jriker1
Posts: 115
Joined: Tue Dec 15, 2015 8:40 pm

Re: Handling alerts from date returned from external app?

Post by jriker1 »

Thanks for the reply. This is written in C#. I actually took the source for this and just built everything in. At least hope it works.

[*]So it accepts a warning and critical threshold as arguments.
[*]Does it's thing and gets the date.
[*]Calculates if a warning or error situation is happening based on the argument values and the date variance from now.
[*]Outputs a warning or critical message with a dash after and the message.
[*]Sends a return value of 0,1 or 2 for OK, warning, error.

Hoping this will work but not sure yet as haven't tried to hook it into Nagios. Been a while since I wrote a custom nrpe side plugin for Nagios and never a .exe version plus figuring how the params are set. Hoping it's as simple on the nsclient.ini side of:

mceguidecheck=scripts\\MCEGuideDate.exe "$ARG1$" "$ARG2$"

Thanks.

JR
Last edited by jriker1 on Mon Aug 15, 2016 2:10 pm, edited 1 time in total.
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Handling alerts from date returned from external app?

Post by rkennedy »

Sounds like you're spot on with your logic. I don't know much C#, so can't be of much help. After writing it, test it over the CLI to make sure it works. (before throwing it into NRPE)

Then, you just have to worry about your C# skills and not the NRPE part. :)

echo $? on a shell will output what the exit code is for the last running script, so might help with your debugging.
Former Nagios Employee
jriker1
Posts: 115
Joined: Tue Dec 15, 2015 8:40 pm

Re: Handling alerts from date returned from external app?

Post by jriker1 »

Thanks testing now. One other thing I'm going to have to figure out is NRPE timeout. Looks like it's running 10 seconds and can add -t to the command line to extend it. Adding timeout settings in the nsclient.ini doesn't seem to work.

Oddly getting the following:

If I give bogus attributes wich a char like:

./check_nrpe -H 192.168.0.2 -p 5666 -c mceguidecheck -t 45 -a F 3

Program comes back in nagios server with "Non numeric arguments passed" as I would want. Has a return code of 2 which is what I pass.

If I do:

./check_nrpe -H 192.168.0.2 -p 5666 -c mceguidecheck -t 45 -a 8 3

which normally brings back an OK message, I get "The command mceguidecheck returned an invalid return code: 1131.

Doing echo $? returns a 3. I pass a zero in the program and in dos it shows a zero for the returncode.

And if I run it another time get Receiving 0 bytes from daemon. Check the remote server logs for error messages. Message in nsclient.log is "error:c:\source\nscp\include\socket/connection.hpp:149: Failed to send data: The file handle supplied is not valid"

Here is the output if I run this in a dos window on the Windows box:

Code: Select all

C:\Program Files\NSClient++\scripts>MCEGuideDate.exe 13 8
Warning - 12 Days left (8/27/2016 11:55:00 PM)

C:\Program Files\NSClient++\scripts>echo %ERRORLEVEL%
1

C:\Program Files\NSClient++\scripts>
Thoughts?

Thanks.

JR
jriker1
Posts: 115
Joined: Tue Dec 15, 2015 8:40 pm

Re: Handling alerts from date returned from external app?

Post by jriker1 »

Not to overload my last message. If I take out the method that determines the date, and hard code NOW in there so it returns a result immediately, it comes out with the expected message and a result code of 2 which it should. And if I force an OK status it returns the right message and a 0 for the result code. So even putting 60 seconds in the -t setting there is something else giving up before it is done running. Any idea what's happening?

Essentially in the code I literally just commented out the method, and told it to return now so no other code was altered. This is strictly a duration to complete thing, not an output thing.

Thanks.

JR
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Handling alerts from date returned from external app?

Post by rkennedy »

It sounds like it's possibly looping somewhere, are you grabbing your time using any kind of variables that require admin rights? As for the timeout with NSClient++, it can be really finicky depending where it's placed. Can you post your NSClient++ configuration file for us to look at?
Former Nagios Employee
User avatar
tgriep
Madmin
Posts: 9190
Joined: Thu Oct 30, 2014 9:02 am

Re: Handling alerts from date returned from external app?

Post by tgriep »

Take a look at the bottom of this page for some timeout settings that could help out on that issue.
http://docs.nsclient.org/faq/
Be sure to check out our Knowledgebase for helpful articles and solutions!
jriker1
Posts: 115
Joined: Tue Dec 15, 2015 8:40 pm

Re: Handling alerts from date returned from external app?

Post by jriker1 »

Thanks for the replies. Got it fixed, just got around to responding. Must have been a placement thing as the timeout settings were erroring in the logs and when I added them again later it was fine. Not sure what did it. Right now I'm using -t in the command file, and have a timeout setting on the server and external scripts level in the ini. Just using the -t in the command file didn't solve it.

Thanks.

JR
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Handling alerts from date returned from external app?

Post by rkennedy »

Sounds good! Are we good to mark this as resolved then?
Former Nagios Employee
Locked