Zabbixでsnmptrapdを使い、VMwareのホストから受信(snmptrapd編 その1)

VMwareでの仮想サーバでサイトを運営しているプロジェクトに入っているけど、最近メモリが圧迫されてきたとかで
パフォーマンス低下によるエラーが上がることから、VMwareが何をしているのか。スワップやバルーニング(メモリの貸し出しとかでHDDに読書)が発生していないかをzabbixで監視できないかという要望だった。

snmptrapdの部分も相当面倒くさいと思ったけれど、日本語HEXで文書が出てくるところとかも肝だった。
下記、備忘録。ネットにはそれほど出回っていないのと、同じ環境ではそれほど物理サーバ増えないし、
増えたところで、この文書を使用する機会なんて数度あるぐらいだから、風化しちゃうよりも他で使ってもらえたら嬉しいとか思ったり。

ZABBIX SNMPTrap設定

こちらを参考にさせていただきました。

まずは、sourceのtarボールを取得し、下記のスクリプトを抽出。※1.8.8当時です。

/zabbix-1.8.8/misc/snmptrap/snmptrap.sh

■初期状態

#!/bin/bash
#
# Zabbix
# Copyright (C) 2000,2001,2002,2003 Alexei Vladishev
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
 
# CONFIGURATION
 
ZABBIX_SERVER="localhost";
ZABBIX_PORT="10051";
 
ZABBIX_SENDER="~zabbix/bin/zabbix_sender";
 
KEY="snmptraps";
HOST="snmptraps";
 
# END OF CONFIGURATION
 
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"
 
$ZABBIX_SENDER -z $ZABBIX_SERVER -p $ZABBIX_PORT -s $HOST -k $KEY -o "$str"

トラップを受けるスクリプトの追加

# vi /usr/local/bin/zabbix_snmptrap.sh
# chmod +x /usr/local/bin/zabbix_snmptrap.sh

■設定ファイル

/etc/snmp/snmptrapd.conf

authCommunity log,execute,net snmptraptest
 
traphandle default /bin/bash /usr/local/bin/zabbix_snmptrap.sh

設定して、snmptrapd を再起動。
# /etc/init.d/snmptrapd restart

■zabbix側の設定とスクリプトの変更

zabbixのsnmptrap受信設定とzabbix_senderの利用
※参考にさせていただきました。zabbixの管理画面が載っていてわかりやすかったです。

snmptrap.sh のsnmptrapsの部分はzabbixでいう、ホスト設定のサーバ名だったことが判明。
僕の場合もホストの追加でsnmptrapsというものを作ったけれど、もしかして、細かく設定したら
既存サーバ毎に作れるんじゃないかと思ったり…大変か。
HOST=$hostname とかしたらいいんだろうか?とりあえずは試していないので、不明。

KEY="snmptraps";
HOST="snmptraps";

ホストやアイテムを作る。
上記のスクリプト内設定とホスト名、アイテムのキーを合わせることが必要。
タイプはsnmptrap 等はなく、Zabbixトラッパーになっていることが注意点。

自分自身に投げてみるコマンド

# /usr/bin/zabbix_sender -vv -z 127.0.0.1 -s snmptraps -k snmptraps -o "Test"

スクリプトの変更点

ZABBIX_SERVER="localhost";
ZABBIX_SENDER="~zabbix/bin/zabbix_sender";

この部分は変更が必要だったので下記の通り。localhostじゃダメな理由・・・忘れてしまった。
zabbix_senderはRPMインストールだったので、このパス。

ZABBIX_SERVER="127.0.0.1";
ZABBIX_SENDER="/usr/bin/zabbix_sender";