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