Run Powershell on critical check

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
User avatar
JohnFLi
Posts: 521
Joined: Mon Jun 17, 2013 3:11 pm

Run Powershell on critical check

Post by JohnFLi »

I have some basic Nagios checks that run against windows servers......C drive, cpu, memory etc.....
but what I want to do is if a check (CPU for example) returns with a critical, then I want a powershell script to run.

How to??
Everybody is somebody else’s weirdo
dwasswa

Re: Run Powershell on critical check

Post by dwasswa »

Hi @JohnFLi,

Given what you are trying to accomplish, event handlers are just the thing you need.

Event handlers are optional system commands (scripts or executables) that are run when a host or service
state change occurs. These commands include, but are not limited to, restarting services, parsing logs,
checking other host or service states, making database calls, etc. The possibilities are near limitless.
Essentially, through event handlers, Nagios XI is capable of running any operation that can be performed from
the command line with the added ability of utilizing macros passed by Nagios XI.

Please follow this guide on how to configure event handlers:
How to configure Event Handlers

Please let me know if you any questions.
User avatar
JohnFLi
Posts: 521
Joined: Mon Jun 17, 2013 3:11 pm

Re: Run Powershell on critical check

Post by JohnFLi »

The only thing I see in there shows directly running the 'event handler', not running it IF a state is critical. In the example from that link.....the test check is running a .sh file

so basicly, I don't see on how running a script each time (no matter if its up, down or sideways) is anything different than a regular check.
Everybody is somebody else’s weirdo
User avatar
mcapra
Posts: 3739
Joined: Thu May 05, 2016 3:54 pm

Re: Run Powershell on critical check

Post by mcapra »

So perhaps our remote Windows machine is running NSClient++. NSClient++ has all sorts of commands you can call remotely from the Nagios XI machine via check_nrpe. Commands for checking disk, cpu, drives, counters, and all sorts of custom commands that you can configure yourself. What if, instead of that custom command being responsible for checking some obscure piece of the Windows machine, it instead was responsible for restarting a service? Killing a process?

That is essentially what this documentation gets at. Configuring a custom command within a NSClient++ configuration that restarts a service, then calling that custom command from Nagios XI:
https://assets.nagios.com/downloads/nag ... ios-XI.pdf
Last edited by mcapra on Tue Oct 10, 2017 3:44 pm, edited 2 times in total.
Former Nagios employee
https://www.mcapra.com/
dwasswa

Re: Run Powershell on critical check

Post by dwasswa »

Thanks @mcapra.
User avatar
JohnFLi
Posts: 521
Joined: Mon Jun 17, 2013 3:11 pm

Re: Run Powershell on critical check

Post by JohnFLi »

go ahead and close this thread as it isn't providing anything usefull
Everybody is somebody else’s weirdo
User avatar
cdienger
Support Tech
Posts: 5045
Joined: Tue Feb 07, 2017 11:26 am

Re: Run Powershell on critical check

Post by cdienger »

The HOSTSTATE and HOSTSTATETYPE variables can be used in the script to determine the state and state type of a service or host and then execute commands based on them. Hope this helps.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
Locked