4 require 'logcheck.conf';
10 print "-----------------------------\n";
11 print "This is logcheck.pl V1.0.3\n";
12 print "http://peters-webcorner.de\n";
13 print "project hosted on origo\n";
14 print "http://logcheck.origo.ethz.ch\n";
15 print "-----------------------------\n\n";
18 if (($ARGV[0] ne "") && ($ARGV[0] ne "debug")) {
20 print "you can use 'logcheck.pl debug' or 'logcheck.pl' without any parameters\n";
21 print "hint: using debug will prevent script from sending mail...\n";
26 if ($ARGV[0] eq "debug") {
28 print "debug mode on...\n";
33 if (-e $file_whitelist) {
34 if($mode eq "debug") {
35 print "whitelist found...\n";
40 open(ADR, ">$file_whitelist");
43 print "Please edit ".$file_whitelist." first...\n";
47 if (-e $file_logfilelist) {
48 if($mode eq "debug") {
49 print "list of logfiles found...\n";
52 open(ADR, ">$file_logfilelist");
55 print "Please edit ".$file_logfilelist." first...\n";
62 open(ADR, "<$file_whitelist");
67 if (substr($_,0,1) ne "#")
70 push @whitelisted, $_;
76 if($mode eq "debug") {
77 print $read." entries in whitelist found\n";
82 if($mode eq "debug") {
83 print "no entries in whitelist found, may be not normal...\n";
90 open(ADR, "<$file_logfilelist");
95 if (substr($_,0,1) ne "#")
104 if($mode eq "debug") {
105 print $read." entries in logfile list found\n";
110 print "there must be at least one entry in "..$file_logfilelist."\n";
111 print "ABORTING NOW!!!\n";
116 foreach $thisfile (@logfiles) {
121 if($mode eq "debug") {
122 print "processing ".$thisfile."\n";
128 if(-e $thisfile.".offset") {
129 if($mode eq "debug") {
130 print "using ".$thisfile.".offset\n";
133 open(OFF,"<$thisfile.offset");
137 if($mode eq "debug") {
138 print "offset is $_\n";
146 unlink($thisfile.".offset");
147 if($mode eq "debug") {
148 print "offset not found, reparsing without offset\n";
154 if ($outtext ne "") {
155 if($mode eq "debug") {
156 print "mail not sent, cause debug is enabled\n";
157 print "content of mail to $emailaddress would be:\n---------------------------------\n";
159 print "\n---------------------------------\nend of mail\n";
162 $Jetztzeit = localtime($Jetztwert);
163 $mailer = '/usr/sbin/sendmail';
164 $Sender = $senderaddress;
165 open(MAIL, "|$mailer -t") || die "Can't open $mailer!\n";
166 print MAIL "To: ".$emailaddress."\n";
167 print MAIL "Subject: ($thisfile) violation report $Jetztzeit\n\n\n";
170 $command="\/usr\/bin\/logger -p warn logcheckprint";
174 if($mode eq "debug") {
175 print "nothing to send, $thisfile seems to be ok\n";
178 if ($noffset ne "") {
179 if($mode eq "debug") {
180 print "new offset written in ".$thisfile.".offset\n";
182 open(ADR, ">$thisfile.offset");
189 print STDERR "logfile $thisfile not found...ignoring\n";
196 # checks the logfile itself
197 open(LOG,"<$thisfile");
200 if ($jumpover == 0) {
202 foreach $wltext (@whitelisted)
211 $outtext=$outtext.$_;
214 $noffset = substr($_,0,15,);
215 if(substr($_,0,15) eq $offset) {
217 if($mode eq "debug") {
218 print "offset found\n";