Is there a way to get alarms from vCenter that arent host or VM related? There are lots of alarms in vCenter for example certificate status, licensing, services and so on. Some of them can be covered by observing the host. Others cant. How can we observe this values?
Monitor vCenter
Votes:
0
Best Answer
Votes:
6
This seems to be an ongoing topic. I took the time and come up with a possible solution - I will post it here and you also will find it here: https://www.it-admins.com/vmware-alert-monitoring-with-prtg-and-powershell/
There is a way to read out and process ALL alerts of your VMware environment using PowerShell and reporting the results back to PRTG. The script further down in this article does this. What you get is similar to the graphic here.
This show you the following channels:
- Overall status
- this will be green as long there aren’t any not acknowledged warnings or alerts in VMware
- if the warning or alert is acknowledged, the sensor / script will return to green cause it is nothing that is new
- Total Alerts – amount of alerts acknowledged and not ackowledged
- Total Alerts – Acknowledged
- Total Alerts – NOT Acknowledged
- Total Warnings
- Total Warnings – Acknowledged
- Total Warnings – NOT Acknowledged
- Total Warnings and Alerts
- Total Warnings and Alerts – Acknowledged
- Total Warnings and Alerts – NOT Acknowledged
As you can see – you can get more granular on your PRTG statuses if you use the channels for Warnings/Alerts that are acknowledged. You could set upper warning or error limits of 0 to keep a warning / error level in PRTG if you want to see them still.
While I was writing the script, I decided to create a new lookup value in PRTG to make it more clear. If you adjust the script in regards to add additional statuses for the channel overall status – you will need to adjust this file as well.
Let’s start with the value lookup file, you need to copy the text from the first script block in to a file you store here: C:\Program Files (x86)\PRTG Network Monitor\lookups\custom
Name the file: vmware.alerts.search.ovl
<?xml version="1.0" encoding="utf-8"?> <ValueLookup id="vmware.alerts.search" desiredValue="0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="PaeValueLookup.xsd" undefinedState="Warning"> <Lookups> <SingleInt state="Ok" value="0">Overall Status - Green - OK</SingleInt> <SingleInt state="Warning" value="1">Overall Status - Yellow - Warning</SingleInt> <SingleInt state="Error" value="2">Overall Status - Red - Error</SingleInt> </Lookups> </ValueLookup>
Now we need to create a custom EXE/XML sensor in this directory: C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXEXML
Name the file: VMwareAlerts.ps1
#make sure the executing user and system has those two commands run #Find-Module -Name VMware.PowerCLI #Install-Module -Name VMware.PowerCLI #useful command #Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP:$false -confirm:$false #Set-PowerCLIConfiguration -InvalidCertificateAction ignore -confirm:$false # #alternative look here: https://blogs.vmware.com/PowerCLI/2017/04/powercli-install-process-powershell-gallery.html param( [string] $VCenterServer = "", [string] $DomainAndUser = "", [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 $VCenterServer -username "$DomainAndUser" -Password "$Password" $colAlarms = (Get-DataCenter).ExtensionData.TriggeredAlarmState $XML = "<PRTG>" [int] $Warnings = 0 [int] $WarningsAck = 0 [int] $Alerts = 0 [int] $AlertsAck = 0 [int] $OverallStatus = 0 #default green if ($colAlarms.Count -gt 0) { foreach ($entry in $colAlarms) { if ($entry.OverallStatus -eq "yellow") { $Warnings += 1 if ($entry.Acknowledged) { $WarningsAck =+ 1 } else { #we only increase the overall status if this alert is not acknowledged if ($OverallStatus -lt 1) { $OverallStatus = 1 } } } elseif ($entry.OverallStatus -eq "red") { $Alerts += 1 if ($entry.Acknowledged) { $AlertsAck =+ 1 } else { #we only increase the overall status if this alert is not acknowledged if ($OverallStatus -lt 2) { $OverallStatus = 2 } } } } } $XML += "<result><channel>Overwall Status</channel><value>" + $OverallStatus + "</value><ValueLookup>vmware.alerts.search</ValueLookup></result>" $XML += "<result><channel>Total Warnings and Alerts</channel><value>" + $colAlarms.Count + "</value><CustomUnit>#</CustomUnit></result>" $XML += "<result><channel>Total Warnings and Alerts - NOT Acknowledged</channel><value>" + ($colAlarms.Count - $WarningsAck + $AlertsAck) + "</value><CustomUnit>#</CustomUnit></result>" $XML += "<result><channel>Total Warnings and Alerts - Acknowledged</channel><value>" + ($WarningsAck + $AlertsAck) + "</value><CustomUnit>#</CustomUnit></result>" $XML += "<result><channel>Total Warnings</channel><value>" + $Warnings + "</value><CustomUnit>#</CustomUnit></result>" $XML += "<result><channel>Total Warnings - NOT Acknowledged</channel><value>" + ($Warnings - $WarningsAck) + "</value><CustomUnit>#</CustomUnit></result>" $XML += "<result><channel>Total Warnings - Acknowledged</channel><value>" + $WarningsAck + "</value><CustomUnit>#</CustomUnit></result>" $XML += "<result><channel>Total Alerts</channel><value>" + $Alerts + "</value><CustomUnit>#</CustomUnit></result>" $XML += "<result><channel>Total Alerts - NOT Acknowledged</channel><value>" + ($Alerts - $AlertsAck) + "</value><CustomUnit>#</CustomUnit></result>" $XML += "<result><channel>Total Alerts - Acknowledged</channel><value>" + $AlertsAck + "</value><CustomUnit>#</CustomUnit></result>" $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(); } #Clear WriteXmlToScreen "$XML"
Once you have both files created, go to PRTG and add a new sensor called EXE/Script Advanced and select the new created script file. As Parameter you either type the host-name of your vSphere server or if you created it underneath the device in PRTG just use %host.
UPDATE: I changed the script cause I found it to be better to go with the following expected parameters and always making sure you have control over username and password used to connect to VMware. Please use the follow parameter moving forward:
%host "%windowsdomain\%windowsuser" "%windowspassword"
There are still a few challenges you might need to overcome on top of this:
- install the VMware PowerShell extensions on your PRTG probe server
- in a PowerShell execute
- Find-Module -Name VMware.PowerCLI
- Install-Module -Name VMware.PowerCLI
- alternative use the documentation mentioned in the next link
- in a PowerShell execute
- outdated - credentials to connect to VMware can be a challenge as I tested this
- outdated - you might need to have the service account of the PRTG probe have sufficient access rights – needs working SSO
- outdated - alternative use a stored credentials file in PowerShell – somewhat secure
- outdated - or provide the credentials clear text in PowerShell – least secure
- outdated - please see line 20 respective the command “connect-viserver” for more details
- updated the script - it now expects username and password as parameter
You might wanna test the script before you add a sensor to PRTG – the best way to do this is directly on the PRTG server with the service account of the PRTG probe to make sure it will work as a sensor later on.
Keep in mind that the script expects a parameter – the VMware vSphere server name / web-address.
Hopefully this is what everyone wanted - or at least helps you to get there.
Regards
Florian Rossmark
43 Replies
Votes:
0
At the moment we have no sensor that covers this. I will however send you an email shortly with another version of the VMware sensors that are capable to doing what you ask for to test it.
Kind regards.
Votes:
0
Hi Erhard, would it be possible for you to sending it to me also? I would be happy to test it for you.
Thank you.
Votes:
0
@Iniano: You've got mail.
Kind regards.
Votes:
0
@ Erhard would you be so kind to send me same email...I am havin issues monitoring a vmware cluster environment
Votes:
0
Hi Frank,
You've got mail.
Kind regards,
Erhard
Votes:
0
Thank you Erhard for your prompt response.
Votes:
0
Hi Erhard, I'm also interested by monitoring other vcenter part, like services, licensing. Could you send me this vmware sensor ?
Is there an ETA for the final release of this sensor ?
Regards, Yannick
Votes:
0
Hi Yannick,
I've just sent you an email with instructions how to set it up. At this point I'm afraid there is no final ETA for "fully integrating" the sensor.
Kind regards,
Erhard
Votes:
0
Hi Erhard,
Could it be possible to also have the email with the instructions ?
Thank you.
Best regards, Anthony
Votes:
0
Hi Anthony,
Sure, mail sent.
Kind regards,
Erhard
Votes:
0
Hi Erhard -
Can I get this mail also ?
TIA ,
Votes:
0
Hi Chezenko,
Of course you can ;)
Mail's out, kind regards,
Erhard
Votes:
0
Hi Erhard,
We are also interested in this e-mail :) Thank you.
Kind Regards, Roy
Votes:
0
Hi Roy,
Sure, you've got mail :)
Kind regards,
Erhard
Votes:
0
Hi Erhard,
Any ETA on the release of this sensor? In the meantime could you please send it to me as well as I am interested in testing it out.
Cheers,
Tyson
Votes:
0
Hello Tyson,
Nothing new so far I'm afraid, mail's out.
Kind regards,
Erhard
Votes:
0
Hi, I am also interested in this sensor. Does it work with the appliance as well as with the Windows installation? Could you kindly send me the email with instructions so we can test it out?
Thanks, much appreciated.
Votes:
0
Hi Ralph,
You've got mail.
Kind regards,
Erhard
Votes:
0
i'm interesrested in this sensor too. is it also possible to get this email? thanks in advance.
kind regards, andré
Votes:
0
Hi André,
Sure, you've got mail.
Kind regards,
Erhard
Votes:
0
Hi Erhard,
We would also like to test any new VMware related sensors. Would you please send us an e-mail with instructions on how to get started?
Best regards, Yarno
Votes:
0
Hi Erhard,
I would also like to test the VMware Vcenter sensors. Would you please send us an e-mail with instructions . Thanks smittycsi
Votes:
0
Hi smittycsi,
You've got mail.
Kind regards,
Erhard
Votes:
0
I would like info on this monitoring too please.
Votes:
0
Hello Erhard,
would also be interested, since own VMware SOAP Calls are not that easy :)
best Regards Michele
Votes:
0
Hi, I guess there's still no ETA for the sensors? I would appreciate if I also could get an email.
Thank you.
Votes:
0
Hello Erhard,
I would also like that email. Or has it been released?
/SJ
Votes:
0
Hello Søren,
You've got mail.
Kind regards,
Erhard
Votes:
0
Hello Erhard, I would also like to test/use the extra VMware sensors. Could you please send an email to me as well? Thank you!
Kind regards, Tamas
Votes:
0
Hi Tamas,
You've got mail.
Kind regards,
Erhard
Votes:
0
Hi Erhard Can you please send me also the instruction for this sensors! Kind regards, Marcel
Votes:
0
Hi Marcel,
You've got mail.
Kind regards,
Erhard
Votes:
0
Hi Erhard,
I would also like to test the VMware Vcenter sensors. Would you please send me an e-mail with instructions?
Kind regards,
Dominik
Votes:
0
Hi Erhard,
We are also looking forward to test the VMware vCenter sensors. Can you send us the instructions for this ?
Kind regards,
Wouter
Votes:
0
Hello Erhard,
would also be interested
Ben
Votes:
0
Here the instructions for everyone interested:
1. Download
2. Copy the file "VMWareSensorAlarms.exe" to the path <PRTG installation folder>\Custom Sensors\EXEXML\
2.1 In case a Remote Probe should run this sensor, perform step 1 on this very probe.
3. Now create an "EXE/Script Advanced" sensor. (It must be the "Advanced" version!) Please pick the VMWareSensorAlarms.exe file as sensor.
4. You also need to set the correct parameters in the sensor. Here is an example:
-s="%host" -m=group-d1 -u="%windowsdomain\%windowsuser" -p="%windowspassword" -alarms -sessionstore="C:\ProgramData\Paessler\PRTG Network Monitor\Sensordata (NonPersistent)\VMware Sessionpool"
(In case you have configured a different data-path for your PRTG installation, adjust the path accordingly)
Most parameters should be self-explanatory. The -m parameter is used to set the view. "group-d1" should give you the view of the entire vCenter server. If you just want to check some sections, please use the Managed Object Browser (on the vCenter server, just add /mob to the URL) to get the according names.
Please note that the sensor is a "proof of concept" right now. Currently it's unlikely that it will make its way into PRTG as a standard "stock sensor".
Kind regards,
Erhard
Created on Mar 19, 2018 9:02:05 AM by
Erhard Mikulik [Paessler Support]
Last change on Mar 19, 2018 9:05:05 AM by
Erhard Mikulik [Paessler Support]
Votes:
0
Hello,
I just updated the esxi Server from 6.0 to 6.7 and "VMWareSensorAlarms.exe" not works anymore. Any updates available?
Best regards, Chris
Votes:
0
Hello Chris,
I see what I can find out and post an update here.
Kind regards,
Erhard
Votes:
0
Hello Chris and to everyone else interested,
First of all, sorry for the late reply.
So here's a quick recap of this sensor aka "What happened so far":
- The sensor was not developed by our sensor developer team, it was a "side-project" from one of our admins who initially also built the VMware Sensors.
- The executable was provided "as is" to anyone interested. Overall interest was not that huge, also feedback about it was quite scarce.
- Now the admin who initially created this file, is no longer able to maintain it any further and the sensor team does not know the code at all and would need to start from scratch and sensor team have their hands full with other tasks.
In the end the executable needs some overhauling and recompiling as well based on newer .NET versions in order to cope with stuff like working with hosts where certain TLS versions were disabled and alike, which the current build is not able to deal with properly.
Since it's no official sensor, we cannot treat this as a bug per se that needs to be fixed, I'm afraid, due to the aforementioned reasons/the sensor's "history".
Therefor we currently would suggest to post this as a feature request as mentioned here. That way there is at least a chance it could make it into a standard sensor in the future. Of course feel free to fill out the feature request outlining how the sensor ideally should work. I mean the sensor basically dumps lots of messages into the "Messages" area of the sensor, without any formatting like simple breaks and alike, this would be a good opportunity to address this as well, meaning how the data could be presented "prettier".
Kind regards,
Erhard
Votes:
6
This seems to be an ongoing topic. I took the time and come up with a possible solution - I will post it here and you also will find it here: https://www.it-admins.com/vmware-alert-monitoring-with-prtg-and-powershell/
There is a way to read out and process ALL alerts of your VMware environment using PowerShell and reporting the results back to PRTG. The script further down in this article does this. What you get is similar to the graphic here.
This show you the following channels:
- Overall status
- this will be green as long there aren’t any not acknowledged warnings or alerts in VMware
- if the warning or alert is acknowledged, the sensor / script will return to green cause it is nothing that is new
- Total Alerts – amount of alerts acknowledged and not ackowledged
- Total Alerts – Acknowledged
- Total Alerts – NOT Acknowledged
- Total Warnings
- Total Warnings – Acknowledged
- Total Warnings – NOT Acknowledged
- Total Warnings and Alerts
- Total Warnings and Alerts – Acknowledged
- Total Warnings and Alerts – NOT Acknowledged
As you can see – you can get more granular on your PRTG statuses if you use the channels for Warnings/Alerts that are acknowledged. You could set upper warning or error limits of 0 to keep a warning / error level in PRTG if you want to see them still.
While I was writing the script, I decided to create a new lookup value in PRTG to make it more clear. If you adjust the script in regards to add additional statuses for the channel overall status – you will need to adjust this file as well.
Let’s start with the value lookup file, you need to copy the text from the first script block in to a file you store here: C:\Program Files (x86)\PRTG Network Monitor\lookups\custom
Name the file: vmware.alerts.search.ovl
<?xml version="1.0" encoding="utf-8"?> <ValueLookup id="vmware.alerts.search" desiredValue="0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="PaeValueLookup.xsd" undefinedState="Warning"> <Lookups> <SingleInt state="Ok" value="0">Overall Status - Green - OK</SingleInt> <SingleInt state="Warning" value="1">Overall Status - Yellow - Warning</SingleInt> <SingleInt state="Error" value="2">Overall Status - Red - Error</SingleInt> </Lookups> </ValueLookup>
Now we need to create a custom EXE/XML sensor in this directory: C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXEXML
Name the file: VMwareAlerts.ps1
#make sure the executing user and system has those two commands run #Find-Module -Name VMware.PowerCLI #Install-Module -Name VMware.PowerCLI #useful command #Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP:$false -confirm:$false #Set-PowerCLIConfiguration -InvalidCertificateAction ignore -confirm:$false # #alternative look here: https://blogs.vmware.com/PowerCLI/2017/04/powercli-install-process-powershell-gallery.html param( [string] $VCenterServer = "", [string] $DomainAndUser = "", [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 $VCenterServer -username "$DomainAndUser" -Password "$Password" $colAlarms = (Get-DataCenter).ExtensionData.TriggeredAlarmState $XML = "<PRTG>" [int] $Warnings = 0 [int] $WarningsAck = 0 [int] $Alerts = 0 [int] $AlertsAck = 0 [int] $OverallStatus = 0 #default green if ($colAlarms.Count -gt 0) { foreach ($entry in $colAlarms) { if ($entry.OverallStatus -eq "yellow") { $Warnings += 1 if ($entry.Acknowledged) { $WarningsAck =+ 1 } else { #we only increase the overall status if this alert is not acknowledged if ($OverallStatus -lt 1) { $OverallStatus = 1 } } } elseif ($entry.OverallStatus -eq "red") { $Alerts += 1 if ($entry.Acknowledged) { $AlertsAck =+ 1 } else { #we only increase the overall status if this alert is not acknowledged if ($OverallStatus -lt 2) { $OverallStatus = 2 } } } } } $XML += "<result><channel>Overwall Status</channel><value>" + $OverallStatus + "</value><ValueLookup>vmware.alerts.search</ValueLookup></result>" $XML += "<result><channel>Total Warnings and Alerts</channel><value>" + $colAlarms.Count + "</value><CustomUnit>#</CustomUnit></result>" $XML += "<result><channel>Total Warnings and Alerts - NOT Acknowledged</channel><value>" + ($colAlarms.Count - $WarningsAck + $AlertsAck) + "</value><CustomUnit>#</CustomUnit></result>" $XML += "<result><channel>Total Warnings and Alerts - Acknowledged</channel><value>" + ($WarningsAck + $AlertsAck) + "</value><CustomUnit>#</CustomUnit></result>" $XML += "<result><channel>Total Warnings</channel><value>" + $Warnings + "</value><CustomUnit>#</CustomUnit></result>" $XML += "<result><channel>Total Warnings - NOT Acknowledged</channel><value>" + ($Warnings - $WarningsAck) + "</value><CustomUnit>#</CustomUnit></result>" $XML += "<result><channel>Total Warnings - Acknowledged</channel><value>" + $WarningsAck + "</value><CustomUnit>#</CustomUnit></result>" $XML += "<result><channel>Total Alerts</channel><value>" + $Alerts + "</value><CustomUnit>#</CustomUnit></result>" $XML += "<result><channel>Total Alerts - NOT Acknowledged</channel><value>" + ($Alerts - $AlertsAck) + "</value><CustomUnit>#</CustomUnit></result>" $XML += "<result><channel>Total Alerts - Acknowledged</channel><value>" + $AlertsAck + "</value><CustomUnit>#</CustomUnit></result>" $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(); } #Clear WriteXmlToScreen "$XML"
Once you have both files created, go to PRTG and add a new sensor called EXE/Script Advanced and select the new created script file. As Parameter you either type the host-name of your vSphere server or if you created it underneath the device in PRTG just use %host.
UPDATE: I changed the script cause I found it to be better to go with the following expected parameters and always making sure you have control over username and password used to connect to VMware. Please use the follow parameter moving forward:
%host "%windowsdomain\%windowsuser" "%windowspassword"
There are still a few challenges you might need to overcome on top of this:
- install the VMware PowerShell extensions on your PRTG probe server
- in a PowerShell execute
- Find-Module -Name VMware.PowerCLI
- Install-Module -Name VMware.PowerCLI
- alternative use the documentation mentioned in the next link
- in a PowerShell execute
- outdated - credentials to connect to VMware can be a challenge as I tested this
- outdated - you might need to have the service account of the PRTG probe have sufficient access rights – needs working SSO
- outdated - alternative use a stored credentials file in PowerShell – somewhat secure
- outdated - or provide the credentials clear text in PowerShell – least secure
- outdated - please see line 20 respective the command “connect-viserver” for more details
- updated the script - it now expects username and password as parameter
You might wanna test the script before you add a sensor to PRTG – the best way to do this is directly on the PRTG server with the service account of the PRTG probe to make sure it will work as a sensor later on.
Keep in mind that the script expects a parameter – the VMware vSphere server name / web-address.
Hopefully this is what everyone wanted - or at least helps you to get there.
Regards
Florian Rossmark
Votes:
0
I edited the script to accept username and password. PRTG allows the following parameters giving you more control and avoiding the username/password issues therefor.
%host "%windowsdomain\%windowsuser" "%windowspassword"
Updated script in the previous post - to avoid confusion.
Regards and hoping this is what everyone was looking for...
Florian
Votes:
0
Thanks for providing the PowerShell Script Florian! I have modified it quite a bit, to fix some issues i have personally encountered. This is my Lookup file, adding Status 3 to show failed logins of Connect-VIServer
<?xml version="1.0" encoding="utf-8"?> <ValueLookup id="vmware.alerts.search" desiredValue="0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="PaeValueLookup.xsd" undefinedState="Warning"> <Lookups> <SingleInt state="Ok" value="0">Overall Status - Green - OK</SingleInt> <SingleInt state="Warning" value="1">Overall Status - Yellow - Warning</SingleInt> <SingleInt state="Error" value="2">Overall Status - Red - Error</SingleInt> <SingleInt state="Error" value="3">Overall Status - Red - Sensor Error! Can't connect to vCenter Server</SingleInt> </Lookups> </ValueLookup>
This is the PowerShell script: My Changes: - Moving variable declarations up, so OverallStatus can be set on Connect-VIServer - Added a check for Connect-VIServer returning false, thus setting OverallStatus to 3(Sensor Error) - Changed =+ for += (I don't know if this worked before, but when i tested it didn't work with =+) - Fixed typo in Overwall (Overall) Status Channel - Fixed math in Channel Total Warnings and Alerts - NOT Acknowledged
#make sure the executing user and system has those two commands run #Find-Module -Name VMware.PowerCLI #Install-Module -Name VMware.PowerCLI #useful command #Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP:$false -confirm:$false #Set-PowerCLIConfiguration -InvalidCertificateAction ignore -confirm:$false # #alternative look here: https://blogs.vmware.com/PowerCLI/2017/04/powercli-install-process-powershell-gallery.html param( [string] $VCenterServer = "", [string] $DomainAndUser = "", [string] $Password = "" ) [int] $Warnings = 0 [int] $WarningsAck = 0 [int] $Alerts = 0 [int] $AlertsAck = 0 [int] $OverallStatus = 0 #default green Import-Module VMware.PowerCLI #avoid unecessary output Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP:$false -confirm:$false #avoid certificate issues Set-PowerCLIConfiguration -InvalidCertificateAction ignore -confirm:$false if(!(Connect-VIServer $VCenterServer -username "$DomainAndUser" -Password "$Password")) { $OverallStatus = 3 } $colAlarms = (Get-DataCenter).ExtensionData.TriggeredAlarmState $XML = "<PRTG>" if ($colAlarms.Count -gt 0) { foreach ($entry in $colAlarms) { if ($entry.OverallStatus -eq "yellow") { $Warnings += 1 if ($entry.Acknowledged) { $WarningsAck += 1 } else { #we only increase the overall status if this alert is not acknowledged if ($OverallStatus -lt 1) { $OverallStatus = 1 } } } elseif ($entry.OverallStatus -eq "red") { $Alerts += 1 if ($entry.Acknowledged) { $AlertsAck += 1 } else { #we only increase the overall status if this alert is not acknowledged if ($OverallStatus -lt 2) { $OverallStatus = 2 } } } } } $XML += "<result><channel>Overall Status</channel><value>" + $OverallStatus + "</value><ValueLookup>vmware.alerts.search</ValueLookup></result>" $XML += "<result><channel>Total Warnings and Alerts</channel><value>" + $colAlarms.Count + "</value><CustomUnit>#</CustomUnit></result>" $XML += "<result><channel>Total Warnings and Alerts - NOT Acknowledged</channel><value>" + ($colAlarms.Count - ($WarningsAck + $AlertsAck)) + "</value><CustomUnit>#</CustomUnit></result>" $XML += "<result><channel>Total Warnings and Alerts - Acknowledged</channel><value>" + ($WarningsAck + $AlertsAck) + "</value><CustomUnit>#</CustomUnit></result>" $XML += "<result><channel>Total Warnings</channel><value>" + $Warnings + "</value><CustomUnit>#</CustomUnit></result>" $XML += "<result><channel>Total Warnings - NOT Acknowledged</channel><value>" + ($Warnings - $WarningsAck) + "</value><CustomUnit>#</CustomUnit></result>" $XML += "<result><channel>Total Warnings - Acknowledged</channel><value>" + $WarningsAck + "</value><CustomUnit>#</CustomUnit></result>" $XML += "<result><channel>Total Alerts</channel><value>" + $Alerts + "</value><CustomUnit>#</CustomUnit></result>" $XML += "<result><channel>Total Alerts - NOT Acknowledged</channel><value>" + ($Alerts - $AlertsAck) + "</value><CustomUnit>#</CustomUnit></result>" $XML += "<result><channel>Total Alerts - Acknowledged</channel><value>" + $AlertsAck + "</value><CustomUnit>#</CustomUnit></result>" $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(); } #Clear WriteXmlToScreen "$XML"
The following script also records the messages from the vCenter Appliance and not only from the DataCenter level:
#make sure the executing user and system has those two commands run #Find-Module -Name VMware.PowerCLI #Install-Module -Name VMware.PowerCLI #useful command #Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP:$false -confirm:$false #Set-PowerCLIConfiguration -InvalidCertificateAction ignore -confirm:$false # #alternative look here: https://blogs.vmware.com/PowerCLI/2017/04/powercli-install-process-powershell-gallery.html param( [string] $VCenterServer = "", [string] $DomainAndUser = "", [string] $Password = "" ) [int] $Warnings = 0 [int] $WarningsAck = 0 [int] $Alerts = 0 [int] $AlertsAck = 0 [int] $OverallStatus = 0 #default green #Import-Module VMware.PowerCLI #avoid unecessary output Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP:$false -confirm:$false #avoid certificate issues Set-PowerCLIConfiguration -InvalidCertificateAction ignore -confirm:$false if(!(Connect-VIServer $VCenterServer -username "$DomainAndUser" -Password "$Password")) { $OverallStatus = 3 } #$colAlarms = (Get-DataCenter).ExtensionData.TriggeredAlarmState #Datacenter without vcenter messages $colAlarms = (Get-Folder -Name Datacenters).ExtensionData.TriggeredAlarmState #Datacenter with vcenter messages e.g. vcenter root password expired $XML = "<PRTG>" if ($colAlarms.Count -gt 0) { foreach ($entry in $colAlarms) { if ($entry.OverallStatus -eq "yellow") { $Warnings += 1 if ($entry.Acknowledged) { $WarningsAck += 1 } else { #we only increase the overall status if this alert is not acknowledged if ($OverallStatus -lt 1) { $OverallStatus = 1 } } } elseif ($entry.OverallStatus -eq "red") { $Alerts += 1 if ($entry.Acknowledged) { $AlertsAck += 1 } else { #we only increase the overall status if this alert is not acknowledged if ($OverallStatus -lt 2) { $OverallStatus = 2 } } } } } $XML += "<result><channel>Overall Status</channel><value>" + $OverallStatus + "</value><ValueLookup>vmware.alerts.search</ValueLookup></result>" $XML += "<result><channel>Total Warnings and Alerts</channel><value>" + $colAlarms.Count + "</value><CustomUnit>#</CustomUnit></result>" $XML += "<result><channel>Total Warnings and Alerts - NOT Acknowledged</channel><value>" + ($colAlarms.Count - ($WarningsAck + $AlertsAck)) + "</value><CustomUnit>#</CustomUnit></result>" $XML += "<result><channel>Total Warnings and Alerts - Acknowledged</channel><value>" + ($WarningsAck + $AlertsAck) + "</value><CustomUnit>#</CustomUnit></result>" $XML += "<result><channel>Total Warnings</channel><value>" + $Warnings + "</value><CustomUnit>#</CustomUnit></result>" $XML += "<result><channel>Total Warnings - NOT Acknowledged</channel><value>" + ($Warnings - $WarningsAck) + "</value><CustomUnit>#</CustomUnit></result>" $XML += "<result><channel>Total Warnings - Acknowledged</channel><value>" + $WarningsAck + "</value><CustomUnit>#</CustomUnit></result>" $XML += "<result><channel>Total Alerts</channel><value>" + $Alerts + "</value><CustomUnit>#</CustomUnit></result>" $XML += "<result><channel>Total Alerts - NOT Acknowledged</channel><value>" + ($Alerts - $AlertsAck) + "</value><CustomUnit>#</CustomUnit></result>" $XML += "<result><channel>Total Alerts - Acknowledged</channel><value>" + $AlertsAck + "</value><CustomUnit>#</CustomUnit></result>" $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(); } #Clear WriteXmlToScreen "$XML"
Created on May 27, 2019 2:30:02 PM
Last change on Jan 29, 2024 7:40:31 AM by
Timo Dambach [Paessler Support]
Votes:
0
Thank you Florian for providing the script and Eren for modifying it.
I tested with the script and at first after creating a sensor, I kept receiving a timeout error (PE018). I troubleshot it from a credentials issue for a while but it turned out to be because the default timeout settings of the sensor were 60 seconds and when the Import-Module VMware.PowerCLI command ran manually, it would take several minutes. After further testing, it looks like that line is not needed as long as the module is installed on the probe system so I removed it, which resolved the issue in my case. The other solution would be to extend the timeout + scanning interval.
What I am curious of now is if there would be any way to bring in the specific alert/warning error message to display within the PRTG sensor.
Add comment