More Related Content
Similar to Zabbix API (20)
Zabbix API
- 3. Zabbix APIについて
—軽量なJSON RPC形式
出来ること
—Zabbix上のデータの取得・アイテムの登録・更新
—大体なんでも出来る
—構成管理/CIツールとの連携(Ansible, Puppet, Chef,
@社内勉強会 2014/12 林原3
- 5. 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
- 6. 1. トークン発行
{
"jsonrpc": "2.0",
"result": "3f9b110f93368a0786efee16bc907e6f",
"id": "1"
}
resultをトークンとして利用
@社内勉強会 2014/12 林原6
- 7. 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
- 8. 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
- 9. 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
- 11. 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
- 12. 2. maintenance.create
curl -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