Git Repository Public Repository

logcheck

URLs

Copy to Clipboard

Diff Revisions f14b4c ... vs 3de031 ... for //logcheck.pl

Diff revisions: vs.
  @@ -20,11 +20,19 @@
20 20 require 'logcheck.conf';
21 21 $mode="run";
22 22
23 + use File::Basename;
24 + use File::Spec;
25 + $dirname = File::Spec->rel2abs(dirname(__FILE__));
26 +
27 + $file_pidfile = $dirname."/logcheck.pid";
28 +
29 + $file_whitelist = $dirname."/".$file_whitelist;
30 + $file_logfilelist = $dirname."/".$file_logfilelist;
23 31
24 32 sub head() {
25 33 print "\n";
26 34 print "-----------------------------\n";
27 - print "This is logcheck.pl V1.0.4\n";
35 + print "This is logcheck.pl V1.0.5\n";
28 36 print "https://peters-webcorner.de\n";
29 37 print "project hosted on github\n";
30 38 print "https://github.com/pstimpel/logcheck\n\n";
  @@ -35,12 +43,21 @@
35 43 print "-----------------------------\n\n";
36 44 }
37 45
38 - if (($ARGV[0] ne "") && ($ARGV[0] ne "debug") && ($ARGV[0] ne "-l")) {
46 + if (($ARGV[0] ne "") && ($ARGV[0] ne "debug") && ($ARGV[0] ne "-l") && ($ARGV[0] ne "-r") && ($ARGV[0] ne "-d")) {
39 47 head();
40 48 print "Parameters:\n";
41 49 print "logcheck.pl normal run, parse logfiles and fire email if needed\n";
42 50 print "logcheck.pl debug prevents script from sending mail\n";
51 + print "logcheck.pl -d prevents script from sending mail\n";
43 52 print "logcheck.pl -l prints license to console\n";
53 + print "logcheck.pl -p removes existing pid-file with no further checks\n";
54 + print "logcheck.pl -h this screen\n";
55 + print "PID: ".$$." \n";
56 + print "DIR: ".$dirname."\n";
57 + getpidfilecontent();
58 + if($pidstring ne "unknown") {
59 + print "!!! PID-file existing, created by process ".$pidstring." !!!\n";
60 + }
44 61 exit 0;
45 62
46 63 }
  @@ -52,7 +69,14 @@
52 69 exit 0;
53 70 }
54 71
55 - if ($ARGV[0] eq "debug") {
72 + if ($ARGV[0] eq "-r") {
73 + head();
74 + unlink($file_pidfile);
75 + print "done...\n";
76 + exit 0;
77 + }
78 +
79 + if ($ARGV[0] eq "debug" || $ARGV[0] eq "-d") {
56 80 head();
57 81 print "debug mode on...\n";
58 82 $mode="debug";
  @@ -141,6 +165,34 @@
141 165 exit 1;
142 166 }
143 167
168 + if (-e $file_pidfile) {
169 + if($mode eq "debug") {
170 + print "There is a pid-file already, ".$file_pidfile.", abort execution\n";
171 + exit 1;
172 + } else {
173 + getpidfilecontent();
174 + $psstring = `ps fax`;
175 + $Jetztwert = time();
176 + $Jetztzeit = localtime($Jetztwert);
177 + $mailer = '/usr/sbin/sendmail';
178 + $Sender = $senderaddress;
179 + open(MAIL, "|$mailer -t") || die "Can't open $mailer!\n";
180 + print MAIL "To: ".$emailaddress."\n";
181 + print MAIL "Subject: Logs NOT CHECKED report $Jetztzeit\n\n\n";
182 + print MAIL "There is a pid-file already at ".$file_pidfile.", and the execution of logcheck was aborted!\n\nRemove the pid-file, but make sure logcheck is not running anymore. See output of ps fax below\n\n";
183 + print MAIL "Pid of this (the aborted process) is: ".$$."\n";
184 + print MAIL "Pid of blocking process is: ".$pidstring."\n\n";
185 +
186 + print MAIL $psstring."\n\n";
187 + close(MAIL);
188 + exit 1;
189 + }
190 + }
191 +
192 + open(ADR, ">$file_pidfile");
193 + print ADR $$;
194 + close(ADR);
195 +
144 196
145 197 foreach $thisfile (@logfiles) {
146 198 $outtext="";
  @@ -218,6 +270,9 @@
218 270 print STDERR "logfile $thisfile not found...ignoring\n";
219 271 }
220 272 }
273 +
274 + unlink($file_pidfile);
275 +
221 276 exit 0;
222 277
223 278
  @@ -251,4 +306,18 @@
251 306 close(LOG);
252 307 }
253 308
254 -
309 + sub getpidfilecontent() {
310 + $pidstring="unknown";
311 + open(ADR, "<$file_pidfile");
312 + while(<ADR>)
313 + {
314 + chop($_);
315 + if(length($_) > 1) {
316 + if (substr($_,0,1) ne "#")
317 + {
318 + $pidstring = $_;
319 + }
320 + }
321 + }
322 + close(ADR);
323 + }