[LON-CAPA-cvs] cvs: doc /loncapafiles loncapafiles.lpml loncom currhostips.tab loncron loncom/interface domainprefs.pm

raeburn raeburn at source.lon-capa.org
Sun Mar 17 19:23:32 EDT 2019


raeburn		Sun Mar 17 23:23:32 2019 EDT

  Added files:                 
    /loncom	currhostips.tab 

  Modified files:              
    /loncom	loncron 
    /loncom/interface	domainprefs.pm 
    /doc/loncapafiles	loncapafiles.lpml 
  Log:
  - loncron will check for changes in IP addresses of LON-CAPA hosts in network.
    Domain configuration for recipient of e-mail if changes occur. Also logged 
    permanently in /home/httpd/perl/logs/hostip.log
  
  
-------------- next part --------------
Index: loncom/loncron
diff -u loncom/loncron:1.116 loncom/loncron:1.117
--- loncom/loncron:1.116	Sat Dec 22 20:05:16 2018
+++ loncom/loncron	Sun Mar 17 23:23:21 2019
@@ -2,7 +2,7 @@
 
 # Housekeeping program, started by cron, loncontrol and loncron.pl
 #
-# $Id: loncron,v 1.116 2018/12/22 20:05:16 raeburn Exp $
+# $Id: loncron,v 1.117 2019/03/17 23:23:21 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -45,6 +45,7 @@
 use GDBM_File;
 use Storable qw(thaw);
 use File::ReadBackwards;
+use File::Copy;
 #globals
 use vars qw (%perlvar %simplestatus $errors $warnings $notices $totalcount);
 
@@ -1027,6 +1028,94 @@
     return;
 }
 
+sub write_hostips {
+    my $lontabdir = $perlvar{'lonTabDir'};
+    my $defdom = $perlvar{'lonDefDomain'};
+    my $lonhost = $perlvar{'lonHostID'};
+    my $newfile = "$lontabdir/currhostips.tab";
+    my $oldfile = "$lontabdir/prevhostips.tab";
+    my (%prevhosts,%currhosts,%ipchange);
+    if ((-e $newfile) && (-s $newfile)) {
+        move($newfile,$oldfile);
+        chmod(0644,$oldfile);
+        if (open(my $fh,'<',$oldfile)) {
+            while (my $line=<$fh>) {
+                chomp($line);
+                if ($line =~ /^([^:]+):([\d.]+)$/) {
+                    $prevhosts{$1} = $2;
+                }
+            }
+            close($fh);
+        }
+    }
+    my ($ip_info,$cached) =
+        &Apache::lonnet::is_cached_new('iphost','iphost');
+    if (!$cached) {
+        &Apache::lonnet::get_iphost();
+        ($ip_info,$cached) =
+        &Apache::lonnet::is_cached_new('iphost','iphost');
+    }
+    if (ref($ip_info) eq 'ARRAY') {
+        %currhosts = %{$ip_info->[1]};
+        if (open(my $fh,'>',$newfile)) {
+            foreach my $key (keys(%currhosts)) {
+                print $fh "$key:$currhosts{$key}\n";
+            }
+            close($fh);
+            chmod(0644,$newfile);
+        }
+    }
+    if (keys(%prevhosts) && keys(%currhosts)) {
+        foreach my $key (keys(%prevhosts)) {
+            unless ($currhosts{$key} eq $prevhosts{$key}) {
+                $ipchange{$key} = $prevhosts{$key}.'|'.$currhosts{$key};
+            }
+        }
+        foreach my $key (keys(%currhosts)) {
+            unless ($currhosts{$key} eq $prevhosts{$key}) {
+                $ipchange{$key} = $prevhosts{$key}.' | '.$currhosts{$key};
+            }
+        }
+    }
+    if (&Apache::lonnet::domain($defdom,'primary') eq $lonhost) {
+        if (keys(%ipchange)) {
+            if (open(my $fh,'>>',$perlvar{'lonDaemons'}.'/logs/hostip.log')) {
+               print $fh "********************\n".localtime(time).' Changes --'."\n".
+                         "Hostname | Previous IP | New IP\n".
+                         "--------------------------------\n";
+               foreach my $hostname (sort(keys(%ipchange))) {
+                    print $fh "$hostname | $ipchange{$hostname}\n";
+                }
+                print $fh "\n*******************\n\n";
+                close($fh);
+            }
+            my $emailto = &Apache::loncommon::build_recipient_list(undef,
+                                   'hostipmail',$defdom);
+            if ($emailto) {
+                my $subject = "LON-CAPA Hostname to IP change ($perlvar{'lonHostID'})";
+                my $chgmail = "To: $emailto\n".
+                              "Subject: $subject\n".
+                              "Content-type: text/plain\; charset=UTF-8\n".
+                              "MIME-Version: 1.0\n\n".
+                              "Host/IP changes\n".
+                              " \n".
+                              "Hostname | Previous IP | New IP\n".
+                              "--------------------------------\n";
+                foreach my $hostname (sort(keys(%ipchange))) {
+                    $chgmail .= "$hostname | $ipchange{$hostname}\n";
+                }
+                $chgmail .= "\n\n";
+                if (open(my $mailh, "|/usr/lib/sendmail -oi -t -odb")) {
+                    print $mailh $chgmail;
+                    close($mailh);
+                    print "Sending mail notification of hostname/IP changes.\n";
+                }
+            }
+        }
+    }
+    return;
+}
+
 sub clean_nosslverify {
     my ($fh) = @_;
     my %unlinked; 
@@ -1533,6 +1622,7 @@
         &write_loncaparevs();
         &write_serverhomeIDs();
 	&write_checksums();
+        &write_hostips();
         my %sslrem = &clean_nosslverify($fh);
         my %conchgs = &write_connection_config();
         my %hosttypechgs = &write_hosttypes();
Index: loncom/interface/domainprefs.pm
diff -u loncom/interface/domainprefs.pm:1.349 loncom/interface/domainprefs.pm:1.350
--- loncom/interface/domainprefs.pm:1.349	Fri Feb 15 20:56:14 2019
+++ loncom/interface/domainprefs.pm	Sun Mar 17 23:23:27 2019
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set domain-wide configuration settings
 #
-# $Id: domainprefs.pm,v 1.349 2019/02/15 20:56:14 raeburn Exp $
+# $Id: domainprefs.pm,v 1.350 2019/03/17 23:23:27 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -3383,7 +3383,7 @@
         }
     } elsif ($position eq 'middle') {
         @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
-                     'updatesmail','idconflictsmail');
+                     'updatesmail','idconflictsmail','hostipmail');
         foreach my $type (@mailings) {
             $otheremails{$type} = '';
         }
