ab’s blog

インフラの呟きです。

Zabbix4.0 アクションの設定一覧をshellで取得する REDHAT8

hahahahahaha

はじめに

アクション設定をshellで取得する方法です。私は設定前後の差分比較用に使います。REDHAT7の場合、shell中に使う「jq」がインストールされていないので追加が前提です。REDHAT8はjq使えます。

サンプル

#!/bin/bash
#################################################################
TMPFILE=tmp.tmp
header='Content-Type:application/json-rpc'
apiurl='http://localhost/zabbix/api_jsonrpc.php'
RPC='"jsonrpc":"2.0"'

# ログイン
METHOD='"method":"user.login"'
PARAMS='"params":{"user": "Admin","password": "Pass"}'
ID='"id": 1'
AUTH='"auth": null'
json="{$RPC,$METHOD,$PARAMS,$ID,$AUTH}"

curl -sS -X POST -H "${header}" -d "${json}" ${apiurl} > $TMPFILE
zbxauth=$(jq -r .result < $TMPFILE)


/# アクション一覧取得
METHOD='"method": "action.get"'
PARAMS='"params": {"output": "extend","selectOperations": "extend","selectRecoveryOperations": "extend","selectUpdateOperations": "extend","selectFilter": "extend","filter": { "eventsource": 0}}'
ID='"id": 2'
AUTH='"auth": "'$zbxauth'"'
json="{$RPC,$METHOD,$PARAMS,$ID,$AUTH}"

curl -sS -X POST -H "${header}" -d "${json}" ${apiurl}




# ログアウト
METHOD='"method":"user.logout"'
PARAMS='"params":[]'
ID='"id": 4'
AUTH='"auth": "'$zbxauth'"'
json="{$RPC,$METHOD,$PARAMS,$ID,$AUTH}"

curl -sS -X POST -H "${header}" -d "${json}" ${apiurl} > $TMPFILE