Attention! Translated article might be found on my English blog.

2015年1月22日木曜日

logwatchの404リストに参照元IPを付加する

参考: logwatchのhttpログ監視の出力項目をカスタマイズ(アクセス元IPを出力してみる) - ike-daiの日記

上記記事のパッチを自サーバも適用しました。
ただしそのままでは使えなかったので若干修正しました。

137a138
> my %ip_list =();
566a568
>       $ip_list{$fmt_url} = $ip_list{$fmt_url}.$field{client_ip}."\n";
721c723,724
<             print "      $url: $needs_exam{$code}{$url} Time(s)\n";
---
> #            print "      $url: $needs_exam{$code}{$url} Time(s)\n";
>             print "\n     $url: $needs_exam{$code}{$url} Time(s)\n$ip_list{$url}" ;

diffの方向を変えたのと、IPを連想配列へ追加している部分を別の行に変更しました。
なお、自サーバは
・CentOS 6.4
・Logwatch 7.3.6
・Apache 2.2.15
です。
perlスクリプトのバージョンは

##########################################################################
# $Id: http,v 1.37 2007/03/05 04:53:42 bjorn Exp $

##########################################################################

となってました。