2007-05-22 18:12:09 +02:00
|
|
|
#! /usr/bin/perl -w
|
|
|
|
###################################################################
|
|
|
|
# Oreon is developped with GPL Licence 2.0
|
|
|
|
#
|
2007-07-27 12:07:37 +02:00
|
|
|
# GPL License: http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
|
2007-05-22 18:12:09 +02:00
|
|
|
#
|
|
|
|
# Developped by : Julien Mathis - Romain Le Merlus
|
2007-06-27 16:41:38 +02:00
|
|
|
# Christophe Coraboeuf - Sugumaran Mathavarajan
|
2007-05-22 18:12:09 +02:00
|
|
|
#
|
|
|
|
###################################################################
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# For information : contact@merethis.com
|
|
|
|
####################################################################
|
|
|
|
#
|
|
|
|
# Script init
|
|
|
|
#
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use Net::SNMP qw(:snmp);
|
|
|
|
use FindBin;
|
|
|
|
use lib "$FindBin::Bin";
|
2008-04-24 18:13:04 +02:00
|
|
|
use lib "@NAGIOS_PLUGIN@";
|
2007-05-22 18:12:09 +02:00
|
|
|
use utils qw($TIMEOUT %ERRORS &print_revision &support);
|
|
|
|
|
|
|
|
use vars qw($PROGNAME);
|
|
|
|
use Getopt::Long;
|
2007-05-23 14:02:27 +02:00
|
|
|
use vars qw($opt_h $opt_V $opt_H $opt_C $opt_v $opt_o $opt_c $opt_w $opt_t $opt_p $opt_k $opt_u);
|
2007-05-22 18:12:09 +02:00
|
|
|
|
|
|
|
$PROGNAME = $0;
|
|
|
|
sub print_help ();
|
|
|
|
sub print_usage ();
|
|
|
|
|
|
|
|
Getopt::Long::Configure('bundling');
|
|
|
|
GetOptions
|
|
|
|
("h" => \$opt_h, "help" => \$opt_h,
|
2007-05-23 14:02:27 +02:00
|
|
|
"u=s" => \$opt_u, "username=s" => \$opt_u,
|
|
|
|
"p=s" => \$opt_p, "password=s" => \$opt_p,
|
|
|
|
"k=s" => \$opt_k, "key=s" => \$opt_k,
|
2007-05-22 18:12:09 +02:00
|
|
|
"V" => \$opt_V, "version" => \$opt_V,
|
|
|
|
"v=s" => \$opt_v, "snmp=s" => \$opt_v,
|
|
|
|
"C=s" => \$opt_C, "community=s" => \$opt_C,
|
2007-05-23 14:02:27 +02:00
|
|
|
"o=s" => \$opt_o, "oid=s" => \$opt_o,
|
|
|
|
"t=s" => \$opt_t, "type=s" => \$opt_t,
|
2007-05-22 18:12:09 +02:00
|
|
|
"w=s" => \$opt_w, "warning=s" => \$opt_w,
|
|
|
|
"c=s" => \$opt_c, "critical=s" => \$opt_c,
|
|
|
|
"H=s" => \$opt_H, "hostname=s" => \$opt_H);
|
|
|
|
|
|
|
|
if ($opt_V) {
|
|
|
|
print_revision($PROGNAME,'$Revision: 1.0');
|
|
|
|
exit $ERRORS{'OK'};
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($opt_h) {
|
|
|
|
print_help();
|
|
|
|
exit $ERRORS{'OK'};
|
|
|
|
}
|
|
|
|
|
|
|
|
$opt_H = shift unless ($opt_H);
|
|
|
|
(print_usage() && exit $ERRORS{'OK'}) unless ($opt_H);
|
|
|
|
|
|
|
|
my $snmp = "1";
|
|
|
|
if ($opt_v && $opt_v =~ /^[0-9]$/) {
|
2007-05-23 14:02:27 +02:00
|
|
|
$snmp = $opt_v;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($snmp eq "3") {
|
|
|
|
if (!$opt_u) {
|
|
|
|
print "Option -u (--username) is required for snmpV3\n";
|
|
|
|
exit $ERRORS{'OK'};
|
|
|
|
}
|
|
|
|
if (!$opt_p && !$opt_k) {
|
|
|
|
print "Option -k (--key) or -p (--password) is required for snmpV3\n";
|
|
|
|
exit $ERRORS{'OK'};
|
|
|
|
}elsif ($opt_p && $opt_k) {
|
|
|
|
print "Only option -k (--key) or -p (--password) is needed for snmpV3\n";
|
|
|
|
exit $ERRORS{'OK'};
|
|
|
|
}
|
2007-05-22 18:12:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
($opt_C) || ($opt_C = shift) || ($opt_C = "public");
|
|
|
|
|
|
|
|
my $DS_type = "GAUGE";
|
|
|
|
($opt_t) || ($opt_t = shift) || ($opt_t = "GAUGE");
|
|
|
|
$DS_type = $1 if ($opt_t =~ /(GAUGE)/ || $opt_t =~ /(COUNTER)/);
|
|
|
|
|
|
|
|
if (!$opt_c || !$opt_w) {
|
|
|
|
print "You must specify -c and -w options\n";
|
|
|
|
exit $ERRORS{'OK'};
|
|
|
|
}
|
|
|
|
|
|
|
|
($opt_c) || ($opt_c = shift);
|
|
|
|
my $critical = $1 if ($opt_c =~ /([0-9]+)/);
|
|
|
|
|
|
|
|
($opt_w) || ($opt_w = shift);
|
|
|
|
my $warning = $1 if ($opt_w =~ /([0-9]+)/);
|
|
|
|
if ($critical <= $warning){
|
|
|
|
print "(--critical) must be superior to (--warning)";
|
|
|
|
print_usage();
|
|
|
|
exit $ERRORS{'OK'};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$opt_o) {
|
|
|
|
print "Option -o needed.\n";
|
|
|
|
exit $ERRORS{'OK'};
|
|
|
|
}elsif (!($opt_o =~ /^[0-9\.]+$/)) {
|
|
|
|
print "Wrong OID format\n";
|
|
|
|
exit $ERRORS{'OK'};
|
|
|
|
}
|
|
|
|
|
|
|
|
my $name = $0;
|
|
|
|
$name =~ s/\.pl.*//g;
|
|
|
|
my $day = 0;
|
|
|
|
|
|
|
|
#=== create a SNMP session ====
|
|
|
|
|
2007-05-23 14:02:27 +02:00
|
|
|
my ($session, $error);
|
|
|
|
if ($snmp eq "1" || $snmp eq "2") {
|
|
|
|
($session, $error) = Net::SNMP->session(-hostname => $opt_H, -community => $opt_C, -version => $snmp);
|
2007-05-22 18:12:09 +02:00
|
|
|
if (!defined($session)) {
|
2007-05-23 14:02:27 +02:00
|
|
|
print("UNKNOWN: SNMP 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'};
|
|
|
|
}
|
2007-05-22 18:12:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
my $result = $session->get_request(-varbindlist => [$opt_o]);
|
|
|
|
if (!defined($result)) {
|
|
|
|
printf("UNKNOWN: %s.\n", $session->error);
|
|
|
|
$session->close;
|
|
|
|
exit $ERRORS{'UNKNOWN'};
|
|
|
|
}
|
|
|
|
|
|
|
|
my $return_result = $result->{$opt_o};
|
|
|
|
|
|
|
|
#=== Plugin return code ====
|
|
|
|
|
|
|
|
if (defined($return_result)){
|
2007-11-06 16:24:40 +01:00
|
|
|
if ($return_result !~ /^[0-9]+$/) {
|
2007-05-23 14:02:27 +02:00
|
|
|
print "Snmp return value isn't numeric.\n";
|
|
|
|
exit $ERRORS{'OK'};
|
|
|
|
}
|
2007-05-22 18:12:09 +02:00
|
|
|
if ($opt_w && $opt_c && $return_result < $opt_w){
|
|
|
|
print "Ok value : " . $return_result . "|value=".$return_result.";".$opt_w.";".$opt_c.";;\n";
|
|
|
|
exit $ERRORS{'OK'};
|
|
|
|
} elsif ($opt_w && $opt_c && $return_result >= $opt_w && $return_result < $opt_c){
|
|
|
|
print "Warning value : " . $return_result . "|value=$return_result;".$opt_w.";".$opt_c.";;\n";
|
|
|
|
exit $ERRORS{'WARNING'};
|
|
|
|
} elsif ($opt_w && $opt_c && $return_result >= $opt_c){
|
|
|
|
print "Critical value : " . $return_result."|value=".$return_result.";".$opt_w.";".$opt_c.";;\n";
|
|
|
|
exit $ERRORS{'CRITICAL'};
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
print "CRITICAL Host unavailable\n";
|
|
|
|
exit $ERRORS{'CRITICAL'};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sub print_usage () {
|
2007-11-06 16:24:40 +01:00
|
|
|
print "Usage:";
|
2007-05-22 18:12:09 +02:00
|
|
|
print "$PROGNAME\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 " -t (--type) Data Source Type (GAUGE or COUNTER) (GAUGE by default)\n";
|
|
|
|
print " -o (--oid) OID to check\n";
|
2007-06-27 16:20:37 +02:00
|
|
|
print " -k (--key) snmp V3 key\n";
|
|
|
|
print " -p (--password) snmp V3 password\n";
|
|
|
|
print " -u (--username) snmp v3 username \n";
|
2007-05-22 18:12:09 +02:00
|
|
|
print " -w (--warning) Warning level\n";
|
|
|
|
print " -c (--critical) Critical level\n";
|
|
|
|
print " -V (--version) Plugin version\n";
|
|
|
|
print " -h (--help) usage help\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
sub print_help () {
|
2007-07-30 11:07:11 +02:00
|
|
|
print "##############################################\n";
|
|
|
|
print "# Copyright (c) 2004-2007 Centreon #\n";
|
|
|
|
print "# Bugs to http://bugs.oreon-project.org/ #\n";
|
|
|
|
print "##############################################\n";
|
2007-05-22 18:12:09 +02:00
|
|
|
print_usage();
|
|
|
|
print "\n";
|
|
|
|
}
|