Detailed Power Supply Unit Monitor

Dell.WindowsServer.Detailed.PSUnitUnitMonitor (UnitMonitor)

Knowledge Base article:

Summary

This Health Monitor fetches the State of the Dell Power Supply Sensors. The status can be one of the following three types:

Success: If the status is success, the power supply sensor returned to a normal state.

Warning: If the status is warning, the power supply sensor is reporting a warning state.

Critical: If the status is critical, the power supply sensor detected a failure state.

Causes

Warning: The cause for a Warning status may be that a power supply sensor reading in the specified system has exceeded a user-defined warning threshold.

Critical: The cause for a Critical status may be that a power supply sensor in the specified system has been disconnected, has failed, or has detected an error from which it cannot recover. Additional details are available in the product knowledge of the last modified Dell OpenManage alert that caused the state change.

Resolutions

Perform the following steps for the Warning and Critical messages:

Warning: A Warning message refers to an event that is not necessarily significant, but may indicate a possible future problem. Plan to proactively reconnect the unplugged power supply or change the failed power supply, based on the impact to operations, if the power supply sensor goes to a critical state.

Critical: A Critical message refers to a significant event that indicates actual or imminent loss of data or loss of function. Reconnect the unplugged power supply or change the failed power supply. Additional details are available in the product knowledge of the last modified Dell OpenManage alert that caused the state change.

When the issue has been resolved, the status changes to Success.

Element properties:

TargetDell.WindowsServer.Detailed.PSUnit
Parent MonitorSystem.Health.AvailabilityState
CategoryCustom
EnabledTrue
Alert GenerateFalse
Alert Auto ResolveFalse
Monitor TypeMicrosoft.Windows.TimedScript.ThreeStateMonitorType
RemotableTrue
AccessibilityPublic
RunAsDefault

Source Code:

<UnitMonitor ID="Dell.WindowsServer.Detailed.PSUnitUnitMonitor" Accessibility="Public" Enabled="true" Target="Dell.WindowsServer.Detailed.PSUnit" ParentMonitorID="SystemHealth!System.Health.AvailabilityState" Remotable="true" Priority="Normal" TypeID="Windows!Microsoft.Windows.TimedScript.ThreeStateMonitorType" ConfirmDelivery="false">
<Category>Custom</Category>
<OperationalStates>
<OperationalState ID="Dell.WindowsServer.Detailed.PSUnitSuccess" MonitorTypeStateID="Success" HealthState="Success"/>
<OperationalState ID="Dell.WindowsServer.Detailed.PSUnitWarning" MonitorTypeStateID="Warning" HealthState="Warning"/>
<OperationalState ID="Dell.WindowsServer.Detailed.PSUnitFailure" MonitorTypeStateID="Error" HealthState="Error"/>
</OperationalStates>
<Configuration>
<IntervalSeconds>3600</IntervalSeconds>
<SyncTime/>
<ScriptName>DellServerPowerSupplyUnit.vbs</ScriptName>
<Arguments>$MPElement$ $Target/Id$ $Config/Computer$ $Target/Property[Type="Dell.WindowsServer.Detailed.PSUnit"]/DeviceID$</Arguments>
<ScriptBody><Script>
'**********************************************************************************
' Script Name - DellServerPowerSupplyUnit
' Author: Vignesh Pandian
'
' Description:
' Determine Unit Monitor health for ServerPowerSupplies
'
' (c) Copyright &#xA9; 2009&#x2013; 2017 Dell Inc, or its subsidiaries. All Rights Reserved
'**********************************************************************************
Option Explicit
On Error Resume Next
SetLocale("en-us")

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

Dim strComputer, objDellConnection, logMessage, sQuery, colItems, objItemPower, PowerStatus, TargetComputer, PowerValue, prmDeviceID, i
Dim bAPI
Set bAPI = CreateObject("MOM.ScriptAPI")

TargetComputer = oArgs(2)
prmDeviceID = ""
For i=3 to (oArgs.Count-1)
prmDeviceID = prmDeviceID &amp; " " &amp; oArgs(i)
Next

strComputer = "."
PowerValue = -1

set objDellConnection = GetObject("winmgmts:" &amp; "{impersonationLevel=impersonate}!\\" &amp; strComputer &amp; "\root\cimv2\Dell")
If Err.Number &lt;&gt; 0 Then
logMessage = "WMI Cimv2Dell Error Number : " &amp; Err.Number &amp; ". Description :" &amp; Err.Description
Err.Clear
Else
If IsEmpty(objDellConnection) Then
logMessage = "Unable to open WMI Namespace root-cimv2-dell. Check to see if the WMI service is enabled and running, and Install/Re-Install ServerAdministrator to ensure this WMI namespace exists. " &amp; Err
Else
sQuery = "Select * from CIM_PowerSupply"
Set colItems = GetObjectSet(objDellConnection, sQuery, "Name", "CIM_PowerSupply")
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-dell"
End If
Err.Clear
End If
If colItems is Nothing Then
logMessage = "Unable to retrieve CIM_PowerSupply object"
Else
logMessage = "CIM_PowerSupply object retrieved"
For Each objItemPower in colItems
If Err.Number &lt;&gt; 0 Then
If Err.Number = -2147023169 Then
logMessage = "RPC Failure occurred for cimv2\dell - bmc info : " &amp; Err.Number
ElseIf Err.Number = -2147217389 Then
logMessage = "If Power present, Please Install/Re-Install ServerAdministrator on Dell Server : " &amp; fqdn2 &amp; Err.Number
Else
logMessage = "Object RetrievalLoop Error Number:" &amp; Err.Number &amp; "Description:" &amp; Err.Description
End If
Err.Clear
End If
If Not (objItemPower is Nothing) Then
If (StrComp(Trim(objItemPower.DeviceID),Trim(prmDeviceID),1)=0) Then
PowerStatus = objItemPower.Status
End If
End If
Next
End If 'colItems is nothing
Set colItems = Nothing
End If 'dellconnection is noting
On Error GoTo 0
End If

Set bAPI = Nothing

If PowerStatus = "Stressed" OR PowerStatus = "Degraded" Then
PowerStatus = "Warning"
ElseIf PowerStatus = "Non-recover" Then
PowerStatus = "Error"
End If

Dim oAPI, oBag
Set oAPI = CreateObject("MOM.ScriptAPI")
Set oBag = oAPI.CreatePropertyBag()
Call oBag.AddValue("Status",PowerStatus)
Call oAPI.Return(oBag)
'Call oAPI.LogScriptEvent("Vig4",101,2,prmDeviceID &amp; sQuery &amp; "PowerStatus=" &amp; PowerStatus)

Set oAPI = Nothing

' *** Add double query fix

' Function to retrieve the object

Function GetObjectSet(ByRef objDellConnection, 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 = objDellConnection.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-dell"
Case -2147217389
logMessage = "Please Install/Re-Install ServerAdministrator 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
'*** Add MOMDebug
Const DEBUG_LOG_FILENAME = "DellServerPowerSupplyUnit.log"
Dim loginited: loginited = False
Dim objLogTextFile, objLogFSO

Sub InitLog(strFileName)
' Begin Logheader
If logLevel &lt;&gt; 0 And loginited = False Then
Dim fileSize, strOutFile
Const ForAppending = 8
Const ForWriting = 2
Const MaxFileSize = 524288 'File Size is limited to 512 KB

dim wsShell : Set wsShell = Createobject("WScript.Shell")
dim wshSysEnv : Set wshSysEnv = wsShell.Environment
dim tFolder : tFolder = wshSysEnv("TEMP")
dim wshPrcEnv : Set wshPrcEnv = wsShell.Environment("Process")
tFolder = Replace(tFolder, "%SystemRoot%", wshPrcEnv("SYSTEMROOT"), 1, -1, vbTextCompare)

Set objLogFSO = CreateObject("Scripting.FileSystemObject")
If Not objLogFSO.FolderExists(tFolder) Then
objLogFSO.CreateFolder(tFolder)
End If
strOutFile = tFolder &amp; "\"&amp; strFileName
WScript.Echo strOutFile
If Not objLogFSO.FileExists(strOutFile) Then
Set objLogTextFile = objLogFSO.CreateTextFile(strOutFile)
objLogTextFile.Close()
End If
fileSize = objLogFSO.GetFile(strOutFile).Size
If (fileSize &gt; MaxFileSize) Then
Set objLogTextFile = objLogFSO.OpentextFile(strOutFile, ForWriting, True)
Else
Set objLogTextFile = objLogFSO.OpentextFile(strOutFile, ForAppending, True)
End If
loginited = True
MOMDebugLog 1, "------------------------------------------------------"
MOMDebugLog 1, "INFO: Script - " &amp; strFileName &amp; ": Start()"
Err.Clear
End If
End Sub

Sub MOMDebugLog (ByVal debugLevel, ByVal Message)
'On Error Resume Next
If (debugLevel &gt; 0) and (debugLevel &lt;= logLevel) Then
If loginited = False Then
InitLog DEBUG_LOG_FILENAME
End If
objLogTextFile.WriteLine(Now() &amp; " ---- " &amp; Message)
Err.Clear
End If
End Sub

Sub CloseLog
' Begin Logheader
If loginited = True Then
objLogTextFile.Close
End If
End Sub

CloseLog
</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>