Skip to content

Various scripts to automate tasks in Zabbix


Notifications You must be signed in to change notification settings



Repository files navigation


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.

API tools:

  • - Interactive Zabbix API client.

History related:

  • - Gets values from history for an itemid.

Inv related:

  • - Switches inv. mode on host(group)s.
  • - Prints host inventory in CSV format.
  • - Updates host properties.

Item related:

  • - Finds items on a host.
  • - Get item values from history (Trends are not supported!).

Graph related:

  • - Finds graphs configured on a Zabbix host.
  • - Downloads a graph .PNG from the Zabbix frontend (needs user frontend access) and saves it.

Group related:

  • - Finds member hosts in a hostgroup.

Host related:

  • - Finds hosts in Zabbix based on search string.
  • - Updates hosts properties.

Proxy related:

  • - Finds configured proxy for a Zabbix host.

Template related:

  • - Imports .xml template into zabbix
  • - Finds linked templates for a Zabbix host.
  • - Finds hosts that are linked to a template.
  • - Links host(group)s to a list of templates.
  • - Unlinks host(group)s from a list of templates.

Trigger related:

  • - Finds triggers on a host.
  • Switches a trigger to enabled or discabled status.

Macro related:

  • - Updates host properties.

Event related:

  • - Finds events based on filters (includes a tail -f like mode).
  • - Gets details for eventids, including ack's and alert actions.
  • - Acknowledges events based on eventids.


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]

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 ( specifically) install Pillow (a fork of PIL):

pip install pillow

Usage examples

Save a 1 month 'CPU load' graph starting on the 1st of January 2014 for the host as ~/jan.png:

graphid=$(./ -e | grep 'CPU load' | cut -d ':' -f 1) ./ -s $(date --date 'jan 1 2014' +%s) -t 2678400 -f ~/jan.png $graphid

Take note that this requires GNU date.

Using to use the proper Zabbix proxy in a zabbix_sender script.
zabbix_sender -k $ITEMKEY -o $ITEMVALUE -s $HOSTNAME -z $( $HOSTNAME)
Using to link 3 templates to all the hosts in a hostgroup:
./ -t "Template App Apache" "Template App MySQL" "Template OS Linux" -G "LAMP Servers"
Using to unlink a template from all the hosts in a hostgroup:
./ -G "Webservers" -t "Template App MySQL"
Import all .xml templates verbosely from the directory 'templates' and continue with the next template on error.
./ -v -C ./templates/*.xml

Get the latest item value from history for the item with itemid 1001

./ 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

./ -s $(date --date 'jan 1 2014' +%s) -t 7200 -e 1030

Disable the 'Unavailable by ICMP' trigger on the host named 'Google DNS'

./ -D $(./ -s "Unavailable by ICMP" -n "Google DNS")

Count the number of active triggers on the host 'Webserver'

./ -A "Webserver" | wc -l
Switch the inventory mode to manual for all the hosts in a hostgroup
./ -G "Linux Servers" -m manual
Switch the inventory mode to automatic on all the hosts in Zabbix
./ --all-hosts
Find all the hosts in the 'Customer A' hostgroup that match a name that starts with 'web'
./ "Customer A" | grep -i '^web.*'
Print the last known value for the available memory in Bytes on the host 'Webserver'
./ -C 1 $(./ -k 'vm.memory.size[available]' -n Webserver)
Perform a search for all monitored hosts matching the hostname string 'zabbix'
./ -m -S zabbix
Output a CSV with hostid, hostname, OS, vendor and contact fields for all hosts in the 'Zabbix Servers' group
./ -G "Zabbix Servers" -F "os" "vendor" "contact" > report.csv
Update the visible name of the host web001 to 'primary webserver'
./ web001 -V 'primary webserver'
Enable the host web001, apply the macro {$APACHEPROC} and update the 'Sofware Application A' inv field
./ web001 -E -M apacheproc=15 -I software_app_a="Apache"
Find all PROBLEM events during the last hour for the the hosts in the group 'Linux Servers' (Limited to 100 events)
./ -P -t 3600 -G 'Linux Servers' 
Acknowledge 3 events with the message "Power outage"
./ -m "Power outage" 6578 6689 6590
Print details on 3 events including trigger comments, actions and acknowledgements
./ -ACL 6578 6689 6590 
Acknowledge all PROBLEM events in the last 15 minutes for the hosts in the 'Linux Serves' group
./ -m 'Foobar with Fabric :-(' $(./ -i -P -t 900 -G 'Linux servers') 
Follow Zabbix trigger events for all hosts
./ -L 10 --all-hosts -f
Using the API client to test Zabbix API calls:
Logging in on '' with user 'Admin'.
Welcome to the interactive Zabbix API client.
zapi: z host.get(filter={"host": "Zabbix Server"})
[{u'hostid': u'1001'}]

List of inventory fields

Please see the Zabbix manual for your version of Zabbix for the latest list of supported fields, these are only here for your convience.

Property Description
alias Alias.
asset_tag Asset tag.
chassis Chassis.
contact Contact person.
contract_number Contract number.
date_hw_decomm HW decommissioning date.
date_hw_expiry HW maintenance expiry date.
date_hw_install HW installation date.
date_hw_purchase HW purchase date.
deployment_status Deployment status.
hardware Hardware.
hardware_full Detailed hardware.
host_netmask Host subnet mask.
host_networks Host networks.
host_router Host router.
hw_arch HW architecture.
installer_name Installer name.
location Location.
location_lat Location latitude.
location_lon Location longitude.
macaddress_a MAC address A.
macaddress_b MAC address B.
model Model.
name Name.
notes Notes.
oob_ip OOB IP address.
oob_netmask OOB host subnet mask.
oob_router OOB router.
os OS name.
os_full Detailed OS name.
os_short Short OS name.
poc_1_cell Primary POC mobile number.
poc_1_email Primary email.
poc_1_name Primary POC name.
poc_1_notes Primary POC notes.
poc_1_phone_a Primary POC phone A.
poc_1_phone_b Primary POC phone B.
poc_1_screen Primary POC screen name.
poc_2_cell Secondary POC mobile number.
poc_2_email Secondary POC email.
poc_2_name Secondary POC name.
poc_2_notes Secondary POC notes.
poc_2_phone_a Secondary POC phone A.
poc_2_phone_b Secondary POC phone B.
poc_2_screen Secondary POC screen name.
serialno_a Serial number A.
serialno_b Serial number B.
site_address_a Site address A.
site_address_b Site address B.
site_address_c Site address C.
site_city Site city.
site_country Site country.
site_notes Site notes.
site_rack Site rack location.
site_state Site state.
site_zip Site ZIP/postal code.
software Software.
software_app_a Software application A.
software_app_b Software application B.
software_app_c Software application C.
software_app_d Software application D.
software_app_e Software application E.
software_full Software details.
tag Tag.
type Type.
type_full Type details.
url_a URL A.
url_b URL B.
url_c URL C.
vendor Vendor.


Various scripts to automate tasks in Zabbix







No releases published




  • Python 100.0%