diff options
Diffstat (limited to 'scripts/keepalived')
-rwxr-xr-x | scripts/keepalived/vyatta-keepalived.pl | 21 | ||||
-rwxr-xr-x | scripts/keepalived/vyatta-show-vrrp.pl | 75 | ||||
-rwxr-xr-x | scripts/keepalived/vyatta-vrrp-state.pl | 9 |
3 files changed, 89 insertions, 16 deletions
diff --git a/scripts/keepalived/vyatta-keepalived.pl b/scripts/keepalived/vyatta-keepalived.pl index 1deeafe8..0f1301db 100755 --- a/scripts/keepalived/vyatta-keepalived.pl +++ b/scripts/keepalived/vyatta-keepalived.pl @@ -81,6 +81,21 @@ sub keepalived_get_values { } } + $config->setLevel("$path vrrp vrrp-group $group run-transition-scripts"); + my $run_backup_script = $config->returnValue("backup"); + if(!defined $run_backup_script){ + $run_backup_script = "null"; + } + my $run_fault_script = $config->returnValue("fault"); + if(!defined $run_fault_script){ + $run_fault_script = "null"; + } + my $run_master_script = $config->returnValue("master"); + if(!defined $run_master_script){ + $run_master_script = "null"; + } + + $output .= "vrrp_instance $vrrp_instance \{\n"; if ($preempt eq "false") { $output .= "\tstate BACKUP\n"; @@ -105,11 +120,11 @@ sub keepalived_get_values { } $output .= "\t\}\n"; $output .= "\tnotify_master "; - $output .= "\"$state_transition_script master $intf $group @vips\" \n"; + $output .= "\"$state_transition_script master $intf $group $run_master_script @vips\" \n"; $output .= "\tnotify_backup "; - $output .= "\"$state_transition_script backup $intf $group @vips\" \n"; + $output .= "\"$state_transition_script backup $intf $group $run_backup_script @vips\" \n"; $output .= "\tnotify_fault "; - $output .= "\"$state_transition_script fault $intf $group @vips\" \n"; + $output .= "\"$state_transition_script fault $intf $group $run_fault_script @vips\" \n"; $output .= "\}\n"; } diff --git a/scripts/keepalived/vyatta-show-vrrp.pl b/scripts/keepalived/vyatta-show-vrrp.pl index eacba25c..86dbef3d 100755 --- a/scripts/keepalived/vyatta-show-vrrp.pl +++ b/scripts/keepalived/vyatta-show-vrrp.pl @@ -64,17 +64,26 @@ sub elapse_time { return $string; } -sub link_updown { - my ($intf) = @_; - - my $status = `sudo /usr/sbin/ethtool $intf | grep Link`; - if ($status =~ m/yes/) { - return "up"; +sub get_state_link { + my $intf = shift; + + my $IFF_UP = 0x1; + my ($state, $link); + my $flags = `cat /sys/class/net/$intf/flags 2> /dev/null`; + my $carrier = `cat /sys/class/net/$intf/carrier 2> /dev/null`; + chomp $flags; chomp $carrier; + my $hex_flags = hex($flags); + if ($hex_flags & $IFF_UP) { + $state = "up"; + } else { + $state = "admin down"; } - if ($status =~ m/no/) { - return "down"; + if ($carrier eq "1") { + $link = "up"; + } else { + $link = "down"; } - return "unknown"; + return ($state, $link); } sub get_master_info { @@ -102,13 +111,33 @@ sub get_master_info { } } +sub vrrp_showsummary { + my ($file) = @_; + + my ($start_time, $intf, $group, $state, $ltime) = + VyattaKeepalived::vrrp_state_parse($file); + my ($interface_state, $link) = get_state_link($intf); + if ($state eq "master" || $state eq "backup" || $state eq "fault") { + my ($primary_addr, $priority, $preempt, $advert_int, $auth_type, + @vips) = VyattaKeepalived::vrrp_get_config($intf, $group); + print "\n$intf\t\t$group\tint\t$primary_addr\t$link\t\t$state"; + foreach my $vip (@vips){ + print "\n\t\t\tvip\t$vip"; + + } + } else { + print "Physical interface $intf, State: unknown\n"; + } +} + + sub vrrp_show { my ($file) = @_; my $now_time = time; my ($start_time, $intf, $group, $state, $ltime) = VyattaKeepalived::vrrp_state_parse($file); - my $link = link_updown($intf); + my ($interface_state, $link) = get_state_link($intf); if ($state eq "master" || $state eq "backup" || $state eq "fault") { my ($primary_addr, $priority, $preempt, $advert_int, $auth_type, @vips) = VyattaKeepalived::vrrp_get_config($intf, $group); @@ -146,9 +175,18 @@ sub vrrp_show { # my $intf = "eth"; my $group = "all"; +my $showsummary = 0; + if ($#ARGV >= 0) { - $intf = $ARGV[0]; + + if ($ARGV[0] eq "summary") { + $showsummary = 1; + } else { + $intf = $ARGV[0]; + } + } + if ($#ARGV == 1) { $group = $ARGV[1]; } @@ -158,9 +196,22 @@ if (!VyattaKeepalived::is_running()) { exit 1; } +if ($showsummary == 1) { + + print "\t\tVRRP\tAddr\t\t\tInterface\tVRRP\n"; + print "Interface\tGroup\tType\tAddress\t\tState\t\tState\n"; + print "---------\t-----\t----\t-------\t\t-----\t\t-----"; + + +} + my @state_files = VyattaKeepalived::get_state_files($intf, $group); foreach my $state_file (@state_files) { - vrrp_show($state_file); + if ($showsummary == 1) { + vrrp_showsummary($state_file); + } else { + vrrp_show($state_file); + } } exit 0; diff --git a/scripts/keepalived/vyatta-vrrp-state.pl b/scripts/keepalived/vyatta-vrrp-state.pl index 8b813529..9e11b649 100755 --- a/scripts/keepalived/vyatta-vrrp-state.pl +++ b/scripts/keepalived/vyatta-vrrp-state.pl @@ -55,7 +55,8 @@ sub vrrp_state_log { my $vrrp_state = $ARGV[0]; my $vrrp_intf = $ARGV[1]; my $vrrp_group = $ARGV[2]; -my $vrrp_vip = $ARGV[3]; +my $vrrp_transitionscript = $ARGV[3]; +my $vrrp_vip = $ARGV[4]; my $sfile = VyattaKeepalived::get_state_file($vrrp_intf, $vrrp_group); my ($old_time, $old_intf, $old_group, $old_state, $old_ltime) = @@ -77,6 +78,12 @@ if ($vrrp_state eq "backup") { system("rm -f $mfile"); } + +if (!($vrrp_transitionscript eq "null")){ + exec("$vrrp_transitionscript"); +} + + exit 0; # end of file |