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.stdoutbl_Healthy = false
Do until oStdOut.AtEndofStream
sLine = “”
sLine = oStdOut.ReadLine
if instr(sLine, “LISTENING”) > 0 and instr(sLine,”:” & nPortToCheck) then
bl_healthy = true
end if
loop
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.
It looks like netstat needs -p instead of -proto in my case. Also, I’m sometimes getting a Status code of 1 or 128 back from Exec(). Should Run() be used instead?
Sorry, been pretty busy lately. I’ll have a look into the errors, are you seeing any patterns?
What if I wanted to monitor a second port with the same monitor (ie: SIP for 5060/5070)?