This discussion has been locked. The information referenced herein may be inaccurate due to age, software updates, or external references.
You can no longer post new replies to this discussion. If you have a similar question you can start a new discussion in this forum.

Return Good status if service is stopped and Bad/Critical status if service is running - Reverse Service Status

Some times you get a requirement where you have to monitor a service/process if it is running i.e. monitor and tell me if this service is running and if it is not running then everything is fine. Also turn the status of the application template into green colour if service is stopped and turn it red if it is running. Below is the custom power shell script that can be applied on the windows machine whose services need to be monitored as in above mentioned scenarios.

*****************************************************************************

$a="Running"

$stat=Get-Service "Service_Name"

$c=$stat.status

if ($c -eq $a){

write-host "Statistic: 1";

Write-host "Message: Service is $c";

exit 3;

}

else{

write-host "Statistic: 0";

Write-host "Message: Service is $c";

exit 0;

}

******************************************************************************

Remove double quotes above while giving the exact service name. You can also use arguments if there are multiple services to monitor.

Parents Reply Children
No Data