Send Linux-ha-cvs mailing list submissions to
        linux-ha-cvs@lists.linux-ha.org

To subscribe or unsubscribe via the World Wide Web, visit
        http://lists.community.tummy.com/mailman/listinfo/linux-ha-cvs
or, via email, send a message with subject or body 'help' to
        [EMAIL PROTECTED]

You can reach the person managing the list at
        [EMAIL PROTECTED]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Linux-ha-cvs digest..."


Today's Topics:

   1. Linux-HA CVS: ldirectord by horms from 
      (linux-ha-cvs@lists.linux-ha.org)
   2. Linux-HA CVS: ldirectord by horms from 
      (linux-ha-cvs@lists.linux-ha.org)


----------------------------------------------------------------------

Message: 1
Date: Tue, 15 Aug 2006 02:36:21 -0600 (MDT)
From: linux-ha-cvs@lists.linux-ha.org
Subject: [Linux-ha-cvs] Linux-HA CVS: ldirectord by horms from 
To: [EMAIL PROTECTED]
Message-ID: <[EMAIL PROTECTED]>

linux-ha CVS committal

Author  : horms
Host    : 
Project : linux-ha
Module  : ldirectord

Dir     : linux-ha/ldirectord


Modified Files:
      Tag: STABLE_1_2
        ldirectord 


Log Message:
refactor emalalerts resend functionality to use a hash instead of an array

The old implementation held all real servers in an array, which was
recreated once per interation of the main event loop. The new
implementation just holds real servers that need alerts resent.  Being a
hash, insertion, deletion and updating is trivial.  The entire hash still
needs to be iterated through once per main loop iteration in order to
effect resend as needed.  This could be made more efficient, though it may
not be worth the additional code complexity.

Backport of 1.165 (ldirectord.cf 1.21)

Signed-Off-By: Simon Horman <[EMAIL PROTECTED]>

===================================================================
RCS file: /home/cvs/linux-ha/linux-ha/ldirectord/Attic/ldirectord,v
retrieving revision 1.77.2.68
retrieving revision 1.77.2.69
diff -u -3 -r1.77.2.68 -r1.77.2.69
--- ldirectord  15 Aug 2006 08:34:40 -0000      1.77.2.68
+++ ldirectord  15 Aug 2006 08:36:21 -0000      1.77.2.69
@@ -1,5 +1,5 @@
 #!/usr/bin/perl
-my($VERSION)=(qw$Id: ldirectord,v 1.77.2.68 2006/08/15 08:34:40 horms Exp 
$)[2];
+my($VERSION)=(qw$Id: ldirectord,v 1.77.2.69 2006/08/15 08:36:21 horms Exp 
$)[2];
 
 ######################################################################
 # ldirectord                 http://www.vergenet.net/linux/ldirectord/
@@ -515,8 +515,7 @@
            @REAL
            @VIRTUAL
            $HOSTNAME
-           @EMAILSTATUS
-           @OLDEMAILSTATUS
+           %EMAILSTATUS
 
            $CRLF
 );
@@ -1765,8 +1764,6 @@
        my $nr;
        my $server_down = {};
 
-       undef @EMAILSTATUS;
-       
        # read status of current ipvsadm -L -n
         $oldsrv=&ld_read_ipvsadm();
 
