Fans Unit State Unit Monitor

Huawei.Server.HuaweiFansUnitStateUnitMonitor (UnitMonitor)

Description for the new unit monitor.

Element properties:

TargetHuawei.Server.ServerFansUnit
Parent MonitorSystem.Health.AvailabilityState
CategoryAvailabilityHealth
EnabledTrue
Alert GenerateFalse
Alert Auto ResolveFalse
Monitor TypeMicrosoft.Windows.TimedScript.ThreeStateMonitorType
RemotableTrue
AccessibilityInternal
RunAsDefault

Source Code:

<UnitMonitor ID="Huawei.Server.HuaweiFansUnitStateUnitMonitor" Accessibility="Internal" Enabled="true" Target="Huawei.Server.ServerFansUnit" ParentMonitorID="Health!System.Health.AvailabilityState" 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>1800</IntervalSeconds>
<SyncTime/>
<ScriptName>FansUnitStateUnitMonitor.vbs</ScriptName>
<Arguments>$MPElement$ $Target/Id$ $Config/Computer$ $Target/Property[Type="Huawei.Server.ServerFansUnit"]/DeviceID$</Arguments>
<ScriptBody><Script>
'**********************************************************************************
' Script Name - FansUnitStateUnitMonitor
' Author:
'
' Description:
' Determine Unit Monitor health for fans
'
' (c) Copyright Huawei Inc. 2013 - All rights reserved
'**********************************************************************************
Option Explicit
On Error Resume Next

Dim oArgs
Set oArgs = WScript.Arguments
if oArgs.Count &lt; 4 Then
Wscript.Quit -1
End If

Dim strComputer, objHuaweiConnection, LogMessage, sQuery, colItems, objItemFan, FanStatus, TargetComputer, prmDeviceID, timer
TargetComputer = oArgs(2)
strComputer = "."
prmDeviceID = oArgs(3)
timer = 3000 * prmDeviceID
WScript.Sleep(timer)
set objHuaweiConnection = GetObject("winmgmts:" &amp; "{impersonationLevel=impersonate}!\\" &amp; strComputer &amp; "\root\cimv2\Huawei")
If Err.Number &lt;&gt; 0 Then
LogMessage = "WMI Cimv2Huawei Error Number : " &amp; Err.Number &amp; ". Description :" &amp; Err.Description
Err.Clear
Else
If IsEmpty(objHuaweiConnection) Then
LogMessage = "Unable to open WMI Namespace root-cimv2-Huawei. Check to see if the WMI service is enabled and running, and Install/Re-Install BMA to ensure this WMI namespace exists. " &amp; Err
Else
sQuery = "Select * from Huawei_FanInfo WHERE FanId = " &amp; prmDeviceID
MOMDebugLog(sQuery)
'Set colItems = objHuaweiConnection.ExecQuery(sQuery)
Set colItems = GetObjectSet(objHuaweiConnection, sQuery, "FanHealth", "Huawei_FanInfo")

If Err.Number &lt;&gt; 0 Then
LogMessage = sQuery &amp; " Error Number:" &amp; Err.Number &amp; "Description:" &amp; Err.Description
If Err.Number = -2147023169 Then
LogMessage = "RPC Failure occurred for namespace root-cimv2-Huawei"
End If
Err.Clear
End If
If colItems is Nothing Then
LogMessage = "Unable to retrieve Huawei_FanInfo object"
Else
LogMessage = "Huawei_FanInfo object retrieved"
For Each objItemFan in colItems
If Err.Number &lt;&gt; 0 Then
If Err.Number = -2147023169 Then
LogMessage = "RPC Failure occurred for cimv2\Huawei - bmc info : " &amp; Err.Number
ElseIf Err.Number = -2147217389 Then
LogMessage = "If PWS present, Please Install/Re-Install BMA on Dell Server : " &amp; Err.Number
Else
LogMessage = "Object RetrievalLoop Error Number:" &amp; Err.Number &amp; "Description:" &amp; Err.Description
End If
Err.Clear
End If
MOMDebugLog(LogMessage)
If Not objItemFan is Nothing Then
FanStatus = objItemFan.FanHealth
MOMDebugLog("Fan" &amp; prmDeviceID &amp; " FanHealth: " &amp; FanStatus)
MOMDebugLog(FanStatus)
End If
Next
End If 'colItems is nothing
Set colItems = Nothing
End If 'objHuaweiConnection is noting

End If


