Instantly share code, notes, and snippets.

@tolleiv /README.md
Last active Feb 7, 2017

Embed
What would you like to do?
Basic script to push Pingdom data into Zabbix - relies on using the same "item" keys in both systems

About

This script is used along with a basic autodiscovery (see the zbx_template.xml and the pingdom_ldd.json) to have Pingdom data available within Zabbix and to have Zabbix triggers based on that data.

How it works:

The zbx_pingdom_discovery.sh script:

  1. fetches the Pingdom data through the API, filtered by a tag which relates to the specific Zabbix Proxy
  2. transforms the Pingdom data with jq so that it fits the zabbix_sender data format
  3. pushes the information about available checks to the Zabbix proxy with zabbix_sender

The zbx_pingdom.sh script:

  1. fetches the Pingdom data through the API, filtered by a tag which relates to the specific Zabbix Proxy
  2. transforms the Pingdom data with jq so that it fits the zabbix_sender data format
  3. pushes the measurements to the Zabbix proxy with zabbix_sender

Prerequisites

  1. Pingdom checks have to have a clean naming "<host> <check>" (e.g. www0.example.org homepage) within Pingdom
  2. Pingdom check have to have a tag which allows filtering when fething the data
  3. Zabbix LLD needs to be in place (imported template)
  4. curl and jq have to be installed on the system
  5. A cronjob should run the scripts on a regular basis
