File: puppet

package info (click to toggle)
logwatch 7.14-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,572 kB
  • sloc: perl: 8,290; sh: 354; makefile: 38
file content (321 lines) | stat: -rw-r--r-- 11,358 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321

########################################################
# Please file all bug reports, patches, and feature
# requests under:
#      https://sourceforge.net/p/logwatch/_list/tickets
# Help requests and discusion can be filed under:
#      https://sourceforge.net/p/logwatch/discussion/
########################################################

########################################################
## Copyright (c) 2011 Nathan Crawford
## Covered under the included MIT/X-Consortium License:
##    http://www.opensource.org/licenses/mit-license.php
## All modifications and contributions by other persons to
## this script are assumed to have been donated to the
## Logwatch project and thus assume the above copyright
## and licensing terms.  If you want to make contributions
## under your own copyright or a different license this
## must be explicitly stated in the contribution and the
## Logwatch project reserves the right to not accept such
## contributions.  If you have made significant
## contributions to this script and want to claim
## copyright please contact logwatch-devel@lists.sourceforge.net.
#########################################################
use strict;

# Detail level
my $Detail = $ENV{'LOGWATCH_DETAIL_LEVEL'} || 0;

# Config
my $offline = $ENV{'puppet_offline_ok'};

# Init counters
my $FailedRuns = 0;
my $SuccessfulRuns = 0;
my $ResourceFailures = 0;
my $DependencyFailures = 0;
#Init String containers
my (
$attr,      $content,   $file,
$fileinfo,  $from,      $name,
$source,    $target,    $to,
$type
);
# Init hashes
my (
%Changed,           %ChangedPackages,   %Created,
%Errors,            %ExecRuns,          %ExpiryChanged,
%Failures,          %FileBucketed,      %InstalledPackages,
%OtherList,         %PasswordChanged,   %Removed,
%RemovedPackages,   %Reparsed,          %ScheduledRefresh,
%ServiceStarts,     %ServiceStops
);

while (defined(my $ThisLine = <STDIN>)) {
   chomp($ThisLine);
   if (
      ($ThisLine =~ /Using cached catalog/) or
      ($ThisLine =~ /Caching catalog for /) or
      ($ThisLine =~ /Caching node for /) or
      ($ThisLine =~ /Caught TERM; calling stop/) or
      ($ThisLine =~ /[sS]hutting down/) or
      ($ThisLine =~ /Reopening log files/) or
      ($ThisLine =~ /Starting Puppet client version /) or
      ($ThisLine =~ /Restarting with.+puppetd/) or
      ($ThisLine =~ /Caught HUP; calling restart/) or
      ($ThisLine =~ /Skipping because of failed dependencies/) or
      ($ThisLine =~ /Failed to generate additional resources/) or
      ($ThisLine =~ /Could not evaluate: getaddrinfo: Name or service not known/) or
      ($ThisLine =~ /replacing from source .+ with contents /) or
      ($ThisLine =~ /Starting catalog run/) or
      ($ThisLine =~ /Applying configuration version/) or
      ($ThisLine =~ /Loading facts in/) or
      ($ThisLine =~ /Retrieving plugin/) or
      ($ThisLine =~ /FileBucket adding/) or
      ($ThisLine =~ /^Caching certificate/) or
      ($ThisLine =~ /^Certificate Request fingerprint/) or
      ($ThisLine =~ /^Creating state file/) or
      ($ThisLine =~ /Provider useradd does not support features manages/)
   ) {
      # Ignore
   } elsif (my ($junk, $failure, $reason) = ($ThisLine =~ /^(\(.*\) |)Could not ([^:]*): (.*)/)) {
      if ($reason == "getaddrinfo: Name or service not known" && $offline) {
         $FailedRuns--;
      } else {
         $Failures{$failure}->{$reason}++;
      }
   } elsif ($ThisLine =~ /Finished catalog run in [0-9]+\.[0-9]+ seconds/) {
      $SuccessfulRuns++;
   } elsif ($ThisLine =~ /Applied catalog in [0-9]+\.[0-9]+ seconds/) {
      $SuccessfulRuns++;
   } elsif ($ThisLine =~ /skipping run/) {
      $FailedRuns++;
   } elsif ($ThisLine =~ /(Did not receive certificate)/) {
      $Errors{$1}++;
   } elsif (($file) = $ThisLine =~ /Reparsing (.*)/) {
      $Reparsed{$file}++;
   } elsif (($fileinfo) = ($ThisLine =~ /Filebucketed (.*)/)) {
      $FileBucketed{$1}++;
   } elsif ($ThisLine =~ /Dependency .+\[.+\] has ([0-9]+ |)failure/) {
      $DependencyFailures++;
   } elsif (
      ($ThisLine =~ /Failed to retrieve current state of resource/) or
      ($ThisLine =~ /Package.+ensure.+Could not find package/) or
      ($ThisLine =~ /File\[.+\].+ Could not describe /) or
      ($ThisLine =~ /File\[.+\].+ No specified sources exist/)
   ) {
      $ResourceFailures++;
   } elsif ($ThisLine =~ /Package\[(.+)\].+ensure changed/) {
      $ChangedPackages{$1}++;
   } elsif ($ThisLine =~ /Package\[(.+)\].+ensure\) created/) {
      $InstalledPackages{$1}++;
   } elsif ($ThisLine =~ /Package\[(.+)\].+ensure\) removed/) {
      $RemovedPackages{$1}++;
   } elsif ($ThisLine =~ /Exec\[(.+)\].+executed successfully/) {
      $ExecRuns{$1}++;
   } elsif ($ThisLine =~ /Exec\[(.+)\].+Trigger(?:ing|ed) 'refresh' from [0-9]+ (?:dependencies|events)/) {
      $ExecRuns{$1}++;
   } elsif ($ThisLine =~ /Exec\[(.+)\].+Triggered 'refresh' from [0-9]+ events/) {
      $ExecRuns{$1}++;
   } elsif ($ThisLine =~ /Service\[(.+)\].+ensure changed \'.+\' to \'running\'/) {
      $ServiceStarts{$1}++;
   } elsif ($ThisLine =~ /Service\[(.+)\].+Trigger(?:ing|ed) 'refresh' from [0-9]+ (?:dependencies|events)/) {
      $ServiceStarts{$1}++;
   } elsif ($ThisLine =~ /Service\[(.+)\].+Triggered 'refresh' from [0-9]+ events/) {
      $ServiceStarts{$1}++;
   } elsif ($ThisLine =~ /Service\[(.+)\].+ensure changed \'.+\' to \'stopped\'/) {
      $ServiceStops{$1}++;
   } elsif ($ThisLine =~ /User\[(.+)\].+changed password/) {
      $PasswordChanged{$1}++;
   } elsif ($ThisLine =~ /User\[(.+)\].+defined \'expiry\' as \'([0-9-]{10})\'/) {
      $ExpiryChanged{$1}{$2}++;

   # Generic rules need to be last
   } elsif (($type, $name, $attr) = $ThisLine =~ /([^\/]+)\[([^\]]+)\]\/([^\/]+)\) (created|defined content)/) {
      $Created{$type}->{$name}++;
   } elsif (($type, $name, $attr) = $ThisLine =~ /([^\/]+)\[([^\]]+)\]\/([^\/]+)\) removed/) {
      $Removed{$type}->{$name}++;
   } elsif (($type, $name, $attr, $from, $to) = $ThisLine =~ /([^\/]+)\[([^\]]+)\]\/([^\/]+)\) .+ changed '(.*)' to '(.*)/) {
      if ($attr eq 'content' or $attr eq 'checksum') {
         # Only count these types of changes
         $Changed{$type}->{$name}->{$attr}++;
      } else {
         # Get details for all other types of changes
         $Changed{$type}->{$name}->{$attr}->{'from'} = $from;
         $Changed{$type}->{$name}->{$attr}->{'to'} = $to;
      }
   } elsif (($type, $name, $attr, $from) = $ThisLine =~ /([^\/]+)\[([^\]]+)\]\/([^\/]+)\) undefined '.+' from '(.*)'/) {
      $Changed{$type}->{$name}->{$attr}->{'from'} = $from;
      $Changed{$type}->{$name}->{$attr}->{'to'} = 'undefined';
   } elsif (($type, $name, $content) = $ThisLine =~ /([^\/]+)\[([^\]]+)\]\/content\)(.*)/) {
      $content =~ s/#011/\t/g;
      $content =~ s/#012/\n            /g or $content .= "\n            ";
      $Changed{$type}->{$name}->{'contents'} .= $content;
   } elsif (($source, $target) = $ThisLine =~ /^\(\/(.*)\) Scheduling refresh of (.*)/) {
      $ScheduledRefresh{"$source -> $target"}++;
   } else {
      # Report any unmatched entries...
      $OtherList{$ThisLine}++;
   }
}

#######################################

if ($SuccessfulRuns > 0 && $Detail > 0) {
   print "\nSuccessful runs: $SuccessfulRuns\n";
}

if ($FailedRuns > 0) {
   print "\nFailed runs: $FailedRuns\n";
}

if (keys %Errors) {
   print "\nERRORS:\n";
   foreach my $ThisOne (keys %Errors) {
      print "    $ThisOne: $Errors{$ThisOne} Time(s)\n";
   }
}

foreach my $failure (sort(keys %Failures)) {
   print "\nERROR: Could not $failure:\n";
   foreach my $ThisOne (keys %{$Failures{$failure}}) {
      print "    $ThisOne: $Failures{$failure}->{$ThisOne} Time(s)\n";
   }
}

