Fix #2654
This commit is contained in:
parent
0477dd2ff3
commit
1351acbbee
|
@ -190,7 +190,7 @@ if( $rta == -1 ) {
|
|||
} elsif ( ($pl >= $pl_critical) || ($rta >= $rta_critical) ) {
|
||||
$ping_result_array[@ping_result_array -1 ] =~ s/\%/percent/g;
|
||||
my @tab = split(/,/,$ping_result_array[@ping_result_array -1 ]);
|
||||
print "PING CRITICAL - ". $tab[0] ."|time=".$time_answer."ms;$rta_warning;$rta_critical;0; ok=0\n";
|
||||
print "PING CRITICAL - ". $tab[0] ."|time=".$time_answer."ms;$rta_warning;$rta_critical;0; ok=1\n";
|
||||
exit $ERRORS{'CRITICAL'};
|
||||
} elsif ( ($pl >= $pl_warning) || ($rta >= $rta_warning) ) {
|
||||
$ping_result_array[@ping_result_array -1 ] =~ s/\%/percent/g;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#! /usr/bin/perl -w
|
||||
################################################################################
|
||||
# Copyright 2004-2011 MERETHIS
|
||||
# Copyright 2004-2013 MERETHIS
|
||||
# Centreon is developped by : Julien Mathis and Romain Le Merlus under
|
||||
# GPL Licence 2.0.
|
||||
#
|
||||
|
@ -40,25 +40,15 @@
|
|||
#
|
||||
|
||||
use strict;
|
||||
use Net::SNMP qw(:snmp);
|
||||
use FindBin;
|
||||
use lib "$FindBin::Bin";
|
||||
use lib "@NAGIOS_PLUGINS@";
|
||||
use utils qw($TIMEOUT %ERRORS &print_revision &support);
|
||||
|
||||
if (eval "require centreon" ) {
|
||||
use centreon qw(get_parameters);
|
||||
use vars qw($VERSION %centreon);
|
||||
%centreon = get_parameters();
|
||||
} else {
|
||||
print "Unable to load centreon perl module\n";
|
||||
exit $ERRORS{'UNKNOWN'};
|
||||
}
|
||||
require "@NAGIOS_PLUGINS@/Centreon/SNMP/Utils.pm";
|
||||
|
||||
use vars qw($PROGNAME);
|
||||
use Getopt::Long;
|
||||
use vars qw($opt_V $opt_h $opt_v $opt_C $opt_H $opt_c $opt_w $opt_D $snmp $opt_k $opt_u $opt_p @critical @warning $opt_l);
|
||||
use vars qw($opt_V $opt_h $opt_c $opt_w $opt_D $snmp @critical @warning $opt_l);
|
||||
|
||||
my %ERRORS = ('OK' => 0, 'WARNING' => 1, 'CRITICAL' => 2, 'UNKNOWN' => 3);
|
||||
|
||||
my %centreon = Centreon::SNMP::Utils::load_oids($ERRORS{'UNKNOWN'}, "@NAGIOS_PLUGINS@/centreon.conf");
|
||||
# Plugin var init
|
||||
|
||||
my($return_code);
|
||||
|
@ -67,18 +57,35 @@ $PROGNAME = "$0";
|
|||
sub print_help ();
|
||||
sub print_usage ();
|
||||
|
||||
my %OPTION = (
|
||||
"host" => undef,
|
||||
"snmp-community" => "public", "snmp-version" => 1, "snmp-port" => 161,
|
||||
"snmp-auth-key" => undef, "snmp-auth-user" => undef, "snmp-auth-password" => undef, "snmp-auth-protocol" => "MD5",
|
||||
"snmp-priv-key" => undef, "snmp-priv-password" => undef, "snmp-priv-protocol" => "DES",
|
||||
"maxrepetitions" => undef,
|
||||
"64-bits" => undef,
|
||||
);
|
||||
|
||||
Getopt::Long::Configure('bundling');
|
||||
GetOptions
|
||||
("h" => \$opt_h, "help" => \$opt_h,
|
||||
"u=s" => \$opt_u, "username=s" => \$opt_u,
|
||||
"p=s" => \$opt_p, "password=s" => \$opt_p,
|
||||
"k=s" => \$opt_k, "key=s" => \$opt_k,
|
||||
(
|
||||
"H|hostname|host=s" => \$OPTION{'host'},
|
||||
"C|community=s" => \$OPTION{'snmp-community'},
|
||||
"v|snmp|snmp-version=s" => \$OPTION{'snmp-version'},
|
||||
"P|snmpport|snmp-port=i" => \$OPTION{'snmp-port'},
|
||||
"u|username=s" => \$OPTION{'snmp-auth-user'},
|
||||
"p|authpassword|password=s" => \$OPTION{'snmp-auth-password'},
|
||||
"k|authkey=s" => \$OPTION{'snmp-auth-key'},
|
||||
"authprotocol=s" => \$OPTION{'snmp-auth-protocol'},
|
||||
"privpassword=s" => \$OPTION{'snmp-priv-password'},
|
||||
"privkey=s" => \$OPTION{'snmp-priv-key'},
|
||||
"privprotocol=s" => \$OPTION{'snmp-priv-protocol'},
|
||||
"maxrepetitions=s" => \$OPTION{'maxrepetitions'},
|
||||
"64-bits" => \$OPTION{'64-bits'},
|
||||
"h" => \$opt_h, "help" => \$opt_h,
|
||||
"V" => \$opt_V, "version" => \$opt_V,
|
||||
"v=s" => \$opt_v, "snmp=s" => \$opt_v,
|
||||
"C=s" => \$opt_C, "community=s" => \$opt_C,
|
||||
"w=s" => \$opt_w, "warning=s" => \$opt_w,
|
||||
"c=s" => \$opt_c, "critical=s" => \$opt_c,
|
||||
"H=s" => \$opt_H, "hostname=s" => \$opt_H,
|
||||
"l" => \$opt_l);
|
||||
|
||||
if ($opt_V) {
|
||||
|
@ -91,71 +98,24 @@ if ($opt_h) {
|
|||
exit $ERRORS{'OK'};
|
||||
}
|
||||
|
||||
if (!$opt_H) {
|
||||
print_usage();
|
||||
exit $ERRORS{'OK'};
|
||||
}
|
||||
|
||||
$opt_l = 0 if (!defined($opt_l));
|
||||
|
||||
($opt_v) || ($opt_v = shift) || ($opt_v = "2");
|
||||
my $snmp = $1 if ($opt_v =~ /(\d)/);
|
||||
|
||||
$opt_c = 95 if (!defined($opt_c) || !$opt_c);
|
||||
$opt_w = 90 if (!defined($opt_w) || !$opt_w);
|
||||
|
||||
if ($snmp eq "3") {
|
||||
if (!$opt_u) {
|
||||
print "Option -u (--username) is required for snmpV3\n";
|
||||
exit $ERRORS{'UNKNOWN'};
|
||||
}
|
||||
if (!$opt_p && !$opt_k) {
|
||||
print "Option -k (--key) or -p (--password) is required for snmpV3\n";
|
||||
exit $ERRORS{'UNKNOWN'};
|
||||
} elsif ($opt_p && $opt_k) {
|
||||
print "Only option -k (--key) or -p (--password) is needed for snmpV3\n";
|
||||
exit $ERRORS{'UNKNOWN'};
|
||||
}
|
||||
}
|
||||
|
||||
$opt_C = "public" if (!$opt_C);
|
||||
|
||||
my $name = $0;
|
||||
$name =~ s/\.pl.*//g;
|
||||
|
||||
# Plugin snmp requests
|
||||
|
||||
my ($session, $error);
|
||||
if ($snmp eq "1" || $snmp eq "2") {
|
||||
($session, $error) = Net::SNMP->session(-hostname => $opt_H, -community => $opt_C, -version => $snmp);
|
||||
$session->max_msg_size(50000);
|
||||
if (!defined($session)) {
|
||||
print("UNKNOWN: SNMP 1 or 2 Session : $error\n");
|
||||
exit $ERRORS{'UNKNOWN'};
|
||||
}
|
||||
} elsif ($opt_k) {
|
||||
($session, $error) = Net::SNMP->session(-hostname => $opt_H, -version => $snmp, -username => $opt_u, -authkey => $opt_k);
|
||||
if (!defined($session)) {
|
||||
print("UNKNOWN: SNMP Session : $error\n");
|
||||
exit $ERRORS{'UNKNOWN'};
|
||||
}
|
||||
} elsif ($opt_p) {
|
||||
($session, $error) = Net::SNMP->session(-hostname => $opt_H, -version => $snmp, -username => $opt_u, -authpassword => $opt_p);
|
||||
if (!defined($session)) {
|
||||
print("UNKNOWN: SNMP Session : $error\n");
|
||||
exit $ERRORS{'UNKNOWN'};
|
||||
}
|
||||
}
|
||||
my ($session_params) = Centreon::SNMP::Utils::check_snmp_options($ERRORS{'UNKNOWN'}, \%OPTION);
|
||||
my $session = Centreon::SNMP::Utils::connection($ERRORS{'UNKNOWN'}, $session_params);
|
||||
|
||||
sub get_netsnmp_version ($){
|
||||
my $sess = $_[0];
|
||||
my $OID_VERSION = "1.3.6.1.2.1.25.6.3.1.2";
|
||||
my $result = $sess->get_table(Baseoid => $OID_VERSION);
|
||||
if (!defined($result)) {
|
||||
printf("ERROR when getting SNMP version : %s.\n", $session->error);
|
||||
$session->close;
|
||||
exit $ERRORS{'UNKNOWN'};
|
||||
}
|
||||
|
||||
my $result = Centreon::SNMP::Utils::get_snmp_table($OID_VERSION, $session, $ERRORS{'UNKNOWN'}, \%OPTION, " Error getting SNMP version.");
|
||||
while ( my ($key, $value) = each(%$result) ) {
|
||||
if ($value =~ m/net-snmp-5.3.*/) {
|
||||
return "NetSNMP-5.3"
|
||||
|
@ -172,14 +132,8 @@ if ( "$snmpver" eq "NetSNMP-5.3" ) {
|
|||
$OID_CPU = ".1.3.6.1.2.1.25.3.3.1.2";
|
||||
}
|
||||
|
||||
|
||||
# Get all datas
|
||||
my $result = $session->get_table(Baseoid => $OID_CPU);
|
||||
if (!defined($result)) {
|
||||
printf("ERROR when getting CPU percentage use values : ProcessorLoad Table : %s.\n", $session->error);
|
||||
$session->close;
|
||||
exit $ERRORS{'UNKNOWN'};
|
||||
}
|
||||
my $result = Centreon::SNMP::Utils::get_snmp_table($OID_CPU, $session, $ERRORS{'UNKNOWN'}, \%OPTION, " Error getting CPU percentage.");
|
||||
|
||||
# Get all values and computes average cpu.
|
||||
my $cpu = 0;
|
||||
|
@ -213,7 +167,6 @@ if ($opt_l == 0) {
|
|||
|
||||
# Display Ouptut
|
||||
print $str."\n";
|
||||
undef($str);
|
||||
exit $ERRORS{$status};
|
||||
|
||||
sub print_usage () {
|
||||
|
@ -221,23 +174,32 @@ sub print_usage () {
|
|||
print "$PROGNAME\n";
|
||||
print "This Plugin is design for return CPU percent on windows Serveurs (1 min Average)\n";
|
||||
print "\n";
|
||||
print " -H (--hostname) Hostname to query - (required)\n";
|
||||
print " -C (--community) SNMP read community (defaults to public,\n";
|
||||
print " -H (--hostname) Hostname to query (required)\n";
|
||||
print " -C (--community) SNMP read community (defaults to public)\n";
|
||||
print " used with SNMP v1 and v2c\n";
|
||||
print " -v (--snmp-version) 1 for SNMP v1 (default)\n";
|
||||
print " 2 for SNMP v2c\n";
|
||||
print " 3 for SNMP v3\n";
|
||||
print " -P (--snmp-port) SNMP port (default: 161)\n";
|
||||
print " -k (--key) snmp V3 key\n";
|
||||
print " -u (--username) snmp V3 username \n";
|
||||
print " -p (--password) snmp V3 password\n";
|
||||
print " --authprotocol protocol MD5/SHA1 (v3)\n";
|
||||
print " --privprotocol encryption system (DES/AES)(v3) \n";
|
||||
print " --privpassword passphrase (v3) \n";
|
||||
print " --64-bits Use 64 bits OID\n";
|
||||
print " --maxrepetitions To use when you have the error: 'Message size exceeded buffer maxMsgSize'\n";
|
||||
print " Work only with SNMP v2c and v3 (Example: --maxrepetitions=1)\n";
|
||||
print " -c (--critical) Three critical tresholds (defaults : 95)\n";
|
||||
print " -w (--warning) Three warning tresholds (defaults : 90)\n";
|
||||
print " -l Display only cpu average\n";
|
||||
print " -v (--snmp_version) 1 for SNMP v1 (default)\n";
|
||||
print " 2 for SNMP v2c\n";
|
||||
print " -k (--key) snmp V3 key\n";
|
||||
print " -p (--password) snmp V3 password\n";
|
||||
print " -u (--username) snmp v3 username \n";
|
||||
print " -V (--version) Plugin version\n";
|
||||
print " -h (--help) usage help\n";
|
||||
}
|
||||
|
||||
sub print_help () {
|
||||
print "##############################################\n";
|
||||
print "# Copyright (c) 2004-2011 Centreon #\n";
|
||||
print "# Copyright (c) 2004-2013 Centreon #\n";
|
||||
print "# Bugs to http://forge.centreon.com/ #\n";
|
||||
print "##############################################\n";
|
||||
print_usage();
|
||||
|
|
|
@ -52,7 +52,7 @@ my %ERRORS = ('OK' => 0, 'WARNING' => 1, 'CRITICAL' => 2, 'UNKNOWN' => 3);
|
|||
my %centreon = Centreon::SNMP::Utils::load_oids($ERRORS{'UNKNOWN'}, "@NAGIOS_PLUGINS@/centreon.conf");
|
||||
|
||||
# Plugin var init
|
||||
my ($session, $error);
|
||||
my $session;
|
||||
my ($row, $last_check_time, $last_in_bits, $last_out_bits, @last_values, $update_time, $in_traffic, $out_traffic, $in_usage, $out_usage);
|
||||
|
||||
$PROGNAME = "$0";
|
||||
|
|
Loading…
Reference in New Issue