[LON-CAPA-cvs] cvs: loncom /cgi clusterstatus.pl

www lon-capa-cvs@mail.lon-capa.org
Mon, 18 Feb 2002 23:45:23 -0000


www		Mon Feb 18 18:45:23 2002 EDT

  Added files:                 
    /loncom/cgi	clusterstatus.pl 
  Log:
  Cluster Status Script
  
  

Index: loncom/cgi/clusterstatus.pl
+++ loncom/cgi/clusterstatus.pl
#!/usr/bin/perl
$|=1;
# The LearningOnline Network with CAPA
# Cluster Status
# (Versions
# (Running loncron
# 09/06/01 Gerd Kortemeyer)
# 02/18/02 Gerd Kortemeyer)
#
use LWP::UserAgent();
use HTTP::Headers;
use IO::File;

sub connected {
    my ($local,$remote)=@_;
    $local=~s/\W//g;
    $remote=~s/\W//g;

    unless ($hostname{$local}) { return 'local_unknown'; }
    unless ($hostname{$remote}) { return 'remote_unknown'; }

    my $ua=new LWP::UserAgent;
    
    my $request=new HTTP::Request('GET',
      "http://".$hostname{$local}.'/cgi-bin/ping.pl?'.$remote);

    my $response=$ua->request($request);

    unless ($response->is_success) { return 'local_offline'; }

    my $reply=$response->content;
    $reply=(split("\n",$reply))[0];
    $reply=~s/\W//g;
    if ($reply ne $remote) { return $reply; }
    return 'ok';
}

 
print "Content-type: text/html\n\n".
      "<html><body bgcolor=#FFFFFF>\n";
# ------------------------------------------------------------ Read access.conf
{
    my $config=IO::File->new("/etc/httpd/conf/access.conf");

    while (my $configline=<$config>) {
        if ($configline =~ /PerlSetVar/) {
	   my ($dummy,$varname,$varvalue)=split(/\s+/,$configline);
           $perlvar{$varname}=$varvalue;
        }
    }
    delete $perlvar{'lonReceipt'}; # remove since sensitive and not needed
    delete $perlvar{'lonSqlAccess'}; # remove since sensitive and not needed
}

# ------------------------------------------------------------- Read hosts file
{
    my $config=IO::File->new("$perlvar{'lonTabDir'}/hosts.tab");

    while (my $configline=<$config>) {
       my ($id,$domain,$role,$name,$ip)=split(/:/,$configline);
       $hostname{$id}=$name;
       $hostdom{$id}=$domain;
       $hostrole{$id}=$role;
       $hostip{$id}=$ip;
       if (($role eq 'library') && ($id ne $perlvar{'lonHostID'})) {
	   $libserv{$id}=$name;
       }
    }
}

print "<h1>Cluster Status</h1>\n";
print &connected('gerdl1','msul1');

print "</body></html>";