--- loncom/cgi/clusterstatus.pl 2002/02/18 23:45:23 1.1 +++ loncom/cgi/clusterstatus.pl 2002/02/19 20:23:59 1.2 @@ -5,11 +5,21 @@ $|=1; # (Versions # (Running loncron # 09/06/01 Gerd Kortemeyer) -# 02/18/02 Gerd Kortemeyer) +# 02/18/02,02/19/02 Gerd Kortemeyer) # use LWP::UserAgent(); use HTTP::Headers; use IO::File; +use Net::Ping; + +sub online { + my $host=shift; + my $p=Net::Ping->new("tcp",10); + my $online=$p->ping("$host"); + $p->close(); + undef ($p); + return $online; +} sub connected { my ($local,$remote)=@_; @@ -19,6 +29,8 @@ sub connected { unless ($hostname{$local}) { return 'local_unknown'; } unless ($hostname{$remote}) { return 'remote_unknown'; } + unless (&online($hostname{$local})) { return 'local_offline'; } + my $ua=new LWP::UserAgent; my $request=new HTTP::Request('GET', @@ -26,7 +38,7 @@ sub connected { my $response=$ua->request($request); - unless ($response->is_success) { return 'local_offline'; } + unless ($response->is_success) { return 'local_error'; } my $reply=$response->content; $reply=(split("\n",$reply))[0]; @@ -56,19 +68,91 @@ print "Content-type: text/html\n\n". { my $config=IO::File->new("$perlvar{'lonTabDir'}/hosts.tab"); + $total=0; while (my $configline=<$config>) { my ($id,$domain,$role,$name,$ip)=split(/:/,$configline); $hostname{$id}=$name; $hostdom{$id}=$domain; $hostrole{$id}=$role; $hostip{$id}=$ip; + $total++; if (($role eq 'library') && ($id ne $perlvar{'lonHostID'})) { $libserv{$id}=$name; } } } -print "

Cluster Status

\n"; -print &connected('gerdl1','msul1'); - +print +"

Cluster Status

"; +print "Please be patient while building cluster status ...

\n"; +$table=''; + +$table.="". +""; +foreach $remote (sort keys %hostname) { + $table.="$remote"; +} +$table.=""; +foreach $local (sort keys %hostname) { + print "Checking $local "; + $table.="$local
". + $hostrole{$local}.' '.$hostdom{$local}.'
'. + "". + $hostname{$local}."
". + "New Report". + ""; + if (&online($hostname{$local})) { + foreach $remote (sort keys %hostname) { + $status=&connected($local,$remote); + if ($status eq 'ok') { + $table.="
". + "lonc"; + if (&online($hostname{$remote})) { + $table.=" lond". + ""; + } else { + $table.=' offline'; + } + + } + } + } else { + print "offline"; + $table.='
'; + } + $table.="\n"; + print "
\n"; +} +$table.="
From (local)To (remote)
Offline
"; +print $table; print "";