2018-09-27 16:40:53 -06:00
|
|
|
#!/usr/bin/perl
|
|
|
|
|
|
|
|
#############################################################################
|
|
|
|
# $Id$
|
|
|
|
#############################################################################
|
|
|
|
# Log: CloudFlare updater script (cfddns)
|
2021-05-09 10:43:05 -06:00
|
|
|
# Revision 2.1 2021/05/08
|
2018-09-27 16:40:53 -06:00
|
|
|
# Written by Asif Bacchus
|
|
|
|
#############################################################################
|
|
|
|
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
|
|
|
|
### Get Logwatch detail level
|
|
|
|
my $detailLevel = $ENV{'LOGWATCH_DETAIL_LEVEL'} || 0;
|
|
|
|
|
|
|
|
|
|
|
|
### Declare variables
|
|
|
|
my $summaryErr;
|
2021-05-08 04:40:31 -06:00
|
|
|
my $summaryFailedUpdate;
|
|
|
|
my $summaryInvalidHost;
|
|
|
|
my $summaryUpdated;
|
|
|
|
my $summaryUpToDate;
|
2021-05-09 10:43:05 -06:00
|
|
|
my $summaryWarning;
|
2018-09-27 16:40:53 -06:00
|
|
|
|
|
|
|
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>)) {
|
2021-05-09 10:43:05 -06:00
|
|
|
if ($ThisLine =~ /ERR: Unable to update IP address/) {
|
2021-05-08 04:40:31 -06:00
|
|
|
$summaryFailedUpdate++;
|
|
|
|
}
|
|
|
|
elsif ($ThisLine =~ /ERROR: /) {
|
2018-09-27 16:40:53 -06:00
|
|
|
$summaryErr++;
|
|
|
|
}
|
2021-05-09 10:43:05 -06:00
|
|
|
elsif ($ThisLine =~ /WARN: Cannot find existing record/) {
|
2021-05-08 04:40:31 -06:00
|
|
|
$summaryInvalidHost++;
|
2018-09-27 16:40:53 -06:00
|
|
|
}
|
2021-05-09 10:43:05 -06:00
|
|
|
elsif ($ThisLine =~ /WARNING: /){
|
|
|
|
$summaryWarning++;
|
|
|
|
}
|
2021-05-08 04:40:31 -06:00
|
|
|
elsif ($ThisLine =~ /SUCCESS: /) {
|
|
|
|
$summaryUpdated++;
|
2018-09-27 16:40:53 -06:00
|
|
|
}
|
2021-05-08 04:40:31 -06:00
|
|
|
elsif ($ThisLine =~ /already up-to-date/) {
|
|
|
|
$summaryUpToDate++;
|
2018-09-27 16:40:53 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-27 16:57:41 -06:00
|
|
|
### fill hash table with headings and summary counts
|
2021-05-08 04:40:31 -06:00
|
|
|
if ($summaryUpdated > 0) {
|
|
|
|
$reportHash{"Entries successfully updated"} = $summaryUpdated;
|
|
|
|
}
|
|
|
|
if ($summaryUpToDate > 0) {
|
|
|
|
$reportHash{"Entries already up-to-date"} = $summaryUpToDate;
|
2018-09-27 16:40:53 -06:00
|
|
|
}
|
2021-05-09 10:43:05 -06:00
|
|
|
if ($summaryFailedUpdate > 0) {
|
|
|
|
$reportHash{"Hosts failed to update"} = $summaryFailedUpdate;
|
|
|
|
}
|
2021-05-08 04:40:31 -06:00
|
|
|
if ($summaryInvalidHost > 0) {
|
|
|
|
$reportHash{"Undefined hosts"} = $summaryInvalidHost;
|
2018-09-27 16:40:53 -06:00
|
|
|
}
|
2021-05-09 10:43:05 -06:00
|
|
|
if ($summaryWarning > 0) {
|
|
|
|
$reportHash{"Total warnings"} = $summaryWarning;
|
2018-09-27 16:40:53 -06:00
|
|
|
}
|
|
|
|
if ($summaryErr > 0) {
|
2021-05-09 10:43:05 -06:00
|
|
|
$reportHash{"Total errors"} = $summaryErr;
|
2018-09-27 16:40:53 -06:00
|
|
|
}
|
|
|
|
|
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>)) {
|
2021-05-09 10:43:05 -06:00
|
|
|
if ($ThisLine =~ /ERR: /) {
|
2018-09-27 16:53:23 -06:00
|
|
|
print $ThisLine;
|
|
|
|
}
|
2021-05-09 10:43:05 -06:00
|
|
|
elsif ($ThisLine =~ /WARN: /) {
|
2018-09-27 16:53:23 -06:00
|
|
|
print $ThisLine;
|
|
|
|
}
|
2021-05-08 04:40:31 -06:00
|
|
|
elsif ($ThisLine =~ /SUCCESS: /) {
|
2018-09-27 16:53:23 -06:00
|
|
|
print $ThisLine;
|
|
|
|
}
|
2021-05-09 10:43:05 -06:00
|
|
|
elsif ($ThisLine =~ /already up-to-date/) {
|
|
|
|
print $ThisLine;
|
|
|
|
}
|
2018-09-27 16:53:23 -06:00
|
|
|
}
|
|
|
|
}
|
2021-05-09 10:43:05 -06:00
|
|
|
### Level 5 includes warning and error tally count messages and Cloudflare
|
|
|
|
### debugging messages
|
|
|
|
elsif ($detailLevel == 5) {
|
|
|
|
while (defined(my $ThisLine = <STDIN>)) {
|
|
|
|
if ($ThisLine =~ /ERR: /) {
|
|
|
|
print $ThisLine;
|
|
|
|
}
|
|
|
|
elsif ($ThisLine =~ /ERROR: /) {
|
|
|
|
print $ThisLine;
|
|
|
|
}
|
|
|
|
elsif ($ThisLine =~ /CF-ERR: /) {
|
|
|
|
print $ThisLine;
|
|
|
|
}
|
|
|
|
elsif ($ThisLine =~ /WARN: /) {
|
|
|
|
print $ThisLine;
|
|
|
|
}
|
|
|
|
elsif ($ThisLine =~ /WARNING: /) {
|
|
|
|
print $ThisLine;
|
|
|
|
}
|
|
|
|
elsif ($ThisLine =~ /SUCCESS: /) {
|
|
|
|
print $ThisLine;
|
|
|
|
}
|
|
|
|
elsif ($ThisLine =~ /already up-to-date/) {
|
|
|
|
print $ThisLine;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
### Any level 6 or above will echo the entire log. The log itself is purposefully terse
|
2021-05-08 04:40:31 -06:00
|
|
|
### so while this level of detail is likely rarely needed, it is still not an overwhelming
|
|
|
|
### level of detail.
|
|
|
|
### Generally, however, 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.
|
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
|
2021-05-08 04:40:31 -06:00
|
|
|
# End:
|