X-Git-Url: https://git.openstreetmap.org./dns.git/blobdiff_plain/2be0aa31e74d747f8fcf891a4365772dc7a0abb7..f001db6d56d84f3b90badb78287280b4eff5eb1b:/bin/mkgeo diff --git a/bin/mkgeo b/bin/mkgeo index 94c600a..3a69d89 100755 --- a/bin/mkgeo +++ b/bin/mkgeo @@ -35,7 +35,7 @@ while (my($name,$cluster) = each %$clusters) push @servers, $server; } } - else + elsif ($cluster->{requests} > 0) { my $server = { cluster => $cluster, @@ -50,6 +50,10 @@ while (my($name,$cluster) = each %$clusters) push @servers, $server; } + else + { + $cluster->{servers} = []; + } $cluster->{name} = $name; $cluster->{status} = "down"; @@ -62,14 +66,13 @@ foreach my $server (@servers) } # If statuscake support is enabled then check which servers are up -if ($ENV{STATUSCAKE_USERNAME} && $ENV{STATUSCAKE_APIKEY}) +if ($ENV{STATUSCAKE_APIKEY}) { my $ua = LWP::UserAgent->new; my $cache; $ua->agent("mkgeo/1.0"); - $ua->default_header("Username", $ENV{STATUSCAKE_USERNAME}); - $ua->default_header("API", $ENV{STATUSCAKE_APIKEY}); + $ua->default_header("Authorization", "Bearer $ENV{STATUSCAKE_APIKEY}"); if (-f "statuscake.yml") { @@ -80,24 +83,33 @@ if ($ENV{STATUSCAKE_USERNAME} && $ENV{STATUSCAKE_APIKEY}) $cache = {}; } - my $response = $ua->get("https://app.statuscake.com/API/Tests/"); + my $page = 1; + my $pages = 1; - if ($response->is_success) + while ($page <= $pages) { - my $tests = decode_json($response->content); + my $response = $ua->get("https://api.statuscake.com/v1/uptime?nouptime=true&limit=100&page=${page}"); - foreach my $test (@$tests) + if ($response->is_success) { - my $testid = $test->{TestID}; + my $uptime = decode_json($response->content); - if ($test->{Status} eq "Up" && !$test->{Paused}) - { - $cache->{$testid} = "up"; - } - else + foreach my $test (@{$uptime->{data}}) { - $cache->{$testid} = "down"; + my $testid = $test->{id}; + + if ($test->{status} eq "up" && !$test->{paused}) + { + $cache->{$testid} = "up"; + } + else + { + $cache->{$testid} = "down"; + } } + + $page = $page + 1; + $pages = $uptime->{metadata}->{page_count}; } } @@ -137,6 +149,9 @@ foreach my $server (@servers) } } +# Abort if no servers at all are up +exit 0 unless grep { $_->{status} eq "up" } values(%$clusters); + # Create target origins object my $targetorigins = {}; @@ -213,6 +228,25 @@ while (grep { !exists($_->{cluster}) } values %$origins) allocate_clusters(@mappings); } +# Report on allocation results +foreach my $name (sort keys %$clusters) +{ + my $cluster = $clusters->{$name}; + my $used = int($cluster->{requests_used} + 0.5); + my $limit = $cluster->{requests_limit}; + + if ($limit > 0) + { + my $proportion = int($used / $limit * 100 + 0.5); + + print "${name}: used ${used} of ${limit} (${proportion}%)\n"; + } + else + { + print "${name}: used ${used} of ${limit}\n"; + } +} + # Create JSON collection object my @json; @@ -321,7 +355,7 @@ if (defined($gdnsname)) my $continent = ""; $gdnsmapfile->print("${gdnsname} => {\n"); - $gdnsmapfile->print(" geoip2_db => /usr/share/GeoIP/GeoLite2-Country.mmdb\n"); + $gdnsmapfile->print(" geoip2_db => /etc/gdnsd/geoip/GeoLite2-Country.mmdb\n"); $gdnsmapfile->print(" datacenters => [" . join(",", sort(keys(%$clusters))) . "]\n"); $gdnsmapfile->print(" map => {\n"); $gdnsmapfile->print(" default => [" . join(",", sort(map { $_->{name} } grep { $_->{default} } values(%$clusters))) . "]\n");