#!/usr/bin/perl ############################################################################# # $Id$ ############################################################################# # Log: CloudFlare updater script (cfddns) # Revision 3.0 2026/07/25 # Written by Asif Bacchus ############################################################################# use strict; ### Get Logwatch detail level my $detailLevel = $ENV{'LOGWATCH_DETAIL_LEVEL'} || 0; ### Declare variables my $summaryErr; my $summaryFailedUpdate; my $summaryInvalidHost; my $summaryUpdated; my $summaryUpToDate; my $summaryWarning; my %reportHash = (); my $key; ### Minimal detail level: provide summary data only if ($detailLevel == 0) { ### process logfile and summarize message types while (defined(my $ThisLine = )) { if ($ThisLine =~ /[FAIL] Unable to update the IP address for/) { $summaryFailedUpdate++; } elsif ($ThisLine =~ /[FAIL] /) { $summaryErr++; } elsif ($ThisLine =~ /[WARN] Cannot find an existing record matching/) { $summaryInvalidHost++; } elsif ($ThisLine =~ /[WARN] /){ $summaryWarning++; } elsif ($ThisLine =~ /[SUCCESS] /) { $summaryUpdated++; } elsif ($ThisLine =~ /already up to date/) { $summaryUpToDate++; } } ### fill hash table with headings and summary counts if ($summaryUpdated > 0) { $reportHash{"Entries successfully updated"} = $summaryUpdated; } if ($summaryUpToDate > 0) { $reportHash{"Entries already up to date"} = $summaryUpToDate; } if ($summaryFailedUpdate > 0) { $reportHash{"Hosts failed to update"} = $summaryFailedUpdate; } if ($summaryInvalidHost > 0) { $reportHash{"Undefined hosts"} = $summaryInvalidHost; } if ($summaryWarning > 0) { $reportHash{"Total warnings"} = $summaryWarning; } if ($summaryErr > 0) { $reportHash{"Total errors"} = $summaryErr; } ### print hash table foreach $key (sort keys %reportHash) { print "$key: $reportHash{$key}\n"; } } ### 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 = )) { if ($ThisLine =~ /[ERR] /) { print $ThisLine; } elsif ($ThisLine =~ /[WARN] /) { print $ThisLine; } elsif ($ThisLine =~ /[SUCCESS] /) { print $ThisLine; } elsif ($ThisLine =~ /already up to date/) { print $ThisLine; } } } ### Level 5 includes warning and error tally count messages and Cloudflare ### debugging messages elsif ($detailLevel == 5) { while (defined(my $ThisLine = )) { if ($ThisLine =~ /[ERR] /) { print $ThisLine; } elsif ($ThisLine =~ /CF-ERR: /) { print $ThisLine; } elsif ($ThisLine =~ /[WARN] /) { 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 ### 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. elsif ($detailLevel > 5) { while (defined(my $ThisLine = )) { print $ThisLine; } } ### Exit gracefully exit (0); # vi: shiftwidth=3 tabstop=3 et # Local Variables: # mode: perl # perl-indent-level: 3 # indent-tabs-mode: nil # End: