LoginSignup
11
15

More than 5 years have passed since last update.

ZabbixAPIを使用したトリガー有効化

Last updated at Posted at 2016-02-08

解決したい問題

  • Active-StandbyのHA構成にしているシステムでF/Oのトリガーを任意のプロセスに指定していて、Zabbixのトリガーもそのプロセスの監視にしている場合、通常時はPrimaryでは正常だが、Secondaryでは異常として検知し続けてしまう。

方法

イメージ

cloudcraft - zabbix API.png

zabbix api

user.loginメソッドで認証

  • リクエスト
$ curl -X GET -H "Content-Type:application/json-rpc" -d '{"auth":null,"method":"user.login","id":1,"params":{"user":"*****","password":"*****"},"jsonrpc":"2.0"}' http[s]://*****/api_jsonrpc.php
  • レスポンス
{"jsonrpc":"2.0","result":"****************************","id":1}

host.getメソッドによるホスト一覧取得

  • リクエスト
    • 取得したキーを記述してリクエストする
$ curl -X GET -H "Content-Type:application/json-rpc" -d '{"auth":"****************************","method":"host.get","id":1,"params":{},"jsonrpc":"2.0"}' http[s]://*****/api_jsonrpc.php

trigger.getメソッドによるトリガーID取得

$ curl -X GET -H "Content-Type:application/json-rpc" -d '{"auth":"****************************","method":"trigger.get","id":1,"params":{},"jsonrpc":"2.0"}' http[s]://*****/api_jsonrpc.php | jq '.' > zabbix-api-trigger_get

trigger.updateメソッドによるトリガー有効化

$ curl -X GET -H "Content-Type:application/json-rpc" -d '{"auth":"****************************","method":"trigger.update","id":1,"params":{"triggerid":"****","status":0},"jsonrpc":"2.0"}' http[s]://*****/api_jsonrpc.php | jq '.'

設定

  • ホストIDでFilterし目的のトリガーIDを取得
    • paramsにtriggeridとdescriptionを併せて記述しておくと分かりやすい

$ curl -X GET -H "Content-Type:application/json-rpc" -d '{"auth":"****************************","method":"trigger.get","id":1,"params":{"output":["triggerid","description"],"filter":{"hostid":"****"}},"jsonrpc":"2.0"}' http[s]://*****/api_jsonrpc.php | jq '.'

{
  "id": 1,
  "result": [
    {
      "description": "Host name of zabbix_agentd was changed on {HOST.NAME}",
      "triggerid": "*****"
    },
    {
      "description": "Zabbix agent on {HOST.NAME} is unreachable for 1 minutes",
      "triggerid": "*****"
    },
    {
      "description": "Version of zabbix_agent(d) was changed on {HOST.NAME}",
      "triggerid": "*****"
    },
省略
  ],
  "jsonrpc": "2.0"
}

  • descriptionを指定した検索が便利
$ curl -X GET -H "Content-Type:application/json-rpc" -d '{"auth":"****************************","method":"trigger.get","id":1,"params":{"output":["triggerid","description"],"filter":{"hostid":"*****"},"search":{"description":"Zabbix trapper processes more than 75% busy"}},"jsonrpc":"2.0"}' http[s]://*****/api_jsonrpc.php | jq '.'
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   353  100   117  100   236    104    209  0:00:01  0:00:01 --:--:--   209
{
  "id": 1,
  "result": [
    {
      "description": "Zabbix trapper processes more than 75% busy",
      "triggerid": "*****"
    }
  ],
  "jsonrpc": "2.0"
}

トリガーIDを指定して有効化


$ curl -X GET -H "Content-Type:application/json-rpc" -d '{"auth":"****************************","method":"trigger.update","id":1,"params":{"triggerid":"*****","status":0},"jsonrpc":"2.0"}' http[s]://*****/api_jsonrpc.php | jq '.'
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   192  100    58  100   134    602   1391 --:--:-- --:--:-- --:--:--  1395
{
  "id": 1,
  "result": {
    "triggerids": [
      "*****"
    ]
  },
  "jsonrpc": "2.0"
}

トリガーIDを指定して無効化


$ curl -X GET -H "Content-Type:application/json-rpc" -d '{"auth":"****************************","method":"trigger.update","id":1,"params":{"triggerid":"*****","status":1},"jsonrpc":"2.0"}' http[s]://*****/api_jsonrpc.php | jq '.'
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   192  100    58  100   134     50    117  0:00:01  0:00:01 --:--:--   117
{
  "id": 1,
  "result": {
    "triggerids": [
      "*****"
    ]
  },
  "jsonrpc": "2.0"
}

  • 有効化コマンドを自動アクションに組み込んでアクションの実行条件に”F/O発生時”とし、実行内容を作成する Screenshot from 2016-02-08 23:28:48.png
11
15
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
15