Current Sensor Monitor

PowerToolsShm.Shm.CurrentSensor.Monitor.vbs (UnitMonitor)

Description for the new unit monitor.

Element properties:

TargetPowerToolsShm.EnclosureCurrentSensor
Parent MonitorSystem.Health.EntityState
CategoryAvailabilityHealth
EnabledTrue
Alert GenerateFalse
Alert Auto ResolveFalse
Monitor TypeMicrosoft.Windows.TimedScript.ThreeStateMonitorType
RemotableTrue
AccessibilityInternal
RunAsDefault

Source Code:

<UnitMonitor ID="PowerToolsShm.Shm.CurrentSensor.Monitor.vbs" Accessibility="Internal" Enabled="true" Target="PowerToolsShm.EnclosureCurrentSensor" ParentMonitorID="Health!System.Health.EntityState" Remotable="true" Priority="Normal" TypeID="Windows!Microsoft.Windows.TimedScript.ThreeStateMonitorType" ConfirmDelivery="false">
<Category>AvailabilityHealth</Category>
<OperationalStates>
<OperationalState ID="Error" MonitorTypeStateID="Error" HealthState="Error"/>
<OperationalState ID="Warning" MonitorTypeStateID="Warning" HealthState="Warning"/>
<OperationalState ID="Success" MonitorTypeStateID="Success" HealthState="Success"/>
</OperationalStates>
<Configuration>
<IntervalSeconds>900</IntervalSeconds>
<SyncTime/>
<ScriptName>EnclosureElementMonitor.vbs</ScriptName>
<Arguments>currentsensors $Target/Property[Type="PowerToolsShm.EnclosureCurrentSensor"]/EnclosureWWID$ $Target/Property[Type="PowerToolsShm.EnclosureCurrentSensor"]/ElementIndex$</Arguments>
<ScriptBody><Script>Option Explicit

Const HKEY_LOCAL_MACHINE = &amp;H80000002

Dim restReq, url, userName, password, oAPI, oBag

Dim elementType, uid, encId

elementType = WScript.Arguments(0)
encId = WScript.Arguments(1)
uid = WScript.Arguments(2)

Set restReq = CreateObject("MSXML2.ServerXMLHTTP")
restReq.setTimeouts 5000, 5000, 240000, 240000

' Instantiate MOM API
Set oAPI = CreateObject("MOM.ScriptAPI")
Set oBag = oAPI.CreatePropertyBag()

On Error Resume Next

'''''''''''''''''''''''''''''''''''''''''
Dim restUrl, value

dim sRegValue
sRegValue = ReadRegStr (HKEY_LOCAL_MACHINE, "SOFTWARE\Dell, Inc.\PowerTools\ServerHardwareManager\ServerManager", "RestAddress", 64)

if err.number &lt;&gt; 0 then
call oAPI.LogScriptEvent("DriveMonitor",8002,1,"Error (" &amp; restReq.status &amp; ") connecting to REST server (will attempt to use default 127.0.0.1:8012")
restUrl= "http://127.0.0.1:8012"
else

restUrl = "http://" &amp; sRegValue
end if

url = restUrl &amp; "/api/SEM/1.0/enc/" &amp; encId &amp; "/" + elementType + "/" + uid + "/status"
'call oAPI.LogScriptEvent("DriveMonitor",8003,1,url)
'''''''''''''''''''''''''''''''''''''''''

restReq.open "GET", url, false
restReq.send

If restReq.Status &gt;= 400 And restReq.Status &lt;= 599 Then
WScript.echo "Error communicating with REST server"
call oAPI.LogScriptEvent("SHM Enclosure Element Monitor",8001,1,"Error connecting to REST server: " &amp; restReq.Status)
End If

Dim ResultArray,i

ResultArray = Split(restReq.responseText,"\n")

Dim errorPos
errorPos = InStr(restReq.responseText,"No target objects found for specified criteria.")

if (errorPos &lt;= 0) then

Dim statusPos, startPos, endPos, statusString
WScript.echo restReq.responseText
WScript.echo """Status"":"
statusPos = InStr(restReq.responseText,"""Status"":")
WScript.echo statusPos

If (statusPos &gt; 0) Then
' find next two quotes
startPos = InStr(statusPos+8,restReq.responseText,"""")
WScript.echo startPos

endPos = InStr(startPos+1,restReq.responseText,"""")
WScript.echo endPos

' between the two quotes is the status
statusString = Mid(restReq.responseText,startPos+1,endPos-startPos-1)
WScript.echo statusString
end if

If len(statusString) = 0 then
call oAPI.LogScriptEvent("EnclosureMonitor",8005,1,"Status=" &amp; statusString &amp; "____" &amp; url)
End If

call oBag.AddValue("Status",statusString)
end if

call oAPI.Return(oBag)

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function ReadRegStr (RootKey, Key, Value, RegType)
Dim oCtx, oLocator, oReg, oInParams, oOutParams

Set oCtx = CreateObject("WbemScripting.SWbemNamedValueSet")
oCtx.Add "__ProviderArchitecture", RegType

Set oLocator = CreateObject("Wbemscripting.SWbemLocator")
Set oReg = oLocator.ConnectServer("", "root\default", "", "", , , , oCtx).Get("StdRegProv")

Set oInParams = oReg.Methods_("GetStringValue").InParameters
oInParams.hDefKey = RootKey
oInParams.sSubKeyName = Key
oInParams.sValueName = Value

Set oOutParams = oReg.ExecMethod_("GetStringValue", oInParams, , oCtx)

ReadRegStr = oOutParams.sValue
End Function


</Script></ScriptBody>
<SecureInput/>
<TimeoutSeconds>60</TimeoutSeconds>
<ErrorExpression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="String">Property[@Name='Status']</XPathQuery>
</ValueExpression>
<Operator>Equal</Operator>
<ValueExpression>
<Value Type="String">CRITICAL</Value>
</ValueExpression>
</SimpleExpression>
</ErrorExpression>
<WarningExpression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="String">Property[@Name='Status']</XPathQuery>
</ValueExpression>
<Operator>Equal</Operator>
<ValueExpression>
<Value Type="String">NON CRITICAL</Value>
</ValueExpression>
</SimpleExpression>
</WarningExpression>
<SuccessExpression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="String">Property[@Name='Status']</XPathQuery>
</ValueExpression>
<Operator>Equal</Operator>
<ValueExpression>
<Value Type="String">OK</Value>
</ValueExpression>
</SimpleExpression>
</SuccessExpression>
</Configuration>
</UnitMonitor>