Top / Zabbix / Zabbix API

やってみる

$ cat auth.json
{
  "auth": null,
  "method": "user.login",
  "id": 1,
  "params": {
    "user": "Admin",
    "password": "xxxx"
  },
  "jsonrpc":"2.0"
}

などのJSONデータを用意し、下記の通りZabbixサーバにリクエストを送ることでトークンを取得します。

$ curl  -s -X GET  --data-binary @auth.json  \     ← ファイルデータをパラメタとして
> -H "Content-Type:application/json-rpc" \         ←  Content-Type を指定
> http://[zabbix Server]/api_jsonrpc.php  | \    ←所定のサーバに
> jq -r .result    ← JQで整形、 resultプロパティだけ取得、通常は" " がつくが -r オプションで除去
e5f6ee796acfxxxxxxxxxxxxxx

トークンがとれました。 つぎにこのトークンを用いて、HOST一覧を取得してみます

$ cat param.json
{
  "auth": "e5f6ee796acfxxxxxxxxxxxxxx",    ←先のトークン
  "method": "host.get",
  "id": 1,
  "params": {
    "output": "extend",
    "selectInterfaces": "extend"
  },
  "jsonrpc": "2.0"
}
$ curl  -s -X GET  --data-binary @param.json  \
> -H "Content-Type:application/json-rpc" \
> http://[zabbix Server]/api_jsonrpc.php   | jq
{
  "jsonrpc": "2.0",
  "result": [
    {
      "hostid": "10263",
      "proxy_hostid": "0",
      "host": "windowsEsxi",
      "status": "0",
      "disable_until": "0",
      "error": "",
      "available": "1",
      ...
      "name": "ESXi上のWindows10",
      "flags": "0",
      "templateid": "0",
      "description": "",
      "tls_connect": "1",
      "tls_accept": "1",
      "tls_issuer": "",
      "tls_subject": "",
      "tls_psk_identity": "",
      "tls_psk": "",
      "interfaces": [
        {
          "interfaceid": "12",
          "hostid": "10263",
          "main": "1",
          "type": "1",
          "useip": "1",
          "ip": "192.168.10.203",
          "dns": "",
          "port": "10050",
          "bulk": "1"
        }
      ]
    },.....
  ],
  "id": 1
}

関連リンク


この記事は

選択肢 投票
おもしろかった 0  
そうでもない 0  

Top / Zabbix / Zabbix API

現在のアクセス:1990


トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2018-05-06 (日) 14:27:26 (2181d)