[LON-CAPA-cvs] cvs: loncom / loncron /interface domainprefs.pm loncommon.pm

raeburn raeburn at source.lon-capa.org
Tue Nov 6 10:37:42 EST 2018


raeburn		Tue Nov  6 15:37:42 2018 EDT

  Modified files:              
    /loncom/interface	domainprefs.pm loncommon.pm 
    /loncom	loncron 
  Log:
  - Nightly loncron: threshold for sending mail, and weighting for notices,
    warnings and errors in "totalcount" are configurable in node's default domain.
  - Whether to copy status mail to core dev. group (and threshold) configurable. 
  
  
-------------- next part --------------
Index: loncom/interface/domainprefs.pm
diff -u loncom/interface/domainprefs.pm:1.339 loncom/interface/domainprefs.pm:1.340
--- loncom/interface/domainprefs.pm:1.339	Mon Oct 22 13:46:14 2018
+++ loncom/interface/domainprefs.pm	Tue Nov  6 15:37:37 2018
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set domain-wide configuration settings
 #
-# $Id: domainprefs.pm,v 1.339 2018/10/22 13:46:14 raeburn Exp $
+# $Id: domainprefs.pm,v 1.340 2018/11/06 15:37:37 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -352,6 +352,8 @@
                                 col2 => 'Value',},
                                {col1 => 'Recipient(s) for notifications',
                                 col2 => 'Value',},
+                               {col1 => 'Nightly status check e-mail',
+                                col2 => 'Settings',},
                                {col1 => 'Ask helpdesk form settings',
                                 col2 => 'Value',},],
                     print => \&print_contacts,
@@ -904,6 +906,23 @@
              </tr>'."\n";
                 if ($action eq 'coursecategories') {
                     $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
+                } elsif ($action eq 'contacts') {
+                    $output .= $item->{'print'}->('lower',$dom,$settings,\$rowtotal).'
+             </tr>
+            </table>
+           </td>
+          </tr>
+          <tr>
+           <td>
+            <table class="LC_nested">
+             <tr class="LC_info_row">
+              <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
+              <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'.
+                           $item->{'print'}->('bottom',$dom,$settings,\$rowtotal).'
+            </table>
+          </td>
+         </tr>
+         <tr>';
                 } else {
                     $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
                 }
@@ -3323,7 +3342,7 @@
     my $datatable;
     my @contacts = ('adminemail','supportemail');
     my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
-        $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions, at mailings);
+        $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions, at mailings,%lonstatus);
     if ($position eq 'top') {
         if (ref($settings) eq 'HASH') {
             foreach my $item (@contacts) {
@@ -3338,6 +3357,12 @@
         foreach my $type (@mailings) {
             $otheremails{$type} = '';
         }
+    } elsif ($position eq 'lower') {
+        if (ref($settings) eq 'HASH') {
+            if (ref($settings->{'lonstatus'}) eq 'HASH') {
+                %lonstatus = %{$settings->{'lonstatus'}};
+            }
+        }
     } else {
         @mailings = ('helpdeskmail','otherdomsmail');
         foreach my $type (@mailings) {
@@ -3350,7 +3375,7 @@
         ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
     }
     if (ref($settings) eq 'HASH') {
-        unless ($position eq 'top') {
+        unless (($position eq 'top') || ($position eq 'lower')) {
             foreach my $type (@mailings) {
                 if (exists($settings->{$type})) {
                     if (ref($settings->{$type}) eq 'HASH') {
@@ -3482,7 +3507,7 @@
         $datatable .= '</td></tr>'."\n";
         $rownum ++;
     }
-    unless ($position eq 'top') {
+    unless (($position eq 'top') || ($position eq 'lower')) {
         foreach my $type (@mailings) {
             $css_class = $rownum%2?' class="LC_odd_row"':'';
             $datatable .= '<tr'.$css_class.'>'.
@@ -3529,18 +3554,110 @@
     }
     if ($position eq 'middle') {
         my %choices;
-        $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
-                                       &Apache::loncommon::modal_link('http://loncapa.org/core.html',
-                                       &mt('LON-CAPA core group - MSU'),600,500));
+        my $corelink = &core_link_msu();
+        $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',$corelink);
         $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
-                                        &Apache::loncommon::modal_link('http://loncapa.org/core.html',
-                                        &mt('LON-CAPA core group - MSU'),600,500));
-        my @toggles = ('reporterrors','reportupdates');
+                                        $corelink);
+        $choices{'reportstatus'} = &mt('E-mail status if errors above threshold to [_1]',$corelink);
+        my @toggles = ('reporterrors','reportupdates','reportstatus');
         my %defaultchecked = ('reporterrors'  => 'on',
-                              'reportupdates' => 'on');
+                              'reportupdates' => 'on',
+                              'reportstatus'  => 'on');
         (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
                                                    \%choices,$rownum);
         $datatable .= $reports;
+    } elsif ($position eq 'lower') {
+        $css_class = $rownum%2?' class="LC_odd_row"':'';
+        my ($threshold,$sysmail,%excluded,%weights);
+        my ($defaults,$names) = &Apache::loncommon::lon_status_items();
+        if ($lonstatus{'threshold'} =~ /^\d+$/) {
+            $threshold = $lonstatus{'threshold'};
+        } else {
+            $threshold = $defaults->{'threshold'};
+        }
+        if ($lonstatus{'sysmail'} =~ /^\d+$/) {
+            $sysmail = $lonstatus{'sysmail'};
+        } else {
+            $sysmail = $defaults->{'sysmail'};
+        }
+        if (ref($lonstatus{'weights'}) eq 'HASH') {
+            foreach my $type ('E','W','N') {
+                if ($lonstatus{'weights'}{$type} =~ /^\d+$/) {
+                    $weights{$type} = $lonstatus{'weights'}{$type};
+                } else {
+                    $weights{$type} = $defaults->{$type};
+                }
+            }
+        } else {
+            foreach my $type ('E','W','N') {
+                $weights{$type} = $defaults->{$type};
+            }
+        }
+        if (ref($lonstatus{'excluded'}) eq 'ARRAY') {
+            if (@{$lonstatus{'excluded'}} > 0) {
+                map {$excluded{$_} = 1; } @{$lonstatus{'excluded'}};
+            }
+        }
+        $datatable .= '<tr'.$css_class.'>'.
+                      '<td class="LC_left_item"><span class="LC_nobreak">'.
+                      $titles->{'errorthreshold'}.
+                      '</span></td><td class="LC_left_item">'.
+                      '<input type="text" name="errorthreshold" value="'.
+                      $threshold.'" size="5" /></td></tr>';
+        $rownum ++;
+        $css_class = $rownum%2?' class="LC_odd_row"':'';
+        $datatable .= '<tr'.$css_class.'>'.
+                      '<td class="LC_left_item">'.
+                      '<span class="LC_nobreak">'.$titles->{'errorweights'}.
+                      '</span></td><td class="LC_left_item"><table><tr>';
+        foreach my $type ('E','W','N') {
+            $datatable .= '<td>'.$names->{$type}.'<br />'.
+                          '<input type="text" name="errorweights_'.$type.'" value="'.
+                          $weights{$type}.'" size="5" /></td>';
+        }
+        $datatable .= '</tr></table></tr>';
+        $rownum ++;
+        $css_class = $rownum%2?' class="LC_odd_row"':'';
+        $datatable .= '<tr'.$css_class.'><td class="LC_left_item">'.
+                      $titles->{'errorexcluded'}.'</td>'.
+                      '<td class="LC_left_item"><table>';
+        my $numinrow = 4;
+        my @ids = sort(values(%Apache::lonnet::serverhomeIDs));
+        for (my $i=0; $i<@ids; $i++) {
+            my $rem = $i%($numinrow);
+            if ($rem == 0) {
+                if ($i > 0) {
+                    $datatable .= '</tr>';
+                }
+                $datatable .= '<tr>';
+            }
+            my $check;
+            if ($excluded{$ids[$i]}) {
+                $check = ' checked="checked" ';
+            }
+            $datatable .= '<td class="LC_left_item">'.
+                          '<span class="LC_nobreak"><label>'.
+                          '<input type="checkbox" name="errorexcluded" '.
+                          'value="'.$ids[$i].'"'.$check.' />'.
+                          $ids[$i].'</label></span></td>';
+        }
+        my $colsleft = $numinrow - @ids%($numinrow);
+        if ($colsleft > 1 ) {
+            $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
+                          ' </td>';
+        } elsif ($colsleft == 1) {
+            $datatable .= '<td class="LC_left_item"> </td>';
+        }
+        $datatable .= '</tr></table></td></tr>';
+        $rownum ++;
+        $css_class = $rownum%2?' class="LC_odd_row"':'';
+        $datatable .= '<tr'.$css_class.'>'.
+                      '<td class="LC_left_item"><span class="LC_nobreak">'.
+                      $titles->{'errorsysmail'}.
+                      '</span></td><td class="LC_left_item">'.
+                      '<input type="text" name="errorsysmail" value="'.
+                      $sysmail.'" size="5" /></td></tr>';
+        $rownum ++;
     } elsif ($position eq 'bottom') {
         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
         my (@posstypes,%usertypeshash);
@@ -3614,6 +3731,11 @@
     return $datatable;
 }
 
+sub core_link_msu {
+    return &Apache::loncommon::modal_link('http://loncapa.org/core.html',
+                                          &mt('LON-CAPA core group - MSU'),600,500);
+}
+
 sub overridden_helpdesk {
     my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
         $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
@@ -6594,6 +6716,10 @@
                    'requestsmail'    => 'E-mail from course requests requiring approval',
                    'updatesmail'     => 'E-mail from nightly check of LON-CAPA module integrity/updates',
                    'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
+                   'errorthreshold'  => 'Error/warning threshold for status e-mail',
+                   'errorsysmail'    => 'Error threshold for e-mail to core group',
+                   'errorweights'    => 'Weights used to compute error count',
+                   'errorexcluded'   => 'Servers with unsent updates excluded from count',
                  );
     my %short_titles = &Apache::lonlocal::texthash (
                            adminemail   => 'Admin E-mail address',
@@ -12662,7 +12788,8 @@
     my @contacts = ('supportemail','adminemail');
     my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
                     'lonstatusmail','requestsmail','updatesmail','idconflictsmail');
-    my @toggles = ('reporterrors','reportupdates');
+    my @toggles = ('reporterrors','reportupdates','reportstatus');
+    my @lonstatus = ('threshold','sysmail','weights','excluded');
     my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
     foreach my $type (@mailings) {
         @{$newsetting{$type}} = 
@@ -12695,6 +12822,41 @@
             $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
         }
     }
+    my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
+    foreach my $item (@lonstatus) {
+        if ($item eq 'excluded') {
+            my (%serverhomes, at excluded);
+            map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
+            my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
+            if (@possexcluded) {
+                foreach my $id (sort(@possexcluded)) {
+                    if ($serverhomes{$id}) {
+                        push(@excluded,$id);
+                    }
+                }
+            }
+            if (@excluded) {
+                $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
+            }
+        } elsif ($item eq 'weights') {
+            foreach my $type ('E','W','N') {
+                $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
+                if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
+                    unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
+                        $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
+                            $env{'form.error'.$item.'_'.$type};
+                    }
+                }
+            }
+        } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
+            $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
+            if ($env{'form.error'.$item} =~ /^\d+$/) {
+                unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
+                    $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
+                }
+            }
+        }
+    }
     if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
         foreach my $field (@{$fields}) {
             if (ref($possoptions->{$field}) eq 'ARRAY') {
@@ -12833,6 +12995,76 @@
                 }
             }
         }
+        if (ref($currsetting{'lonstatus'}) eq 'HASH') {
+            foreach my $key ('excluded','weights','threshold','sysmail') {
+                if ($key eq 'excluded') {
+                    if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
+                        (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
+                        if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
+                            (@{$currsetting{'lonstatus'}{$key}})) {
+                            my @diffs =
+                                &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
+                                                                   $currsetting{'lonstatus'}{$key});
+                            if (@diffs) {
+                                push(@{$changes{'lonstatus'}},$key);
+                            }
+                        } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
+                            push(@{$changes{'lonstatus'}},$key);
+                        }
+                    } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
+                             (@{$currsetting{'lonstatus'}{$key}})) {
+                        push(@{$changes{'lonstatus'}},$key);
+                    }
+                } elsif ($key eq 'weights') {
+                    if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
+                        (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
+                        if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
+                            foreach my $type ('E','W','N') {
+                                unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
+                                        $currsetting{'lonstatus'}{$key}{$type}) {
+                                    push(@{$changes{'lonstatus'}},$key);
+                                    last;
+                                }
+                            }
+                        } else {
+                            foreach my $type ('E','W','N') {
+                                if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
+                                    push(@{$changes{'lonstatus'}},$key);
+                                    last;
+                                }
+                            }
+                        }
+                    } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
+                        foreach my $type ('E','W','N') {
+                            if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
+                                push(@{$changes{'lonstatus'}},$key);
+                                last;
+                            }
+                        }
+                    }
+                } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
+                    if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
+                        if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
+                            if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
+                                push(@{$changes{'lonstatus'}},$key);
+                            }
+                        } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
+                            push(@{$changes{'lonstatus'}},$key);
+                        }
+                    } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
+                        push(@{$changes{'lonstatus'}},$key);
+                    }
+                }
+            }
+        } else {
+            if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
+                foreach my $key ('excluded','weights','threshold','sysmail') {
+                    if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
+                        push(@{$changes{'lonstatus'}},$key);
+                    }
+                }
+            }
+        }
     } else {
         my %default;
         $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
@@ -12877,6 +13109,13 @@
                 }
             }
         }
+        if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
+            foreach my $key ('excluded','weights','threshold','sysmail') {
+                if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
+                    push(@{$changes{'lonstatus'}},$key);
+                }
+            }
+        }
     }
     foreach my $item (@toggles) {
         if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
@@ -13002,22 +13241,79 @@
                 }
             }
             my @offon = ('off','on');