@@ -1799,21 +1796,6 @@
 
                for $nr (@$nreal) {
                        my $real_str = "$nr->{server}:$nr->{port}";
-                       my %emailstat;
-                       $emailstat{server}=$real_str . " " . $nv->{server} . 
":" . $nv->{port};
-                       if (defined $nv->{emailalertfreq}) {
-                               
$emailstat{emailalertfreq}=$nv->{emailalertfreq};
-                       } 
-                       else {
-                               $emailstat{emailalertfreq}=$EMAILALERTFREQ;
-                       }
-                       if (defined $nv->{emailalert}) {
-                               $emailstat{emailalert}=$nv->{emailalert};
-                       }
-                       else {
-                               $emailstat{emailalert}=$EMAILALERT;
-                       }
-                       push(@EMAILSTATUS, \%emailstat);                        
                        if (! defined($or->{$real_str}) or
                                        $or->{$real_str}->{weight} == 0) {
                                $server_down->{$real_str} = [$nv, $nr];
@@ -2750,7 +2732,7 @@
        $log_args .= "(" #. scalar(%{$v->{real_status}}) 
                . " x $virtual_str)";
 
-       my $currentserver=$rservice . " " . $virtual_str;
+       my $server_str=$rservice . " " . $virtual_str;
        my $currenttime=time();
        if(defined($is_quiescent)) {
                if (defined($or)) {
@@ -2764,17 +2746,16 @@
                        &ld_log("Quiescent $log_args (Weight set to 0)");
                }
                &ld_emailalert("Quiescent $log_args (Weight set to 0)",
-                              $$v{emailalert}, $currentserver, $currenttime);
+                              $v, $server_str, $currenttime);
         }
        else {
                 &system_wrapper("$IPVSADM -d $ipvsadm_args");
                &ld_log("Deleted $log_args");
-               &ld_emailalert("Deleted $log_args",$$v{emailalert},
-                              $currentserver, $currenttime);
+               &ld_emailalert("Deleted $log_args", $v,
+                              $server_str, $currenttime);
        }
 }
 
-
 # _restore_service
 # Make a retore a real server. The opposite of _quiescent_server.
 # Should be called by _service_up or fallback_on
@@ -2818,7 +2799,7 @@
         if(defined($ov)){
                 $or=$ov->{"real"}->{$rservice};
         }
-        my $currentserver=$rservice . " " . $v->{server} . ":" . $v->{port};
+        my $server_str=$rservice . " " . $v->{server} . ":" . $v->{port};
         if(defined($or)){
                 unless($or->{"weight"} eq $rwght and
                        get_forward_flag($or->{"forward"}) eq $rforw){
@@ -2826,14 +2807,14 @@
                        &ld_log("Restored $log_args (Weight set to $rwght)");
                        &ld_emailalert("Restored $log_args " .
                                       "(Weight set to $rwght)",
-                                      $$v{emailalert}, $currentserver, 0);
+                                      $v, $server_str, 0);
                 }
         }
         else {
                 &system_wrapper("$IPVSADM -a $ipvsadm_args");
                &ld_log("Added $log_args (Weight set to $rwght)");
                &ld_emailalert("Added $log_args (Weight set to $rwght)",
-                              $$v{emailalert}, $currentserver, 0);
+                              $v, $server_str, 0);
         }
 }
 
@@ -2964,17 +2945,6 @@
        my ($v, $r, $force) = @_;
 
        if (! _status_down($v, $r) and ! defined($force)) {
-               my $currenttime=time();
-               foreach my $emailstats (@EMAILSTATUS) {
-                       my $currentserver=$r->{server} . ":" . $r->{port} . " " 
. $v->{server} . ":" . $v->{port};
-                       if ($currentserver eq $emailstats->{server}){
-                               if ($emailstats->{alertfreq} > 0){
-                                       if ($currenttime - 
$emailstats->{alerttime} > $emailstats->{alertfreq}){
-                                               &ld_log("email alert freq: " . 
$currentserver);
-                                       }
-                               } 
-                       }
-               }
                return;
        }
 
@@ -3184,31 +3154,36 @@
        return(0);
 }
 
+
 # ld_emailalert
 # Send email alerts per virtual server
 # pre: message: Message to email
 # post: message is emailed if emailalert defined for virtualserver 
 # return: 0 on success
 #         1 on error
+
 sub ld_emailalert
 {
-       my ($emailsubject, $emailto, $currentserver, $currenttime) = (@_);
+       my ($emailsubject, $v, $server_str, $currenttime) = (@_);
        my $emailmsg;
        my $emailfh;
        my $status = 0;
+       my $to_addr;
+       my $frequency;
 
-       if (not defined $emailto) {
-               $emailto = $EMAILALERT;
-       }
-       if ($emailto eq "") {
+       $to_addr = defined $v->{emailalert} ? $v->{emailalert} : $EMAILALERT;
+       if ($to_addr eq "") {
                return 0;
        }
 
+       $frequency = defined $v->{emailalertfreq} ? $v->{emailalert} :
+                               $EMAILALERTFREQ;
+       
        use Mail::Send;
 
        &ld_log("emailalert: $emailsubject");
 
-       unless ($emailmsg = new Mail::Send Subject=>$emailsubject, To=>$emailto
+       unless ($emailmsg = new Mail::Send Subject=>$emailsubject, To=>$to_addr
                        and $emailfh = $emailmsg->open
                        and print $emailfh $emailsubject
                        and $emailfh->close) {
@@ -3216,51 +3191,42 @@
                $status = 1;
        }
 
-       &ld_set_email_status($currentserver, $currenttime);
+        if ($currenttime == 0 or $frequency == 0) {
+                delete $EMAILSTATUS{"$server_str"};
+        }
+       else {
+               $EMAILSTATUS{$server_str}->{v} = $v;
+               $EMAILSTATUS{$server_str}->{alerttime} = $currenttime;
+        }
 
        return($status);
 }
 
+
 # ld_emailalert_resend
 # Resend email alerts as neccessary
 # pre: none
 # post: EMAILSTATUS array is updated and alears are sent as neccessary
 # return: none
+
 sub ld_emailalert_resend
 {
-       my $currenttime=time();
-       foreach my $es (@EMAILSTATUS){
-               if ($es->{alerttime} == 0 or
-                   $currenttime - $es->{alerttime} < $es->{emailalertfreq}){
+       my $currenttime = time();
+       my $es;
+       my $server_str;
+       my $frequency;
+
+       foreach $server_str (keys %EMAILSTATUS) {
+               $es = $EMAILSTATUS{$server_str};
+               $frequency = defined $es->{v}->{emailalertfreq} ? 
+                                       $es->{v}->{emailalertfreq} :
+                                       $EMAILALERTFREQ;
+               if ($currenttime - $es->{alerttime} < $frequency) {
                        next;
                }
-               &ld_emailalert("Inaccessible real server: " . $es->{server}, 
-                              $es->{emailalert}, $es->{server}, $currenttime);
-       }
-}
-
-# ld_set_email_status
-# Change the alert time for the real server
-# pre: real server and time setting
-# post: EMAILSTATUS array is updated
-# return: none
-sub ld_set_email_status{
-       my ($currentserver, $emailtime) = (@_);
-       @OLDEMAILSTATUS = @EMAILSTATUS;
-       undef @EMAILSTATUS;
-       foreach my $es (@OLDEMAILSTATUS){
-               my (%emailstats);
-               $emailstats{server}=$es->{server};
-               $emailstats{emailalertfreq}=$es->{emailalertfreq};
-               $emailstats{emailalert}=$es->{emailalert};
-               if ($currentserver eq $emailstats{server}){
-                       $emailstats{alerttime}=$emailtime;
-               }else{
-                       $emailstats{alerttime}=$es->{alerttime};
-               }
-               push(@EMAILSTATUS, \%emailstats);
+               &ld_emailalert("Inaccessible real server: " . $server_str, 
+                              $es->{v}, $server_str, $currenttime);
        }
-       return;
 }
 
 # ld_debug




------------------------------

Message: 2
Date: Tue, 15 Aug 2006 02:37:28 -0600 (MDT)
From: linux-ha-cvs@lists.linux-ha.org
Subject: [Linux-ha-cvs] Linux-HA CVS: ldirectord by horms from 
To: [EMAIL PROTECTED]
Message-ID: <[EMAIL PROTECTED]>

linux-ha CVS committal

Author  : horms
Host    : 
Project : linux-ha
Module  : ldirectord

Dir     : linux-ha/ldirectord


Modified Files:
      Tag: STABLE_1_2
        ldirectord 


Log Message:
Rename ld_emailalert to ld_emailalert_send

Backport of 1.166 (ldirectord.in 1.22)

Signed-Off-By: Simon Horman <[EMAIL PROTECTED]>

===================================================================
RCS file: /home/cvs/linux-ha/linux-ha/ldirectord/Attic/ldirectord,v
retrieving revision 1.77.2.69
retrieving revision 1.77.2.70
diff -u -3 -r1.77.2.69 -r1.77.2.70
--- ldirectord  15 Aug 2006 08:36:21 -0000      1.77.2.69
+++ ldirectord  15 Aug 2006 08:37:27 -0000      1.77.2.70
@@ -1,5 +1,5 @@
 #!/usr/bin/perl
-my($VERSION)=(qw$Id: ldirectord,v 1.77.2.69 2006/08/15 08:36:21 horms Exp 
$)[2];
+my($VERSION)=(qw$Id: ldirectord,v 1.77.2.70 2006/08/15 08:37:27 horms Exp 
$)[2];
 
 ######################################################################
 # ldirectord                 http://www.vergenet.net/linux/ldirectord/
@@ -2745,14 +2745,14 @@
                                        . "$ipvsadm_args $rforw -w 0");
                        &ld_log("Quiescent $log_args (Weight set to 0)");
                }
-               &ld_emailalert("Quiescent $log_args (Weight set to 0)",
-                              $v, $server_str, $currenttime);
+               &ld_emailalert_send("Quiescent $log_args (Weight set to 0)",
+                                   $v, $server_str, $currenttime);
         }
        else {
                 &system_wrapper("$IPVSADM -d $ipvsadm_args");
                &ld_log("Deleted $log_args");
-               &ld_emailalert("Deleted $log_args", $v,
-                              $server_str, $currenttime);
+               &ld_emailalert_send("Deleted $log_args", $v,
+                                   $server_str, $currenttime);
        }
 }
 
@@ -2805,16 +2805,16 @@
                        get_forward_flag($or->{"forward"}) eq $rforw){
                         &system_wrapper("$IPVSADM -e $ipvsadm_args");
                        &ld_log("Restored $log_args (Weight set to $rwght)");
-                       &ld_emailalert("Restored $log_args " .
-                                      "(Weight set to $rwght)",
-                                      $v, $server_str, 0);
+                       &ld_emailalert_send("Restored $log_args " .
+                                           "(Weight set to $rwght)",
+                                           $v, $server_str, 0);
                 }
         }
         else {
                 &system_wrapper("$IPVSADM -a $ipvsadm_args");
                &ld_log("Added $log_args (Weight set to $rwght)");
-               &ld_emailalert("Added $log_args (Weight set to $rwght)",
-                              $v, $server_str, 0);
+               &ld_emailalert_send("Added $log_args (Weight set to $rwght)",
+                                   $v, $server_str, 0);
         }
 }
 
@@ -3155,14 +3155,14 @@
 }
 
 
-# ld_emailalert
+# ld_emailalert_send
 # Send email alerts per virtual server
 # pre: message: Message to email
 # post: message is emailed if emailalert defined for virtualserver 
 # return: 0 on success
 #         1 on error
 
-sub ld_emailalert
+sub ld_emailalert_send
 {
        my ($emailsubject, $v, $server_str, $currenttime) = (@_);
        my $emailmsg;
@@ -3224,7 +3224,7 @@
                if ($currenttime - $es->{alerttime} < $frequency) {
                        next;
                }
-               &ld_emailalert("Inaccessible real server: " . $server_str, 
+               &ld_emailalert_send("Inaccessible real server: " . $server_str, 
                               $es->{v}, $server_str, $currenttime);
        }
 }




------------------------------

_______________________________________________
Linux-ha-cvs mailing list
Linux-ha-cvs@lists.linux-ha.org
http://lists.community.tummy.com/mailman/listinfo/linux-ha-cvs


End of Linux-ha-cvs Digest, Vol 33, Issue 54
********************************************

Reply via email to