--- loncom/loncron 2018/08/08 11:49:48 1.108
+++ loncom/loncron 2018/11/06 15:37:42 1.113
@@ -2,7 +2,7 @@
# Housekeeping program, started by cron, loncontrol and loncron.pl
#
-# $Id: loncron,v 1.108 2018/08/08 11:49:48 raeburn Exp $
+# $Id: loncron,v 1.113 2018/11/06 15:37:42 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -113,17 +113,20 @@ sub checkon_daemon {
my $result;
&log($fh,'
'.$daemon.'
Log
');
printf("%-15s ",$daemon);
- if (-e "$perlvar{'lonDaemons'}/logs/$daemon.log"){
- open (DFH,"tail -n25 $perlvar{'lonDaemons'}/logs/$daemon.log|");
- while (my $line=) {
- &log($fh,"$line");
- if ($line=~/INFO/) { $notices++; }
- if ($line=~/WARNING/) { $notices++; }
- if ($line=~/CRITICAL/) { $warnings++; }
- };
- close (DFH);
+ if ($fh) {
+ if (-e "$perlvar{'lonDaemons'}/logs/$daemon.log"){
+ if (open(DFH,"tail -n25 $perlvar{'lonDaemons'}/logs/$daemon.log|")) {
+ while (my $line=) {
+ &log($fh,"$line");
+ if ($line=~/INFO/) { $notices++; }
+ if ($line=~/WARNING/) { $notices++; }
+ if ($line=~/CRITICAL/) { $warnings++; }
+ }
+ close (DFH);
+ }
+ }
+ &log($fh,"
");
}
- &log($fh,"");
my $pidfile="$perlvar{'lonDaemons'}/logs/$daemon.pid";
@@ -169,7 +172,7 @@ sub checkon_daemon {
&clean_lonc_childpids();
}
&log($fh,"$daemon not running, trying to start
");
-
+
if (&start_daemon($fh,$daemon,$pidfile,$args)) {
&log($fh,"$daemon at pid $daemonpid responding
");
$simplestatus{$daemon}='restarted';
@@ -194,17 +197,19 @@ sub checkon_daemon {
&log($fh,"Unable to start $daemon
");
}
}
-
- if (-e "$perlvar{'lonDaemons'}/logs/$daemon.log"){
- &log($fh,"");
- open (DFH,"tail -n100 $perlvar{'lonDaemons'}/logs/$daemon.log|");
- while (my $line=) {
- &log($fh,"$line");
- if ($line=~/WARNING/) { $notices++; }
- if ($line=~/CRITICAL/) { $notices++; }
- };
- close (DFH);
- &log($fh,"
");
+ if ($fh) {
+ if (-e "$perlvar{'lonDaemons'}/logs/$daemon.log"){
+ &log($fh,"");
+ if (open(DFH,"tail -n100 $perlvar{'lonDaemons'}/logs/$daemon.log|")) {
+ while (my $line=) {
+ &log($fh,"$line");
+ if ($line=~/WARNING/) { $notices++; }
+ if ($line=~/CRITICAL/) { $notices++; }
+ }
+ close (DFH);
+ }
+ &log($fh,"
");
+ }
}
}
@@ -708,9 +713,9 @@ sub check_delayed_msg {
}
sub finish_logging {
- my ($fh)=@_;
+ my ($fh,%weights)=@_;
&log($fh,"\n");
- $totalcount=$notices+4*$warnings+100*$errors;
+ $totalcount=($weights{'N'}*$notices)+($weights{'W'}*$warnings)+($weights{'E'}*$errors);
&errout($fh);
&log($fh,"Total Error Count: $totalcount
");
my $now=time;
@@ -856,20 +861,8 @@ sub clean_lonc_childpids {
}
sub write_connection_config {
- my ($isprimary,$domconf,$url,%connectssl,%changes);
- my $primaryLibServer = &Apache::lonnet::domain($perlvar{'lonDefDomain'},'primary');
- if ($primaryLibServer eq $perlvar{'lonHostID'}) {
- $isprimary = 1;
- } elsif ($primaryLibServer ne '') {
- my $protocol = $Apache::lonnet::protocol{$primaryLibServer};
- my $hostname = &Apache::lonnet::hostname($primaryLibServer);
- unless ($protocol eq 'https') {
- $protocol = 'http';
- }
- $url = $protocol.'://'.$hostname.'/cgi-bin/listdomconfig.pl';
- }
- my $domconf = &get_domain_config($perlvar{'lonDefDomain'},$primaryLibServer,$isprimary,
- $url);
+ my ($domconf,%connectssl,%changes);
+ $domconf = &get_domain_config();
if (ref($domconf) eq 'HASH') {
if (ref($domconf->{'ssl'}) eq 'HASH') {
foreach my $connect ('connto','connfrom') {
@@ -922,8 +915,19 @@ sub write_connection_config {
}
sub get_domain_config {
- my ($dom,$primlibserv,$isprimary,$url) = @_;
- my %confhash;
+ my ($dom,$primlibserv,$isprimary,$url,%confhash);
+ $dom = $perlvar{'lonDefDomain'};
+ $primlibserv = &Apache::lonnet::domain($dom,'primary');
+ if ($primlibserv eq $perlvar{'lonHostID'}) {
+ $isprimary = 1;
+ } elsif ($primlibserv ne '') {
+ my $protocol = $Apache::lonnet::protocol{$primlibserv};
+ my $hostname = &Apache::lonnet::hostname($primlibserv);
+ unless ($protocol eq 'https') {
+ $protocol = 'http';
+ }
+ $url = $protocol.'://'.$hostname.'/cgi-bin/listdomconfig.pl';
+ }
if ($isprimary) {
my $lonusersdir = $perlvar{'lonUsersDir'};
my $fname = $lonusersdir.'/'.$dom.'/configuration.db';
@@ -1057,8 +1061,8 @@ sub reset_nosslverify_pids {
if ($sslrem{$host}) {
if (ref($pids_by_host{$host}) eq 'HASH') {
if (ref($pids_by_host{$host}{'insecure'}) eq 'HASH') {
- if (keys($pids_by_host{$host}{'insecure'})) {
- foreach my $pid (keys($pids_by_host{$host}{'insecure'})) {
+ if (keys(%{$pids_by_host{$host}{'insecure'}})) {
+ foreach my $pid (keys(%{$pids_by_host{$host}{'insecure'}})) {
if (open(PIPE,"ps -o ppid= -p $pid |")) {
my $ppid = ;
chomp($ppid);
@@ -1083,11 +1087,12 @@ sub reset_nosslverify_pids {
}
sub send_mail {
+ my ($sysmail,$reportstatus) = @_;
my $defdom = $perlvar{'lonDefDomain'};
my $origmail = $perlvar{'lonAdmEMail'};
my $emailto = &Apache::loncommon::build_recipient_list(undef,
'lonstatusmail',$defdom,$origmail);
- if ($totalcount>2500) {
+ if (($totalcount>$sysmail) && ($reportstatus)) {
$emailto.=",$perlvar{'lonSysEMail'}";
}
my $from;
@@ -1171,8 +1176,8 @@ sub main () {
chop $hostname;
$hostname=~s/[^\w\.]//g; # make sure is safe to pass through shell
my $subj="LON: Unconfigured machine $hostname";
- system("echo 'Unconfigured machine $hostname.' |\
- mailto $emailto -s '$subj' > /dev/null");
+ system("echo 'Unconfigured machine $hostname.' |".
+ " mail -s '$subj' $emailto > /dev/null");
exit 1;
}
@@ -1182,8 +1187,8 @@ sub main () {
print("User ID mismatch. This program must be run as user 'www'.\n");
my $emailto="$perlvar{'lonAdmEMail'},$perlvar{'lonSysEMail'}";
my $subj="LON: $perlvar{'lonHostID'} User ID mismatch";
- system("echo 'User ID mismatch. loncron must be run as user www.' |\
- mailto $emailto -s '$subj' > /dev/null");
+ system("echo 'User ID mismatch. loncron must be run as user www.' |".
+ " mail -s '$subj' $emailto > /dev/null");
exit 1;
}
@@ -1282,8 +1287,37 @@ sub main () {
&checkon_daemon($fh,'lond',40000,'USR2');
&reset_nosslverify_pids($fh,%sslrem);
}
- &finish_logging($fh);
- if ($totalcount>200 && !$noemail) { &send_mail(); }
+ my $domconf = &get_domain_config();
+ my ($defaults,$names) = &Apache::loncommon::lon_status_items();
+ my (%weights,$threshold);
+ foreach my $type ('E','W','N') {
+ $weights{$type} = $defaults->{$type};
+ }
+ my $threshold = $defaults->{'threshold'};
+ my $sysmail = $defaults->{'sysmail'};
+ my $reportstatus = 1;
+ if (ref($domconf->{'contacts'}) eq 'HASH') {
+ if ($domconf->{'contacts'}{'reportstatus'} == 0) {
+ $reportstatus = 0;
+ }
+ if (ref($domconf->{'contacts'}{'lonstatus'}) eq 'HASH') {
+ if (ref($domconf->{'contacts'}{'lonstatus'}{weights}) eq 'HASH') {
+ foreach my $type ('E','W','N') {
+ if (exists($domconf->{'contacts'}{'lonstatus'}{weights}{$type})) {
+ $weights{$type} = $domconf->{'contacts'}{'lonstatus'}{weights}{$type};
+ }
+ }
+ }
+ }
+ if (exists($domconf->{'contacts'}{'lonstatus'}{'threshold'})) {
+ $threshold = $domconf->{'contacts'}{'lonstatus'}{'threshold'};
+ }
+ if (exists($domconf->{'contacts'}{'lonstatus'}{'sysmail'})) {
+ $sysmail = $domconf->{'contacts'}{'lonstatus'}{'sysmail'};
+ }
+ }
+ &finish_logging($fh,%weights);
+ if ($totalcount>$threshold && !$noemail) { &send_mail($sysmail,$reportstatus); }
}
}