# The below code requires DELL openmanager with WMI enabled classes to be installed, to fetch appropriate classes to get the hardware status.
param(
[Parameter(Mandatory=$True, Position=0, ValueFromPipeline=$false)]
[System.String] $component # this will take parameter as fan,memory,cpu,temp,amp,vlt,watt
)
#Write-host $component
function convertUnitModifier{
param (
[int16]$unitModifier,
[int32]$convCurrentReading
)
switch ($unitModifier)
{
0 { return($convCurrentReading) }
-1 { return($convCurrentReading/10) }
-2 { return($convCurrentReading/100) }
-3 { return($convCurrentReading/1000) }
-4 { return($convCurrentReading/10000) }
-5 { return($convCurrentReading/100000) }
-6 { return($convCurrentReading/1000000) }
default { return ($convCurrentReading) }
}
}
try
{
$ok_flag=""
$war_flag=""
$cri_flag=""
$unknown_flag=""
$undetermind_flag=""
$ObjChassis = Get-WmiObject -Namespace root\cimv2\dell -class CIM_Chassis | Select-Object DeviceID,Name,CurrentReading,Status,SystemName,UnitModifier|Sort-Object DeviceID #Chassi info
# Fan sensor check
If( $component -eq "fan")
{
# Fan Status property return states mapped w.r.t Nagios #change as required to the tool processing logic
#OK ("OK"); return(0)
#Error ("Error"); return(2)
#Degraded ("Degraded"); return(2)
#Unknown ("Unknown"); return(3)
#Pred Fail ("Pred Fail"); return(2)
#Starting ("Starting"); return(1)
#Stopping ("Stopping"); return(1)
#Service ("Service"); return(1)
#Stressed ("Stressed"); return(2)
#NonRecover ("NonRecover") or "Non-recover"; return(2)
#No Contact ("No Contact"); return(2)
#Lost Comm ("Lost Comm") return(3)
$ObjFanRpm = Get-WmiObject -Namespace root\cimv2\dell -class CIM_Tachometer | Select-Object DeviceID,Name,CurrentReading,Status,SystemName,UnitModifier|Sort-Object DeviceID #- Fans
$fname=@()
foreach($fan in $ObjFanRpm)
{
if($fan.Status -eq "OK")
{
$ok_flag=0
}
elseif($fan.Status -eq "Starting" -or $fan.Status -eq "Stopping" -or $fan.Status -eq "Service")
{
$war_flag=1
}
elseif($fan.Status -eq "Error" -or $fan.Status -eq "Degraded" -or $fan.Status -eq "Pred Fail" -or $fan.Status -eq "Stressed" -or $fan.Status -eq "NonRecover" -or $fan.Status -eq "No Contact" -or $fan.Status -eq "Non-recover")
{
$cri_flag=2
}
elseif($fan.Status -eq "Unknown" -or $fan.Status -eq "Lost Comm")
{
$unknown_flag=3
}
else
{
$undetermind_flag=4
}
$f_format= $fan.Status+":"+$fan.Name+":"+$fan.CurrentReading + "rpm;"
$fname=$fname + $f_format
}
# IF none of the status values matches then consider it as Critical
if($undetermind_flag -eq 4)
{
$cri_flag=2
}
# detrmine the state of the matched status to return the value from plugin and exit the shell
If($cri_flag -eq 2)
{
Write-Host "$fname"
exit($cri_flag)
}
if($war_flag -eq 1)
{
Write-Host "$Fname"
exit($war_flag)
}
if($unknown_flag -eq 3)
{
Write-Host "$Fname"
exit($unknown_flag)
}
if($ok_flag -eq 0)
{
Write-Host "$Fname"
exit($ok_flag)
}
}
If($component -eq "temp")
{
$ObjTemp = Get-WmiObject -Namespace root\cimv2\dell -class CIM_TemperatureSensor | Select-Object DeviceID,Name,CurrentReading,Status,SystemName,UnitModifier|Sort-Object DeviceID #- Temperature divide it by 10 to get the value in Degree Celcius
$tname=@()
$tempConv=@()
foreach ($temp in $ObjTemp)
{
$ObjTempConv = "" | Select-Object DeviceID,Name,CurrentReading,Status,SystemName
$conv_temp=convertUnitModifier -unitModifier $temp.UnitModifier -convCurrentReading $temp.CurrentReading
$ObjTempConv.DeviceID = $temp.DeviceID
$ObjTempConv.Name = $temp.Name
$ObjTempConv.CurrentReading = $conv_temp
$ObjTempConv.Status=$temp.Status
$ObjTempConv.SystemName = $temp.SystemName
$tempConv = $tempConv + $ObjTempConv
}
foreach($temp in $tempConv)
{
if($temp.Status -eq "OK")
{
$ok_flag=0
}
elseif($temp.Status -eq "Starting" -or $temp.Status -eq "Stopping" -or $temp.Status -eq "Service")
{
$war_flag=1
}
elseif($temp.Status -eq "Error" -or $temp.Status -eq "Degraded" -or $temp.Status -eq "Pred Fail" -or $temp.Status -eq "Stressed" -or $temp.Status -eq "NonRecover" -or $temp.Status -eq "No Contact" -or $temp.Status -eq "Non-recover")
{
$cri_flag=2
}
elseif($temp.Status -eq "Unknown" -or $temp.Status -eq "Lost Comm")
{
$unknown_flag=3
}
else
{
$undetermind_flag=4
}
$t_format= $temp.Status+":"+$temp.Name+":"+$temp.CurrentReading + "DegCel;"
$tname=$tname + $t_format
}
# IF none of the status values matches then consider it as Critical
if($undetermind_flag -eq 4)
{
$cri_flag=2
}
# detrmine the state of the matched status to return the value from plugin and exit the shell
If($cri_flag -eq 2)
{
Write-Host "$tname"
exit($cri_flag)
}
if($war_flag -eq 1)
{
Write-Host "$tname"
exit($war_flag)
}
if($unknown_flag -eq 3)
{
Write-Host "$tname"
exit($unknown_flag)
}
if($ok_flag -eq 0)
{
Write-Host "$tname"
exit($ok_flag)
}
}
If($component -eq "pwr")
{
$ObjPwrWatt = Get-WmiObject -Namespace root\cimv2\dell -class DELL_PowerConsumptionWattsSensor | Select-Object DeviceID,Name,CurrentReading,Status,SystemName,UnitModifier|Sort-Object DeviceID #- PoweSupply Watt
$pname=@()
$pwrConv=@()
foreach ($pwr in $ObjPwrWatt)
{
$ObjPwrWattConv = "" | Select-Object DeviceID,Name,CurrentReading,Status,SystemName
$conv_pwr=convertUnitModifier -unitModifier $pwr.UnitModifier -convCurrentReading $pwr.CurrentReading
$ObjPwrWattConv.DeviceID = $pwr.DeviceID
$ObjPwrWattConv.Name = $pwr.Name
$ObjPwrWattConv.CurrentReading = $conv_pwr
$ObjPwrWattConv.Status=$pwr.Status
$ObjPwrWattConv.SystemName = $pwr.SystemName
$pwrConv = $pwrConv + $ObjPwrWattConv
}
foreach($pwr in $pwrConv)
{
if($pwr.Status -eq "OK")
{
$ok_flag=0
}
elseif($pwr.Status -eq "Starting" -or $pwr.Status -eq "Stopping" -or $pwr.Status -eq "Service" -or $pwr.Status -eq "Warning" -or $pwr.Status -eq "Predictive Failure")
{
$war_flag=1
}
elseif($pwr.Status -eq "Error" -or $pwr.Status -eq "Degraded" -or $pwr.Status -eq "Pred Fail" -or $pwr.Status -eq "Stressed" -or $pwr.Status -eq "NonRecover" -or $pwr.Status -eq "No Contact" -or $pwr.Status -eq "Non-recover" -or $pwr.Status -eq "Non-Recoverable Error" -or $pwr.Status -eq "Non-Recoverable" -or $pwr.Status -eq "Aborted")
{
$cri_flag=2
}
elseif($pwr.Status -eq "Unknown" -or $pwr.Status -eq "Lost Comm" -or $pwr.Status -eq "Lost Communication")
{
$unknown_flag=3
}
else
{
$undetermind_flag=4
}
$p_format= $pwr.Status+":"+$pwr.Name+":"+$pwr.CurrentReading + "W;"
$pname=$pname + $p_format
}
# IF none of the status values matches then consider it as Critical
if($undetermind_flag -eq 4)
{
$cri_flag=2
}
# detrmine the state of the matched status to return the value from plugin and exit the shell
If($cri_flag -eq 2)
{
Write-Host "$pname"
exit($cri_flag)
}
if($war_flag -eq 1)
{
Write-Host "$pname"
exit($war_flag)
}
if($unknown_flag -eq 3)
{
Write-Host "$pname"
exit($unknown_flag)
}
if($ok_flag -eq 0)
{
Write-Host "$pname"
exit($ok_flag)
}
}
If($component -eq "amp")
{
$ObjPwrAmp = Get-WmiObject -Namespace root\cimv2\dell -class DELL_PowerConsumptionAmpsSensor | Select-Object DeviceID,Name,CurrentReading,Status,SystemName,UnitModifier|Sort-Object DeviceID #- PoweSupply Current (CurrentValue*10^-1) - 10^-1 is the unitmodifier
$aname=@()
$pwraConv=@()
foreach ($pwra in $ObjPwrAmp)
{
$ObjPwrAmpConv = "" | Select-Object DeviceID,Name,CurrentReading,Status,SystemName
$conv_pwra=convertUnitModifier -unitModifier $pwra.UnitModifier -convCurrentReading $pwra.CurrentReading
$ObjPwrAmpConv.DeviceID = $pwra.DeviceID
$ObjPwrAmpConv.Name = $pwra.Name
$ObjPwrAmpConv.CurrentReading = $conv_pwra
$ObjPwrAmpConv.Status=$pwra.Status
$ObjPwrAmpConv.SystemName = $pwra.SystemName
$pwraConv = $pwraConv + $ObjPwrAmpConv
}
foreach($pwra in $pwraConv)
{
if($pwra.Status -eq "OK")
{
$ok_flag=0
}
elseif($pwra.Status -eq "Starting" -or $pwra.Status -eq "Stopping" -or $pwra.Status -eq "Service" -or $pwra.Status -eq "Warning" -or $pwra.Status -eq "Predictive Failure")
{
$war_flag=1
}
elseif($pwra.Status -eq "Error" -or $pwra.Status -eq "Degraded" -or $pwra.Status -eq "Pred Fail" -or $pwra.Status -eq "Stressed" -or $pwra.Status -eq "NonRecover" -or $pwra.Status -eq "No Contact" -or $pwra.Status -eq "Non-recover" -or $pwra.Status -eq "Non-Recoverable Error" -or $pwra.Status -eq "Non-Recoverable" -or $pwra.Status -eq "Aborted")
{
$cri_flag=2
}
elseif($pwra.Status -eq "Unknown" -or $pwra.Status -eq "Lost Comm" -or $pwra.Status -eq "Lost Communication")
{
$unknown_flag=3
}
else
{
$undetermind_flag=4
}
$pa_format= $pwra.Status+":"+$pwra.Name+":"+$pwra.CurrentReading + "A;"
$aname=$aname + $pa_format
}
# IF none of the status values matches then consider it as Critical
if($undetermind_flag -eq 4)
{
$cri_flag=2
}
# detrmine the state of the matched status to return the value from plugin and exit the shell
If($cri_flag -eq 2)
{
Write-Host "$aname"
exit($cri_flag)
}
if($war_flag -eq 1)
{
Write-Host "$aname"
exit($war_flag)
}
if($unknown_flag -eq 3)
{
Write-Host "$aname"
exit($unknown_flag)
}
if($ok_flag -eq 0)
{
Write-Host "$aname"
exit($ok_flag)
}
}
If($component -eq "vlt")
{
$ObjPwrVlt = Get-WmiObject -Namespace root\cimv2\dell -class CIM_VoltageSensor | Select-Object DeviceID,Name,CurrentReading,Status,SystemName,UnitModifier|Sort-Object DeviceID #- PoweSupply Voltage
$vname=@()
$pwrvConv=@()
foreach ($pwrv in $ObjPwrVlt)
{
$ObjPwrVltConv = "" | Select-Object DeviceID,Name,CurrentReading,Status,SystemName
$conv_pwrv=convertUnitModifier -unitModifier $pwrv.UnitModifier -convCurrentReading $pwrv.CurrentReading
$ObjPwrVltConv.DeviceID = $pwrv.DeviceID
$ObjPwrVltConv.Name = $pwrv.Name
$ObjPwrVltConv.CurrentReading = $conv_pwrv
$ObjPwrVltConv.Status=$pwrv.Status
$ObjPwrVltConv.SystemName = $pwrv.SystemName
$pwrvConv = $pwrvConv + $ObjPwrVltConv
}
foreach($pwrv in $pwrvConv)
{
if($pwrv.Status -eq "OK")
{
$ok_flag=0
}
elseif($pwrv.Status -eq "Starting" -or $pwrv.Status -eq "Stopping" -or $pwrv.Status -eq "Service" -or $pwrv.Status -eq "Warning" -or $pwrv.Status -eq "Predictive Failure")
{
$war_flag=1
}
elseif($pwrv.Status -eq "Error" -or $pwrv.Status -eq "Degraded" -or $pwrv.Status -eq "Pred Fail" -or $pwrv.Status -eq "Stressed" -or $pwrv.Status -eq "NonRecover" -or $pwrv.Status -eq "No Contact" -or $pwrv.Status -eq "Non-recover" -or $pwrv.Status -eq "Non-Recoverable Error" -or $pwrv.Status -eq "Non-Recoverable" -or $pwrv.Status -eq "Aborted")
{
$cri_flag=2
}
elseif($pwrv.Status -eq "Unknown" -or $pwrv.Status -eq "Lost Comm" -or $pwrv.Status -eq "Lost Communication")
{
$unknown_flag=3
}
else
{
$undetermind_flag=4
}
$pv_format= $pwrv.Status+":"+$pwrv.Name+":"+$pwrv.CurrentReading + "v;"
$vname=$vname + $pv_format
}
# IF none of the status values matches then consider it as Critical
if($undetermind_flag -eq 4)
{
$cri_flag=2
}
# detrmine the state of the matched status to return the value from plugin and exit the shell
If($cri_flag -eq 2)
{
Write-Host "$vname"
exit($cri_flag)
}
if($war_flag -eq 1)
{
Write-Host "$vname"
exit($war_flag)
}
if($unknown_flag -eq 3)
{
Write-Host "$vname"
exit($unknown_flag)
}
if($ok_flag -eq 0)
{
Write-Host "$vname"
exit($ok_flag)
}
}
If($component -eq "processor")
{
$ObjProcessor = Get-WmiObject -Namespace root\cimv2\dell -class CIM_Processor | Select-Object DeviceID,Name,CurrentReading,Status,SystemName,UnitModifier|Sort-Object DeviceID # CPU health
$pname=@()
$ProcessorConv=@()
foreach ($Processor in $ObjProcessor)
{
if($Processor.Status -eq "OK")
{
$ok_flag=0
}
elseif($Processor.Status -eq "Starting" -or $Processor.Status -eq "Stopping" -or $Processor.Status -eq "Service" -or $Processor.Status -eq "Warning" -or $Processor.Status -eq "Predictive Failure")
{
$war_flag=1
}
elseif($Processor.Status -eq "Error" -or $Processor.Status -eq "Degraded" -or $Processor.Status -eq "Pred Fail" -or $Processor.Status -eq "Stressed" -or $Processor.Status -eq "NonRecover" -or $Processor.Status -eq "No Contact" -or $Processor.Status -eq "Non-recover" -or $Processor.Status -eq "Non-Recoverable Error" -or $Processor.Status -eq "Non-Recoverable" -or $Processor.Status -eq "Aborted")
{
$cri_flag=2
}
elseif($Processor.Status -eq "Unknown" -or $Processor.Status -eq "Lost Comm" -or $Processor.Status -eq "Lost Communication")
{
$unknown_flag=3
}
else
{
$undetermind_flag=4
}
$Processor_format= $Processor.Status+":"+$Processor.Name + ";"
$pname=$pname + $Processor_format
}
# IF none of the status values matches then consider it as Critical
if($undetermind_flag -eq 4)
{
$cri_flag=2
}
# detrmine the state of the matched status to return the value from plugin and exit the shell
If($cri_flag -eq 2)
{
Write-Host "$pname"
exit($cri_flag)
}
if($war_flag -eq 1)
{
Write-Host "$pname"
exit($war_flag)
}
if($unknown_flag -eq 3)
{
Write-Host "$pname"
exit($unknown_flag)
}
if($ok_flag -eq 0)
{
Write-Host "$pname"
exit($ok_flag)
}
}
If($component -eq "memory")
{
$ObjMem = Get-WmiObject -Namespace root\cimv2\dell -class CIM_PhysicalMemory | Select-Object Name,Status|Sort-Object Name # Memory Health
$mname=@()
foreach ($Memory in $ObjMem)
{
if($Memory.Status -eq "OK")
{
$ok_flag=0
}
elseif($Memory.Status -eq "Starting" -or $Memory.Status -eq "Stopping" -or $Memory.Status -eq "Service" -or $Memory.Status -eq "Warning" -or $Memory.Status -eq "Predictive Failure")
{
$war_flag=1
}
elseif($Memory.Status -eq "Error" -or $Memory.Status -eq "Degraded" -or $Memory.Status -eq "Pred Fail" -or $Memory.Status -eq "Stressed" -or $Memory.Status -eq "NonRecover" -or $Memory.Status -eq "No Contact" -or $Memory.Status -eq "Non-recover" -or $Memory.Status -eq "Non-Recoverable Error" -or $Memory.Status -eq "Non-Recoverable" -or $Memory.Status -eq "Aborted")
{
$cri_flag=2
}
elseif($Memory.Status -eq "Unknown" -or $Memory.Status -eq "Lost Comm" -or $Memory.Status -eq "Lost Communication")
{
$unknown_flag=3
}
else
{
$undetermind_flag=4
}
$Memory_format= $Memory.Status+":"+$Memory.Name + ";"
$mname=$mname + $Memory_format
}
# IF none of the status values matches then consider it as Critical
if($undetermind_flag -eq 4)
{
$cri_flag=2
}
# detrmine the state of the matched status to return the value from plugin and exit the shell
If($cri_flag -eq 2)
{
Write-Host "$mname"
exit($cri_flag)
}
if($war_flag -eq 1)
{
Write-Host "$mname"
exit($war_flag)
}
if($unknown_flag -eq 3)
{
Write-Host "$mname"
exit($unknown_flag)
}
if($ok_flag -eq 0)
{
Write-Host "$mname"
exit($ok_flag)
}
}
}
catch
{
Write-Host "Exception occured."
$e = $_.Exception
$msg = $e.Message
while ($e.InnerException)
{
$e = $e.InnerException
$msg += "`n" + $e.Message
}
Write-Host $msg
}