Zabbix + Pushbullet: an easy way to push alerts

    In our company, the main way to notify about the events of the Zabbix monitoring system is via email. Jabber did not take root due to its low prevalence, and SMS is outdated (albeit very universal). I wanted to offer another alternative, which became push notifications.

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



    Step 1: Find out your Pushbullet API


    It is assumed that you already have an account on this service. In this case, just 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 . Name himpushbullet-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 $Nare the variables. $1- a unique API (later indicated in the Zabbix user profile), $2- will be the header, $3- will become the body of the message. See Zabbix Help for more details .

    The script needs to be copied to the folder of alertscriptsyour Zabbix server (for example:) /usr/local/share/zabbix/alertscripts. Remember to make the script executable ( chmod +x pushbullet-all).

    Option 2: Send messages to specific devices

    A little later, in the comments, they began to offer different versions of scripts for sending messages to specific devices . In principle, this method can be used both instead of and together with what is indicated above. I decided to add variability 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 needs to be copied to the folder of alertscriptsyour Zabbix server (for example:) /usr/local/share/zabbix/alertscripts. Remember to make the script executable ( chmod +x pushbullet-all).

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

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

    Where apiis your API key ( api_key), and devis your device identifier ( dev_iden).

    Below are screenshots for option 1, with the second just keep in mind that the name of the script is - pushbullet-dev, and in the field "Send to" you need to specify as API well ID.

    Step 3: Configure Zabbix


    Create a new notification method (Administration - Alert Methods)



    Create a new action, on the "Operations" tab, define a new type of notification



    In the user profile settings, specify your API Key



    Accordingly, each responsible employee indicates a personal API in his profile and begins to receive notifications.

    Step 4: Enjoy




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

    Also popular now: