自作の Nagios プラグインをシェルスクリプトで作成するとき、今まで自分で STATE_OK と定義していたのですが、他のシェルスクリプトでできている Nagios プラグインをみてみたところ、Nagios プラグインに付属している utils.sh を使っていました。
utils.sh は、次のような内容でした。
#! /bin/sh
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
STATE_DEPENDENT=4
if test -x /usr/bin/printf; then
ECHO=/usr/bin/printf
else
ECHO=echo
fi
print_revision() {
echo "$1 v$2 (nagios-plugins 1.4.15)"
$ECHO "The nagios plugins come with ABSOLUTELY NO WARRANTY. You may redistribute\ncopies of the plugins under the terms of the GNU General Public License.\nFor more information about these matters, see the file named COPYING.\n" | sed -e 's/\n/ /g'
}
support() {
$ECHO "Send email to nagios-users@lists.sourceforge.net if you have questions\nregarding use of this software. To submit patches or suggest improvements,\nsend email to nagiosplug-devel@lists.sourceforge.net.\nPlease include version information with all correspondence (when possible,\nuse output from the --version option of the plugin itself).\n" | sed -e 's/\n/ /g'
}
なるほど、この utils.sh を使えば、かなり便利そうです。
この utils.sh を組み込んで、さらに –hostname パラメータを解析する Nagios プラグインのテンプレートを次のように作ってみました。
#!/bin/sh
PROGNAME=`basename $0`
PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'`
. $PROGPATH/utils.sh
for i in $*; do
case $i in
--hostname=*)
HOSTNAME=`echo $i | awk -F= '{print $2}'`
;;
*)
;;
esac
done
(さまざまな処理)
exit $STATE_OK
しばらくこのテンプレートをベースに自作の Nagios Plugin を作成してみようと思います。
Tags: nagios
![エキスパートのためのMySQL[運用+管理]トラブルシューティングガイド](http://ecx.images-amazon.com/images/I/41oqE-9dM2L._SL160_.jpg)






