Page 1 of 1

Script help pliz

Posted: Sat Feb 27, 2021 4:13 am
by mocosoft
Hi, I am running a powershell script which stops and starts a service, it is a very simple one that stops a service, waits a number of seconds then restarts the service and sends an email as below

Service enters critical state

Calls this command
$USER1$/check_ncpa.py -H $HOSTADDRESS$ -t 'mytoken' -P 5693 -M 'plugins/myscript.ps1' -q "args=-servicename myservice -waittorestart 5"

Which in turn calls myscript.ps1

stop-Service $servicename
start-sleep $waittorestart
start-Service $servicename
postie -host:my host -to:my to email address -from:my from email address -s:"My subject" -msg:"my message here"

My issue is when I call this script it seems to run and restart the service when the check enters critical and then runs again when it changes back to OK from critical

Can anyone assist me please

Thanks in advance

Re: Script help pliz

Posted: Tue Mar 02, 2021 6:07 am
by IPOInS
This sounds like an event handler issue based on the change of HARD state. How is the script actually called?

This documentation shows how you can perform conditional actions based on the state e.g. only if it's HARD and CRITICAL do something.
https://assets.nagios.com/downloads/nag ... dlers.html