Zabbix API and related tools - How to interface with Zabbix- Takanori Suzuki
Takanori Suzuki Member of Zabbix-JP, Zabbix community in Japan.
Reported bugs and Posted patches. Crashing bug patch
Zabbix proxy stop sending data bug patch
Disk monitoring improvement patch for LVM
 
Zabbix An enterprise-class open source distributed monitoring solution. auto-discovery of servers and network devices
distributed monitoring with centralised WEB administration
server software for many Un*x
native high performance agents for almost all famous OS
agent-less monitoring
web-based interface
etc…
Zabbix API
Zabbix API Zabbix supports Zabbix API from 1.8
Zabbix API enables us to control Zabbix by program.
Though API spec is not fixed as far as 1.8.x release, some users started to use API Before Zabbix API No command line tool to control Zabbix monitoring settings
There is no way to control Zabbix from external programs except directly executing DB query. After Zabbix API We can control Zabbix easily from programs.
Non official command line tools are available.
Mobile phone applications for Zabbix are released
Zabbix API Zabbix API Refernce URL: http://www.zabbix.com/documentation/1.8/api Functions Get, create, delete, update are supported on hosts, items, triggers, actions and many other objects.  Now there are many useful tools zabcon, command line zabbix managing tool
Libraries for API, easy to use from perl, php, ruby and python.
zabcon One of the earliest programs using Zabbix API
Enables controlking Zabbix by command line and interactive shell
Installable by Ruby gem
Site URL:  http://trac.red-tux.net/wiki/zbx_api/zabcon
zabcon: How to use Executing ./zabcon.rb it works as interactive shell

