logwatchの設定
システムログ内容を設定により抽出、編集し、メールで管理者に通知してくれるlogwatchの説明(logatchのバージョンは7.3系です)
logwatchはcronで定期的に実行されます。あらかじめ定義したパターンにより内容を抽出します。
出力例 ################### Logwatch 7.3 (03/24/06) #################### Processing Initiated: Tue Nov 2 12:27:18 2007 Date Range Processed: yesterday ( 2007-Nov-1 ) Period is day. Detail Level of Output: 0 Type of Output: unformatted Logfiles for Host: hoge.hooge.jp ################################################################## --------------------- httpd Begin ------------------------ Requests with error response codes 404 Not Found /xxx/favicon.ico: 2 Time(s) /robots.txt: 4 Time(s) ---------------------- httpd End ------------------------- --------------------- pam_unix Begin ------------------------ runuser: Unknown Entries: session closed for user beaglidx: 2 Time(s) session opened for user beaglidx by (uid=0): 2 Time(s) su-l: Authentication Failures: hoge(500) -> root: 1 Time(s) Sessions Opened: hoge(uid=500) -> root: 1 Time(s) ---------------------- pam_unix End ------------------------- --------------------- postfix Begin ------------------------ 62872 bytes transferred 4 messages sent 4 messages removed from queue Relaying denied: 3 Time(s) Messages rejected using Anti-Spam site 4 Time(s) all.rbl.jp identified 4 spam messages. Connections lost: Connection lost while DATA : 3 Time(s) Connection lost while EHLO : 3 Time(s) ---------------------- postfix End ------------------------- --------------------- Connections (secure-log) Begin ------------------------ **Unmatched Entries** webmin[32016]: Successful login as root from 192.168.1.1 : 1 Time(s) ---------------------- Connections (secure-log) End ------------------------- --------------------- SSHD Begin ------------------------ Users logging in through sshd: hoge: xxx.xxx.xxx.xxx (hogehoge.ne.jp): 1 time ---------------------- SSHD End ------------------------- --------------------- XNTPD Begin ------------------------ Total synchronizations 134 (hosts: 3) ---------------------- XNTPD End ------------------------- --------------------- Disk Space Begin ------------------------ Filesystem Size Used Avail Use% Mounted on /dev/hda1 6.8G 3.3G 3.3G 51% / /dev/hda2 9.7G 3.2G 6.1G 35% /work /dev/hda4 130G 21G 103G 17% /demo ---------------------- Disk Space End ------------------------- ###################### Logwatch End #########################
logwatchの設定ファイル
logwatch-7.3系でのデフォルト設定ファイルは/usr/share/logwatch/default.conf/logwatch.conf*1です。
ログファイルの保存場所、メール送信先、対象ログの抽出期間などを設定できます。デフォルト設定から変更する事はないと思います。
各ログファイル、各サービス毎の条件設定
各サービスごと、各ログファイルごとに抽出条件を設定できます。
各サービスの設定は
/usr/share/logwatch/default.conf/services/
各ログファイルの設定は
/usr/share/logwatch/default.conf/logfiles/
のディレクトリ配下になります。
設定例
デフォルトの設定でPostfixを運用していると、「statistics: max connection rate 1/60s」のようなログがlogwatchが拾っています。
このログは情報を示しているログでPostfixの異常ではありません。今回は「statistics」を含む行をlogwatchで拾わないように設定します。
- /usr/share/logwatch/default.conf/services/postfix.confの編集
上記がPostfixの設定ファイルなので、下記の行を追加します。
*Remove = statistics
*Removeは指定した文字列にマッチした行はチェック対象外にする(大文字小文字の区別なし)と言う意味です。
- 実行結果の確認
下記コマンドを入力するとlogwatchの実行結果をターミナルに出力します
/usr/share/logwatch/scripts/logwatch.pl --print
翌日からは、上記結果を同じ内容がメールで送信されます。
参考URL
アクセスログの改ざんと検出方法 (2/2):不正侵入の手口と対策(6) - @IT~
http://memo.blogdns.net/logwatch.html
*1:logwatch 5系は/etc/log.d/logwatch配下です