Check Value from PowerShell Script/Set Warning or Critical

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
mbishop4
Posts: 11
Joined: Tue Jul 14, 2020 10:08 am

Check Value from PowerShell Script/Set Warning or Critical

Post 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?
User avatar
mbellerue
Posts: 1403
Joined: Fri Jul 12, 2019 11:10 am

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

Post 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.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.

Be sure to check out our Knowledgebase for helpful articles and solutions!
mbishop4
Posts: 11
Joined: Tue Jul 14, 2020 10:08 am

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

Post by mbishop4 »

I did set up condition checking on exit and it does work fine now, thank you.
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

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

Post by scottwilkerson »

mbishop4 wrote:I did set up condition checking on exit and it does work fine now, thank you.
Great!

Locking thread
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
Locked