Forum Discussion

Idan's avatar
8 years ago

Webservice monitor


Below is a Powershell script to monitor a WebService that need NTLM authentication,

The script will return the status code and has an option to search a text in the results (e.g. of the response is a web page or XML) and check if a string exists.

I created 3 data points:


ResponseTime (responseTime    None. Use the value directly)



You can create an alert if the status code is !=200 or the ResponseTime is more than X ms.

Hope you will find it useful

$username = "##wmi.user##"
$password =  "##wmi.pass##"
$strintToFind = "ProbersTypes"

$webclient = new-object System.Net.WebClient
$webclient.Credentials = new-object System.Net.NetworkCredential($username, $password)
$webpage = $webclient.DownloadString($url)
$WebOutput =  $webclient.DownloadString($url)

$req = [system.Net.WebRequest]::Create($url)
# method 1 $req.UseDefaultCredentials = $true
$req.Credentials = new-object System.Net.NetworkCredential($username, $password); 

    $res = $req.GetResponse()
catch [System.Net.WebException]
    $res = $_.Exception.Response

$int = [int]$res.StatusCode
$status = $res.StatusCode

if ($WebOutput.Contains($strintToFind)) 

    write-host "FoundString= 1"

    write-host "FoundString= 2"

write-host "StatusCode="$int
write-host "StatusDetails="$status