Re: howto virtual/real server monitoring

olivier chirossel <[email protected]>
Newsgroups gmane.linux.keepalived.devel
Message-ID <CAK8LaAbb1bM6zrKFj4_vdhDrk2UGKqE+c3kVgPzBLa3dk7xT_Q@mail.gmail.com>
Hi

i use the script attach for checks the status of a vip. This script is run
by nagios-nrpe-server
with conf :

command[check_load_balancing_arg]=/usr/lib/nagios/plugins/
check_keepalived_arg.pl /etc/keepalived/keepalived.conf "$ARG1$:$ARG2$"
$ARG3$
command[check_load_balancing_ipv6_arg]=/usr/lib/nagios/plugins/
check_keepalived_arg.pl /etc/keepalived/keepalived.conf "[$ARG1$]:$ARG2$"
$ARG3$

The first arg is the ip, the second the port the third the protocol ("udp"
or "tcp" )

The principe is to compare the output of ipvsadm command with the
keepalived configuration

the user use for run the script should run ipvsadm through sudo without
password.
for exemple :
nagios          ALL = (root) NOPASSWD:  /sbin/ipvsadm


Hope, this can help

Regards,


Olivier




On Mon, Jan 19, 2015 at 8:57 PM, Tom van Leeuwen <
[email protected]> wrote:

> Hi list!
>
> I'm being spammed by keepalived when real servers stop working due to
> reboot or application restart and I was wondering if there are any tools
> around to manage this.
> It would be great if you could simply check the state of the virtual
> servers by checking how many backends are up and down.
>
> A thing that comes to mind is tailing the logfile to see what's
> happening...
> It would also be great if keepalived would have some "state" file that
> could be read to check the status of all virtual servers preferably in
> json format :-)
>
> Anyway... I'm wondering how you guys handle the monitoring of keepalived
> virtual/real servers.
>
> Kind regards,
> Tom van Leeuwen
>
>
> ------------------------------------------------------------------------------
> New Year. New Location. New Benefits. New Data Center in Ashburn, VA.
> GigeNET is offering a free month of service with a new server in Ashburn.
> Choose from 2 high performing configs, both with 100TB of bandwidth.
> Higher redundancy.Lower latency.Increased capacity.Completely compliant.
> http://p.sf.net/sfu/gigenet
> _______________________________________________
> Keepalived-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/keepalived-devel
>

------------------------------------------------------------------------------
New Year. New Location. New Benefits. New Data Center in Ashburn, VA.
GigeNET is offering a free month of service with a new server in Ashburn.
Choose from 2 high performing configs, both with 100TB of bandwidth.
Higher redundancy.Lower latency.Increased capacity.Completely compliant.
http://p.sf.net/sfu/gigenet

_______________________________________________
Keepalived-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/keepalived-devel
check_keepalived_arg.pl (application/octet-stream, 2.2 KB)
#!/usr/bin/perl -w
# $Id: check_keepalived_arg.pl,v 1.1 2014/01/20 15:02:41 cvs Exp $


use strict;

my $status = 0;
my $output = 0;
my $compteur = 0;
my @result;
my @retgrep;
my $tab;
my $type = "";
my $vip = "";
my $vip_check_ipvsadm = "";
my $keepalived_conf;
my @list;
my $liste_reel_down;
my $vip_ip;
my $vip_port;
my $compteur_reel_down;
my $ind_ipv6 = 0;


if (scalar(@ARGV) != 3) {
   $status = 2;
   $output = "KO - usage \"fichier_keepalived\" \"vip\" \"type\"\n";
   Error();
}
$type = $ARGV[2];
$vip = $ARGV[1];
$vip_check_ipvsadm = $vip;
$keepalived_conf = $ARGV[0];
my $encours = 0;
if (!($vip =~ /^([^\s]*):(\d*)$/)) {
   $status = 2;
   $output = "KO - format vip (argument 1)  $vip invalide\n";
   Error();
}
$vip_ip = $1;
$vip_port = $2;
if ($vip_ip =~ /^\[(.*)\]$/) {
  $ind_ipv6 = 1;
  $vip_ip = $1;
  $vip_check_ipvsadm = "\Q$vip\E";
}
if (!(open(KEEPALIVED,$keepalived_conf))) {
   $status = 2;
   $output = "ouverture conf keepalived $keepalived_conf impossible\n";
   Error();
} 
while (<KEEPALIVED>) {
  if ($encours == 1) {
      if ($_ =~ /virtual_server/) {
         $encours = 0;
      }
      if ($_ =~ /real_server\s*([^\s]*)\s*(\d*)/) {
          if ($ind_ipv6 == 1) {
            push(@list,"[$1]:$2");
          }
          else {
            push(@list,"$1:$2");
          }
      }
  }
  if ($_ =~ /virtual_server\s*$vip_ip\s*$vip_port/) {
         $encours = 1;
  }

}
close(KEEPALIVED);

if ($type eq "udp") { 
  @result = `sudo /sbin/ipvsadm -Ln -u $vip`;
}
elsif  ($type eq "tcp") {
  @result = `sudo ipvsadm -Ln -t $vip`;
}
else {
  $status = 2;
  $output = "KO - type non supporte $type";
  Error();
}


@retgrep = grep(/$vip_check_ipvsadm/,@result);
if (scalar(@retgrep) < 1) {
  $status = 2;
  $output = "KO - virtuelle absente";
  Error();
}

foreach $tab (@list) {
    @retgrep = grep(/\Q$tab\E/,@result);
    if (scalar(@retgrep) < 1) {
      $status = 2;
      $liste_reel_down .= "$tab ";
      $compteur_reel_down += 1;
    }
    $compteur += 1;
}

if ($status != 0) {
  $output =  "KO - " . $compteur_reel_down . " serveur reel down sur " . (scalar(@list)) .  " $liste_reel_down";
  Error();
}
else {
  $status = 0;
  $output = "OK";
  print "$output";
}


sub Error {
  print "$output";
  exit $status;
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.