/usr/share/doc/crossroads/examples/backendmon is in crossroads 2.81-2.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | #!/usr/bin/env perl
use strict;
use XML::Simple;
use LWP::UserAgent;
# Check arguments
if ($#ARGV != 1) {
die << "ENDUSAGE";
Usage: $0 webinterface-url period
Example: $0 http://localhost:20001 5
The XR web interface at the stated URL is checked and the back end states
are reported.
ENDUSAGE
}
# Process
while (1) {
check($ARGV[0]);
sleep($ARGV[1]);
}
# Check the web interface. Take unavailable back ends offline.
sub check($) {
my $url = shift;
# Access web interface
my $ua = LWP::UserAgent->new();
my $resp = $ua->get($url);
if (! $resp->is_success()) {
warn("Failed to access the XR web interface on '$url': ",
$resp->status_line(), "\n");
return;
}
# Parse the XML
my $xml;
eval {
$xml = XMLin($resp->content());
};
if ($@) {
warn("Failed to parse web interface response: $@\n");
return;
}
# print Dumper $xml;
my @backends = @{ $xml->{backend} };
print("\n", scalar(localtime()), "\n");
for my $b (@backends) {
print(" Back end ", $b->{nr}, " at ", $b->{address},
": available=", $b->{available}, " up=", $b->{up});
print(" DEAD") if ($b->{live} ne 'alive');
print("\n");
}
}
|