CloudflareDDNS/etc/logwatch/scripts/services/cfddns
Asif Bacchus 462d081b14 Rewrite logwatch script: changed to PERL instead of BASH.
Initial code, summary only.
2018-09-27 16:40:53 -06:00

77 lines
1.9 KiB
Perl

#!/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) {
### Process logfile and summarize message types
while (defined(my $ThisLine = <STDIN>)) {
if ($ThisLine =~ /\-- \[ERROR\] /) {
$summaryErr++;
}
elsif ($ThisLine =~ /up-to-date./) {
$summaryStatusUpToDate++;
}
elsif ($ThisLine =~ /needs updating.../) {
$summaryStatusNeedsUpdating++;
}
elsif ($ThisLine =~ /\-- \[SUCCESS\] /) {
$summarySuccess++;
}
}
### Fill hashtable with headings and summary counts
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;
}
### Print hash table
foreach $key (sort keys %reportHash) {
print "$key: $reportHash{$key}\n";
}
}
### Exit gracefully
exit (0);
# vi: shiftwidth=3 tabstop=3 et
# Local Variables:
# mode: perl
# perl-indent-level: 3
# indent-tabs-mode: nil
# End: