3

Hello,

I wonder if anyone can please assist me, I am trying to create a 2 State Monitor to alert if a FTP connection fails. I am using the PowerShell script was written by Peter Zerger  (see http://www.systemcentercentral.com/monitoring-ftp-site-availability-in-opsmgr-using-powershell/)

The script works perfectly without any issues when running this from PowerShell, But the 2 State monitor never changes, it always remains in a healthly state, not sure what to try next also is there away of checking what values are being sent back in the Property bag?. I am new to PowerShell so can anyone assist please.

 

$ScomAPI = New-Object -comObject “MOM.ScriptAPI”

$PropertyBag = $ScomAPI.CreatePropertyBag()

 

# Get the object used to communicate with the server.

$Request = [System.Net.WebRequest]::Create(“ftp:ftp URL goes in here/”)

$Request.Method = [System.Net.WebRequestMethods+Ftp]::ListDirectoryDetails

# This example assumes the FTP site uses anonymous logon.

# Username/password not real

$Request.Credentials = New-Object System.Net.NetworkCredential “username”,password

$Response = $Request.GetResponse()

$ResponseStream = $Response.GetResponseStream()

# Read and display the text in the file

$Reader = new-object System.Io.StreamReader $Responsestream

[System.Console]::Writeline($Reader.ReadToEnd())

# Display Status

“Download Complete, status:”

$response.StatusDescription

 

if ($response.StatusDescription -match ‘226’){

#{“Response code is 226. Health is GOOD”} #testing only. Comment out this line for production use.

#Write-Host “We hit a TRUE match”

$PropertyBag.AddValue(“state”,”GOOD”)

#Submit Property Bag

#$API.Return($Bag) #for testing only. Comment out this line for production use.

$PropertyBag #For production use. Un-comment this line for production use.

}

else {

#{“Response code not 226. Health is BAD”} #testing only. Comment out this line for production use.

#If not exists STATE=BAD

#Write-Host “We hit a False match”

$PropertyBag.AddValue(“state”,”BAD”)

#Submit Property Bag

#$API.Return($Bag) #for testing only. Comment out this line for production use.

$PropertyBag #For production use. Un-comment this line for production use.

}

# Close Reader and Response objects

$Reader.Close()

$Response.Close()

 

The Monitor Unhealthily Expression reads:

Property[@Name=’state’] Equals GOOD (Please note I have set this intentionally to generate an alert)

so in theory it should generate an alert

 

The Monitor Healthy Expression reads:

Property[@Name=’state’] Equals BAD

Prakash Bhimji selected answer