Pushing vSphere Events to Phone Notifications

Pushing vSphere Events
to Phone Notifications


Why

I'm embarrassed to say, I created this hacky hack because I'm not smart enough to get the email functionality of ghettoVCB working 🙂 I use the free Pushover service for other notifications in my Home Lab, so I thought I would give Pushover a try to send the status of ghettoVCB backup jobs. Even though ghettoVCB doesn't need this functionality hack, I think this hack may be useful to the community for other purposes as well.

What


Pretty simple parts list for this one:

  • vSphere
  • curl
  • A Pushover Account

How


Create a free Pushover account and API key

Head on over to Pushover.net, click "Login or Signup", then click "create a new account", follow the instructions. 

Once you have your account, create a new Application/API Token at this page. Give your API a name, like "VMware", a description, upload a unique picture as an icon, check the box and click "Create Application".

You should see your new API on your main Pushover page. If you choose the name of your API, you will be presented with the API key to use to send notifications.




You also need your User Key in order to send a notification. You can find your User Key on the main Pushover page



Take note of your User Key and API Key

Install Pushover on your phone

You can find the links to Android and iOS apps on the Pushover web site right at the top.

 
Start the Pushover app on your phone and login.

Install curl on ESXi 


(There are most likely 1,000 security reasons that this is a bad idea, and I am sure I will hear them)

There are literally 21 supported programming languages/utilities supported by Pushover for sending notifications. I like bash, so I typically use curl which is easy. curl is not installed in ESXi (probably for a good security reason). I added curl and opened port 443 outbound in the ESXi firewall to allow curl to work.

Install curl binary

curl binaries for about every OS and chip architecture can be found here. I downloaded the Linux x86_64 binary to my laptop and then scp-ed the binary to my ESXi server. The name of the binary is curl-amd64.


Open port 443 outbound in the ESXi firewall

When I ran a Pushover curl test on ESXi, curl just hung. When I ran curl -v, I saw that I was having trouble connecting over port 443. "Oh!" I thought "Firewall!". Off to vCenter to open port 443 outbound on that ESXi host. To make this even easier, there is already a port 443 outbound rule, for esxupdate, that just needs to be turned on.


Choose Outgoing, EDIT..., check the box for esxupdate and then click OK.

Now the Pushover test code should work

curl -s \
  --form-string "token=APP_TOKEN" \
  --form-string "user=USER_KEY" \
  --form-string "message=hello world" \
  https://api.pushover.net/1/messages.json

Write a hacky shell script


As with all my code, there are much more elegant solutions, but I usually find one that works and never look back. For me, I just grep "Final status:" in today's ghettoVCB status log and send that text to Pushover which goes to my phone. Here is the entire chain:

ghettoVCB status log (cron job once a day @ Midnight)

0 0 * * * [snip]ghettoVCB-master/ghettoVCB.sh -f [snip]vms_to_backup > [snip]ghettoVCB-backup-$(date +\%Y-\%m-\%d_\%H-\%M).log

Hacky Shell Script (cron job once a day @ 2 AM)

0 2 * * * [snip]send_push.sh > [snip]send_push_output-$(date +\%Y-\%m-\%d_\%H-\%M).log

send_push.sh
#!/bin/sh

date_var=$(date +%Y-%m-%d)

grep "Final status:" [snip]ghettoVCB-backup-$date_var*.log > [snip]pushover.txt

[snip]curl-amd64 -s  --form-string "token=[redacted]"  --form-string "user=[redacted]" --form-string "message=`cat [snip]pushover.txt`" https://api.pushover.net/1/messages.json

How to update cron

This article is helpful for updating and restarting cron on ESXi

Thank You

I hope you found this post helpful, or at least informational. I look forward to your feedback, improvements, and corrections.

Comments