Mercurial > repos > other > Puppet
annotate common/logwatch/http-error @ 260:5f63afb70415
Fix naming of files for new VPS overrides
$hostname is just the short host name, not the FQDN
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 29 Dec 2019 10:57:18 -0500 |
parents | 8316d4e55e92 |
children |
rev | line source |
---|---|
126 | 1 #!/usr/bin/perl |
0
956e484adc12
Initial public release of Puppet configs
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
2 # |
126 | 3 ########################################################################## |
4 ## Copyright (c) 2016 Logwatch | |
0
956e484adc12
Initial public release of Puppet configs
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
5 ## Covered under the included MIT/X-Consortium License: |
956e484adc12
Initial public release of Puppet configs
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
6 ## http://www.opensource.org/licenses/mit-license.php |
956e484adc12
Initial public release of Puppet configs
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
7 ## All modifications and contributions by other persons to |
956e484adc12
Initial public release of Puppet configs
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
8 ## this script are assumed to have been donated to the |
956e484adc12
Initial public release of Puppet configs
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
9 ## Logwatch project and thus assume the above copyright |
956e484adc12
Initial public release of Puppet configs
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
10 ## and licensing terms. If you want to make contributions |
956e484adc12
Initial public release of Puppet configs
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
11 ## under your own copyright or a different license this |
956e484adc12
Initial public release of Puppet configs
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
12 ## must be explicitly stated in the contribution an the |
956e484adc12
Initial public release of Puppet configs
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
13 ## Logwatch project reserves the right to not accept such |
956e484adc12
Initial public release of Puppet configs
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
14 ## contributions. If you have made significant |
956e484adc12
Initial public release of Puppet configs
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
15 ## contributions to this script and want to claim |
956e484adc12
Initial public release of Puppet configs
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
16 ## copyright please contact logwatch-devel@lists.sourceforge.net. |
126 | 17 ########################################################################## |
0
956e484adc12
Initial public release of Puppet configs
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
18 |
126 | 19 use diagnostics; |
0
956e484adc12
Initial public release of Puppet configs
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
20 use strict; |
956e484adc12
Initial public release of Puppet configs
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
21 |
126 | 22 my $Detail = $ENV{'LOGWATCH_DETAIL_LEVEL'} || 0; |
0
956e484adc12
Initial public release of Puppet configs
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
23 |
126 | 24 sub CustomizeErrorString { |
25 my ($LogLevel, $ErrorCode, $Description) = @_; | |
26 # This function is only invoked when detail is set to 8 or 9. | |
27 # Here you would modify the Description. Some Description strings | |
28 # may differ only on some printed parameters, and it is preferable | |
29 # to group them together. Examples of these may be process numbers, | |
30 # IP addresses, port numbers, or file names. The purpose of this | |
31 # function is to "collapse" these different messages into the same | |
32 # array entry. | |
0
956e484adc12
Initial public release of Puppet configs
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
33 |
126 | 34 # For now, simply return the string. |
35 return($Description); | |
36 } | |
0
956e484adc12
Initial public release of Puppet configs
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
37 |
126 | 38 my %LogMessages = (); |
39 my $MatchFilter = $ENV{'http_error_matchfilter'} || ""; | |
40 my $ReportFilter = $ENV{'http_error_reportfilter'} || ""; | |
0
956e484adc12
Initial public release of Puppet configs
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
41 |
126 | 42 while (defined(my $ThisLine = <STDIN>)) { |
43 if (my ($LogLevel, $ErrorCode, $Description) = | |
44 ($ThisLine =~ /:(.*?)\].*(AH\d{5}): (.*)/) ) { | |
45 # $MatchFilter is a variable that is set by setting the | |
46 # $HTTP_Error_MatchFilter variable in the conf/services/http-error.conf | |
47 # file. It is executed here, before any other matching statements. | |
48 eval $MatchFilter; | |
49 if ($@) { | |
50 print $@; | |
51 print "While processing MatchFilter:\n$MatchFilter\n"; | |
52 } | |
53 # $ThisLine might have been reset (undef, or empty string) in $MatchFilter | |
54 next unless $ThisLine; | |
55 | |
56 if (($Detail == 8) || ($Detail == 9)) { | |
57 $Description = CustomizeErrorString($LogLevel, $ErrorCode, $Description); | |
58 } | |
59 if (($Detail >= 1) || ($LogLevel =~ "emerg|alert|crit|error")) { | |
60 $LogMessages{$LogLevel}{$ErrorCode}{$Description}++; | |
61 } | |
62 } | |
0
956e484adc12
Initial public release of Puppet configs
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
63 } |
956e484adc12
Initial public release of Puppet configs
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
64 |
126 | 65 # $ReportFilter is a variable that is set by setting the |
66 # $HTTP_Error_ReportFilter variable in the conf/services/http-error.conf | |
67 # file. It is executed here, before any other printing statements. | |
68 eval $ReportFilter; | |
69 if ($@) { | |
70 print $@; | |
71 print "While processing ReportFilter:\n$ReportFilter\n"; | |
0
956e484adc12
Initial public release of Puppet configs
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
72 } |
956e484adc12
Initial public release of Puppet configs
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
73 |
126 | 74 if (keys %LogMessages) { |
75 my $Count = 0; | |
76 foreach my $LogLevel (keys %LogMessages) { | |
77 printf("\nLevel %-6s", $LogLevel); | |
78 foreach my $ErrorCode (keys %{$LogMessages{$LogLevel}}) { | |
79 print "\n Error Code: $ErrorCode" if $Detail >= 5; | |
80 foreach my $Description (keys %{$LogMessages{$LogLevel}{$ErrorCode}}) { | |
81 if ($Detail >= 9) { | |
82 print "\n $Description: "; | |
83 print "$LogMessages{$LogLevel}{$ErrorCode}{$Description} Time(s)"; | |
84 } | |
85 $Count += $LogMessages{$LogLevel}{$ErrorCode}{$Description}; | |
86 } # foreach $Description | |
87 if (($Detail >= 5) && ($Detail < 9)) { | |
88 printf(": %5d Time(s)", $Count); | |
89 $Count = 0; | |
90 if ($Detail >=6) { | |
91 print "\n E.g.: "; | |
92 # print only first entry (index 0) | |
93 my $EG_string = (keys %{$LogMessages{$LogLevel}{$ErrorCode}})[0]; | |
94 if (($Detail == 6) && (length($EG_string) > 66)) { | |
95 printf ("%.62s ...", $EG_string); | |
96 } else { | |
97 print $EG_string; | |
98 } | |
99 } | |
100 } | |
101 } # foreach $ErrorCode | |
102 if ($Detail < 5) { | |
103 printf("%s%5d%s", ": ", $Count, " Time(s)"); | |
104 $Count = 0; | |
105 } | |
106 } # foreach $LogLevel | |
107 } # if keys %LogMessages | |
108 | |
109 exit(0); | |
110 | |
111 # vi: shiftwidth=3 tabstop=3 syntax=perl et | |
112 # Local Variables: | |
113 # mode: perl | |
114 # perl-indent-level: 3 | |
115 # indent-tabs-mode: nil | |
116 # End: |