Page 1 of 1

Check Value from PowerShell Script/Set Warning or Critical

Posted: Wed Aug 05, 2020 2:57 pm
by mbishop4
I've worked with someone to create a PowerShell script to perform a specific check. Testing from the command line and using the API Endpoint returns the value just as it should. Running the service within the Nagios interface returns the value as it should as well.

I'd like for warning or critical to be set based on the value returned but cannot get it to work so far (it always returns ok, I assume because the script executed ok).

Here's the syntax that I've used on the service:

check_p8_queue_count_system_utility!-t <redacted>-q '' -w '25' -c '50'

What am I missing or doing wrong?

Re: Check Value from PowerShell Script/Set Warning or Critic

Posted: Thu Aug 06, 2020 10:57 am
by mbellerue
it always returns ok, I assume because the script executed ok
This is almost certainly what's going on. In your Powershell script, I assume you have a section to parse the -w and -c switches? In the logic that handles whether or not the result has breached the warning/critical thresholds, I would recommend having a variable that is your script's exit code. If the result goes above the warning threshold, the variable is set to 1, if the result goes above the critical threshold, the variable is set to 2.

Then at the bottom of the script, you can write-host whatever message you would like to be displayed, and the very last line will be

Code: Select all

exit $yourexitvariable
This plugin is a good example of setting an exit variable.
https://exchange.nagios.org/directory/U ... s1/details

Otherwise, a lot of people exit the script wherever the script is in its processing. Personally, I like having a single place where the script will exit, and the logic handles things like setting an exit message and exit code.

Re: Check Value from PowerShell Script/Set Warning or Critic

Posted: Thu Aug 06, 2020 4:16 pm
by mbishop4
I did set up condition checking on exit and it does work fine now, thank you.

Re: Check Value from PowerShell Script/Set Warning or Critic

Posted: Fri Aug 07, 2020 7:24 am
by scottwilkerson
mbishop4 wrote:I did set up condition checking on exit and it does work fine now, thank you.
Great!

Locking thread