달력

1

« 2025/1 »

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

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)

:
Posted by 커널64