--- loncom/loncron 2018/10/29 02:57:30 1.112 +++ 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.112 2018/10/29 02:57:30 raeburn Exp $ +# $Id: loncron,v 1.113 2018/11/06 15:37:42 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -713,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; @@ -861,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') { @@ -927,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'; @@ -1088,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; @@ -1287,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); } } }