Create a calculated SNMP monitor

Sometimes you need a SCOM monitor which was calculated from one or more SNMP values. Maybe the values have to be calculated, cause the value is in an unhandy format or unit. In this example i will monitor the input frequency for an for an UPS. The originaly readed value is in 1/10 Hz, but i like to monitor in Hz.

Create the monitor

Select Timed Script Two State Monitor and select the destination managementpack.

Insert this code to the field Script:

Dim oAPI, oBag
Set oAPI = CreateObject("MOM.ScriptAPI")
On Error Resume Next
Dim oArgs
Set oArgs = WScript.Arguments
strDeviceIP = oArgs(0)
strCommunity = Decode(oArgs(1))
set objSNMP = CreateObject("OlePrn.OleSNMP")
objSNMP.Open strDeviceIP, strCommunity, 2, 1000
intValue = Int(objSNMP.Get("."))
intValue = intValue / 10

' Return the values to SCOM
Set oBag = oAPI.CreatePropertyBag()
If intValue < 45 Or intValue > 55 Then
   Call oBag.AddValue("devState", "BAD")
   Call oBag.AddValue("devState", "GOOD")
End If
Call oBag.AddValue("PerfValue", intValue )
Call oAPI.Return(oBag)

Function Decode(strB64)
' decode CommunityString
   strXML = "<B64DECODE xmlns:dt=" & Chr(34) & _
   "urn:schemas-microsoft-com:datatypes" & Chr(34) & " " & _
   "dt:dt=" & Chr(34) & "bin.base64" & Chr(34) & ">" & _
   strB64 & "</B64DECODE>"
   Set oXMLDoc = CreateObject("MSXML2.DOMDocument.3.0")
   decode = oXMLDoc.selectsinglenode("B64DECODE").nodeTypedValue
   set oXMLDoc = nothing
End Function

As you see, you have to define the SNMP OID in the script. After this you can calculate with the returned value and define rules for the GOOD and BAD state.

To get the devices ip address and communitystring, you have to define this parameters, which could be readed by the script with Wscript.Arguments. Click to the Parameters-button:

$Target/Property[Type="MicrosoftSystemCenterNetworkDeviceLibrary6172210!Microsoft.SystemCenter.NetworkDevice"]/IPAddress$ $Target/Property[Type="MicrosoftSystemCenterNetworkDeviceLibrary6172210!Microsoft.SystemCenter.NetworkDevice"]/CommunityString$ $Target/Property[Type="MicrosoftSystemCenterNetworkDeviceLibrary6172210!Microsoft.SystemCenter.NetworkDevice"]/Version$

Please note, that all parameters have to be insert as one (1) line, separated only with a space.

You created your first calculated SNMP monitor, but you didn’t enable it. To enable it, you have to create an override for a group, containing the desired devices.