Create a calculated SNMP Rule in SCOM

Sometimes you need a SCOM Rule 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 create a Rule and a Performance View to show the autonomny time for an APC UPS. The originaly readed value is in 1/100 seconds, but i want it to show in minutes.

Creating the Rule

Insert this Code to the field Script:

Dim oAPI, oBag
Set oAPI = CreateObject("MOM.ScriptAPI")
On Error Resume Next
err.clear
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(".1.3.6.1.4.1.318.1.1.1.2.2.3.0"))
if err.number = 0 then
   ' You can calculate the value here
   ' 1/100seconds to seconds
   intValue = intValue / 100
   ' seconds to minutes
   intValue = intValue / 60
end if
' Return the values to SCOM
Set oBag = oAPI.CreatePropertyBag()
Call oBag.AddValue("DeviceIP", strDeviceIP)
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")
   oXMLDoc.LoadXML(strXML)
   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. To get the devices ip address and communitystring, you have to define this parameters, which could be readed by the script with Wscript.Arguments:

$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.

The evaluated values in the fields Instance and Value are derived from the vbscript’s object oBag.

Set oBag = oAPI.CreatePropertyBag()
Call oBag.AddValue("DeviceIP", strDeviceIP)
Call oBag.AddValue("PerfValue", intValue )
Call oAPI.Return(oBag)

Override the Rule for a group

Override the Rule to enable it for a specified group

Create the Performance View

Create a Performance View for the already defined Object name: