refactor(LOGWATCH): match new script structure

- update keyword filters
- update reporting detail levels
- better targeting of useful information at summary detail level
This commit is contained in:
Asif Bacchus 2021-05-08 04:40:31 -06:00
parent 2805f560d7
commit d9224b5791

View File

@ -4,7 +4,7 @@
# $Id$ # $Id$
############################################################################# #############################################################################
# Log: CloudFlare updater script (cfddns) # Log: CloudFlare updater script (cfddns)
# Revision 1.0 2018/09/26 # Revision 2.0 2021/05/08
# Written by Asif Bacchus # Written by Asif Bacchus
############################################################################# #############################################################################
@ -17,9 +17,10 @@ my $detailLevel = $ENV{'LOGWATCH_DETAIL_LEVEL'} || 0;
### Declare variables ### Declare variables
my $summaryErr; my $summaryErr;
my $summaryStatusUpToDate; my $summaryFailedUpdate;
my $summaryStatusNeedsUpdating; my $summaryInvalidHost;
my $summarySuccess; my $summaryUpdated;
my $summaryUpToDate;
my %reportHash = (); my %reportHash = ();
my $key; my $key;
@ -29,32 +30,38 @@ my $key;
if ($detailLevel == 0) { if ($detailLevel == 0) {
### process logfile and summarize message types ### process logfile and summarize message types
while (defined(my $ThisLine = <STDIN>)) { while (defined(my $ThisLine = <STDIN>)) {
if ($ThisLine =~ /\-- \[ERROR\] /) { if ($ThisLine =~ /ERROR: Unable to update IP address/) {
$summaryFailedUpdate++;
}
elsif ($ThisLine =~ /ERROR: /) {
$summaryErr++; $summaryErr++;
} }
elsif ($ThisLine =~ /up-to-date./) { elsif ($ThisLine =~ /WARNING: Cannot find existing record/) {
$summaryStatusUpToDate++; $summaryInvalidHost++;
} }
elsif ($ThisLine =~ /needs updating.../) { elsif ($ThisLine =~ /SUCCESS: /) {
$summaryStatusNeedsUpdating++; $summaryUpdated++;
} }
elsif ($ThisLine =~ /\-- \[SUCCESS\] /) { elsif ($ThisLine =~ /already up-to-date/) {
$summarySuccess++; $summaryUpToDate++;
} }
} }
### fill hash table with headings and summary counts ### fill hash table with headings and summary counts
if ($summaryStatusNeedsUpdating > 0) { if ($summaryUpdated > 0) {
$reportHash{"Entries needing updates"} = $summaryStatusNeedsUpdating; $reportHash{"Entries successfully updated"} = $summaryUpdated;
} }
if ($summarySuccess > 0) { if ($summaryUpToDate > 0) {
$reportHash{"Entries successfully updated"} = $summarySuccess; $reportHash{"Entries already up-to-date"} = $summaryUpToDate;
} }
if ($summaryStatusUpToDate > 0) { if ($summaryInvalidHost > 0) {
$reportHash{"Entries already up-to-date"} = $summaryStatusUpToDate; $reportHash{"Undefined hosts"} = $summaryInvalidHost;
}
if ($summaryFailedUpdate > 0) {
$reportHash{"Hosts failed to update"} = $summaryFailedUpdate;
} }
if ($summaryErr > 0) { if ($summaryErr > 0) {
$reportHash{"Errors encountered"} = $summaryErr; $reportHash{"Other errors"} = $summaryErr;
} }
### print hash table ### print hash table
@ -66,40 +73,23 @@ if ($detailLevel == 0) {
### a summary count ### a summary count
elsif ($detailLevel >= 1 && $detailLevel <= 4) { elsif ($detailLevel >= 1 && $detailLevel <= 4) {
while (defined(my $ThisLine = <STDIN>)) { while (defined(my $ThisLine = <STDIN>)) {
if ($ThisLine =~ /\-- \[ERROR\] /) { if ($ThisLine =~ /ERROR: /) {
print $ThisLine; print $ThisLine;
} }
elsif ($ThisLine =~ /\-- \[STATUS\] /) { elsif ($ThisLine =~ /WARNING: Cannot find existing/) {
print $ThisLine; print $ThisLine;
} }
elsif ($ThisLine =~ /\-- \[SUCCESS\] /) { elsif ($ThisLine =~ /SUCCESS: /) {
print $ThisLine; print $ThisLine;
} }
} }
} }
### Level 5 is similiar to levels 1-4 except it also reports informational ### Any level 5 or above will echo the entire log. The log itself is purposefully terse
### messages such as the current working IP address and hostnames being ### so while this level of detail is likely rarely needed, it is still not an overwhelming
### checked. This is useful when verifying the cfddns.sh script's operation. ### level of detail.
elsif ($detailLevel == 5) { ### Generally, however, using this level of detail should only be done if you cannot view
while (defined(my $ThisLine = <STDIN>)) { ### the actual log file directly for whatever reason. The actual log file is colour-coded
if ($ThisLine =~ /\-- \[ERROR\] /) { ### for easier debugging.
print $ThisLine;
}
elsif ($ThisLine =~ /\-- \[STATUS\] /) {
print $ThisLine;
}
elsif ($ThisLine =~ /\-- \[SUCCESS\] /) {
print $ThisLine;
}
elsif ($ThisLine =~ /\-- \[INFO\] /) {
print $ThisLine;
}
}
}
### Any level above 5 will echo the entire log including the debugging notes
### within the script meant for troubleshooting. Using this level of detail
### should only be done if you cannot view the actual log file directly for
### whatever reason. The actual log file is colour-coded for easier debugging.
elsif ($detailLevel > 5) { elsif ($detailLevel > 5) {
while (defined(my $ThisLine = <STDIN>)) { while (defined(my $ThisLine = <STDIN>)) {
print $ThisLine; print $ThisLine;
@ -116,4 +106,4 @@ exit (0);
# mode: perl # mode: perl
# perl-indent-level: 3 # perl-indent-level: 3
# indent-tabs-mode: nil # indent-tabs-mode: nil
# End: # End: