Page 1 of 1

Run Powershell on critical check

Posted: Tue Oct 10, 2017 2:14 pm
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??

Re: Run Powershell on critical check

Posted: Tue Oct 10, 2017 2:24 pm
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.

Re: Run Powershell on critical check

Posted: Tue Oct 10, 2017 3:21 pm
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.

Re: Run Powershell on critical check

Posted: Tue Oct 10, 2017 3:36 pm
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

Re: Run Powershell on critical check

Posted: Tue Oct 10, 2017 3:44 pm
by dwasswa
Thanks @mcapra.

Re: Run Powershell on critical check

Posted: Tue Oct 10, 2017 3:58 pm
by JohnFLi
go ahead and close this thread as it isn't providing anything usefull

Re: Run Powershell on critical check

Posted: Tue Oct 10, 2017 4:23 pm
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.