Zabbix API at FISL12 by Takanori Suzuki

  • 1.
    Zabbix API andrelated tools - How to interface with Zabbix- Takanori Suzuki
  • 2.
    Takanori Suzuki Memberof Zabbix-JP, Zabbix community in Japan.
  • 3.
    Reported bugs andPosted patches. Crashing bug patch
  • 4.
    Zabbix proxy stopsending data bug patch
  • 5.
  • 6.
  • 7.
    Zabbix An enterprise-classopen source distributed monitoring solution. auto-discovery of servers and network devices
  • 8.
    distributed monitoring withcentralised WEB administration
  • 9.
  • 10.
    native high performanceagents for almost all famous OS
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
    Zabbix API Zabbixsupports Zabbix API from 1.8
  • 16.
    Zabbix API enablesus to control Zabbix by program.
  • 17.
    Though API specis not fixed as far as 1.8.x release, some users started to use API Before Zabbix API No command line tool to control Zabbix monitoring settings
  • 18.
    There is noway to control Zabbix from external programs except directly executing DB query. After Zabbix API We can control Zabbix easily from programs.
  • 19.
    Non official commandline tools are available.
  • 20.
    Mobile phone applicationsfor Zabbix are released
  • 21.
    Zabbix API ZabbixAPI Refernce URL: http://www.zabbix.com/documentation/1.8/api Functions Get, create, delete, update are supported on hosts, items, triggers, actions and many other objects. Now there are many useful tools zabcon, command line zabbix managing tool
  • 22.
    Libraries for API,easy to use from perl, php, ruby and python.
  • 23.
    zabcon One ofthe earliest programs using Zabbix API
  • 24.
    Enables controlking Zabbixby command line and interactive shell
  • 25.
  • 26.
    Site URL: http://trac.red-tux.net/wiki/zbx_api/zabcon
  • 27.
    zabcon: How touse Executing ./zabcon.rb it works as interactive shell
  • 28.
    By redirecting Zabbixcommands, it returns result. $ echo get host|./zabcon.rb hostid,host 10017,Zabbix Server $ echo 'get item hostids=10017'|./zabcon.rb itemid,description,key_ 18435,Ping to the server (TCP),agent.ping 18436,Version of zabbix_agent(d) running,agent.version 18438,Maximum number of opened files,kernel.maxfiles 18439,Maximum number of processes,kernel.maxproc … ...
  • 29.
    Using Zabbix APIZabbix API is based on JSON RPC 2.0
  • 30.
    If you cansend JSON in POST request, you can use Zabbix API Curl is an easy way to test.
  • 31.
    Let's go tothe demo!
  • 32.
    Using Zabbix API//get auth id $ curl -d '{"auth":null,"method":"user.authenticate","id":1,"params":{"password":"zabbix","user":"api_user"},"jsonrpc":"2.0"}' -H "Content-Type: application/json-rpc" http://localhost/zabbix185/api_jsonrpc.php //get item in "Zabbix Server" $ curl -d '{"jsonrpc":"2.0","method":"item.get","params":{"output":"shorten","host":"Zabbix Server","limit":0},"auth":"PUT_HERE_AUTH_ID","id":1}' -H "Content-Type: application/json-rpc" http://localhost/zabbix185/api_jsonrpc.php
  • 33.
    Zabbix API librariesWriting JSON directly and setting auth id every time is a pain.
  • 34.
    There are ZabbixAPI libraries for php, ruby, python and perl. PHP: http://andrewfarley.com/php/zabbix-1-8-api-php-class-v1-0
  • 35.
  • 36.
  • 37.
  • 38.
    Zabbix API libraries:it is easy to make tools Getting item description list by server name #!/usr/bin/env python from zabbix_api import ZabbixAPI import sys server=sys.argv[1] username=sys.argv[2] password=sys.argv[3] host_name=sys.argv[4] zapi = ZabbixAPI(server=server) zapi.login(username, password) hostid = zapi.host.get({"filter":{"host":host_name}})[0]["hostid"] items = zapi.item.get({ 'hostids' : (hostid), 'output' : 'extend'}) for i in items: print i['description']
  • 39.
    Zabbix web interfaceis also using Zabbix API internally Internally, Zabbix web interface is also using Zabbix API functions.
  • 40.
    Zabbix web interfaceaccess functions without JSON, but directly access same functions.
  • 41.
    If Zabbix webfrontend is installed, we can use it by including 'include/config.inc.php' .
  • 42.
    Zabbix web interfaceis also using Zabbix API internally Sample code http://localhost/zabbix185/test.php <?php require_once('include/config.inc.php'); $params = array( 'host' => &quot;Zabbix Server&quot;, 'output' => API_OUTPUT_EXTEND, 'limit' => 0 ); $items = CItem::get($params); foreach ($items as $i){ print $i['description'] . &quot;<br>&quot;; } ?>
  • 43.
    Other useful wayto interface with Zabbix
  • 44.
    Other useful wayto interface with Zabbix Programs can use Zabbix API for controlling Zabbix.
  • 45.
    If we wantto send or get data to Zabbix, we can use other Zabbix protocols. Zabbix get protocol
  • 46.
  • 47.
  • 48.
    Zabbix get protocolJust sending character data to 10050 port $ telnet localhost 10050 Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. agent.version ZBXD1.8.2Connection closed by foreign host.
  • 49.
    Zabbix get protocolData is returned with header “ZBXD\1” and the following data length.
  • 50.
    Zabbix get protocolIt's so easy a protocol! we can write zabbix_get even by bash. https://github.com/BlueSkyDetector/code-snippet/blob/master/bash-zabbix-tools/zabbix_get.sh &quot; top &quot; by zabbix (demo) https://github.com/BlueSkyDetector/code-snippet/blob/master/bash-zabbix-tools/zabbix_top.sh
  • 51.
    Zabbix sender protocolZabbix Agent(Active) protocol data format is JSON with header.
  • 52.
    Zabbix sender protocolZabbix Agent(Active) protocol JSON data format (send data) { &quot;data&quot;: [ { &quot;host&quot;:&quot;HostA&quot;, &quot;value&quot;:&quot;sent data&quot;, &quot;key&quot;:&quot;AppX_Logger&quot; } ], &quot;request&quot;:&quot;sender data&quot; <--- or“agent data” }
  • 53.
    Zabbix sender protocolZabbix Agent(Active) protocol JSON data format (receive data) { &quot;response&quot;:&quot;success&quot;, &quot;info&quot;:&quot;Processed 2 Failed 0 Total 2 Seconds spent 0.000103&quot; }
  • 54.
    Zabbix sender protocolZabbix Agent(Active) protocol If you impliment Zabbix sender protocol, the program directly sends data to Zabbix without Zabbix Agent or Zabbix Sender
  • 55.
    Zabbix Sender libraryfor Python (demo) https://github.com/BlueSkyDetector/code-snippet/tree/master/ZabbixSender from ZabbixSender import ZabbixSender sender = ZabbixSender(u'127.0.0.1') sender.AddData(u'HostA', u'AppX_Logger', u'data1') sender.AddData(u'HostA', u'AppX_Logger', u'data2') result=sender.Send() sender.ClearData()
  • 56.
    Zabbix is userfriendly. Using Zabbix API and Zabbix protocols, it also become program-friendly software.
  • 57.
  • 58.
    Thank you Theoriginal artwork by orngjce223 is distributed under CC BY license (http://creativecommons.org/licenses/by/3.0/us/)