If FanStatus = "Warning" OR FanStatus = "Ok" Then
else
FanStatus = "OK"
End If
MOMDebugLog("Fan" &amp; prmDeviceID &amp; " Status: " &amp; FanStatus)
Dim oAPI, oBag
Set oAPI = CreateObject("MOM.ScriptAPI")
Set oBag = oAPI.CreatePropertyBag()
Call oBag.AddValue("Status",FanStatus)
Call oAPI.Return(oBag)


' *** Add double query fix

' Function to retrieve the object

Function GetObjectSet(ByRef objHuaweiConnection, SelectQuery, Attribute, objName)
Dim retry, retryFlag
Dim objItem, arrURL, logMessage

On Error Resume Next
RetryFlag = False
For retry = 0 To 1
MOMDebugLog 1, "Retrying for " &amp; retry &amp; " time..."
Set GetObjectSet = objHuaweiConnection.ExecQuery(SelectQuery)
LogErrorNumber(objName)
If (GetObjectSet is Nothing) Or (IsNull(GetObjectSet)) Then
logMessage = "INFO: Unable to retrieve " &amp; objName &amp; " Attributes"
MOMDebugLog 1, logMessage
WScript.Sleep(1000)
RetryFlag = True
Else
logMessage= "INFO: " &amp; objName &amp; " attributes retrieved successfully"
MOMDebugLog 1, logMessage
If Attribute = "__COUNT__" Then
Exit For
End If
For Each objItem in GetObjectSet
If LogErrorNumber(objName) = 0 Then
If Not objItem is nothing Then
Dim attrVal : attrVal = objItem.Properties_.Item(Attribute)
If IsNull(attrVal) Or Len(attrVal) &lt;= 0 Then
MOMDebugLog 1, Attribute &amp; " value is null or empty"
RetryFlag = True
WScript.Sleep(500)
Exit For
Else
Exit Function
End If
End If
End If
Next
If RetryFlag = False Then
Exit For
End If
End If
Next
End Function

Function LogErrorNumber(objName)
Dim logMessage
LogErrorNumber = Err.Number
If Err.Number &lt;&gt; 0 Then
Select Case Err.Number
Case -2147749904
logMessage = "CIM Object not found"
Case -2147749902
logMessage = "Dell CIM object not found"
Case -2147023169
logMessage = "RPC Failure occurred for namespace root-cimv2-huawei"
Case -2147217389
logMessage = "Please Install/Re-Install BMA on Dell Server!"
Case -2147217394 '0x8004100E
logMessage = "Not able to find Dell CIM object"
Case -2147217392 '0x8004100C
logMessage = "Not able to find the collection"
Case -2147749890
logMessage = "Object cannot be found"
Case -2147749892
logMessage = "Object cannot be found"
Case Else
logMessage = "Unable to retrieve " &amp; objName
logMessage = logMessage &amp; " Err Number:" &amp; Err.Number
logMessage = logMessage &amp; " Err Descr:" &amp; Err.Description
End Select
MOMDebugLog 1, "ERROR: " &amp; logMessage
End If
End Function

'*****************************************************************
' Function MOMDebugLog
' Add LogMessage Header - ScriptName and Time and Logging it.
'*****************************************************************
Public Function MOMDebugLog (ByVal strMessage)

Const ForReading = 1, ForWriting = 2, ForAppending = 8

Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile("c:\Storage.txt", ForAppending, True)
f.WriteLine strMessage
f.Close

End Function
</Script></ScriptBody>
<TimeoutSeconds>300</TimeoutSeconds>
<ErrorExpression>
<SimpleExpression>
<ValueExpression>
<XPathQuery>Property[@Name='Status']</XPathQuery>
</ValueExpression>
<Operator>Equal</Operator>
<ValueExpression>
<Value Type="String">Error</Value>
</ValueExpression>
</SimpleExpression>
</ErrorExpression>
<WarningExpression>
<SimpleExpression>
<ValueExpression>
<XPathQuery>Property[@Name='Status']</XPathQuery>
</ValueExpression>
<Operator>Equal</Operator>
<ValueExpression>
<Value Type="String">Warning</Value>
</ValueExpression>
</SimpleExpression>
</WarningExpression>
<SuccessExpression>
<SimpleExpression>
<ValueExpression>
<XPathQuery>Property[@Name='Status']</XPathQuery>
</ValueExpression>
<Operator>Equal</Operator>
<ValueExpression>
<Value Type="String">Ok</Value>
</ValueExpression>
</SimpleExpression>
</SuccessExpression>
</Configuration>
</UnitMonitor>