#!/usr/bin/perl -w #----------------------------------------------------------------- # ServicePingerValidator # Author: Edward Kawas , # For copyright and disclaimer see below. # # $Id: ServicePingerValidator,v 1.2 2008/02/25 18:26:16 kawas Exp $ # # NOTES: # 1. This script assumes that a BioMOBY registry is properly # installed and that SetEnv commands have been added to # the servers environment (e.g. httpd.conf) #----------------------------------------------------------------- use strict; use CGI qw/:standard/; use MOBY::Client::Central; use SOAP::Lite; # the registry to query my $URL = $ENV{MOBY_SERVER} || 'http://moby.ucalgary.ca/moby/MOBY-Central.pl'; my $URI = $ENV{MOBY_URI} || 'http://moby.ucalgary.ca/MOBY/Central'; my $TIMEOUT = 20; # create the central client and get all service providers once my $central = MOBY::Client::Central->new( Registries => { mobycentral => { URL => $URL, URI => $URI } } ); my $url = url( -relative => 1, -path_info => 1 ); my $form = new CGI; my %p = $form->Vars unless param('keywords'); %p = ($form->param('keywords') => '') if param('keywords'); my $service = $p{'service'} || ''; my $authority = $p{'authority'} || ''; if ($service and $authority) { my $name = $p{'service'}; $name =~ s/ //g; $name = "" unless $name; print "Content-type: text/html\n\n"; my $old = $|; $| = 1; # ping the service and output results my ( $second, $minute, $hour, @whatever ) = localtime(); print "

Finding services registered by '$authority' @ $hour:$minute:$second

"; my ( $services, $reg ) = $central->findService( Registry => "mobycentral", serviceName=>$name, authURI => $authority ); ( $second, $minute, $hour, @whatever ) = localtime(); print "

Services found " . scalar @$services . "... processing @ $hour:$minute:$second

"; my $count = 0; print "
\tservice count: " . scalar (@$services) . "
"; foreach (@$services) { # ignore test services my $name = $_->name; my $auth = $_->authority; my $url = $_->URL; do { # dont process localhost addresses ... print "localhost services are usually dead since the service most likely isn't hosted on this server!
"; next; } if $url =~ /localhost/; print "

Calling: " . $auth . "," . $name . "

"; my $soap = SOAP::Lite->uri("http://biomoby.org/") ->proxy( $url, timeout => $TIMEOUT )->on_fault( sub { my $soap = shift; my $res = shift; print "
      " . $auth . "," . $name . " ~ is dead:\n

$res
"; } ); my $input = &_empty_input(); my $out = $soap->$name( SOAP::Data->type( 'string' => "$input" ) )->result; # validate the XML if we get a response my $good_xml = 1; do { eval { my $parser = XML::LibXML->new(); $parser->parse_string($out); }; $good_xml = 0 if $@; } if $out; do { $out =~ s/&/&/g; $out =~ s/>/>/g; $out =~ s/ " . $auth . "," . $name . " isAlive.\n output:\n$out
"; } if $out and $good_xml; do { $out =~ s/&/&/g; $out =~ s/>/>/g; $out =~ s/ " . $auth . "," . $name . " isAlive but produced invalid XML.\n output:\n$out
"; } if $out and not $good_xml; do { print "
     " . $auth . "," . $name . " ~ did not respond!

"; } unless $out; } $| = $old; } elsif ($authority and not $service) { print "Content-type: text/html\n\n"; my $old = $|; $| = 1; # ping the service and output results my ( $second, $minute, $hour, @whatever ) = localtime(); print "

Finding services registered by '$authority' @ $hour:$minute:$second

"; my ( $services, $reg ) = $central->findService( Registry => "mobycentral", authURI => $authority ); ( $second, $minute, $hour, @whatever ) = localtime(); print "

Services found " . scalar @$services . "... processing @ $hour:$minute:$second

"; my $count = 0; print "
\tservice count: " . scalar (@$services) . "
"; foreach (@$services) { # ignore test services my $name = $_->name; my $auth = $_->authority; my $url = $_->URL; do { # dont process localhost addresses ... print "localhost services are usually dead since the service most likely isn't hosted on this server!
"; next; } if $url =~ /localhost/; print "

Calling: " . $auth . "," . $name . "

"; my $soap = SOAP::Lite->uri("http://biomoby.org/") ->proxy( $url, timeout => $TIMEOUT )->on_fault( sub { my $soap = shift; my $res = shift; print "
      " . $auth . "," . $name . " ~ is dead:\n

$res
"; } ); my $input = &_empty_input(); my $out = $soap->$name( SOAP::Data->type( 'string' => "$input" ) )->result; # validate the XML if we get a response my $good_xml = 1; do { eval { my $parser = XML::LibXML->new(); $parser->parse_string($out); }; $good_xml = 0 if $@; } if $out; do { $out =~ s/&/&/g; $out =~ s/>/>/g; $out =~ s/ " . $auth . "," . $name . " isAlive.\n output:\n$out
"; } if $out and $good_xml; do { $out =~ s/&/&/g; $out =~ s/>/>/g; $out =~ s/ " . $auth . "," . $name . " isAlive but produced invalid XML.\n output:\n$out
"; } if $out and not $good_xml; do { print "
     " . $auth . "," . $name . " ~ did not respond!

"; } unless $out; } $| = $old; } else { print "Content-type: text/html\n\n"; print &GENERATE_FORM(); } sub _empty_input { return <<'END_OF_XML'; END_OF_XML } sub GENERATE_FORM { my $values = ""; my $m = MOBY::Client::Central->new(); my @URIs = $m->retrieveServiceProviders(); foreach my $uri (@URIs) { next if $uri eq '127.0.0.1'; $values .= "\n" } my $msg =< Test your services!

Check your services

Introduction

Use this page to determine whether or not the BioMOBY service pinger can successfully contact your services.

Simply select a service provider and enter an optional service name in the form below and submit the form. The pinger then will be called on your service provider/name combination and the results will be printed out below.

How does it work?

The BioMOBY service pinger simply attempts to call your service(s) with the empty BioMOBY xml message shown below. If your service responds, then the service is considered alive. Otherwise the service is reported as dead.

Sample XML message sent to services:

<MOBY>
  <mobyContent></mobyContent>
</MOBY>

Let's check your services: