
Cinemark Infrati (Customer) asked a question.
Hi Guys
We are trying to perform monitoring via PowerShell monitor, specifically monitoring an IIS pool on our Windows machines.
We were able to perform the monitoring, which returned a 200 error (via a link health check). However, we would like WUG to automatically restart this pool whenever it receives any error other than a 200 error.
Is this possible? If so, could you help us with our code? We tried several ways, but the IIS pool wasn't restarted.
Here's the code we're using:
http://" + $Context.GetProperty("Address") + "/apolo/services/sales/hc"
$AppPoolName = "apolosales"
$Headers = @{
"Content-Type" = "application/json"
}
$Response = Invoke-RestMethod -Uri $URL -Method Post -Headers $Headers
if ($Response = "False"){
$Context.SetResult(0, $Response)
}
else {
& "$env:SystemRoot\System32\inetsrv\appcmd.exe" start apppool "$AppPoolName"
$Context.SetResult(1, $Response)
}
Regards,
You could write it into this script to look at the response from the API, or you could create a PowerShell Action and then add the action to an action policy and apply it to the monitor, so what the monitor goes down, the action will fire to restart the app pool.
You should separate between monitor and action. Here is a PowerShell monitor to look for IIS app pool status: https://github.com/progress/WhatsUp-Gold-Script-Examples/blob/main/powershell%20active%20monitors/IIS%20App%20Pool%20Status.ps1
You can then separately create a PowerShell action to trigger when the monitor is unavailable.
I hope this helps!