Upload
shuhei-hayashibara
View
485
Download
6
Embed Size (px)
Citation preview
Zabbix API
@社内勉強会 2014/12 林原 1
Agenda
1. Zabbix APIについて2.サンプル13.サンプル2
@社内勉強会 2014/12 林原 2
Zabbix APIについて
—軽量なJSON RPC形式
出来ること
—Zabbix上のデータの取得・アイテムの登録・更新—大体なんでも出来る—構成管理/CIツールとの連携(Ansible, Puppet, Chef, @社内勉強会 2014/12 林原 3
Sample.1
ホスト一覧を取得し、アイテム一覧からアイテムの値を取得する
@社内勉強会 2014/12 林原 4
1. トークン発行
curl -s -XGET -H "Content-Type:application/json-rpc" -d \'{ "id": "1", "params": { "user": "username", "password": "password" }, "method": "user.login", "jsonrpc": "2.0"}' \https://zabbix.example.com/api_jsonrpc.php | jq .
@社内勉強会 2014/12 林原 5
1. トークン発行
{ "jsonrpc": "2.0", "result": "3f9b110f93368a0786efee16bc907e6f", "id": "1"}
resultをトークンとして利用
@社内勉強会 2014/12 林原 6
2. host.get
curl -s -XGET -H "Content-Type:application/json-rpc" -d \'{ "id": "2", "params": { "output": "extend" }, "method": "host.get", "jsonrpc": "2.0", "auth": "3f9b110f93368a0786efee16bc907e6f"}' \https://zabbix.example.com/api_jsonrpc.php | \jq -r '.result[]|{hostid,name}| if .name == "hostname" then .hostid,.name else "" end'
@社内勉強会 2014/12 林原 7
3. item.get
curl -s -XGET -H "Content-Type:application/json-rpc" -d \'{ "id": "2", "params": { "output": "extend", "hostids": "10160" }, "method": "item.get", "jsonrpc": "2.0", "auth": "3f9b110f93368a0786efee16bc907e6f"}' \https://zabbix.example.com/api_jsonrpc.php | \jq -r '.result | .[] | if .key_ == "keyname" then .itemid,.name else "" end'
@社内勉強会 2014/12 林原 8
4. history.get
curl -s -XGET -H "Content-Type:application/json-rpc" -d \'{ "id": "2", "params": { "output": "extend", "itemids": "56553", "history": 1, "limit": 100, "sortfield": "clock" }, "method": "history.get", "jsonrpc": "2.0", "auth": "3f9b110f93368a0786efee16bc907e6f"}' \https://zabbix.example.com/api_jsonrpc.php | jq .
@社内勉強会 2014/12 林原 9
Sample.2
グループをメンテナンス状態にする
@社内勉強会 2014/12 林原 10
1. hostgroup.get
curl -s -XGET -H "Content-Type:application/json-rpc" -d \'{ "id": "2", "params": { "output": "extend" }, "method": "hostgroup.get", "jsonrpc": "2.0", "auth": "3f9b110f93368a0786efee16bc907e6f"}' \https://zabbix.example.com/api_jsonrpc.php | \jq -r '.result[]'
@社内勉強会 2014/12 林原 11
2. maintenance.createcurl -s -XGET -H "Content-Type:application/json-rpc" -d \'{ "jsonrpc": "2.0", "method": "maintenance.create", "params": { "name": "maintenance test", "active_since": 1417583941, "active_till": 1417670353, "groupids": [ "34" ], "timeperiods": [ { "timeperiod_type": 0, "start_time": 64800, "period": 3600 } ] }, "auth": "3f9b110f93368a0786efee16bc907e6f", "id": 1}' \https://zabbix.example.com/api_jsonrpc.php | jq .
@社内勉強会 2014/12 林原 12
クライアントライブラリ
—Python
https://github.com/gescheit/scripts/tree/master/zabbix
—Rubyzabbixapihttps://github.com/express42/zabbixapi
@社内勉強会 2014/12 林原 13
おまけ
—おすすめChromeプラグイン.1Zabbix-notifierhttps://chrome.google.com/webstore/detail/zabbix-notifier/ikeijbmpddnkaeejokgifioccbcijjfo?hl=ja
@社内勉強会 2014/12 林原 15
—おすすめChromeプラグイン.2Chromixhttps://chrome.google.com/webstore/detail/chromix/odjpdjeegacmncmodjbeboldofhljjjf/reviews?hl=ja
@社内勉強会 2014/12 林原 16