📜 ⬆️ ⬇️

Zabbix + Pushbullet: a simple way to push alerts

In our company, the main way to notify Zabbix monitoring system events is by email. Jabber did not catch on due to low prevalence, and SMS is outdated (albeit very versatile). I wanted to offer another alternative, which became push-notifications.

Pushbullet service has already managed to make a name for itself on the Android platform, and more recently it has been trying to conquer iOS . Pushbullet is able to send "pushes" to phones, receive them in the browser ( Chrome and Firefox ) and send from it again. In general, a very convenient and useful service, which plus has an open API . Through this API, we will send Zabbix events to employee phones.



Step 1: Get to know your Pushbullet API


It is assumed that you already have an account on this service. In this case, simply go to your profile settings .

')

Step 2: Create a bash script


Option 1: Send messages to all devices

Create a bash script to send push notifications to all devices . Call it pushbullet-all
 #!/bin/bash API_KEY="$1" SUBJECT="$2" MESSAGE="$3" curl https://api.pushbullet.com/v2/pushes \ -u $1: \ -d type=note \ -d title="$SUBJECT" \ -d body="$MESSAGE" \ -X POST 

Where $N are variables. $1 - a unique API (later indicated in the Zabbix user profile), $2 - will be the title, $3 - will become the message body. Read more in Zabbix help .

The script must be copied to the alertscripts folder of your Zabbix server (for example: /usr/local/share/zabbix/alertscripts ). Do not forget to make the script executable ( chmod +x pushbullet-all ).

Option 2: Send messages to specific devices

A little later, in the comments, we began to offer different versions of scripts for sending messages to specific devices . In principle, this method can be used both instead of and in conjunction with what is indicated above. I decided to add variation and use scripts together. Name the new script pushbullet-dev :
 #!/bin/bash API_KEY="${1%%_*}" DEV_ID="${1#*_}" SUBJECT="$2" MESSAGE="$3" curl https://api.pushbullet.com/v2/pushes \ -u $API_KEY: \ -d device_iden=$DEV_ID \ -d type=note \ -d title="$SUBJECT" \ -d body="$MESSAGE" \ -X POST 

The script must be copied to the alertscripts folder of your Zabbix server (for example: /usr/local/share/zabbix/alertscripts ). Do not forget to make the script executable ( chmod +x pushbullet-all ).

Now, in the field “Send to” we indicate not only the API, but also the device identifier. You can find out their list in the following way:
 curl -u <your api key here>: https://api.pushbullet.com/api/devices 

The “Send to” field will look like this (separator " _ "):
 api_dev 

Where api is your API key ( api_key ), and dev is your device identifier ( dev_iden ).

Below are the screenshots for option 1, with the second one just keep in mind that the script name is pushbullet-dev , and in the “Send to” field you need to specify both the API and the ID .

Step 3: Configure Zabbix


Create a new alert method (Administration - Alert Methods)



Create a new action, on the “Operations” tab define a new type of notifications



In the user profile settings, specify your API Key



Accordingly, each responsible employee indicates a personal API in his profile and starts receiving notifications.

Step 4: Enjoy




UPD_02.08.2014: Updated the article. Added a script to send to specific devices and using API v2 from Pushbullet.

Source: https://habr.com/ru/post/220379/


All Articles