The following script was created to bypass an issue in the SOAP API in relation with VMware, hardware vendor drivers and PRTG. In any case, you could use the same script for other monitoring systems or any other purpose – of course while adjusting it to your needs.
You can find more information about the issue here: https://kb.paessler.com/en/topic/82458-vmware-host-hardware-status-soap-sensor-returns-warnings-after-update-to-vmware-6-7
In order to make this work you need to install the VMware PowerCLI PowerShell extension on the PRTG probe server. Further will you need to inject username and password as well as the vCenter name and internal hostname in vCenter.
LDAP authentication activated targets:
- $host %host “%windowsdomain\%windowsuser” “%windowspassword”
- $host %host.domain.local “%windowsdomain\%windowsuser” “%windowspassword”
Otherwise – you might need to use this format:
- $host %host root MyRootPW
Test it in PowerShell as the Probe-User first – you should see the results. Eventually the script create a sensor with multiple channels – sensors in GREEN status will be counted only – sensors in UNKNOWN status will be counted and returned as text, while as long as no YELLOW or RED status (warning or error) occurs, the sensor still stays green/okay. Warning or Error levels will automatically apply and have the problematic hardware systems in the sensor message text.
My first attempt was to show all channels on top of the summary – due to getting over 100 separate hardware statuses back and the limitation in PRTG of 50 channels per sensor, I dropped the idea – while the script still has all the code to handle it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | #pre-req #make sure the VMware PowerCLI is installed for all users #install-module -name vmware.powercli -AllowClobber #make sure you set the ignore certificate error - assuming you do not have a valid cert on the vCenter #Set-PowerCLIConfiguration -InvalidCertificateAction Ignore param( [string] $vCenter = "", [string] $HostFQDN = "", [string] $Username = "", [string] $Password = "" ) Import-Module VMware.PowerCLI #avoid unecessary output Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP:$false -confirm:$false #avoid certificate issues Set-PowerCLIConfiguration -InvalidCertificateAction ignore -confirm:$false Connect-VIServer -Server $vCenter -User $Username -Password $Password $VHost = Get-VMHost -Name $HostFQDN $HSS = Get-View -Id $VHost.ExtensionData.ConfigManager.HealthStatusSystem $HSI = $HSS.Runtime.SystemHealthInfo.NumericSensorInfo | Select Name,@{N='Health';E={$_.HealthState.Label}},CurrentReading $XMLDetail = "" $cntGreen = 0 $cntWarning = 0 $cntError = 0 $cntUnknown = 0 $txtWarning = "" $txtError = "" $txtUnknown = "" foreach ($SI in $HSI) { $XMLDetail += "<result><channel>" + $SI.Name + "</channel><value>" + $SI.CurrentReading + "</value></result>" if ($SI.Health.ToLower() -eq "Green".ToLower()) { $cntGreen += 1 } elseif ($SI.Health.ToLower() -eq "Yellow".ToLower()) { $cntWarning += 1 if ($txtWarning.Length -gt 0) { $txtWarning += " - " } $txtWarning += $SI.Name } elseif ($SI.Health.ToLower() -eq "Red".ToLower()) { $cntError += 1 if ($txtError.Length -gt 0) { $txtError += " - " } $txtError += $SI.Name } else { $cntUnknown += 1 if ($txtUnknown.Length -gt 0) { $txtUnknown += " - " } $txtUnknown += $SI.Name } } $OverallStatus = 0 if ($cntWarning -gt 0) { $OverallStatus = 1 } if ($cntError -gt 0) { $OverallStatus = 2 } $OverallText = "" if ($cntError -gt 0) { $OverallText = "Error status: $txtError" } if ($cntError -gt 0) { if ($OverallText.Length -gt 0) { $OverallText += " --- " } $OverallText = "Warning status: $txtWarning" } if ($cntUnknown -gt 0) { if ($OverallText.Length -gt 0) { $OverallText += " --- " } $OverallText = "Unknown status: $txtUnknown" } $XML = "<PRTG>" $XML += "<result><channel>Overall Status</channel><value>$OverallStatus</value><LimitMode>1</LimitMode><LimitMaxError>1</LimitMaxError><LimitMinError>-1</LimitMinError><LimitMaxWarning>0</LimitMaxWarning></result>" $XML += "<result><channel>Total OK</channel><value>$cntGreen</value></result>" $XML += "<result><channel>Total Warning</channel><value>$cntWarning</value></result>" $XML += "<result><channel>Total Error</channel><value>$cntError</value></result>" $XML += "<result><channel>Total Uknown</channel><value>$cntUnknown</value></result>" #$XML += $XMLDetail #can not add the detail to PRTG cause this would create above 100 channels (likely) and PRTG has a 50 channel limit statue per sensor $XML += "<text>$OverallText</text>" $XML += "</PRTG>" Function WriteXmlToScreen ([xml]$xml) #just to make it clean XML code... { $StringWriter = New-Object System.IO.StringWriter; $XmlWriter = New-Object System.Xml.XmlTextWriter $StringWriter; $XmlWriter.Formatting = "indented"; $xml.WriteTo($XmlWriter); $XmlWriter.Flush(); $StringWriter.Flush(); Write-Output $StringWriter.ToString(); } WriteXmlToScreen "$XML" |