Log解析ツールその1

Logファイルを読み込んで、それを解析するツール
複数人で解析できるように、WEBアプリがいいかな。

会社で楽に設定できるように、Java+Tomcatはやめる。面倒なので。
DBはSQLiteでいく。
(Perl|PHP|Python)のどれでやるか?
PHPは嫌いなので、パス。
Perl|Pythonなんだけど、Pythonはインデントと:ってのが苦手だった…

def test(a) :
 if a == "a" :
   a = "a"
 b = "b"

ということで、全く使ったことがないperlで行ってみる。

テーブル構成は
PROJECT情報を格納したテーブルと
PROJECTID、日付、ログの種類、ユーザID、ログの中身かな?
ファイルを取り込む口と検索と、検索結果を表示するところと、管理画面があればOKか。


[Perl] Template-Toolkitをインストール

$ wget http://search.cpan.org/CPAN/authors/id/A/AB/ABW/Template-Toolkit-2.19.tar.gz
$ tar xzfv Template-Toolkit-2.19.tar.gz
$ cd Template-Toolkit-2.19
# perl Makefile.PL
# make test
# make 
# make install

モジュールが足りないと怒られたのでAppConfigを追加

# perl -MCPAN -e shell
cpan> install AppConfig
cpan> quit
# make install

とりあえずインストールが完了したので、サンプルプログラムを作ってみる。
sample.pl

#!/usr/bin/perl

print "Content-type: text/html\n\n";

use strict;
use Template;

my $template = Template->new;
my $output;

$template->process(
'sample.html',
{},
\$output,
);
print $output;

sample.html

<html>
<body>
[%- FOR [1..10] %]
[% loop.count %]:TEST<BR>
[%- END %]
</body>
</html>

sample.plを実行すると

Content-type: text/html
<html>
<body>
1:TEST<BR>
2:TEST<BR>
3:TEST<BR>
4:TEST<BR>
5:TEST<BR>
6:TEST<BR>
7:TEST<BR>
8:TEST<BR>
9:TEST<BR>
10:TEST<BR>
</body>
</html>

httpd.confに設定を追加

LoadModule perl_module modules/mod_perl.so
<Files *.pl>
        SetHandler perl-script
        PerlHandler ModPerl::Registry
        Options +ExecCGI
        PerlSendHeader On
        Order allow,deny
        Allow from all
</Files>

これで拡張子がplのファイルが見れるようになった。