#!/bin/bash
set -e
# Zabbix Trapper
ZABBIX_HOST='localhost'
ZABBIX_PORT=10051
ZABBIX_PROXY='DC001'
# Pingdom
PINGDOM_KEY='_key'
PINGDOM_USER='_user:_base64pw'
# Transform Pingdom data into Zabbix Trapper elements
_get_pingdom_data() {
list=$(curl --silent --user "$PINGDOM_USER" --header "App-Key: $PINGDOM_KEY" "https://api.pingdom.com/api/2.0/checks?tags=zabbix_$ZABBIX_PROXY" )
echo "$list" \
| jq -r '.checks[]' \
| jq -r '{time:.lasttesttime, key:.name ,status:.status, responsetime:.lastresponsetime}' \
| jq -r '.time=(.time | tostring)' \
| jq -r '.responsetime=(.responsetime | tostring)' \
| jq -r 'def mapping: {"up":"2","paused":"1","down":"0"};.status=mapping[.status]' \
| jq -r '[.key + ",status] " + .time + " " + .status, .key + ",time] " + .time + " " + .responsetime]' \
| jq -r '.[]' \
| sed -e 's~ ~ pingdom.response[~1'
}
##############
if [ "x$1" = 'x--debug' ]; then
echo "###### Pingdom Data ########"
_get_pingdom_data
echo "###### Pingdom Data ########"
else
datafile=$(mktemp -t pingdomdataXXXXXX)
trap "rm $datafile" EXIT
_get_pingdom_data > $datafile
zabbix_sender -z $ZABBIX_HOST -p $ZABBIX_PORT -T -i $datafile 2>&1
fi
#!/bin/bash
set -e
ZABBIX_HOST='localhost'
ZABBIX_PORT=10051
ZABBIX_PROXY='DC001'
ZABBIX_KEY='pingdom.discovery[checks]'
# Pingdom
PINGDOM_KEY='_key'
PINGDOM_USER='_user:_base64pw'
# Transform Pingdom checks into Zabbix Trapper elements
_get_pingdom_checks() {
list=$(curl --silent --user "$PINGDOM_USER" --header "App-Key: $PINGDOM_KEY" "https://api.pingdom.com/api/2.0/checks?tags=zabbix_$ZABBIX_PROXY" )
echo "$list" \
| jq -r '.checks[]' \
| sed -e 's/name": "\(\S\+\) /host": "\1", "name": "/' \
| jq -s '. | group_by(.host) | .[]' \
| jq -r '.[0].host as $host | { "data": map({"{#URL}": .hostname, "{#NAME}": .name}) } | $host + " '$ZABBIX_KEY' " + tostring'
}
##############
if [ "x$1" = 'x--debug' ]; then
echo "###### Pingdom Data ########"
_get_pingdom_checks
echo "###### Pingdom Data ########"
else
datafile=$(mktemp -t pingdomdataXXXXXX)
trap "rm $datafile" EXIT
_get_pingdom_checks > $datafile
test -s $datafile || exit 0;
zabbix_sender -vv -z $ZABBIX_HOST -p $ZABBIX_PORT -i $datafile 2>&1
fi
<?xml version="1.0" encoding="UTF-8"?>
<zabbix_export>
<version>2.0</version>
<date>2016-02-01T14:41:20Z</date>
<groups>
<group>
<name>Templates</name>
</group>
</groups>
<templates>
<template>
<template>Template Custom PingDom Data</template>
<name>Template Custom PingDom Data</name>
<description/>
<groups>
<group>
<name>Templates</name>
</group>
</groups>
<applications>
<application>
<name>Pingdom</name>
</application>
</applications>
<items/>
<discovery_rules>
<discovery_rule>
<name>Pingdom Check discovery</name>
<type>2</type>
<snmp_community/>
<snmp_oid/>
<key>pingdom.discovery[checks]</key>
<delay>0</delay>
<status>0</status>
<allowed_hosts/>
<snmpv3_contextname/>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authprotocol>0</snmpv3_authprotocol>
<snmpv3_authpassphrase/>
<snmpv3_privprotocol>0</snmpv3_privprotocol>
<snmpv3_privpassphrase/>
<delay_flex/>
<params/>
<ipmi_sensor/>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<filter>
<evaltype>0</evaltype>
<formula/>
<conditions/>
</filter>
<lifetime>30</lifetime>
<description/>
<item_prototypes>
<item_prototype>
<name>Pingdom {#NAME} latency</name>
<type>2</type>
<snmp_community/>
<multiplier>0</multiplier>
<snmp_oid/>
<key>pingdom.response[{#NAME},time]</key>
<delay>0</delay>
<history>30</history>
<trends>365</trends>
<status>0</status>
<value_type>3</value_type>
<allowed_hosts/>
<units/>
<delta>0</delta>
<snmpv3_contextname/>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authprotocol>0</snmpv3_authprotocol>
<snmpv3_authpassphrase/>
<snmpv3_privprotocol>0</snmpv3_privprotocol>
<snmpv3_privpassphrase/>
<formula>1</formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type>0</data_type>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description>url: {#URL}</description>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>Pingdom</name>
</application>
</applications>
<valuemap/>
<logtimefmt/>
</item_prototype>
<item_prototype>
<name>Pingdom {#NAME} status</name>
<type>2</type>
<snmp_community/>
<multiplier>0</multiplier>
<snmp_oid/>
<key>pingdom.response[{#NAME},status]</key>
<delay>0</delay>
<history>30</history>
<trends>365</trends>
<status>0</status>
<value_type>3</value_type>
<allowed_hosts/>
<units/>
<delta>0</delta>
<snmpv3_contextname/>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authprotocol>0</snmpv3_authprotocol>
<snmpv3_authpassphrase/>
<snmpv3_privprotocol>0</snmpv3_privprotocol>
<snmpv3_privpassphrase/>
<formula>1</formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type>0</data_type>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description>url: {#URL}</description>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>Pingdom</name>
</application>
</applications>
<valuemap/>
<logtimefmt/>
</item_prototype>
</item_prototypes>
<trigger_prototypes>
<trigger_prototype>
<expression>{Template Application PingDom Data:pingdom.response[{#NAME},status].max(#3)}&lt;1</expression>
<name>Pingdom: {#NAME} down</name>
<url/>
<status>0</status>
<priority>4</priority>
<description>Pingdom reports that the related webcheck is down.</description>
<type>0</type>
</trigger_prototype>
<trigger_prototype>
<expression>{Template Application PingDom Data:pingdom.response[{#NAME},status].max(#15)}&lt;1</expression>
<name>Pingdom: {#NAME} down</name>
<url/>
<status>0</status>
<priority>5</priority>
<description>Pingdom reports that the related webcheck is down.</description>
<type>0</type>
</trigger_prototype>
</trigger_prototypes>
<graph_prototypes/>
<host_prototypes/>
</discovery_rule>
</discovery_rules>
<macros/>
<templates/>
<screens/>
</template>
</templates>
</zabbix_export>
@steven792

This comment has been minimized.

Show comment
Hide comment
@steven792

steven792 Mar 7, 2016

Not working as is with Zabbix 3.0.

steven792 commented Mar 7, 2016

Not working as is with Zabbix 3.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment