Save 37% off PRO during our Black Friday Sale! »

ZabbixAPIをつんつんした

246d2365fbcf6685ff7eaa084d1361ea?s=47 2bo
June 03, 2021

 ZabbixAPIをつんつんした

OSC Nagoya 2021
Pyhton東海/JuliaTokai 合同ミニ勉強会
発表資料

246d2365fbcf6685ff7eaa084d1361ea?s=128

2bo

June 03, 2021
Tweet

Transcript

  1. ZabbixAPIΛͭΜͭΜͨ͠ OSC2021 Online/Nagoya( community = “Python౦ւ”, 
 date = “2021/05/29”,

    location = [“Zoom”, “YoutubeLive”] )
  2. Zabbixɺ͝ଘ஌Ͱ͔͢ʁ

  3. ৭ʑͳπʔϧΛ؂ࢹͰ͖Δ 
 Φʔϓϯιʔειϑτ΢ΣΞͰ͢

  4. https://www.zabbix.com/jp/features ΑΓ

  5. ͓࢓ࣄ͔ΒΑ͘࢖͏ͷͰ͕͢ɺ ࡉʑͱͨ͠ॲཧΛWebͰϙνϙν͸ ਏ͍ͷͰAPIΛΑ͘ୟ͖·͢

  6. طʹZabbixAPIΛ؆୯ʹ࢖͑Δ PythonϞδϡʔϧ͸ଟ͍ͷͰ͕͢

  7. ZabbixυΩϡϝϯτʹ͋Δ 
 αϯϓϧJSONΛ ௚઀ίϐϖͰ͖Δ΄͏͕ ݸਓతʹ͸ָͩͬͨͷͰ

  8. ͦΜͳπʔϧΛ࿉੒͠·ͨ͠

  9. https://github.com/2bobo/pyzbxtool

  10. Կ͕Ͱ͖Δ͔? • API΁ͷϩάΠϯͱϩάΠϯ৘ใͷอ࣋ • API༻ͷJSONΛ౤͚͛ͭΔͱ݁ՌΛड͚औΔ

  11. ͱ͍͏͘Β͍Կ΋ͯ͘͠Ε·ͤΜ

  12. ͦͷ୅ΘΓ؆୯Ͱ͢

  13. ࢖͍ํ import pyzbx-tool zbx_api = pyzbx-tool.ZabbixAPI("http://example.com", "Admin", "zabbix") version_json =

    { "jsonrpc": "2.0", "method": "apiinfo.version", "params": [], "auth": "", "id": 1 } version = zbx_api.call_api(version_json) print(version)
  14. ެࣜυΩϡϝϯτͷ JSONΛίϐϖ͢Ε͹OK https://www.zabbix.com/documentation/current/manual/api/reference/apiinfo/version

  15. ؆୯Ͱ͠ΐʁ

  16. ߋʹࠓͳΒͳΜͱʂʂ

  17. ZabbixSenderػೳ΋ ηοτʹ!!

  18. Zabbix Sender? • Zabbixʹ؂ࢹσʔλΛ౤͚͛ͭΔϞϊ • ϗετ΍Ωʔɺ஋Λࢦఆͯ͠ZabbixServerʹૹΔͷ͕ͩɺಠࣗͷύ έοτͰ௨৴͞ΕΔ • ZabbixͰ΋ఏڙ͞Ε͍ͯΔ͕ɺPython͔Β௚઀౤͛ΕΔͱRasPiͱ͔ Ͱ࢖͏ͱ͖ʹָ

  19. ࢖͍ํ import pyzbx-tool zbx_sender = pyzbx-tool.ZabbixSender("zabbix_server_ip", "10051") zbx_sender.add("host", "key", "value")

    result = zbx_sender.send() print(result)
  20. ͜Ε΋؆୯Ͱ͠ΐʁ

  21. ຊདྷ͸෼͚ͨ΄͏͕Α͍ػೳͰ͕͢ ݸਓతʹΑ͘࢖͏ػೳΛࡶʹ 
 ·ͱΊ͚ͨͩͩͬͨΓ͠·͢

  22. None
  23. ͱ͍͏͜ͱͰɺ Pythonͷ࿩ͳͷ͔Zabbixͷ࿩ͳͷ͔ Α͘Θ͔Βͳ͍࿩Ͱͨ͠

  24. ͜ΜͳLTͰ΋OKͳPython౦ւʹ ੋඇ͝ࢀՃ͍ͩ͘͞

  25. ࣍ճ͸8ʙ9݄ࠒʹ։࠵༧ఆͰ͢