ここでは、syslog-ngのもう1つの機能である、swatch で行ったようなログ監査の自動化についてとりあげます。
syslog-ngのインストール方法については syslog-ng.confのインストール 、syslog-ng.confの設定については syslog-ng.confの設定 を参照下さい。
ここでは、syslog-ngのもう1つの機能である、swatch で行ったようなログ監査の自動化についてとりあげます。
syslog-ngのインストール方法については syslog-ng.confのインストール 、syslog-ng.confの設定については syslog-ng.confの設定 を参照下さい。
destination ログの送信設定で program を利用しプログラムを呼び込む設定を行い、filterで match を利用しパターンにマッチした文字列を指定します。
destination d_su { program("/home/hoge/mail.pl"); };
filter f_su { match("su:"); };
log { source(s_sys); filter(f_su); destination(d_su); };
この設定でログの文字列にsu:という文字列があった場合に、外部プログラム(/home/hoge/mail.pl)を実行する事になります。
mail.plは管理者にメールを送るものなど利用するといいと思います。
簡単にperlで送信プログラムを作成しました。よろしければ利用下さい。
#!/usr/local/bin/perl
$sendmail = '/usr/sbin/sendmail';
$from = 'root@example.com';
$to = 'hoge@example.com';
$header = <<END;
From: $from
To: $to
Subject: Syslog Alert!
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-2022-JP
END
while (<STDIN>) {
if ($_) {
$body = $_;
$body =~ s/^<[0-9]*>//g;
open(MAIL, "| $sendmail -t -i");
print MAIL $header,$body;
close(MAIL);
}
}
$from が送信元アドレス
$to が送信先アドレスです。
パターンマッチすると$toに記述したアドレスに以下のようなメールが届きます。
From: root@example.com
To: hoge@example.com
Subject: Syslog Alert!
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-2022-JP
Oct 29 15:31:35 hoge su: (to root) huga on /dev/pts/0
syslog-ngを利用したログ監査の自動化は以上となります。
![]() |
Linuxの教科書―ホントに読んでほしいroot入門講座 (IDGムックシリーズ) アイ・ディ・ジー・ジャパン / 高町 健一郎, 大津 真, 佐藤 竜一, 小林 峰子, 安田 幸弘 ¥ 1,680 |
![]() |
日経 Linux (リナックス) 2008年 04月号 [雑誌] 日経BP出版センター / ¥ 1,490 |
![]() |
日経 Linux (リナックス) 2008年 03月号 [雑誌] 日経BP出版センター / ¥ 1,490 |