#!/usr/bin/perl
#
# Usa la libreria Net::SSH de http://www.stupidfool.org/perl/net-ssh/
#
# Uso: /usr/local/sbin//usr/local/sbin/check_cisco_ping_ssh <host> <port> <user> <pass> <ip> <warn> <crit>
#
#
use strict;

use Net::SSH::Perl;

$ENV{'HOME'} = '/var/lib/nagios';
 
my $router=$ARGV[0];
my $puerto=$ARGV[1];

my $usuariort=$ARGV[2]; 
my $clave=$ARGV[3]; 

my $ip=$ARGV[4]; 

my $warn=$ARGV[5]; 
my $crit=$ARGV[6]; 



my $sesion_ssh = Net::SSH::Perl->new($router, protocol=>1, cipher=>'DES', port=>$puerto, debug=> 'false'); 
$sesion_ssh->login($usuariort, $clave);

my $comando="ping $ip";

my($salida, $salida_error, $valor_exit) = $sesion_ssh->cmd($comando);

$salida =~ /Success rate is (\d*) (.*)/;

my $rate=$1;

if ( $rate <= $crit ) {
        print "PROBLEMA: Rate=$rate%\n";
        exit 2;
}

if ( $rate <= $warn ) {
        print "WARNING: Rate=$rate%\n";
        exit 1;
}

if ( $rate <= 100 ) {
        print "OK: Rate=$rate%\n"; 
        exit 0;
}

exit 3;