2018-09-27 16:40:53 -06:00
|
|
|
#!/usr/bin/perl
|
|
|
|
|
|
|
|
#############################################################################
|
|
|
|
# $Id$
|
|
|
|
#############################################################################
|
|
|
|
# Log: CloudFlare updater script (cfddns)
|
|
|
|
# Revision 1.0 2018/09/26
|
|
|
|
# Written by Asif Bacchus
|
|
|
|
#############################################################################
|
|
|
|
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
|
|
|
|
### Get Logwatch detail level
|
|
|
|
my $detailLevel = $ENV{'LOGWATCH_DETAIL_LEVEL'} || 0;
|
|
|
|
|
|
|
|
|
|
|
|
### Declare variables
|
|
|
|
my $summaryErr;
|
|
|
|
my $summaryStatusUpToDate;
|
|
|
|
my $summaryStatusNeedsUpdating;
|
|
|
|
my $summarySuccess;
|
|
|
|
|
|
|
|
my %reportHash = ();
|
|
|
|
my $key;
|
|
|
|
|
|
|
|
|
|
|
|
### Minimal detail level: provide summary data only
|
|
|
|
if ($detailLevel == 0) {
|
2018-09-27 16:57:41 -06:00
|
|
|
### process logfile and summarize message types
|
2018-09-27 16:40:53 -06:00
|
|
|
while (defined(my $ThisLine = <STDIN>)) {
|
|
|
|
if ($ThisLine =~ /\-- \[ERROR\] /) {
|
|
|
|
$summaryErr++;
|
|
|
|
}
|
|
|
|
elsif ($ThisLine =~ /up-to-date./) {
|
|
|
|
$summaryStatusUpToDate++;
|
|
|
|
}
|
|
|
|
elsif ($ThisLine =~ /needs updating.../) {
|
|
|
|
$summaryStatusNeedsUpdating++;
|
|
|
|
}
|
|
|
|
elsif ($ThisLine =~ /\-- \[SUCCESS\] /) {
|
|
|
|
$summarySuccess++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-27 16:57:41 -06:00
|
|
|
### fill hash table with headings and summary counts
|
2018-09-27 16:40:53 -06:00
|
|
|
if ($summaryStatusNeedsUpdating > 0) {
|
|
|
|
$reportHash{"Entries needing updates"} = $summaryStatusNeedsUpdating;
|
|
|
|
}
|
|
|
|
if ($summarySuccess > 0) {
|
|
|
|
$reportHash{"Entries successfully updated"} = $summarySuccess;
|
|
|
|
}
|
|
|
|
if ($summaryStatusUpToDate > 0) {
|
|
|
|
$reportHash{"Entries already up-to-date"} = $summaryStatusUpToDate;
|
|
|
|
}
|
|
|
|
if ($summaryErr > 0) {
|
|
|
|
$reportHash{"Errors encountered"} = $summaryErr;
|
|
|
|
}
|
|
|
|
|
2018-09-27 16:57:41 -06:00
|
|
|
### print hash table
|
2018-09-27 16:40:53 -06:00
|
|
|
foreach $key (sort keys %reportHash) {
|
|
|
|
print "$key: $reportHash{$key}\n";
|
|
|
|
}
|
|
|
|
}
|
2018-09-27 16:53:23 -06:00
|
|
|
### Levels 1-4 provide the actual error, status and success messages instead of
|
|
|
|
### a summary count
|
|
|
|
elsif ($detailLevel >= 1 && $detailLevel <= 4) {
|
|
|
|
while (defined(my $ThisLine = <STDIN>)) {
|
|
|
|
if ($ThisLine =~ /\-- \[ERROR\] /) {
|
|
|
|
print $ThisLine;
|
|
|
|
}
|
|
|
|
elsif ($ThisLine =~ /up-to-date./) {
|
|
|
|
print $ThisLine;
|
|
|
|
}
|
|
|
|
elsif ($ThisLine =~ /needs updating.../) {
|
|
|
|
print $ThisLine;
|
|
|
|
}
|
|
|
|
elsif ($ThisLine =~ /\-- \[SUCCESS\] /) {
|
|
|
|
print $ThisLine;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
### Level 5 is similiar to levels 1-4 except it also reports informational
|
|
|
|
### messages such as the current working IP address and hostnames being
|
|
|
|
### checked. This is useful when verifying the cfddns.sh script's operation.
|
|
|
|
elsif ($detailLevel == 5) {
|
|
|
|
while (defined(my $ThisLine = <STDIN>)) {
|
|
|
|
if ($ThisLine =~ /\-- \[ERROR\] /) {
|
|
|
|
print $ThisLine;
|
|
|
|
}
|
|
|
|
elsif ($ThisLine =~ /up-to-date./) {
|
|
|
|
print $ThisLine;
|
|
|
|
}
|
|
|
|
elsif ($ThisLine =~ /needs updating.../) {
|
|
|
|
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
|
2018-09-27 16:57:41 -06:00
|
|
|
### whatever reason. The actual log file is colour-coded for easier debugging.
|
2018-09-27 16:53:23 -06:00
|
|
|
elsif ($detailLevel > 5) {
|
|
|
|
while (defined(my $ThisLine = <STDIN>)) {
|
|
|
|
print $ThisLine;
|
|
|
|
}
|
|
|
|
}
|
2018-09-27 16:40:53 -06:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### Exit gracefully
|
|
|
|
exit (0);
|
|
|
|
|
|
|
|
# vi: shiftwidth=3 tabstop=3 et
|
|
|
|
# Local Variables:
|
|
|
|
# mode: perl
|
|
|
|
# perl-indent-level: 3
|
|
|
|
# indent-tabs-mode: nil
|
|
|
|
# End:
|