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) 3. Linux-HA CVS: ldirectord by horms from (linux-ha-cvs@lists.linux-ha.org) 4. Linux-HA CVS: ldirectord by horms from (linux-ha-cvs@lists.linux-ha.org) ---------------------------------------------------------------------- Message: 1 Date: Tue, 15 Aug 2006 01:04:45 -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: ldirectord.cf Log Message: Add emailalert and emailalertfreq to ldirectord.cf Signed-Off-By: Simon Horman <[EMAIL PROTECTED]> =================================================================== RCS file: /home/cvs/linux-ha/linux-ha/ldirectord/ldirectord.cf,v retrieving revision 1.33 retrieving revision 1.34 diff -u -3 -r1.33 -r1.34 --- ldirectord.cf 15 Aug 2006 03:41:33 -0000 1.33 +++ ldirectord.cf 15 Aug 2006 07:04:44 -0000 1.34 @@ -15,6 +15,8 @@ autoreload=yes #logfile="/var/log/ldirectord.log" #logfile="local0" +#emailalert="[EMAIL PROTECTED]" +#emailalertfreq=3600 quiescent=yes # Sample for an http virtual service ------------------------------ Message: 2 Date: Tue, 15 Aug 2006 01:05: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: ldirectord.in Log Message: Add emailalert and emailalertfreq to ldirectord.cf Signed-Off-By: Simon Horman <[EMAIL PROTECTED]> =================================================================== RCS file: /home/cvs/linux-ha/linux-ha/ldirectord/ldirectord.in,v retrieving revision 1.18 retrieving revision 1.19 diff -u -3 -r1.18 -r1.19 --- ldirectord.in 15 Aug 2006 07:03:58 -0000 1.18 +++ ldirectord.in 15 Aug 2006 07:05:27 -0000 1.19 @@ -1,5 +1,5 @@ #!/usr/bin/perl -my($VERSION)=(qw$Id: ldirectord.in,v 1.18 2006/08/15 07:03:58 horms Exp $)[2]; +my($VERSION)=(qw$Id: ldirectord.in,v 1.19 2006/08/15 07:05:27 horms Exp $)[2]; ###################################################################### # ldirectord http://www.vergenet.net/linux/ldirectord/ @@ -3197,6 +3197,8 @@ use Mail::Send; + &ld_log("emailalert: $emailsubject"); + unless ($emailmsg = new Mail::Send Subject=>$emailsubject, To=>$emailto and $emailfh = $emailmsg->open and print $emailfh $emailsubject ------------------------------ Message: 3 Date: Tue, 15 Aug 2006 01:06:40 -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: ldirectord.in Log Message: Add new calls to purge services and virtuals Previously this code was just done inline, and although this is a bit more verbose, it seems a bit more cleaner, and should allow things like emailalerts fit in with start-stop a bit better. Signed-Off-By: Simon Horman <[EMAIL PROTECTED]> =================================================================== RCS file: /home/cvs/linux-ha/linux-ha/ldirectord/ldirectord.in,v retrieving revision 1.19 retrieving revision 1.20 diff -u -3 -r1.19 -r1.20 --- ldirectord.in 15 Aug 2006 07:05:27 -0000 1.19 +++ ldirectord.in 15 Aug 2006 07:06:39 -0000 1.20 @@ -1,5 +1,5 @@ #!/usr/bin/perl -my($VERSION)=(qw$Id: ldirectord.in,v 1.19 2006/08/15 07:05:27 horms Exp $)[2]; +my($VERSION)=(qw$Id: ldirectord.in,v 1.20 2006/08/15 07:06:39 horms Exp $)[2]; ###################################################################### # ldirectord http://www.vergenet.net/linux/ldirectord/ @@ -1839,11 +1839,7 @@ # remove remaining entries for real servers for my $k (keys %$or) { - &system_wrapper("$IPVSADM -d " . $nv->{proto} . - &get_virtual($nv) . " -r $k"); - &ld_log("Removed real server (start): $k (" . - #scalar(%{$nv->{real_status}}) . - " x " . &get_virtual($nv) . ")\n"); + purge_untracked_service($nv, $k, "start"); delete($$or{$k}); } @@ -1864,11 +1860,7 @@ $nv->{protocol}})) { next; } - # service still exists, remove it - &system_wrapper("$IPVSADM -D " . $nv->{proto} . " " . - &get_virtual($nv)); - &ld_log("Removed virtual server (start): " . - &get_virtual($nv) . "\n"); + purge_virtual($nv, "start"); } } @@ -1890,16 +1882,10 @@ my $real = $$v{real}; foreach my $r (@$real) { if (defined $$r{virtual_status}) { - &system_wrapper("$IPVSADM -d $$v{proto} " . &get_virtual($v) . " -r $$r{server}:$$r{port}"); - _status_down($v, $r); - &ld_log("Removed real server (stop): " . - "$$r{server}:$$r{port} (" . - #scalar(%{$v->{real_status}}) . - " x " . &get_virtual($v) . ")" ); + purge_service($v, $r, "stop"); } } - &system_wrapper("$IPVSADM -D $$v{proto} " . &get_virtual($v)); - &ld_log("Removed virtual server (stop): " . &get_virtual($v)); + purge_virtual($v, "stop"); } } @@ -3076,6 +3062,38 @@ } +# Used during stop, start and reload to remove stale real servers from LVS +sub purge_untracked_service +{ + my ($v, $rservice, $tag) = (@_); + + &system_wrapper("$IPVSADM -d $v->{proto} " . &get_virtual($v) . + " -r $rservice"); + &ld_log("Purged real server ($tag): " . + "$rservice (" . &get_virtual($v) . ")"); +} + + +# Used during stop, start and reload to remove stale real servers from LVS +sub purge_service +{ + my ($v, $r, $tag) = (@_); + + purge_untracked_service($v, "$r->{server}:$r->{port}", $tag); + _status_down($v, $r); +} + + +# Used during stop, start and reload to remove stale virtual services from LVS +sub purge_virtual +{ + my ($v, $tag) = (@_); + + &system_wrapper("$IPVSADM -D $v->{proto} " . &get_virtual($v)); + &ld_log("Purged virtual server ($tag): " . &get_virtual($v)); +} + + sub check_cfgfile { my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, ------------------------------ Message: 4 Date: Tue, 15 Aug 2006 01:08:26 -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: ldirectord.in 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. Signed-Off-By: Simon Horman <[EMAIL PROTECTED]> =================================================================== RCS file: /home/cvs/linux-ha/linux-ha/ldirectord/ldirectord.in,v retrieving revision 1.20 retrieving revision 1.21 diff -u -3 -r1.20 -r1.21 --- ldirectord.in 15 Aug 2006 07:06:39 -0000 1.20 +++ ldirectord.in 15 Aug 2006 07:08:25 -0000 1.21 @@ -1,5 +1,5 @@ #!/usr/bin/perl -my($VERSION)=(qw$Id: ldirectord.in,v 1.20 2006/08/15 07:06:39 horms Exp $)[2]; +my($VERSION)=(qw$Id: ldirectord.in,v 1.21 2006/08/15 07:08:25 horms Exp $)[2]; ###################################################################### # ldirectord http://www.vergenet.net/linux/ldirectord/ @@ -515,8 +515,7 @@ @REAL @VIRTUAL $HOSTNAME - @EMAILSTATUS - @OLDEMAILSTATUS + %EMAILSTATUS $CRLF ); @@ -1774,8 +1773,6 @@ my $nr; my $server_down = {}; - undef @EMAILSTATUS; - # read status of current ipvsadm -L -n $oldsrv=&ld_read_ipvsadm(); @@ -1808,21 +1805,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]; @@ -2759,7 +2741,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)) { @@ -2773,17 +2755,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 @@ -2827,7 +2808,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){ @@ -2835,14 +2816,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); } } @@ -2973,17 +2954,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; } @@ -3193,31 +3163,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) { @@ -3225,51 +3200,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 ------------------------------ _______________________________________________ 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 38 ********************************************