Studio3104::BLOG.new

uninitialized constant Studio3104 (NameError)

【CentOS】nagiosの通知をIRCに吐く



nagiosExchangeにあがっているnagircbot
はバージョンが古いので、
開発者のサイトから最新版をDL、インストールした

[root@hoge ~]# cd /usr/local/src/
[root@hoge src]# wget http://www.vanheusden.com/nagircbot/nagircbot-0.0.33.tgz
[root@hoge src]# tar zxvf nagircbot-0.0.33.tgz 
[root@hoge src]# cd nagircbot-0.0.33
[root@hoge nagircbot-0.0.33]# make all && make install

インストールオシマイ(*´Д`)!!簡単!!!

パスが通っていることと、

[root@hoge ~]# which nagircbot 
/usr/local/bin/nagircbot

オプションを確認しておきませう

[root@hoge ~]# nagircbot -h
nagircbot, v0.0.33 (C) 2006-2011 by folkert@vanheusden.com

-f     path to status.log ('status_file' parameter in nagios.cfg)
-F     host:port for retrieving status.log
-x     status.log is in nagios 1.0 format
-X     status.log is in nagios 2.0/3.0 format
-s     IRC server to connect to (host:port)
-c     channel to connect to (#channel - do not forget to escape the '#' in your shell)
-k     keyword for the channel to connect to (default: no keyword)
-C     use colors
-n     nick
-u     username (for logging into the irc server)
-U     name (as seen by other users)
-p     password (for logging into the irc server)
-N     prefix for all in-channel messages, e.g. for nick highlight
-m     display all information on separate lines
-t     show a summary in the topic-line
-i     check interval (in seconds - default 60)
-I     how often to announce the global status in the channel (in seconds, 0 for off)
       do not set it smaller then the -i value
-d     do not fork into the background
-T x   checks to see if nagios is still running. comma-seperated list
       (without spaces!) with the following elements:
       max_time_last_host_update, max_time_oldest_host_update,
       max_time_last_host_check, max_time_oldest_host_check,
       max_time_last_service_check, max_time_oldest_service_check,
       max_time_oldest_next_service_check
       send 'check' in a private message to invoke the check
-z user	user to run as
-H     show only state type 'HARD' (default)
-S     show also state type 'SOFT'
-R     only announce CRITICAL/UNKNOWN errors on the channel
-A x   filter (omit) lines that match with the given regular expression
-P x   write pid to file x
-e     Use encryption (SSL) (default: no)


今回自分の環境で使用したオプションは以下
環境によって過不足あるかと思いますので、適宜変更してください

-s IRCサーバのアドレス:ポート
-c #チャンネル名(シングルクォートで括る or #をエスケープ)
-k チャンネルに入るためにパスワード
-n ニックネーム
-f nagiosのステータスファイル(デフォルトは/usr/local/nagios/var/status.dat)
-P pidファイル
-S softな通知も吐く
-C 色付きで吐く
-e SSL通信を行う

起動スクリプト
雑な作りだけどしっかり動きます(start関数は、環境に応じて変更してください)
気になる方はご自身でご用意を

[root@hoge ~]# vim /etc/init.d/nagircbot

#!/bin/bash
#
# chkconfig:	345 99 01
#
# description: notification from nagios to IRC \
# pidfile: /var/run/nagircbot.pid

PID="/var/run/nagircbot.pid"

start() {
	if [ -f ${PID} ];then
		echo "already running"
	else
		echo -n $"Starting nagircbot: "
		nagircbot \
			-s 192.168.0.1:6667 \
			-c '#channel_name' \
			-k 'channel_keyword' \
			-n 'nagios' \
			-f /usr/local/nagios/var/status.dat \
			-P ${PID} \
			-S -C -e
		echo
	fi
}

stop() {
	if [ -f ${PID} ];then
		echo -n $"Stopping nagircbot: "
		kill `cat ${PID}`
		echo
	else
		echo "pidfile does not exists"
	fi
}

restart() {
	stop
	start
}

case "$1" in
  start)
	start
	;;
  stop) 
	stop
	;;
  restart)
	restart
	;;
  *)
	echo $"Usage: $0 {start|stop|restart}"
	exit 1
esac

自動起動設定

[root@hoge ~]# chkconfig --add nagircbot
[root@hoge ~]# chkconfig nagircbot on
[root@hoge ~]# chkconfig --list nagircbot
nagircbot      	0:off	1:off	2:on	3:on	4:on	5:on	6:off


起動すると、IRCnagiosさんが入ってくるはずです

アラートは、こんな感じで表示されます

(15時08分00秒) nagios: 2011/12/07 15:07 CRIT hoge loadAvg CRITICAL: loadAvg is 32.02
(15時09分00秒) nagios: 2011/12/07 15:07 OK hoge loadAvg OK: loadAvg is 0.00






こんなやり方もあります↓ ※リンク先は当blogとは無関係です
http://d.hatena.ne.jp/hirose31/20090521/1242906800