if ($ResourceFailures > 0) {
   print "\nResource failures: $ResourceFailures\n";
}

if ($DependencyFailures > 0) {
   print "\nDependency failures: $DependencyFailures\n";
}

if (keys %Reparsed) {
   print "\nReparsed:\n";
   foreach my $ThisOne (keys %Reparsed) {
      print "    $ThisOne: $Reparsed{$ThisOne} Time(s)\n";
   }
}

if (keys %FileBucketed and $Detail >= 5) {
   print "\nFileBucketed files:\n";
   foreach my $ThisOne (keys %FileBucketed) {
      print "    $ThisOne\n";
   }
}

if (keys %InstalledPackages) {
   print "\nInstalled packages:\n";
   foreach my $ThisOne (keys %InstalledPackages) {
      print "    $ThisOne: $InstalledPackages{$ThisOne} Time(s)\n";
   }
}

if (keys %ChangedPackages) {
   print "\nChanged packages:\n";
   foreach my $ThisOne (keys %ChangedPackages) {
      print "    $ThisOne: $ChangedPackages{$ThisOne} Time(s)\n";
   }
}

if (keys %RemovedPackages) {
   print "\nRemoved packages:\n";
   foreach my $ThisOne (keys %RemovedPackages) {
      print "    $ThisOne: $RemovedPackages{$ThisOne} Time(s)\n";
   }
}

if (keys %ExecRuns) {
   print "\nExec runs:\n";
   foreach my $ThisOne (keys %ExecRuns) {
      print "    $ThisOne: $ExecRuns{$ThisOne} Time(s)\n";
   }
}

if (keys %ServiceStarts) {
   print "\nService starts:\n";
   foreach my $ThisOne (keys %ServiceStarts) {
      print "    $ThisOne: $ServiceStarts{$ThisOne} Time(s)\n";
   }
}

if (keys %ServiceStops) {
   print "\nService stops:\n";
   foreach my $ThisOne (keys %ServiceStops) {
      print "    $ThisOne: $ServiceStops{$ThisOne} Time(s)\n";
   }
}

if (keys %PasswordChanged) {
   print "\nPassword changed:\n";
   foreach my $ThisOne (keys %PasswordChanged) {
      print "    $ThisOne: $PasswordChanged{$ThisOne} Time(s)\n";
   }
}

if (keys %ExpiryChanged) {
   print "\nExpiry changed:\n";
   foreach my $ThisOne (keys %ExpiryChanged) {
      print "    $ThisOne:\n";
      foreach my $date (keys %{${ExpiryChanged}{$ThisOne}}) {
         print "        $date: $ExpiryChanged{$ThisOne}{$date} Time(s)\n";
      }
   }
}

foreach my $Type (sort(keys %Created)) {
   print "\n$Type created:\n";
   foreach my $Name (sort(keys %{$Created{$Type}})) {
      print "    $Name: $Created{$Type}->{$Name} Time(s)\n";
   }
}

foreach my $Type (sort(keys %Changed)) {
   print "\n$Type changed:\n";
   foreach my $Name (sort(keys %{$Changed{$Type}})) {
      print "    $Name:\n";
      foreach my $Attr (sort(keys %{$Changed{$Type}->{$Name}})) {
         if ($Attr eq 'contents') {
            if ($Detail >= 3) {
                print "        $Attr:";
                print "$Changed{$Type}->{$Name}->{$Attr}\n";
            }
         } else {
            print "        $Attr: ";
            if (defined($Changed{$Type}->{$Name}->{$Attr}->{'from'})) {
               print "from '$Changed{$Type}->{$Name}->{$Attr}->{from}' to '$Changed{$Type}->{$Name}->{$Attr}->{to}'\n";
            } else {
               print "$Changed{$Type}->{$Name}->{$Attr} Time(s)\n";
            }
         }
      }
   }
}

foreach my $Type (sort(keys %Removed)) {
   print "\n$Type removed:\n";
   foreach my $Name (sort(keys %{$Removed{$Type}})) {
      print "    $Name: $Removed{$Type}->{$Name} Time(s)\n";
   }
}

if (keys %ScheduledRefresh) {
   print "\nScheduled refresh:\n";
   foreach my $ThisOne (keys %ScheduledRefresh) {
      print "    $ThisOne: $ScheduledRefresh{$ThisOne} Time(s)\n";
   }
}

if (keys %OtherList) {
   print "\n**Unmatched Entries**\n";
   foreach my $ThisOne (keys %OtherList) {
      print "    $ThisOne: $OtherList{$ThisOne} Time(s)\n";
   }
}

exit(0);

# vi: shiftwidth=3 tabstop=3 syntax=perl et