SCOM: Locally Monitoring a Listening TCP Port
August 13, 2009 3 Comments
The core logic can be seen in this excerpt:
sCmd = “netstat -an -proto TCP”
set objShell = createobject(“wscript.shell”)
set objExec = objShell.exec(sCmd)
set oStdOut = objExec.stdout
bl_Healthy = false
Do until oStdOut.AtEndofStream
sLine = “”
sLine = oStdOut.ReadLine
if instr(sLine, “LISTENING”) > 0 and instr(sLine,”:” & nPortToCheck) then
bl_healthy = true
The full script can be downloaded here (this is provided as-is, with no guarantee of function or support, test before deploying, etc).
Walkthrough on creating a corresponding Unit Monitor behind the cut
Start by creating a new two-state timed script Unit Monitor.
Provide a name and Management Pack, and target it to the Windows Computer class, be sure to deselect the “Enable” option.
Set a polling schedule.
Define the script name and timeout, and copy the text of the script into the window.
Configure the Expressions (the script will return a ‘Status’ property of OK or Error)
Configure the Health States
Configure the alert (the script will return a message string as a property with the name ‘Message’)
To enable the script, override the Enabled property for a single node or a group. To edit the port to monitor, edit the nPorttoCheck variable in the script.