+            my $corelink = &core_link_msu();
             if ($changes{'reporterrors'}) {
                 $resulttext .= '<li>'.
                                &mt('E-mail error reports to [_1] set to "'.
                                    $offon[$env{'form.reporterrors'}].'".',
-                                   &Apache::loncommon::modal_link('http://loncapa.org/core.html',
-                                       &mt('LON-CAPA core group - MSU'),600,500)).
+                                   $corelink).
                                '</li>';
             }
             if ($changes{'reportupdates'}) {
                 $resulttext .= '<li>'.
                                 &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
                                     $offon[$env{'form.reportupdates'}].'".',
-                                    &Apache::loncommon::modal_link('http://loncapa.org/core.html',
-                                        &mt('LON-CAPA core group - MSU'),600,500)).
+                                    $corelink).
                                 '</li>';
             }
+            if ($changes{'reportstatus'}) {
+                $resulttext .= '<li>'.
+                                &mt('E-mail status if errors above threshold to [_1] set to "'.
+                                    $offon[$env{'form.reportstatus'}].'".',
+                                    $corelink).
+                                '</li>';
+            }
+            if (ref($changes{'lonstatus'}) eq 'ARRAY') {
+                $resulttext .= '<li>'.
+                               &mt('Nightly status check e-mail settings').':<ul>';
+                my (%defval,%use_def,%shown);
+                $defval{'threshold'} = $lonstatus_defs->{'threshold'};
+                $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
+                $defval{'weights'} =
+                    join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N'));
+                $defval{'excluded'} = &mt('None');
+                if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
+                    foreach my $item ('threshold','sysmail','weights','excluded') {
+                        if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
+                            if (($item eq 'threshold') || ($item eq 'sysmail')) {
+                                $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
+                            } elsif ($item eq 'weights') {
+                                if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
+                                    foreach my $type ('E','W','N') {
+                                        $shown{$item} .= $lonstatus_names->{$type}.'=';
+                                        if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
+                                            $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
+                                        } else {
+                                            $shown{$item} .= $lonstatus_defs->{$type};
+                                        }
+                                        $shown{$item} .= ', ';
+                                    }
+                                    $shown{$item} =~ s/, $//;
+                                } else {
+                                    $shown{$item} = $defval{$item};
+                                }
+                            } elsif ($item eq 'excluded') {
+                                if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
+                                    $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
+                                } else {
+                                    $shown{$item} = $defval{$item};
+                                }
+                            }
+                        } else {
+                            $shown{$item} = $defval{$item};
+                        }
+                    }
+                } else {
+                    foreach my $item ('threshold','weights','excluded','sysmail') {
+                        $shown{$item} = $defval{$item};
+                    }
+                }
+                foreach my $item ('threshold','weights','excluded','sysmail') {
+                    $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
+                                          $shown{$item}).'</li>';
+                }
+                $resulttext .= '</ul></li>';
+            }
             if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
                 my (@optional, at required, at unused,$maxsizechg);
                 foreach my $field (@{$changes{'helpform'}}) {
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.1321 loncom/interface/loncommon.pm:1.1322
--- loncom/interface/loncommon.pm:1.1321	Tue Sep 18 02:18:43 2018
+++ loncom/interface/loncommon.pm	Tue Nov  6 15:37:37 2018
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.1321 2018/09/18 02:18:43 raeburn Exp $
+# $Id: loncommon.pm,v 1.1322 2018/11/06 15:37:37 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -16420,6 +16420,22 @@
     return @difference;
 }
 
+sub lon_status_items {
+    my %defaults = (
+                     E         => 100,
+                     W         => 4,
+                     N         => 1,
+                     threshold => 200,
+                     sysmail   => 2500,
+                   );
+    my %names = (
+                   E => 'Errors',
+                   W => 'Warnings',
+                   N => 'Notices',
+                );
+    return (\%defaults,\%names);
+}
+
 # -------------------------------------------------------- Initialize user login
 sub init_user_environment {
     my ($r, $username, $domain, $authhost, $form, $args) = @_;
Index: loncom/loncron
diff -u loncom/loncron:1.112 loncom/loncron:1.113
--- loncom/loncron:1.112	Mon Oct 29 02:57:30 2018
+++ loncom/loncron	Tue Nov  6 15:37:42 2018
@@ -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 finish_logging {
-    my ($fh)=@_;
+    my ($fh,%weights)=@_;
     &log($fh,"<a name='errcount' />\n");
-    $totalcount=$notices+4*$warnings+100*$errors;
+    $totalcount=($weights{'N'}*$notices)+($weights{'W'}*$warnings)+($weights{'E'}*$errors);
     &errout($fh);
     &log($fh,"<h1>Total Error Count: $totalcount</h1>");
     my $now=time;
@@ -861,20 +861,8 @@
 }
 
 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 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 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 @@
             &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); }
     }
 }
 


More information about the LON-CAPA-cvs mailing list