Your SlideShare is downloading. ×
Zabbix API at FISL12 by Takanori Suzuki
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Zabbix API at FISL12 by Takanori Suzuki

11,895
views

Published on

Published in: Technology

0 Comments
5 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
11,895
On Slideshare
0
From Embeds
0
Number of Embeds
8
Actions
Shares
0
Downloads
181
Comments
0
Likes
5
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Zabbix API and related tools - How to interface with Zabbix- Takanori Suzuki
  • 2. Takanori Suzuki
    • Member of Zabbix-JP, Zabbix community in Japan.
    • 3. Reported bugs and Posted patches.
      • Crashing bug patch
      • 4. Zabbix proxy stop sending data bug patch
      • 5. Disk monitoring improvement patch for LVM
  • 6.  
  • 7. Zabbix
    • An enterprise-class open source distributed monitoring solution.
      • auto-discovery of servers and network devices
      • 8. distributed monitoring with centralised WEB administration
      • 9. server software for many Un*x
      • 10. native high performance agents for almost all famous OS
      • 11. agent-less monitoring
      • 12. web-based interface
      • 13. etc…
  • 14. Zabbix API
  • 15. Zabbix API
    • Zabbix supports Zabbix API from 1.8
    • 16. Zabbix API enables us to control Zabbix by program.
    • 17. 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
        • 18. 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.
        • 19. Non official command line tools are available.
        • 20. Mobile phone applications for Zabbix are released
  • 21. 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
      • 22. Libraries for API, easy to use from perl, php, ruby and python.
  • 23. zabcon
    • One of the earliest programs using Zabbix API
    • 24. Enables controlking Zabbix by command line and interactive shell
    • 25. Installable by Ruby gem
    • 26. Site URL:
        • http://trac.red-tux.net/wiki/zbx_api/zabcon
  • 27. zabcon: How to use
    • Executing ./zabcon.rb it works as interactive shell
    • 28. By redirecting Zabbix commands, 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 API
    • Zabbix API is based on JSON RPC 2.0
    • 30. If you can send JSON in POST request, you can use Zabbix API
      • Curl is an easy way to test.
      • 31. Let's go to the 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 libraries
    • Writing JSON directly and setting auth id every time is a pain.
    • 34. There are Zabbix API libraries for php, ruby, python and perl.
      • PHP: http://andrewfarley.com/php/zabbix-1-8-api-php-class-v1-0
      • 35. Ruby: http://trac.red-tux.net/wiki/zbx_api
      • 36. Python: https://github.com/gescheit/scripts/tree/master/zabbix/
      • 37. Perl: https://github.com/mikeda/ZabbixAPI
  • 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 interface is also using Zabbix API internally
    • Internally, Zabbix web interface is also using Zabbix API functions.
    • 40. Zabbix web interface access functions without JSON, but directly access same functions.
    • 41. If Zabbix web frontend is installed, we can use it by including 'include/config.inc.php' .
  • 42. Zabbix web interface is 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 way to interface with Zabbix
  • 44. Other useful way to interface with Zabbix
    • Programs can use Zabbix API for controlling Zabbix.
    • 45. If we want to send or get data to Zabbix, we can use other Zabbix protocols.
      • Zabbix get protocol
      • 46. Zabbix Sender protocol
      • 47. Zabbix Agent (Active) protocol
  • 48. Zabbix get protocol
    • Just 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 protocol
    • Data is returned with header “ZBXD1” and the following data length.
  • 50. Zabbix get protocol
    • It'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 protocol Zabbix Agent(Active) protocol
    • data format is JSON with header.
  • 52. Zabbix sender protocol Zabbix 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 protocol Zabbix 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 protocol Zabbix 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 library for 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 user friendly. Using Zabbix API and Zabbix protocols, it also become program-friendly software.
  • 57. Questions
  • 58. Thank you The original artwork by orngjce223 is distributed under CC BY license (http://creativecommons.org/licenses/by/3.0/us/)