A collection of various scripts to automate tasks with the Zabbix API. My main goal is to create a set of simple utilities that can be reused in shell scripts without using a lot of curl voodoo.
All of these tools can be invoked with -h/--help
to get help.
zapi.py
- Interactive Zabbix API client.
zgethistory.py
- Gets values from history for an itemid.
zhinvswitcher.py
- Switches inv. mode on host(group)s.
zhitemfinder.py
- Finds items on a host.zgethistory.py
- Get item values from history (Trends are not supported!).
zhgraphfinder.py
- Finds graphs configured on a Zabbix host.zgetgraph.py
- Downloads a graph .PNG from the Zabbix frontend (needs user frontend access) and saves it.
zghostfinder.py
- Finds member hosts in a hostgroup.
zhproxyfinder.py
- Finds configured proxy for a Zabbix host.
zhtmplfinder.py
- Finds linked templates for a Zabbix host.zthostfinder.py
- Finds hosts that are linked to a template.zthtmllinker.py
- Links host(group)s to a list of templates.zthtmlunlink.py
- Unlinks host(group)s from a list of templates.
zhtrigfinder.py
- Finds triggers on a host.ztrigswitcher.py
- Switches a trigger to enabled or discabled status.
These programs can use .ini style configuration files to retrieve the needed API connection information. To use this type of storage, create a conf file (the default is $HOME/.zbx.conf) that contains at least the [Zabbix API] section and any of the other parameters:
[Zabbix API]
username=johndoe
password=verysecretpassword
api=https://zabbix.mycompany.com/path/to/zabbix/frontend/
no_verify=true
Setting no_verify
to true
will disable TLS/SSL certificate verification when using https.
The scripts will need the pyzabbix module, to install:
pip install pyzabbix
For working with graphs (zgetgraph.py
specifically) install Pillow (a fork of PIL):
pip install pillow
Save a 1 month 'CPU load' graph starting on the 1st of January 2014 for the host server.example.com as ~/jan.png:
graphid=$(./zhgraphfinder.py -e server.example.com | grep 'CPU load' | cut -d ':' -f 1) ./zgetgraph.py -s $(date --date 'jan 1 2014' +%s) -t 2678400 -f ~/jan.png $graphid
Take note that this requires GNU date
.
zabbix_sender -k $ITEMKEY -o $ITEMVALUE -s $HOSTNAME -z $(zhproxyfinder.py $HOSTNAME)
./zhtmpllinker.py -t "Template App Apache" "Template App MySQL" "Template OS Linux" -G "LAMP Servers"
./zhtmplunlink.py -G "Webservers" -t "Template App MySQL"
./zgethistory.py 1001 -C 1
Get a list of item values with timestamps and unit from history for a period of 2hr from Jan 1st 2014 00:00hr
./zgethistory.py -s $(date --date 'jan 1 2014' +%s) -t 7200 -e 1030
./ztrigswitcher.py -D $(./zhtrigfinder.py -s "Unavailable by ICMP" -n "Google DNS")
./zhtrigfinder.py -A "Webserver" | wc -l
./zhinvswitcher.py -G "Linux Servers" -m manual
./zhinvswitcher.py --all-hosts
./zghostfinder.py "Customer A" | grep -i '^web.*'
./zgethistory.py -C 1 $(./zhitemfinder.py -k 'vm.memory.size[available]' -n Webserver)
Logging in on 'https://zabbix.example.com/' with user 'Admin'.
Welcome to the interactive Zabbix API client.
zapi: z host.get(filter={"host": "Zabbix Server"})
[{u'hostid': u'1001'}]
zapi: