--- loncom/loncron 2018/10/25 03:27:22 1.110
+++ 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.110 2018/10/25 03:27:22 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;
@@ -1176,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;
}
@@ -1187,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;
}
@@ -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); }
}
}