summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2018-03-13 11:38:34 +0100
committerFlorian Pritz <bluewind@xinu.at>2018-03-13 11:41:18 +0100
commitee67dcc3ec561eeef2e08b1240cf625fe8491d63 (patch)
tree32bd80af9a267e0096e9f2c6765c6b2df826dd2b /bin
parent803b7ce56fac86ec6d3b3e6dd37d49424b92b884 (diff)
downloadarch-mirror-tools-ee67dcc3ec561eeef2e08b1240cf625fe8491d63.tar.gz
arch-mirror-tools-ee67dcc3ec561eeef2e08b1240cf625fe8491d63.tar.xz
generate-mirror-mail.pl: Refactor template variable definitions
Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'bin')
-rwxr-xr-xbin/generate-mirror-mail.pl45
1 files changed, 25 insertions, 20 deletions
diff --git a/bin/generate-mirror-mail.pl b/bin/generate-mirror-mail.pl
index 6c290d9..037669e 100755
--- a/bin/generate-mirror-mail.pl
+++ b/bin/generate-mirror-mail.pl
@@ -38,23 +38,25 @@ my %templates = (
'subject' => '[{$mirror_name}] Arch Linux mirror out of sync',
'template' => 'Hi,
-Your mirror seems to be out of sync since {$last_sync}, could you please
+Your mirror seems to be out of sync since {$out_of_sync{last_sync}}, could you please
investigate?
-{$mirror_urls}
+{$mirror_url}
+{$out_of_sync{mirror_urls}}
Thanks,
Florian
',
},
'connection-failed' => {
- 'subject' => '[{$mirror_name}] Arch Linux mirror not accessible{$OUT = ", ".join("/", @affected_protocols) if @affected_protocols > 0;}',
+ 'subject' => '[{$mirror_name}] Arch Linux mirror not accessible{$OUT = ", ".join("/", @{$connection_failed{protocols}}) if @{$connection_failed{protocols}} > 0;}',
'template' => 'Hi,
-We\'re having trouble connecting to your mirror{$OUT = " via ".join(", ", @affected_protocols) if @affected_protocols > 0;}, could you
+We\'re having trouble connecting to your mirror{$OUT = " via ".join(", ", @{$connection_failed{protocols}}) if @{$connection_failed{protocols}} > 0;}, could you
please check what\'s going on?
-{$mirror_urls}
+{$mirror_url}
+{$connection_failed{mirror_urls}}
Thanks,
Florian
@@ -165,27 +167,30 @@ while (<STDIN>) {
my $to = $json->{admin_email};
$to .= ",".$json->{alternate_email} if $json->{alternate_email} ne "";
+ my %values = (
+ out_of_sync => {
+ last_sync => join(", ", map {time2str("%Y-%m-%d", $_)} @last_sync),
+ mirror_urls => join("\n", map {${$_}{details_link}} @out_of_sync),
+ },
+ connection_failed => {
+ mirror_urls => join("\n", map {${$_}{details_link}} @connection_failed),
+ },
+ mirror_name => $mirror_name,
+ mirror_url => $url,
+ );
+
+ my @protocols = map {${$_}{protocol}} @connection_failed;
+ if (scalar(@protocols) != scalar(@{$json->{urls}})) {
+ $values{connection_failed}->{protocols} = \@protocols;
+ }
+
+
if (@out_of_sync) {
- my %values = (
- last_sync => join(", ", map {time2str("%Y-%m-%d", $_)} @last_sync),
- mirror_urls => join("\n", $url, map {${$_}{details_link}} @out_of_sync),
- mirror_name => $mirror_name,
- );
send_template_mail($to, $templates{"out-of-sync"}{"subject"}, $templates{"out-of-sync"}{"template"}, \%values);
$sent_mail = 1;
}
if (@connection_failed) {
- my %values = (
- mirror_urls => join("\n", $url, map {${$_}{details_link}} @connection_failed),
- mirror_name => $mirror_name,
- );
-
- my @protocols = map {${$_}{protocol}} @connection_failed;
- if (scalar(@protocols) != scalar(@{$json->{urls}})) {
- $values{affected_protocols} = \@protocols;
- }
-
send_template_mail($to, $templates{"connection-failed"}{"subject"}, $templates{"connection-failed"}{"template"}, \%values);
$sent_mail = 1;
}