Page 1 of 1

Script help please

Posted: Wed Feb 10, 2021 8:53 am
by stepper
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