Due to the way our firewalls are configured we can't use WPM to monitor the status of url's. I wrote the powershell below to get around that.
It works just fine when run in the powershell ISE on the main poller, but when run as a SAM component monitor it fails to bring back the status. It's almost like it's being blocked by the proxy when run as a SAM component, but I don't see how that can be the case when it's the same script running on the same server testing connectivity to the same url. $args[0] is the caption for the url.
$ProxPass = ConvertTo-SecureString "securepass" -AsPlainText -Force
$ProxCred = New-Object System.Management.Automation.PSCredential -ArgumentList "domain\secureuser",$ProxPass
$proxy = "proxy:8080"
$uri = $args[0]
try{
$Response = Invoke-WebRequest -Proxy $proxy -ProxyCredential $ProxCred -Uri "https://$uri"
$StatusCode = $Response.StatusCode
}
catch{
$StatusCode = $_.Exception.Response.StatusCode.Value__
}
if ($StatusCode -match "2[0,1][0-9]"){
$Statistic = '0'
$Message = "Website Available: $StatusCode"
}
else {
$Statistic = '1'
$Message = "Website Unavailable: $StatusCode"
}
Write-Host "Statistic: $Statistic";
Write-Host "Message: $URI $Message ";
exit($Statistic)