Description for the new unit monitor.
Target | Huawei.Server.ServerFansUnit |
Parent Monitor | System.Health.AvailabilityState |
Category | AvailabilityHealth |
Enabled | True |
Alert Generate | False |
Alert Auto Resolve | False |
Monitor Type | Microsoft.Windows.TimedScript.ThreeStateMonitorType |
Remotable | True |
Accessibility | Internal |
RunAs | Default |
<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 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 < 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:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2\Huawei")
If Err.Number <> 0 Then
LogMessage = "WMI Cimv2Huawei Error Number : " & Err.Number & ". Description :" & 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. " & Err
Else
sQuery = "Select * from Huawei_FanInfo WHERE FanId = " & prmDeviceID
MOMDebugLog(sQuery)
'Set colItems = objHuaweiConnection.ExecQuery(sQuery)
Set colItems = GetObjectSet(objHuaweiConnection, sQuery, "FanHealth", "Huawei_FanInfo")
If Err.Number <> 0 Then
LogMessage = sQuery & " Error Number:" & Err.Number & "Description:" & 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 <> 0 Then
If Err.Number = -2147023169 Then
LogMessage = "RPC Failure occurred for cimv2\Huawei - bmc info : " & Err.Number
ElseIf Err.Number = -2147217389 Then
LogMessage = "If PWS present, Please Install/Re-Install BMA on Dell Server : " & Err.Number
Else
LogMessage = "Object RetrievalLoop Error Number:" & Err.Number & "Description:" & Err.Description
End If
Err.Clear
End If
MOMDebugLog(LogMessage)
If Not objItemFan is Nothing Then
FanStatus = objItemFan.FanHealth
MOMDebugLog("Fan" & prmDeviceID & " FanHealth: " & 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" & prmDeviceID & " Status: " & 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 " & retry & " time..."
Set GetObjectSet = objHuaweiConnection.ExecQuery(SelectQuery)
LogErrorNumber(objName)
If (GetObjectSet is Nothing) Or (IsNull(GetObjectSet)) Then
logMessage = "INFO: Unable to retrieve " & objName & " Attributes"
MOMDebugLog 1, logMessage
WScript.Sleep(1000)
RetryFlag = True
Else
logMessage= "INFO: " & objName & " 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) <= 0 Then
MOMDebugLog 1, Attribute & " 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 <> 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 " & objName
logMessage = logMessage & " Err Number:" & Err.Number
logMessage = logMessage & " Err Descr:" & Err.Description
End Select
MOMDebugLog 1, "ERROR: " & 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
</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>