Introduction
After successfully configuring Pushover with PRTG, I moved on to configuring my Synology DiskStation (easy) and VMware vCenter (harder) installation to also notify me via Pushover.
Register An Application
In both cases, I registered a new application within the Pushover console. I did this so that each alert would come though with their own specific icon and description. See my previous blog posting on how to do this.
I used the following icons for each application :
Synology DiskStation Notifications
This is was the easiest change to make, simply…
- Login to your DiskStation,
- Open the Control Panel,
- Select the Notification option,
- Choose either (or both) of the following tabs…
- Push Service
- Enter your Pushover API email address
- [user-key]+a=[api-key]@api.pushover.net
VMware vCenter Alerts
Setting up these alerts were a lot harder. It took a lot of trial and error. Hopefully this will save you the same hassle.
Before you start, make sure you have the Microsoft dotNet framework version 4 or later installed, as well as PowerShell 4 or later. Next, we’ll create a folder and two files on your vCenter server…
- On the C: drive, create a folder called Scripts,
- Create two plain text files and enter the following code…
send-alert.bat
"c:\windows\system32\windowspowershell\v1.0\powershell.exe" c:\scripts\send-alert.ps1 -title '%1' -message '%2'
send-alert.ps1
param( [string]$title, [string]$message ) $parameters = @{ token = "[api-key]" user = "[user-key]" priority = "0" title = $title message = $message } $parameters | Invoke-RestMethod -Uri "https://api.pushover.net/1/messages.json" -Method Post
Remember to enter your own api-key and user-key into the .ps1 script file.
vCenter Configuration
Next we need to configure VMware vCenter to run the batch file whenever an alert condition is met. At last count there are 68 different alert definitions within vCenter. You could change each on manually, but that would take all day. If you have VMware PowerCLI installed (and you really should have) you can script this.
Manual Steps…
Open VMware vSphere Client, and login to your vCenter server,
- Select the very top level entry in the tree view on the left,
- Choose the Alarms tab along the top,
- Click the Definitions button,
- The list of 68+ definitions are list. Double-click on one of them. I’ll choose Datastore usage on disk,
- Select the Actions tab,
- Click Add,
- From the new entry that appears,
- change “Send a notification email“
- to “Run a command“
- Enter the following code into the Configuration column…
c:\scripts\send-alert.bat "{targetName} > {eventDescription}" "{triggeringSummary}"
- Click OK
- Rinse and repeat for the remaining definitions, or…
Automatic Script…
- Open a PowerCLI command window, and connect to your vCenter server
- Copy and paste the following code, and let it run…
$al = Get-AlarmDefinition ForEach ($a in $al) { Get-AlarmDefinition -Name $a | New-AlarmAction -Script -ScriptPath 'c:\scripts\send-alert.bat "{targetName} > {eventDescription}" "{triggeringSummary}"' }
Make sure you get the single quotes ( ‘ ) and double-quotes ( ” ) correct
For a list of variables you can use, check the VMware documentation.
Results
Once you have alerts working, you should get alerts through looking something like this…