このエントリーをはてなブックマークに追加

zabbixのapiを利用

zabbixではapiでの操作をサポートしているのでここでいくつか確認してみます。

公式サイト:https://www.zabbix.com/documentation/3.0/manual/api

認証トークンを取得する

リクエスト

curl -X GET -H "Content-Type:application/json-rpc" -d '{"auth":null, "method":"user.login", "id":1, "params":{"user":"Admin", "password":"zabbix"}, "jsonrpc":"2.0"}' http://192.168.56.101/zabbix/api_jsonrpc.php

レスポンス

{"jsonrpc":"2.0","result":"4da1b3bfbca98636e563fbba391457af","id":1}

ホスト一覧を取得する

リクエスト

curl -X GET -H "Content-Type:application/json-rpc" -d '{"auth":"4da1b3bfbca98636e563fbba391457af", "method":"host.get", "id":1, "params":{"output":"extend"}, "jsonrpc":"2.0"}' http://192.168.56.101/zabbix/api_jsonrpc.php

レスポンス(整形済)

{
    "id": 1,
    "jsonrpc": "2.0",
    "result": [
        {
            "available": "1",
            "description": "",
            "disable_until": "0",
            "error": "",
            "errors_from": "0",
            "flags": "0",
            "host": "Zabbix server",
            "hostid": "10084",
            "ipmi_authtype": "-1",
            "ipmi_available": "0",
            "ipmi_disable_until": "0",
            "ipmi_error": "",
            "ipmi_errors_from": "0",
            "ipmi_password": "",
            "ipmi_privilege": "2",
            "ipmi_username": "",
            "jmx_available": "0",
            "jmx_disable_until": "0",
            "jmx_error": "",
            "jmx_errors_from": "0",
            "lastaccess": "0",
            "maintenance_from": "0",
            "maintenance_status": "0",
            "maintenance_type": "0",
            "maintenanceid": "0",
            "name": "Zabbix server",
            "proxy_hostid": "0",
            "snmp_available": "0",
            "snmp_disable_until": "0",
            "snmp_error": "",
            "snmp_errors_from": "0",
            "status": "0",
            "templateid": "0",
            "tls_accept": "1",
            "tls_connect": "1",
            "tls_issuer": "",
            "tls_psk": "",
            "tls_psk_identity": "",
            "tls_subject": ""
        }
    ]
}

アイテム一覧を取得する

curl -X GET -H "Content-Type:application/json-rpc" -d '{"auth":"4da1b3bfbca98636e563fbba391457af", "method":"item.get", "id":1, "params":{"output":"extend"}, "jsonrpc":"2.0"}' http://192.168.56.101/zabbix/api_jsonrpc.php

トリガー一覧を取得する

curl -X GET -H "Content-Type:application/json-rpc" -d '{"auth":"4da1b3bfbca98636e563fbba391457af", "method":"trigger.get", "id":1, "params":{"output":"extend"}, "jsonrpc":"2.0"}' http://192.168.56.101/zabbix/api_jsonrpc.php

参考にさせていただいたサイト