1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

zabbix で監視対象側にあるshell scriptの実行結果を取得する方法

Posted at

概要

zabbixで柔軟な監視をするためにshell scriptを実行してその値を取得したい時がある。
最終的にshell scriptで取得した値はトリガーにかけてその値によってアラートをあげる事になるが今回はzabbix agent 経由で監視対象サーバ内にあるshell scriptを実行する方法まで説明します。

前提

zabbix server

OS : Ubuntu 22.04
Version : 6.4

監視対象

OS : Ubuntu 22.04
zabbix-agent2

scriptを実行する監視対象側の設定

  1. zabbix agent でscriptを実行出来る様に以下の記述を /etc/zabbix/zabbix_agent2.conf に記載する。
AllowKey=system.run[*]
  1. 対象のscriptを入れる zabbix ユーザーのhomeディレクトリに作る。
    今回は sh という名前のディレクトリを作ります。
mkdir /home/zabbix/sh
  1. scriptを2で作ったディレクトリに作る。
sudo vim /home/zabbix/sh/your_script.sh
  1. scriptに実行権限を付与する。
sudo chmod +x /home/zabbix/sh/your_script.sh
  1. scriptのownerをzabbixに変える。
sudo chown zabbix:zabbix /home/zabbix/sh/your_script.sh

zabbix サーバ側の設定

  1. ブラウザからzabbixを開き監視対象で アイテムの作成 を実行

  2. キー に 以下を指定し、必須項目を入力する事でアイテムがscript実行後の値を取得してくれる

system.run[~/sh/your_script.sh]

終わりに

後はscriptで取得した値をトリガーにかけてアラート発報するなりすれば幸せになれます。

1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?