@@ -3466,6 +3466,7 @@
             $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
             $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
             $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
+            $checked{'hostipmail'}{'adminemail'} = ' checked="checked" ';
         } elsif ($position eq 'bottom') {
             $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
             $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
@@ -6785,6 +6786,7 @@
                    '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',
+                   'hostipmail'      => 'E-mail from nightly check of hostname/IP network changes',
                    'errorthreshold'  => 'Error/warning threshold for status e-mail',
                    'errorsysmail'    => 'Error threshold for e-mail to core group',
                    'errorweights'    => 'Weights used to compute error count',
@@ -13035,7 +13037,7 @@
     my (%others,%to,%bcc,%includestr,%includeloc);
     my @contacts = ('supportemail','adminemail');
     my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
-                    'lonstatusmail','requestsmail','updatesmail','idconflictsmail');
+                    'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
     my @toggles = ('reporterrors','reportupdates','reportstatus');
     my @lonstatus = ('threshold','sysmail','weights','excluded');
     my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
@@ -13324,6 +13326,7 @@
         $default{'lonstatusmail'} = 'adminemail';
         $default{'requestsmail'} = 'adminemail';
         $default{'updatesmail'} = 'adminemail';
+        $default{'hostipmail'} = 'adminemail';
         foreach my $item (@contacts) {
            if ($to{$item} ne $default{$item}) {
                $changes{$item} = 1;
Index: doc/loncapafiles/loncapafiles.lpml
diff -u doc/loncapafiles/loncapafiles.lpml:1.982 doc/loncapafiles/loncapafiles.lpml:1.983
--- doc/loncapafiles/loncapafiles.lpml:1.982	Tue Feb 26 14:42:31 2019
+++ doc/loncapafiles/loncapafiles.lpml	Sun Mar 17 23:23:32 2019
@@ -2,7 +2,7 @@
  "http://lpml.sourceforge.net/DTD/lpml.dtd">
 <!-- loncapafiles.lpml -->
 
-<!-- $Id: loncapafiles.lpml,v 1.982 2019/02/26 14:42:31 raeburn Exp $ -->
+<!-- $Id: loncapafiles.lpml,v 1.983 2019/03/17 23:23:32 raeburn Exp $ -->
 
 <!--
 
@@ -1757,6 +1757,30 @@
   </description>
 </file>
 
+<file>
+  <source>loncom/currhostips.tab</source>
+  <target dist='default'>home/httpd/lonTabs/currhostips.tab</target>
+  <categoryname>www conf</categoryname>
+  <description>
+File containing hostname:IP address for LON-CAPA nodes in the cluster
+to which the node belongs. Updated by loncron using host information
+from authoritative membership lists retrieved from cluster's name servers,
+and standard DNS service used by OS for hostname <=> IP mapping.
+  </description>
+</file>
+
+<file>
+  <source>loncom/currhostips.tab</source>
+  <target dist='default'>home/httpd/lonTabs/prevhostips.tab</target>
+  <categoryname>www conf</categoryname>
+  <description>
+File containing hostname:IP address for LON-CAPA nodes in the cluster
+to which the node belongs, from previous check (usually 24 hours earlier).
+Updated by loncron, and used on domain's primary library server to generate
+an e-mail listing changes in hostnames and/or IP addresses.
+  </description>
+</file>
+
 <fileglob>
 <glob>*.tab</glob>
 <sourcedir>loncom/dns_checksums/</sourcedir>

Index: loncom/currhostips.tab
+++ loncom/currhostips.tab


More information about the LON-CAPA-cvs mailing list