[LON-CAPA-cvs] cvs: modules /raeburn monitor.pl
raeburn
lon-capa-cvs@mail.lon-capa.org
Wed, 06 Apr 2005 17:04:31 -0000
raeburn Wed Apr 6 13:04:31 2005 EDT
Modified files:
/modules/raeburn monitor.pl
Log:
Eliminate need to set CLASSPATH for shell by passing $classpath as argument in call to java. Page load times stored in a hash.
Index: modules/raeburn/monitor.pl
diff -u modules/raeburn/monitor.pl:1.2 modules/raeburn/monitor.pl:1.3
--- modules/raeburn/monitor.pl:1.2 Tue Mar 29 12:46:01 2005
+++ modules/raeburn/monitor.pl Wed Apr 6 13:04:30 2005
@@ -26,7 +26,7 @@
# and DES encrypted password for the username being auto-logged in.
#
# An example would be:
-# itds:msu:cc./msu/35101d1a78a4060msul1:90090777f6d4956adba6590e878b0feb3aa8176180b303d3205c0faca2d5838
+# itds:msu:st./msu/35101d1a78a4060msul1:90090777f6d4956adba6590e878b0feb3aa8176180b303d3205c0faca2d5838
#
# A modified version of londes.js (called londes_auto.js) is required.
# This should be placed in $monitordir.
@@ -44,15 +44,12 @@
# as well as comming out the <script> and </script> tags at the beginning
# and end of the file.
#
-# The Rhino shell which allows Javascript to be called from the command line is # required. Download from http://www.mozilla.org/rhino/download.html
-# and put the js.jar file in $monitordir. Then set the CLASSPATH in
-# .bash_profile of the user calling monitor.pl to include the path to js.jar
-#
-# CLASSPATH="/home/msuremot/monitoring/js.jar"
-#
-# export PATH CLASSPATH
+# The Rhino shell which allows Javascript to be called from the command line is
+# required. Download from http://www.mozilla.org/rhino/download.html
+# and put the js.jar file in $monitordir.
#
-# The java run time envionment (i.e., a Java VM is needed).
+# A Java VM is needed. Set the path to the java binary as $path_to_java
+# e.g., $path_to_java = '/usr/java/j2sdk1.4.2_05/bin/java';
#
# An additional file - recipients -should be added to a server's subdirectory
# in $monitordir. The file will contain an e-mail address of a user to
@@ -61,7 +58,8 @@
# user should be notified.
#
# An example file would be:
-# raeburn@msu.edu:conlost,unavailable,missingparam,unauthenticated,invalidcookie# ,nologin,uninitialized,rolesfailed,navmapfailed,logoutfailed
+# raeburn@msu.edu:conlost,unavailable,missingparam,unauthenticated,invalidcookie
+# ,nologin,uninitialized,rolesfailed,navmapfailed,logoutfailed
# itds@msu.edu:conlost
#
# In this case, raeburn@msu.edu would be contacted whenever consecutive failures
@@ -97,10 +95,16 @@
# This script itself should be called with three parameters:
# encryption key (key used for DES encryption of the auto-user's password),
# hostname of the server (e.g., s1.lite.ms.edu),
-# server nickname (e.g., alias).
+# server nickname (e.g., s1).
+########################################################
+# Configuration
+#
my $monitordir = '/home/msuremot/monitoring';
+my $path_to_java = '/usr/java/j2sdk1.4.2_05/bin/java';
my $contact_email = 'helpdesk@loncapa.org';
+#
+#########################################################
my $ua = LWP::UserAgent->new();
$ua->timeout(20);
@@ -157,7 +161,7 @@
my $logfile = $monitordir.'/'.$serveralias.'/log';
-$outcome = &attempt_access($outcome,$loginpage,$lonid,\@formitems,\%formvalues,\%loadtimes);
+$outcome = &attempt_access($outcome,$loginpage,$lonid,$role,\@formitems,\%formvalues,\%loadtimes,$monitordir,$path_to_java);
my $mailflag = &alertstatus($outcome,$server,$serveralias,\@failures,$logfile,$monitordir);
if ($mailflag) {
my $mailresult = &mailalert($server,$outcome,$contact_email,\%recipients);
@@ -167,14 +171,14 @@
}
sub attempt_access {
- my ($outcome,$loginpage,$lonid,$formitems,$formvalues,$loadtimes) = @_;
+ my ($outcome,$loginpage,$lonid,$role,$formitems,$formvalues,$loadtimes,$monitordir,$path_to_java) = @_;
($outcome,$loginpage) = &get_loginpage($server,$ua,$loadtimes);
if ($outcome eq 'ok') {
$ua->timeout(30);
if ($loginpage) {
$outcome = &parse_loginpage($loginpage,$formitems,$formvalues);
if ($outcome eq 'ok') {
- ($outcome,$lonid) = &logmein($server,$uname,$udom,$upass,$ua,$loncookie_file,$formvalues,$loadtimes);
+ ($outcome,$lonid) = &logmein($server,$uname,$udom,$upass,$ua,$loncookie_file,$formvalues,$loadtimes,$monitordir,$path_to_java);
if ($outcome eq 'ok') {
if ($lonid) {
&setcookie($loncookie_file,$lonid,$server);
@@ -237,9 +241,11 @@
return $outcome;
}
sub logmein {
- my ($server,$uname,$udom,$upass,$ua,$loncookie_file,$formvalues) = @_;
+ my ($server,$uname,$udom,$upass,$ua,$loncookie_file,$formvalues,$loadtimes,$monitordir,$path_to_java) = @_;
my ($outcome,$lonid);
- open(PIPE,"-|") || exec "java org.mozilla.javascript.tools.shell.Main londes_auto.js $$formvalues{uextkey} $$formvalues{lextkey} $upass";
+ my $classpath="$monitordir/js.jar";
+ my $londesfile = "$monitordir/londes_auto.js";
+ open(PIPE,"-|") || exec "$path_to_java -classpath $classpath org.mozilla.javascript.tools.shell.Main $londesfile $$formvalues{uextkey} $$formvalues{lextkey} $upass";
my $cryppass = <PIPE>;
close PIPE;
my $URL = 'http://'.$server.'/adm/authenticate';
@@ -258,20 +264,23 @@
my $res = $ua->request($req);
if ($res->is_success) {
my $dump = $res->content;
- if ($dump =~ m-Username\sand\\or\spassword\scould\snot\sbe\sauthenticated-) {
+ if ($dump =~ m-Username,\spassword\sand\sdomain\sneed\sto\sbe\sspecified-) {
+ $outcome = 'missingparam';
+ } elsif ($dump =~ m-Username\sand\/or\spassword\scould\snot\sbe\sauthenticated-) {
$outcome = 'unauthenticated';
- }
- $loncookie_file->extract_cookies($res);
- my $cookie = $loncookie_file->as_string;
- if ($cookie =~ m/lonID=(\w+);/) {
- $lonid = $1;
- $outcome = 'ok';
} else {
- $outcome = 'invalidcookie';
+ $loncookie_file->extract_cookies($res);
+ my $cookie = $loncookie_file->as_string;
+ if ($cookie =~ m/lonID=(\w+);/) {
+ $lonid = $1;
+ $outcome = 'ok';
+ } else {
+ $outcome = 'invalidcookie';
+ }
+ my $end = [gettimeofday];
+ $loadtimes{login} = tv_interval $start, $end;
+ $loadtimes{login} *= 1000;
}
- my $end = [gettimeofday];
- $loadtimes{login} = tv_interval $start, $end;
- $loadtimes{login} *= 1000;
} else {
$outcome = 'nologin';
}
@@ -279,7 +288,7 @@
}
sub pickrole {
- my ($server,$loncookie_file,$ua,$role) = @_;
+ my ($server,$loncookie_file,$ua,$role,$loadtimes) = @_;
my ($start,$end,$outcome);
my $URL = 'http://'.$server.'/adm/roles';
my $request = POST $URL,
@@ -313,6 +322,7 @@
my $URL = 'http://'.$server.'/adm/navmaps';
my $request = new HTTP::Request;
$request = GET $URL;
+ $loncookie_file->add_cookie_header($request);
my $start = [gettimeofday];
my $res = $ua->request($request);
if ($res->is_success) {
@@ -333,6 +343,7 @@
my $URL = 'http://'.$server.'/adm/logout';
my $request = new HTTP::Request;
$request = GET $URL;
+ $loncookie_file->add_cookie_header($request);
my $res = $ua->request($request);
if ($res->is_success) {
my $dump = $res->content;