Apache Webサーバで記録されているログファイルから、HTTPリザルトコード300以上のもの及びエラーログを抽出し、見やすいHTML形式に成形するPerlスクリプト。cronで毎日のログローテーション後に実行する自動化ツールとして作成しています。
目次 |
##### GLOBAL CONFIG VALUE ##### # LOG directory our $log_directory = './var/log/'; # LOG file pattern ( string for sprintf('name%d%d%d', $y, $m, $d) ) our $log_filename_template = 'access_log_%04d%02d%02d'; # ERROR_LOG file pattern ( string for sprintf('name%d%d%d', $y, $m, $d) ) our $errorlog_filename_template = 'error_log_%04d%02d%02d'; # Output directory our $output_directory = './var/www/'; # Output file pattern ( string for sprintf('name%d%d%d', $y, $m, $d) ) our $output_filename_template = 'log_report_%04d%02d%02d.html'; # Output files index filename our $output_index_filename = 'log_index.html'; # Error Message Log Output (in Output directory) our $error_message_filename = 'log_report_error.txt';
perl parse-apache-log.pl 1
ブラウザで表示させた例
Apacheアクセスログ(ファイル名の例:access_log_20120207)
crawl-66-249-69-107.googlebot.com - - [07/Feb/2012:09:02:19 +0900] "GET /mw/index.php?title=%E7%89%B9%E5%88%A5:%E6%9C%80%E8%BF%91%E3%81%AE%E6%9B%B4%E6%96%B0&limit=100&from=20120128120010 HTTP/1.1" 200 1918 "-" "Mozilla/5.0 (compatible; Goog...skipping... host-92-9-199-86.as43234.net - - [07/Feb/2012:09:16:35 +0900] "GET /mw/index.php?title=http://210.1.60.156:2082/index.html? HTTP/1.1" 301 5 "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)" host-92-9-199-86.as43234.net - - [07/Feb/2012:09:16:36 +0900] "GET /mw/index.php?title=Http://210.1.60.156:2082/index.html%3F HTTP/1.1" 404 5778 "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)" crawl-66-249-69-107.googlebot.com - - [07/Feb/2012:09:16:46 +0900] "GET /mw/index.php?title=%E7%89%B9%E5%88%A5:%E6%9C%80%E8%BF%91%E3%81%AE%E6%9B%B4%E6%96%B0&limit=250&days=1&from=20120127151725 HTTP/1.1" 200 1918 "-" "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)" 113x35x2x244.ap113.ftth.ucom.ne.jp - - [07/Feb/2012:09:16:59 +0900] "GET /other/energy-save/ HTTP/1.1" 200 8893 "http://www.google.co.jp/url?sa=t&rct=j&q=%E6%B6%B2%E6%99%B6%E3%83%86%E3%83%AC%E3%83%93+%E6%B6%88%E8%B2%BB%E9%9B%BB%E5%8A%9B&source=web&cd=3&sqi=2&ved=0CEwQFjAC&url=http%3A%2F%2Foasis.halfmoon.jp%2Fother%2Fenergy-save%2F&ei=a20wT5rGO632mAWCn6DfBQ&usg=AFQjCNEW6Hqfduve0zNyspH36-tR_LSDWA" "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.04506.648; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)"
Apacheエラーログ(ファイル名の例:error_log_20120207 )
[Tue Feb 7 20:58:09 2012] [error] [client 119.63.196.62] client denied by server configuration: /home/user/www/error403.html [Tue Feb 7 21:57:49 2012] [error] [client 195.29.242.19] File does not exist: /home/user/www/extphoto2/bosnia_photo/imgp3790.jpg [Tue Feb 7 22:08:50 2012] [error] [client 119.63.196.123] client denied by server configuration: /home/user/www/traveldia2/adria99/ad-5.html [Tue Feb 7 22:08:50 2012] [error] [client 119.63.196.123] client denied by server configuration: /home/user/www/error403.html [Tue Feb 7 22:58:58 2012] [error] [client 208.115.113.90] client denied by server configuration: /home/user/www/other/eu-enlarge-200405/.ht
GNU GPL フリーソフトウエア http://www.opensource.jp/gpl/gpl.ja.html
このプログラムはフリーソフトウェアです。あなたはこれを、フリーソフトウェア財団によって発行された GNU 一般公衆利用許諾契約書(バージョン2か、希望によってはそれ以降のバージョンのうちどれか)の定める条件の下で再頒布または改変することができます。
このプログラムは有用であることを願って頒布されますが、*全くの無保証* です。商業可能性の保証や特定の目的への適合性は、言外に示されたものも含め全く存在しません。詳しくはGNU 一般公衆利用許諾契約書をご覧ください。
あなたはこのプログラムと共に、GNU 一般公衆利用許諾契約書の複製物を一部受け取ったはずです。もし受け取っていなければ、フリーソフトウェア財団まで請求してください(宛先は the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA)。