trap受信からのzabbix_senderの実行がうまく動作しない

お世話になります。
trap監視を行うための初歩的な話でうまくできなく、質問するのも恐縮ですが、
snmptrapdにてtrap受信して、traphandleでsnmptrap.shを呼び出し、zabbix_senderを実行するように設定をしました。
trap受信はログを確認する限り問題なくできていますが、zabbix_senderまでうまく実行されていないようであるため
snmptrapd.confに以下のようにログ出力設定をいれて、対象のログ(snmptrap_tmp.log)を確認したところ

traphandle default /bin/bash /etc/zabbix/snmptrap.sh >> /var/log/snmptrap_tmp.log

Sending failed. Use option -vv for more detailed output.というメッセージが出力されておりましたが、本メッセージの
意味と対処法がわからず困っております。

実際、コマンドでzabbix_sender受信テストを以下のように実施したところ問題なく成功しており、WebUI側にも
監視データ>トリガーにコマンドで実施したイベントが表示されてきました。

<zabbix_senderのコマンドテスト>
# /usr/bin/zabbix_sender -vv -z 10.9.165.2 -s snmptrap_host -k snmptraps -o "test"
zabbix_sender [3500]: DEBUG: answer [{
"response":"success",
"info":"Processed 1 Failed 0 Total 1 Seconds spent 0.000047"}]
Info from server: "Processed 1 Failed 0 Total 1 Seconds spent 0.000047"
sent: 1; skipped: 0; total: 1

snmptrapd.confと、snmptrap.shの内容は以下になります。

<snmptrapd.conf内容>
authCommunity log,execute,net public
traphandle default /bin/bash /etc/zabbix/snmptrap.sh >> /var/log/snmptrap_tmp.log
traphandle default /usr/bin/logger

<snmptrap.sh内容>
#!/bin/bash

# CONFIGURATION
ZABBIX_SERVER="10.9.165.2";
ZABBIX_PORT="10051";
ZABBIX_SENDER="/usr/bin/zabbix_sender";
KEY="snmptraps";
HOST="snmptraps";

# Execute
read hostname
read ip
read uptime
read oid
read address
read community
read enterprise

oid=`echo $oid|cut -f2 -d' '`
address=`echo $address|cut -f2 -d' '`
community=`echo $community|cut -f2 -d' '`
enterprise=`echo $enterprise|cut -f2 -d' '`

oid=`echo $oid|cut -f11 -d'.'`
community=`echo $community|cut -f2 -d'"'`

str="$hostname $address $community $enterprise $oid"

# Output
$ZABBIX_SENDER -z $ZABBIX_SERVER -vv -p $ZABBIX_PORT -s $HOST -k $KEY -o "$str"

# Debug
echo $str >> /tmp/snmptrap.log

以上になります。

なにかアドバイス頂ければと存じます。

コメント表示オプション

お好みのコメント表示方法を選び「設定の保存」をクリックすると変更が反映されます。
ユーザー TNK の写真

手動で実行された時の対象となるホストは「snmptrap_host」になってます
が、trapperでキックするスクリプトで「snmptraps」を指定されているのは、
タイプミスでしょうか?

記載頂いたスクリプトを利用されるのであれば、Zabbixに「snmptraps」と
いう名前のホストとzabbix_senderから受信するためのアイテムが登録され
ている必要があります。

登録されているかを再度ご確認ください。

ユーザー ttjinma の写真

ご確認いただきありがとうございます。
おっしゃる通り、スクリプトのhost名の記述が間違っておりました。
修正して、問題なく動作しました。
単純なミスが気づかず恥ずかしい限りです。。。

ありがとうございました。