포트 LISTENING 상태 모니터 (다중 파라미터) SystemCenter2009. 1. 8. 19:12
Monitor -> New -> Scripting -> Timed Script Two State Monitor
Parameters
[Port Number] [Port Number] [Port Number] ....
State Expression
For Unhealthy Expression Property[@Name='State'] Equals Good
For Healthy Expresion Property[@Name='State'] Equals Bad
Alert Description
$Data/Context/Property[@Name='Message']$
---------------------------------------------------------------------------------------------------------------
Check.Port.vbs
Dim oAPI, oBag, PortNumber(), strReturn(), strMessage
strMessage = ""
Set oAPI = CreateObject("MOM.ScriptAPI")
Set oBag = oAPI.CreatePropertyBag()
Set oArgs = WScript.Arguments
ParamCount = oArgs.Count
State = 0
If ParamCount < 1 Then
Call oAPI.LogScriptEvent("Check.Port.vbs", 5009, 0, "Script aborted. Not enough parameters provided.")
WScript.Quit -1
End If
ReDim Preserve PortNumber(ParamCount), States(ParamCount), strReturn(ParamCount)
set shellobj=WScript.CreateObject("WScript.Shell")
i = 0
Do While i <> ParamCount
PortNumber(i) = oArgs(i)
val = 0
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile (".\RUNNETSTAT.BAT", 8, True)
objTextFile.WriteLine("netstat -an -p tcp | findstr LISTENING | findstr /C:" & chr(34) & ":" & PortNumber(i)) & " " & chr(34)
objTextFile.Close
set objTextFile = nothing
set execObj=shellobj.Exec(".\RUNNETSTAT.BAT")
OutData=execObj.StdOut.ReadAll()
val=execObj.StdOut.Line - 3
If val => 1 Then
strReturn(i) = "LISTENING"
Call oBag.AddValue("Port " & PortNumber(i),strReturn(i))
Else
strReturn(i) = "NOT LISTENING"
Call oBag.AddValue("Port " & PortNumber(i),strReturn(i))
State = 1
End If
strMessage = strMessage & "Port " & PortNumber(i) & ": " & strReturn(i) & " | "
Set aFile = objFSO.GetFile(".\RUNNETSTAT.BAT")
aFile.Delete
Set aFile = nothing
Set execObj = nothing
i = i + 1
Loop
set shellobj=nothing
If State = 0 Then
Call oBag.AddValue("State","Good")
Else
Call oBag.AddValue("State","Bad")
End If
Call oBag.AddValue("Message", strMessage)
Call oAPI.Return(oBag)