はじめに
nagiosのログ監視をするために、check_logfilesプラグインをインストールしてみたところ、
インストールするだけで躓くところがあったため記事にまとめました
前提条件
Vritualbox環境 OS CentOS7
インストール手順
check_logfilesのtar.gzファイルをダウンロードした
以下のサイトからcheck_logfiles-4.1.1.tar.gzをダウンロードしました。
WinSCPを使用してサーバーにcheck_logfiles-4.1.1.tar.gzをアップロードしました。
https://labs.consol.de/nagios/check_logfiles/#download
サーバーにSSH接続した
任意のフォルダにtarファイルを解凍した
# tar xvzf check_logfiles-4.1.1.tar.gz
check_logfiles-4.1.1フォルダが出力された
# ls -ltr
-rw-r--r--. 1 root root 257140 Jan 18 22:18 check_logfiles-4.1.1.tar.gz
drwxrwxr-x. 4 test test 4096 Jan 18 22:42 check_logfiles-4.1.1
check_logfiles-4.1.1フォルダ配下の中身を確認した
配下を確認したところ、check_logfilesプラグインがまだインストールされていない様です。
[root@localhost ~]#
[root@localhost ~]# ls -tlr check_logfiles-4.1.1
total 464
-rwxrwxr-x. 1 test test 120506 Nov 21 23:08 configure
-rwxr-xr-x. 1 test test 4623 Nov 21 23:08 winconfig.pl
-rwxr-xr-x. 1 test test 6873 Nov 21 23:08 missing
-rwxr-xr-x. 1 test test 13997 Nov 21 23:08 install-sh
-rwxr-xr-x. 1 test test 3427 Nov 21 23:08 configure.ac
-rwxr-xr-x. 1 test test 35521 Nov 21 23:08 config.sub
-rwxr-xr-x. 1 test test 45297 Nov 21 23:08 config.guess
-rw-rw-r--. 1 test test 30037 Nov 21 23:08 aclocal.m4
-rwxr-xr-x. 1 test test 2407 Nov 21 23:08 acinclude.m4
-rwxr-xr-x. 1 test test 630 Nov 21 23:08 TODO
-rwxr-xr-x. 1 test test 2436 Nov 21 23:08 README.windows-exe
-rwxr-xr-x. 1 test test 27951 Nov 21 23:08 README
-rwxr-xr-x. 1 test test 0 Nov 21 23:08 NEWS
-rw-rw-r--. 1 test test 24775 Nov 21 23:08 Makefile.in
-rwxr-xr-x. 1 test test 490 Nov 21 23:08 Makefile.am
-rwxr-xr-x. 1 test test 9240 Nov 21 23:08 INSTALL
-rw-r--r--. 1 test test 16306 Nov 21 23:08 ChangeLog
-rwxr-xr-x. 1 test test 18007 Nov 21 23:08 COPYING
-rwxr-xr-x. 1 test test 44 Nov 21 23:08 AUTHORS
-rwxr-xr-x. 1 root root 27005 Jan 18 22:42 config.status
-rw-r--r--. 1 root root 25656 Jan 18 22:42 Makefile
drwxrwxr-x. 5 test test 4096 Jan 18 22:42 t
-rw-r--r--. 1 root root 7580 Jan 18 22:42 config.log
drwxrwxr-x. 3 test test 150 Jan 18 22:43 plugins-scripts
READMEを確認した
以下の部分がcheck_logfilesプラグインのインストール手順です。翻訳しました。
check_logfilesのインストールは以下のサイトが役に立ちそうです。
http://unixservermemo.web.fc2.com/sv/nagi-install.htm
configure、make、make installの意味が分からずに
以下のQiitaの記事が大変参考になりました。有難うございます。
https://qiita.com/chihiro/items/f270744d7e09c58a50a5
ls -ltr ./check_logfiles-4.1.1/README
-rwxr-xr-x. 1 test test 27951 Nov 21 23:08 ./check_logfiles-4.1.1/README
翻訳
check_logfiles スクリプトを「コンパイル」する方法。
-------------------------------------------------- ------
1) configure スクリプトを実行して変数を初期化し、Makefile などを作成します。
./configure --prefix=BASEDIRECTORY --with-nagios-user=SOMEUSER --with-nagios-group=SOMEGROUP --with-perl=PATH_TO_PERL --with-gzip=PATH_TO_GZIP --with-trusted-path=PATH_YOU_TRUST - -with-seekfiles-dir=SEEKFILES_DIR --with-protocols-dir=PROTOCOLS_DIR
a) BASEDIRECTORY を、Nagios が存在するディレクトリのパスに置き換えます。
インストール済み (デフォルトは「/usr/local/nagios」)
b) SOMEUSER をシステム上のユーザーの名前に置き換えます。
インストールされたプラグインに割り当てられた権限 (デフォルトは「nagios」)
c) SOMEGRP をシステム上のグループの名前に置き換えます。
インストールされたプラグインに割り当てられた権限 (デフォルトは「nagios」)
d) PATH_TO_PERL を perl バイナリが見つかるパスに置き換えます。
システム全体の perl に加えて、プライベート perl をインストールしている可能性があります
nagios プラグイン専用です (デフォルトはパス内の perl です)。
e) PATH_TO_GZIP を、gzip バイナリが見つかるパスに置き換えます。
一部のオペレーティング システムでは、gzip は標準パスにありません。
(デフォルトはパス内の gzip です)。
f) PATH_YOU_TRUST を、プラグインが必要なパスに置き換えます。
特定のパターンが実行された場合に呼び出されるスクリプトを探します
見つかった。 (デフォルトは /sbin:/usr/sbin:/bin:/usr/bin です。HP-UX は、
/usr/contrib/bin をこのリストに追加します。 これは後でオーバーライドできます。
構成ファイル)。
g) SEEKFILES_DIR を、スクリプトに書き込むパスに置き換えます
それは状態ファイルです。 (デフォルトは /tmp です。後でこれをオーバーライドできます。
構成ファイル)。
h) PROTOCOLS_DIR を、スクリプトを書き込むパスに置き換えます
それはプロトコルファイルです。 (デフォルトは /tmp です。後でこれをオーバーライドできます。
構成ファイル)。
check_logfiles を作成するには、./configure を実行するだけで十分です。
構成ファイルを使用して後でカスタマイズできるスクリプト。
2) 次のコマンドでプラグインを「コンパイル」します。
make
これにより、「check_logfiles」スクリプトが生成されます。 あなたも見つけるでしょう
無視したほうがよい「check_logfiles.pl」。 のベースです
プレースホルダーで満たされたコンパイル。 これらは次の期間に交換されます。
作る過程。
3) 次のコマンドを使用して、コンパイル済みのプラグイン スクリプトをインストールします。
make install
インストール手順は、プラグインを
'libexec/' で指定したベース ディレクトリのサブディレクトリ
configure スクリプトへの --prefix 引数。
4) Nagios の構成ファイルに含まれていることを確認します。
新しいプラグインへの正しいパス。
README (1)~(4)の手順を対応しました
(1) configure スクリプトを実行して変数を初期化し、Makefile などを作成します。
Nagios が存在するディレクトリのパス「/etc/nagios」
SOMEUSER をシステム上のユーザーの名前に置き換えます
SOMEGRP をシステム上のグループの名前に置き換えます
上記は念のため、nagiosを指定しました。
他の設定は指定せずに実行しました。
[root@localhost check_logfiles-4.1.1]# ./configure --prefix=/etc/nagios --with-nagios-user=nagios --with-nagios-group=nagios
checking whether to enable maintainer-specific portions of Makefiles... no
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking whether make sets $(MAKE)... (cached) yes
variable with_seekfiles_dir is /var/tmp/check_logfiles
checking for sh... /usr/bin/sh
checking for perl... /usr/bin/perl
checking for gzip... /usr/bin/gzip
checking for gawk... /usr/bin/gawk
checking for echo... /usr/bin/echo
checking for sed... /usr/bin/sed
checking for cat... /usr/bin/cat
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: creating plugins-scripts/Makefile
config.status: creating plugins-scripts/subst
config.status: creating t/Makefile
--with-perl: /usr/bin/perl
--with-gzip: /usr/bin/gzip
--with-seekfiles-dir: /var/tmp/check_logfiles
--with-protocols-dir: /tmp
--with-trusted-path: /bin:/sbin:/usr/bin:/usr/sbin
--with-nagios-user: nagios
--with-nagios-group: nagios
[root@localhost check_logfiles-4.1.1]#
(2) 次のコマンドでプラグインを「コンパイル」します
makeを実行しました。
[root@localhost check_logfiles-4.1.1]# make
Making all in plugins-scripts
make[1]: Entering directory `/root/check_logfiles-4.1.1/plugins-scripts'
/bin/echo "#! #PERL# " | /usr/bin/gawk -f ./subst > check_logfiles
/bin/echo "# nagios: -epn" >> check_logfiles
/bin/echo >> check_logfiles
for m in Nagios/Tivoli/Config/Logfile.pm Nagios/CheckLogfiles.pm Nagios/CheckLogfiles/Search/Errpt.pm Nagios/CheckLogfiles/Search/Ipmitool.pm Nagios/CheckLogfiles/Search/Oraclealertlog.pm Nagios/CheckLogfiles/Search/Esxdiag.pm Nagios/CheckLogfiles/Search/Executable.pm Nagios/CheckLogfiles/Search/Dummy.pm Nagios/CheckLogfiles/Search/Journald.pm Nagios/CheckLogfiles/Search/Dmesg.pm; do \
/bin/sed -e 's/^1;//g' < $m | /bin/sed -e '/^__END__/,$d' | /usr/bin/gawk -f ./subst >> check_logfiles; \
done
/bin/cat check_logfiles.pl | /usr/bin/gawk -f ./subst >> check_logfiles
chmod +x check_logfiles
make[1]: Leaving directory `/root/check_logfiles-4.1.1/plugins-scripts'
Making all in t
make[1]: Entering directory `/root/check_logfiles-4.1.1/t'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/root/check_logfiles-4.1.1/t'
make[1]: Entering directory `/root/check_logfiles-4.1.1'
make[1]: Nothing to be done for `all-am'.
make[1]: Leaving directory `/root/check_logfiles-4.1.1'
[root@localhost check_logfiles-4.1.1]#
(3) 次のコマンドを使用して、コンパイル済みのプラグイン スクリプトをインストールします。
make installを実行しました。
[root@localhost check_logfiles-4.1.1]# make install
Making install in plugins-scripts
make[1]: Entering directory `/root/check_logfiles-4.1.1/plugins-scripts'
make[2]: Entering directory `/root/check_logfiles-4.1.1/plugins-scripts'
/usr/bin/mkdir -p '/etc/nagios/libexec'
/usr/bin/install -c check_logfiles '/etc/nagios/libexec'
make[2]: Nothing to be done for `install-data-am'.
make[2]: Leaving directory `/root/check_logfiles-4.1.1/plugins-scripts'
make[1]: Leaving directory `/root/check_logfiles-4.1.1/plugins-scripts'
Making install in t
make[1]: Entering directory `/root/check_logfiles-4.1.1/t'
make[2]: Entering directory `/root/check_logfiles-4.1.1/t'
make[2]: Nothing to be done for `install-exec-am'.
make[2]: Nothing to be done for `install-data-am'.
make[2]: Leaving directory `/root/check_logfiles-4.1.1/t'
make[1]: Leaving directory `/root/check_logfiles-4.1.1/t'
make[1]: Entering directory `/root/check_logfiles-4.1.1'
make[2]: Entering directory `/root/check_logfiles-4.1.1'
make[2]: Nothing to be done for `install-exec-am'.
make[2]: Nothing to be done for `install-data-am'.
make[2]: Leaving directory `/root/check_logfiles-4.1.1'
make[1]: Leaving directory `/root/check_logfiles-4.1.1'
[root@localhost check_logfiles-4.1.1]#
(4) Nagios の構成ファイルに含まれていることを確認します。
新しいプラグインへの正しいパス。
[root@localhost ~]# cd /etc/nagios
[root@localhost nagios]# ls -tlr
total 100
-rw-r--r--. 1 root root 12835 Mar 12 2021 nrpe.cfgbk
-rw-r-----. 1 root apache 27 Dec 26 01:41 passwd
-rw-rw-r--. 1 root root 45665 Dec 26 01:41 nagios.cfg
-rw-rw-r--. 1 root root 13699 Dec 26 01:41 cgi.cfg
-rw-r--r--. 1 root root 13189 Jan 15 10:19 nrpe.cfg
drwxr-x---. 2 root nagios 26 Jan 16 08:58 private
drwxr-x---. 2 root nagios 167 Jan 16 08:58 objects
※以下フォルダが自動で作成されていることを確認した
drwxr-xr-x. 2 root root 6 Jan 18 22:40 seek
drwxr-xr-x. 2 root root 28 Jan 18 22:44 libexec
[root@localhost nagios]#
check_logfilesプラグインの動作確認をしました。
[root@localhost dummy]# /root/check_logfiles-4.1.1/plugins-scripts/check_logfiles --config
Option config requires an argument
This Nagios Plugin comes with absolutely NO WARRANTY. You may use
it on your own risk!
Copyright by ConSol Software GmbH, Gerhard Lausser.
This plugin looks for patterns in logfiles, even in those who were rotated
since the last run of this plugin.
You can find the complete documentation at
http://labs.consol.de/nagios/check_logfiles/
Usage: check_logfiles [-t timeout] -f <configfile>
The configfile looks like this:
$seekfilesdir = '/opt/nagios/var/tmp';
# where the state information will be saved.
$protocolsdir = '/opt/nagios/var/tmp';
# where protocols with found patterns will be stored.
$scriptpath = '/opt/nagios/var/tmp';
# where scripts will be searched for.
$MACROS = { CL_DISK01 => "/dev/dsk/c0d1", CL_DISK02 => "/dev/dsk/c0d2" };
@searches = (
{
tag => 'temperature',
logfile => '/var/adm/syslog/syslog.log',
rotation => 'bmwhpux',
criticalpatterns => ['OVERTEMP_EMERG', 'Power supply failed'],
warningpatterns => ['OVERTEMP_CRIT', 'Corrected ECC Error'],
options => 'script,protocol,nocount',
script => 'sendnsca_cmd'
},
{
tag => 'scsi',
logfile => '/var/adm/messages',
rotation => 'solaris',
criticalpatterns => 'Sense Key: Not Ready',
criticalexceptions => 'Sense Key: Not Ready /dev/testdisk',
options => 'noprotocol'
},
{
tag => 'logins',
logfile => '/var/adm/messages',
rotation => 'solaris',
criticalpatterns => ['illegal key', 'read error.*$CL_DISK01$'],
criticalthreshold => 4
warningpatterns => ['read error.*$CL_DISK02$'],
}
);
補足情報
以下のログ監視のtagの情報は、
一般的にはエラーメッセージにtag情報を出力することで、フィルタする際のキーワードとして利用することがあります。後は同じ種別の設定をまとめるグルーピング的な役割があります。
nagiosのログ監視のタグ情報は識別用の文字となります。
@searches = (
{
tag => 'logins',
logfile => '/var/adm/messages',
rotation => 'solaris',
criticalpatterns => ['illegal key', 'read error.*$CL_DISK01$'],
criticalthreshold => 4
warningpatterns => ['read error.*$CL_DISK02$'],
}
);