[LON-CAPA-cvs] cvs: modules /gerd getstatus.pl
www
lon-capa-cvs@mail.lon-capa.org
Wed, 20 Aug 2003 18:39:59 -0000
www Wed Aug 20 14:39:59 2003 EDT
Added files:
/modules/gerd getstatus.pl
Log:
Script for recording clusterdata
Index: modules/gerd/getstatus.pl
+++ modules/gerd/getstatus.pl
#!/usr/bin/perl
$|=1;
# The LearningOnline Network with CAPA
# Cluster Status
#
# $Id: getstatus.pl,v 1.1 2003/08/20 18:39:59 www Exp $
use strict;
use LWP::UserAgent();
use HTTP::Headers;
use IO::File;
my $basepath='/home/monitor/clusterstatus';
my %host=();
my %hostname=();
my %hostip=();
my %hostdom=();
my %hostrole=();
my %libserv=();
sub request {
my ($local,$url)=@_;
my $reply='';
unless ($hostname{$local}) {
$reply='local_unknown';
} else {
my $ua=new LWP::UserAgent(timeout => 30);
my $request=new HTTP::Request('GET',
"http://".$hostname{$local}.$url);
$request->authorization_basic('lonadm','litelite');
my $response=$ua->request($request);
unless ($response->is_success) {
$reply='local_error';
} else {
$reply=$response->content;
chomp($reply);
}
}
return $reply;
}
# ================================================== Store the reply to a query
sub storereply {
my ($local,$url,$file)=@_;
open(OUT,'>>'.$basepath.'/'.$local.'/'.$file.'.dat');
print OUT time.':'.&request($local,$url)."\n";
close(OUT);
}
# ==================================================== Main Loop over all Hosts
#
#
sub mainloop {
foreach my $local (sort keys %hostname) {
unless (-e $basepath.'/'.$local) {
mkdir $basepath.'/'.$local;
}
&storereply($local,'/lon-status/loncron_simple.txt','loncron');
&storereply($local,'/lon-status/version.txt','version');
&storereply($local,'/cgi-bin/userstatus.pl?simple','users');
&storereply($local,'/lon-status/mysql.txt','mysql');
&storereply($local,'/lon-status/checkrpms.txt','checkrpms');
# =============================================================== End Main Loop
}
}
# =============================================================================
# =============================================================================
# Main program
#
# ========================================================= Get form parameters
# ------------------------------------------------------------- Read hosts file
{
my $config=IO::File->new("hosts.tab");
while (my $configline=<$config>) {
$configline=~s/#.*$//;
unless ($configline=~/\w/) { next; }
my ($id,$domain,$role,$name,$ip)=split(/:/,$configline);
$hostname{$id}=$name;
$hostdom{$id}=$domain;
$hostrole{$id}=$role;
$hostip{$id}=$ip;
}
}
unless (-e $basepath) { mkdir $basepath; }
&mainloop();
exit 0;