Page 2 of 2 FirstFirst 12
Results 11 to 17 of 17

Thread: define Business Rules - if 2 of 3 IP down then warning, if 3/3 down critical

  1. #11
    Junior Member
    Join Date
    Jun 2015
    Posts
    15
    PS: You can have a look at Business rules too. It might do what you want.

  2. #12
    Junior Member
    Join Date
    May 2015
    Posts
    21
    Hello langlais115,

    I just saw your script.
    Thank you for this imense work.
    I will try to use it
    I'll try it on thursday and give you feedback.

    Meanwhile a collegue of mine created a commande line in few lines ... but works OK.
    i will share it with you quickly and you can compare it.

    back very soon

  3. #13
    Junior Member
    Join Date
    May 2015
    Posts
    21
    Hi all,

    this is de command tham my collegue (Linux & DBA expert) has created. Looks simple but works fine.

    define command {
    command_name check_cluster_host
    command_line $PLUGINSDIR$/check_cluster -h -w 0 -c 1 -d $HOSTSTATEIDMVPN1$,$HOSTSTATEIDMVPN2$
    }

    I dont understand why this syntaxe , think he juste copied from another commande ans adapted it, but doesn't matters.
    you can compare it.

    i'll check langlais115 script very soon to see the result.

    One more time, shinken is a great tool but so flexible on configuration poit of view that is difficult to configure it right, cause right can be on many ways, ans without tool experience juste you don't know which way to take.

    nice day

  4. #14
    Junior Member
    Join Date
    May 2015
    Posts
    21
    Now I need some macro to replace DMVPN1 & 2 about 40 times and not to copy this commande 40 times
    cause i have 40 clusters
    but will be OK

  5. #15
    Junior Member
    Join Date
    Jun 2015
    Posts
    15
    Hi Tome,

    I've got an error in my script, it will be always OK in Shinken.
    Here is the version corrected: check_cluster.zip
    Code:
    #!/usr/bin/perl
    ############################
    # Description:
    # ------------
    # This script check multiple IPs and give a Warning or Critical message if more than the threshold number of IPs are down.
    ############################
    
    ############################
    # Revision History:
    # -----------------
    # 26/06/2015 => Gael Langlais   : Creation
    # 30/06/2015 => Gael Langlais   : Fixing exit code
    ############################
    
    
    ########################################################
    #                    SYSTEM REQUIRMENT                 #
    # Copy and past the following if you have some trouble #
    # cpan Net::Ping::External Switch Net::Ping            #
    ########################################################
    
    
    use strict;
    use warnings;
    
    use Switch;
    use Getopt::Std;
    use Net::Ping::External qw(ping);
    
    
    
    # Get command line arguments
    # -H "ARRAY of IP"  : ex: -H "192.168.1.1, 192.168.1.2"
    # -w WARNING        : ex: -w 1
    # -c CRITICAL       : ex: -c 2
    getopts("H:l:L:w:c:");
    our ($opt_H,$opt_w,$opt_c,$opt_L);
    
    
    
    # In normal state this should be set to 0
    # 0 = Debug Off, 1 = Debug Level 1
    my $debug       = 0;
    my @host_array  = "";
    my $fail_count  = 0;
    my $warning     = 1; # set warning default value
    my $critical    = 2; # set critical default value
    my $label       = "$0";
    my $status	= "2"; # Default status is critical
    my @host_down   = "";
    my $p;
    
    my $help ="Syntax: $0 -H [list of IPs to check] -l [LOCAL SOURCE IP] -w [VALUE]-c [VALUE]
    
    Options:
        -H \"ARRAY of IP\"      : ex: -H \"192.168.1.1, 192.168.1.2\"
        -l \"LOCAL SOURCE IP\"  : ex: -l \"192.168.1.100\"
        -L \"LABEL\"            : ex: -L \"VPN Cluster\"
        -w WARNING              : ex: -w 1
        -c CRITICAL             : ex: -c 2
    
    Example:
        $0 -H \"192.168.1.1, 192.168.1.2\" -i \"192.168.1.100\" -w 1 -c 2
     Will return:
        VPN Cluster OK - 2/2 hosts are up | host=2
    ";
    
            ############
            ##  MAIN  ##
            ############
    
            
    die "ERROR: Nothing to check. (option \"-H\")\n\n"                  .$help if ( ! defined $opt_H );
    # Uncomment the line below to make warning and critical threshold mandatory
    #die "ERROR: No threshold specify. (options \"-w and -c\")\n\n"     .$help if ( ! defined $opt_w or ! defined $opt_c );
    die "ERROR: Critical value lower or equal to Warning value. (check your options -w and -c)\n\n" .$help if ( $opt_w >= $opt_c );
    
    $warning    = $opt_w if defined $opt_w;
    $critical   = $opt_c if defined $opt_c;
    $label      = $opt_L if defined $opt_L;
    
    #print "* Using ICMP ping.\n" if ( $debug >= 1 );
    #$p = Net::Ping->new("icmp");
    #print "* Option \"-l\" = $local_add\n" if ( $debug >= 1 );
    #$p->bind($local_add); # We will use this interface for the ping
    
    print "* Hosts to check = $opt_H.\n" if ( $debug >= 1 );
    # Grab the list of hosts and put them in an array
    @host_array     = split /, ?/, $opt_H if defined $opt_H;
    
    
    
    $fail_count = &check_hosts();
    print &return_status();
    exit $status;
    
    
    
    
    
    
    
    
    
    
    #######
    # SUB #
    #######
    
    sub check_hosts
    {
        my $fail_increment = 0;
        my $host;
        foreach $host (@host_array)
        {
            print "Checking host: $host | \$fail_count before: $fail_count => \$fail_count after: " if ( $debug >= 1 );
            if ( ! ping(hostname => $host, timeout => 5) )
            {
                $fail_increment++;
                push @host_down, "$host";
            }
            print "$fail_count after:\n" if ( $debug >= 1 );
            
        }
        return $fail_increment;
    }
    
    
    sub return_status
    {
        my $host_total      = @host_array;
        my $host_ok         = ($host_total - $fail_count);
        my $show_host_down  = "";
        if ($#host_down > 0)
        {
            $show_host_down = join(', ',@host_down);
            $show_host_down =~ s/^..(.*)$/$1/;
            if ($#host_down == 1)
            {
                $show_host_down = "Host down is: ".$show_host_down;
            }else
            {
                $show_host_down = "Hosts down are: ".$show_host_down;
            }
        }
        
        print "* Evaluatings \$fail_count: $fail_count\n" if ( $debug >= 1 );
        if ( $fail_count < $warning)
        {
    	$status = 0;
            return "$label OK - $host_ok/$host_total host are up. $show_host_down| host_up=$host_ok\n";
        }elsif ( $fail_count < $critical)
        {
    	$status = 1;
            return "$label WARNING - $host_ok/$host_total host are up. $show_host_down| host_up=$host_ok\n";
        }elsif ( $fail_count >= $critical)
        {
    	$status = 2;
            return "$label CRITICAL - $host_ok/$host_total host are up. $show_host_down| host_up=$host_ok\n";
        }else{
    	$status = 3;
            return "$label UNKNOW - $host_ok/$host_total host are up. $show_host_down| host_up=$host_ok\n";
        }
    }

  6. #16
    Junior Member
    Join Date
    May 2015
    Posts
    21
    Good evening,

    sorry for the late feedback, the script is working great after my collegue, but for now he uses his own commande line.
    Could not test it by my self because i'm out of sight for a month (as i said before time was running out).
    before i go we used the commande line that i mentioned before.

    for me the subject is closed thank u all specially langlais115

    best regards

  7. #17
    Junior Member
    Join Date
    May 2015
    Posts
    21
    Hello,

    langlais115,
    script tested, work great. Few modifications made i think, but we still use the command line that my collegue made.

    best regards

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •