Skip to content

Instantly share code, notes, and snippets.

@mackyle
Created July 29, 2014 01:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mackyle/e11f34a92b53b07c8caf to your computer and use it in GitHub Desktop.
Save mackyle/e11f34a92b53b07c8caf to your computer and use it in GitHub Desktop.
ddclient always generate emails for IP updates & connect errors
commit 92149f8ee6cfb16c59a173395f5ae1749ce12c96
Author: Kyle J. McKay <mackyle@gmail.com>
Date: Wed Jun 11 22:31:13 2014 -0700
Always send update & error messages to mail-failure address
diff --git a/ddclient b/ddclient
index 945745d0..671def55 100755
--- a/ddclient
+++ b/ddclient
@@ -1651,8 +1651,10 @@ sub info { _msg(1, 'INFO:', @_) if opt('verbose'); }
sub debug { _msg(0, 'DEBUG:', @_) if opt('debug'); }
sub debug2 { _msg(0, 'DEBUG:', @_) if opt('debug') && opt('verbose');}
sub warning { _msg(1, 'WARNING:', @_); }
+sub error { _msg(1, 'ERROR:', @_); $result = 'ERROR'; }
sub fatal { _msg(1, 'FATAL:', @_); sendmail(); exit(1); }
sub success { _msg(1, 'SUCCESS:', @_); }
+sub updated { _msg(1, 'UPDATED:', @_); $result = 'UPDATED'; }
sub failed { _msg(1, 'FAILED:', @_); $result = 'FAILED'; }
sub prettytime { return scalar(localtime(shift)); }
@@ -1897,7 +1899,7 @@ sub geturl {
MultiHomed => 1,
Timeout => opt('timeout'),
);
- defined $sd or warning("cannot connect to $peer:$port socket: $@ " . IO::Socket::SSL::errstr());
+ defined $sd or error("cannot connect to $peer:$port socket: $@ " . IO::Socket::SSL::errstr());
} else {
$sd = IO::Socket::INET->new(
PeerAddr => $peer,
@@ -1906,7 +1908,7 @@ sub geturl {
MultiHomed => 1,
Timeout => opt('timeout'),
);
- defined $sd or warning("cannot connect to $peer:$port socket: $@");
+ defined $sd or error("cannot connect to $peer:$port socket: $@");
}
if (defined $sd) {
@@ -1917,7 +1919,7 @@ sub geturl {
#$0 = sprintf("%s - sending to %s port %s", $program, $peer, $port);
my $result = syswrite $sd, $rq;
if ($result != length($rq)) {
- warning("cannot send to $peer:$port ($!).");
+ error("cannot send to $peer:$port ($!).");
} else {
#$0 = sprintf("%s - reading from %s port %s", $program, $peer, $port);
eval {
@@ -2357,7 +2359,7 @@ sub nic_dyndns1_update {
$config{$h}{'ip'} = $ip;
$config{$h}{'mtime'} = $now;
$config{$h}{'status'} = 'good';
- success("updating %s: %s: IP address set to %s (%s)", $h, $return_code, $ip, $title);
+ updated("updating %s: %s: IP address set to %s (%s)", $h, $return_code, $ip, $title);
}
}
}
@@ -2529,11 +2531,11 @@ sub nic_dyndns2_update {
if ($status eq 'good') {
$config{$h}{'ip'} = $ip;
$config{$h}{'mtime'} = $now;
- success("updating %s: %s: IP address set to %s", $h, $status, $ip);
+ updated("updating %s: %s: IP address set to %s", $h, $status, $ip);
} elsif (exists $errors{$status}) {
if ($status eq 'nochg') {
- warning("updating %s: %s: %s", $h, $status, $errors{$status});
+ updated("updating %s: %s: %s", $h, $status, $errors{$status});
$config{$h}{'ip'} = $ip;
$config{$h}{'mtime'} = $now;
$config{$h}{'status'} = 'good';
@@ -2552,7 +2554,7 @@ sub nic_dyndns2_update {
$sec = $wait * $scale;
$config{$h}{'wtime'} = $now + $sec;
- warning("updating %s: %s: wait $wait $units before further updates", $h, $status, $ip);
+ updated("updating %s: %s: wait $wait $units before further updates", $h, $status, $ip);
} else {
failed("updating %s: %s: unexpected status (%s)", $h, $line);
@@ -2633,11 +2635,11 @@ sub nic_noip_update {
if ($status eq 'good') {
$config{$h}{'ip'} = $ip;
$config{$h}{'mtime'} = $now;
- success("updating %s: %s: IP address set to %s", $h, $status, $ip);
+ updated("updating %s: %s: IP address set to %s", $h, $status, $ip);
} elsif (exists $errors{$status}) {
if ($status eq 'nochg') {
- warning("updating %s: %s: %s", $h, $status, $errors{$status});
+ updated("updating %s: %s: %s", $h, $status, $errors{$status});
$config{$h}{'ip'} = $ip;
$config{$h}{'mtime'} = $now;
$config{$h}{'status'} = 'good';
@@ -2656,7 +2658,7 @@ sub nic_noip_update {
$sec = $wait * $scale;
$config{$h}{'wtime'} = $now + $sec;
- warning("updating %s: %s: wait $wait $units before further updates", $h, $status, $ip);
+ updated("updating %s: %s: wait $wait $units before further updates", $h, $status, $ip);
} else {
failed("updating %s: %s: unexpected status (%s)", $h, $line);
@@ -2771,7 +2773,7 @@ sub nic_concont_update {
$config{$h}{'ip'} = $ip;
$config{$h}{'mtime'} = $now;
$config{$h}{'status'} = 'good';
- success("updating %s: good: IP address set to %s", $h, $ip);
+ updated("updating %s: good: IP address set to %s", $h, $ip);
}
else
{
@@ -2851,7 +2853,7 @@ sub nic_dslreports1_update {
$config{$h}{'ip'} = $ip;
$config{$h}{'mtime'} = $now;
$config{$h}{'status'} = 'good';
- success("updating %s: %s: IP address set to %s", $h, $return_code, $ip);
+ updated("updating %s: %s: IP address set to %s", $h, $return_code, $ip);
}
}
}
@@ -2916,7 +2918,7 @@ sub nic_hammernode1_update {
$config{$h}{'ip'} = $ip;
$config{$h}{'mtime'} = $now;
$config{$h}{'status'} = 'good';
- success("updating %s: good: IP address set to %s", $h, $ip);
+ updated("updating %s: good: IP address set to %s", $h, $ip);
} else {
$config{$h}{'status'} = 'failed';
warning("SENT: %s", $url) unless opt('verbose');
@@ -3018,7 +3020,7 @@ sub nic_zoneedit1_update {
$config{$h}{'mtime'} = $now;
$config{$h}{'status'} = 'good';
- success("updating %s: IP address set to %s (%s: %s)", $h, $ip, $status_code, $status_text);
+ updated("updating %s: IP address set to %s (%s: %s)", $h, $ip, $status_code, $status_text);
} else {
$config{$h}{'status'} = 'failed';
@@ -3173,7 +3175,7 @@ sub nic_easydns_update {
if ($status eq 'NOERROR') {
$config{$h}{'ip'} = $ip;
$config{$h}{'mtime'} = $now;
- success("updating %s: %s: IP address set to %s", $h, $status, $ip);
+ updated("updating %s: %s: IP address set to %s", $h, $status, $ip);
} elsif ($status =~ /TOOSOON/) {
## make sure we wait at least a little
@@ -3184,7 +3186,7 @@ sub nic_easydns_update {
($scale, $units) = (60, 'minutes') if $units eq 'm';
($scale, $units) = (60*60, 'hours') if $units eq 'h';
$config{$h}{'wtime'} = $now + $sec;
- warning("updating %s: %s: wait $wait $units before further updates", $h, $status, $ip);
+ updated("updating %s: %s: wait $wait $units before further updates", $h, $status, $ip);
} elsif (exists $errors{$status}) {
failed("updating %s: %s: %s", $h, $line, $errors{$status});
@@ -3332,7 +3334,7 @@ sub nic_dnspark_update {
if ($status eq 'ok') {
$config{$h}{'ip'} = $ip;
$config{$h}{'mtime'} = $now;
- success("updating %s: %s: IP address set to %s", $h, $status, $ip);
+ updated("updating %s: %s: IP address set to %s", $h, $status, $ip);
} elsif ($status =~ /TOOSOON/) {
## make sure we wait at least a little
@@ -3343,7 +3345,7 @@ sub nic_dnspark_update {
($scale, $units) = (60, 'minutes') if $units eq 'm';
($scale, $units) = (60*60, 'hours') if $units eq 'h';
$config{$h}{'wtime'} = $now + $sec;
- warning("updating %s: %s: wait $wait $units before further updates", $h, $status, $ip);
+ updated("updating %s: %s: wait $wait $units before further updates", $h, $status, $ip);
} elsif (exists $errors{$status}) {
failed("updating %s: %s: %s", $h, $line, $errors{$status});
@@ -3429,7 +3431,7 @@ sub nic_namecheap_update {
$config{$h}{'ip'} = $ip;
$config{$h}{'mtime'} = $now;
$config{$h}{'status'} = 'good';
- success("updating %s: good: IP address set to %s", $h, $ip);
+ updated("updating %s: good: IP address set to %s", $h, $ip);
} else {
$config{$h}{'status'} = 'failed';
warning("SENT: %s", $url) unless opt('verbose');
@@ -3512,7 +3514,7 @@ sub nic_sitelutions_update {
$config{$h}{'ip'} = $ip;
$config{$h}{'mtime'} = $now;
$config{$h}{'status'} = 'good';
- success("updating %s: good: IP address set to %s", $h, $ip);
+ updated("updating %s: good: IP address set to %s", $h, $ip);
} else {
$config{$h}{'status'} = 'failed';
warning("SENT: %s", $url) unless opt('verbose');
@@ -3613,7 +3615,7 @@ sub nic_freedns_update {
$config{$h}{'ip'} = $ip;
$config{$h}{'mtime'} = $now;
$config{$h}{'status'} = 'good';
- success("updating %s: good: IP address set to %s", $h, $ip);
+ updated("updating %s: good: IP address set to %s", $h, $ip);
} else {
$config{$h}{'status'} = 'failed';
warning("SENT: %s", $freedns_hosts{$h}->[2]) unless opt('verbose');
@@ -3688,7 +3690,7 @@ sub nic_changeip_update {
$config{$h}{'ip'} = $ip;
$config{$h}{'mtime'} = $now;
$config{$h}{'status'} = 'good';
- success("updating %s: good: IP address set to %s", $h, $ip);
+ updated("updating %s: good: IP address set to %s", $h, $ip);
} else {
$config{$h}{'status'} = 'failed';
warning("SENT: %s", $url) unless opt('verbose');
@@ -3767,7 +3769,7 @@ sub nic_dtdns_update {
$config{$h}{'ip'} = $ip;
$config{$h}{'mtime'} = $now;
$config{$h}{'status'} = 'good';
- success("updating %s: good: IP address set to %s", $h, $ip);
+ updated("updating %s: good: IP address set to %s", $h, $ip);
}
else
{
@@ -3871,7 +3873,7 @@ EoINSTR3
foreach (@hosts) {
$config{$_}{'ip'} = $ip;
$config{$_}{'mtime'} = $now;
- success("updating %s: %s: IP address set to %s", $_, $status, $ip);
+ updated("updating %s: %s: IP address set to %s", $_, $status, $ip);
}
} else {
foreach (@hosts) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment