git-svn-id: http://svn.centreon.com/Plugins/Dev@2205 6bcd3966-0018-0410-8128-fd23d134de7e
This commit is contained in:
parent
c872f28a51
commit
0bfce160f5
|
@ -1,134 +0,0 @@
|
|||
#! /usr/bin/perl -w
|
||||
# $Id: check_graph_tcp.pl,v 1.2 2005/08/01 17:50:50 gollum123 Exp $
|
||||
#
|
||||
# Oreon's plugins are developped with GPL Licence :
|
||||
# http://www.fsf.org/licenses/gpl.txt
|
||||
# Developped by : Julien Mathis - Romain Le Merlus
|
||||
#
|
||||
# Modified for Oreon Project by : Mathieu Chateau - Christophe Coraboeuf
|
||||
# Modified By Julien Mathis For Merethis Company
|
||||
#
|
||||
# The Software is provided to you AS IS and WITH ALL FAULTS.
|
||||
# OREON makes no representation and gives no warranty whatsoever,
|
||||
# whether express or implied, and without limitation, with regard to the quality,
|
||||
# safety, contents, performance, merchantability, non-infringement or suitability for
|
||||
# any particular or intended purpose of the Software found on the OREON web site.
|
||||
# In no event will OREON be liable for any direct, indirect, punitive, special,
|
||||
# incidental or consequential damages however they may arise and even if OREON has
|
||||
# been previously advised of the possibility of such damages.
|
||||
|
||||
use strict;
|
||||
use FindBin;
|
||||
use lib "$FindBin::Bin";
|
||||
use lib "@NAGIOS_PLUGINS@";
|
||||
use utils qw($TIMEOUT %ERRORS &print_revision &support);
|
||||
|
||||
if (eval "require oreon" ) {
|
||||
use oreon qw(get_parameters create_rrd update_rrd &is_valid_serviceid);
|
||||
use vars qw($VERSION %oreon);
|
||||
%oreon=get_parameters();
|
||||
} else {
|
||||
print "Unable to load oreon perl module\n";
|
||||
exit $ERRORS{'UNKNOWN'};
|
||||
}
|
||||
|
||||
use Getopt::Long;
|
||||
use vars qw($opt_V $opt_h $opt_p $opt_c $opt_w $opt_H $opt_S $opt_g $opt_D $opt_step);
|
||||
use vars qw($PROGNAME);
|
||||
|
||||
my $pathtorrdbase = $oreon{GLOBAL}{DIR_RRDTOOL};
|
||||
my $pathtolibexectcp = $oreon{GLOBAL}{NAGIOS_LIBEXEC}."check_tcp";
|
||||
|
||||
sub print_help ();
|
||||
sub print_usage ();
|
||||
$PROGNAME = "check_graph_tcp";
|
||||
|
||||
#
|
||||
# get options
|
||||
#
|
||||
|
||||
Getopt::Long::Configure('bundling');
|
||||
GetOptions
|
||||
("h|help" => \$opt_h,
|
||||
"V|version" => \$opt_V,
|
||||
"H|hostname=s" => \$opt_H,
|
||||
"p|port=s" => \$opt_p,
|
||||
"w|warning=s" => \$opt_w,
|
||||
"c|critical=s" => \$opt_c,
|
||||
"S|ServiceId=s" => \$opt_S,
|
||||
"rrd_step=s" => \$opt_step,
|
||||
"g|rrdgraph" => \$opt_g);
|
||||
|
||||
if (defined($opt_h)) {
|
||||
print_help();
|
||||
exit $ERRORS{'OK'};
|
||||
}
|
||||
|
||||
$opt_H = shift unless ($opt_H);
|
||||
(print_usage() && exit $ERRORS{'OK'}) unless ($opt_H);
|
||||
|
||||
($opt_S) || ($opt_S = shift) || ($opt_S = "1_1");
|
||||
my $ServiceId = is_valid_serviceid($opt_S);
|
||||
|
||||
($opt_step) || ($opt_step = shift) || ($opt_step = "300");
|
||||
my $step = $1 if ($opt_step =~ /(\d+)/);
|
||||
|
||||
##################################################
|
||||
#### Create Command line
|
||||
#
|
||||
|
||||
my $args_check_tcp = "-H $opt_H -p $opt_p";
|
||||
$args_check_tcp .= " -w $opt_w -c $opt_c" if ($opt_w && $opt_c);
|
||||
|
||||
my $start=time;
|
||||
|
||||
|
||||
##
|
||||
## RRDTools create rrd
|
||||
##
|
||||
if ($opt_g) {
|
||||
create_rrd ($pathtorrdbase.$ServiceId.".rrd",1,$start,$step,"U","U","GAUGE") if (! -e $pathtorrdbase.$ServiceId.".rrd");
|
||||
}
|
||||
|
||||
my $result = `$pathtolibexectcp $args_check_tcp`;
|
||||
my $return_code = $? / 256;
|
||||
$_ = $result;
|
||||
m/(\d*\.\d*) second/;
|
||||
my $time = $1;
|
||||
|
||||
#
|
||||
# RRDtools update
|
||||
#
|
||||
|
||||
update_rrd ($pathtorrdbase.$ServiceId.".rrd",$start,$time) if ($opt_g && $time );
|
||||
|
||||
print "$result";
|
||||
exit $return_code;
|
||||
|
||||
sub print_usage () {
|
||||
print "\nUsage:\n";
|
||||
print $0."\n";
|
||||
print "\t-H (--hostname)\t\tHostname to query (required)\n";
|
||||
print "\t-p, --port\t\tPort number (required)\n";
|
||||
print "\t-w, --warning\t\tResponse time to result in warning status (seconds) - optional\n";
|
||||
print "\t-c, --critical\t\tResponse time to result in critical status (seconds) - optional\n";
|
||||
print "\t--rrd_step\t\tSpecifies the base interval in seconds with which data will be fed into the RRD (300 by default)\n";
|
||||
print "\t-V (--version)\t\tVieuw plugin version\n";
|
||||
print "\t-h (--help)\t\tusage help\n";
|
||||
|
||||
}
|
||||
|
||||
sub print_help () {
|
||||
print "################################################\n";
|
||||
print "# Bugs to http://bugs.oreon-project.org/ #\n";
|
||||
print "################################################\n";
|
||||
print "\n";
|
||||
print_usage();
|
||||
print "\n";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -136,7 +136,7 @@ if( $rta == -1 ) {
|
|||
my @tab = split(/,/,$ping_result_array[@ping_result_array -1 ]);
|
||||
print "GPING CRITICAL - ". $tab[1] ."|time=".$time_answer."ms;$pl_warning;$pl_critical;; ok=1\n";
|
||||
exit $ERRORS{'CRITICAL'};
|
||||
} elsif ( ($pl >= $pl_warning) || ($rta >= $rta_warning) ) {
|
||||
} elsif (($pl >= $pl_warning) || ($rta >= $rta_warning) ) {
|
||||
$ping_result_array[@ping_result_array -1 ] =~ s/\%/percent/g;
|
||||
my @tab = split(/,/,$ping_result_array[@ping_result_array -1 ]);
|
||||
print "GPING WARNING - ".$tab[0]."|time=".$time_answer."ms;$pl_warning;$pl_critical;; ok=1\n";
|
||||
|
|
|
@ -0,0 +1,286 @@
|
|||
#! /usr/bin/perl -w
|
||||
###################################################################
|
||||
# Oreon is developped with GPL Licence 2.0
|
||||
#
|
||||
# GPL License: http://www.gnu.org/licenses/gpl.txt
|
||||
#
|
||||
# Developped by : Julien Mathis - Romain Le Merlus
|
||||
# Christophe Coraboeuf
|
||||
#
|
||||
###################################################################
|
||||
# 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";
|
||||
use lib "@NAGIOS_PLUGINS@";
|
||||
use utils qw($TIMEOUT %ERRORS &print_revision &support);
|
||||
|
||||
use vars qw($PROGNAME);
|
||||
use Getopt::Long;
|
||||
use vars qw($opt_V $opt_h $opt_v $opt_C $opt_d $opt_n $opt_w $opt_c $opt_H $opt_D $opt_s @test);
|
||||
|
||||
# Plugin var init
|
||||
|
||||
my ($hrStorageDescr, $hrStorageAllocationUnits, $hrStorageSize, $hrStorageUsed);
|
||||
my ($AllocationUnits, $Size, $Used);
|
||||
my ($tot, $used, $pourcent, $return_code);
|
||||
|
||||
$PROGNAME = "check_snmp_remote_storage";
|
||||
sub print_help ();
|
||||
sub print_usage ();
|
||||
|
||||
Getopt::Long::Configure('bundling');
|
||||
GetOptions
|
||||
("h" => \$opt_h, "help" => \$opt_h,
|
||||
"V" => \$opt_V, "version" => \$opt_V,
|
||||
"s" => \$opt_s, "show" => \$opt_s,
|
||||
"v=s" => \$opt_v, "snmp=s" => \$opt_v,
|
||||
"C=s" => \$opt_C, "community=s" => \$opt_C,
|
||||
"d=s" => \$opt_d, "disk=s" => \$opt_d,
|
||||
"n" => \$opt_n, "name" => \$opt_n,
|
||||
"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.2 $');
|
||||
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);
|
||||
|
||||
if ($opt_n && !$opt_d) {
|
||||
print "Option -n (--name) need option -d (--disk)\n";
|
||||
exit $ERRORS{'UNKNOWN'};
|
||||
}
|
||||
|
||||
($opt_v) || ($opt_v = shift) || ($opt_v = "2");
|
||||
my $snmp = $1 if ($opt_v =~ /(\d)/);
|
||||
|
||||
($opt_C) || ($opt_C = shift) || ($opt_C = "public");
|
||||
|
||||
($opt_d) || ($opt_d = shift) || ($opt_d = 2);
|
||||
|
||||
my $partition = 0;
|
||||
if ($opt_d =~ /([0-9]+)/ && !$opt_n){
|
||||
$partition = $1;
|
||||
}
|
||||
elsif (!$opt_n){
|
||||
print "Unknown -d number expected... or it doesn't exist, try another disk - number\n";
|
||||
exit $ERRORS{'UNKNOWN'};
|
||||
}
|
||||
|
||||
($opt_c) || ($opt_c = shift) || ($opt_c = 95);
|
||||
my $critical = $1 if ($opt_c =~ /([0-9]+)/);
|
||||
|
||||
($opt_w) || ($opt_w = shift) || ($opt_w = 80);
|
||||
my $warning = $1 if ($opt_w =~ /([0-9]+)/);
|
||||
if ($critical <= $warning){
|
||||
print "(--crit) must be superior to (--warn)";
|
||||
print_usage();
|
||||
exit $ERRORS{'OK'};
|
||||
}
|
||||
|
||||
($opt_step) || ($opt_step = shift) || ($opt_step = "300");
|
||||
$step = $1 if ($opt_step =~ /(\d+)/);
|
||||
|
||||
my $name = $0;
|
||||
$name =~ s/\.pl.*//g;
|
||||
|
||||
# Plugin snmp requests
|
||||
|
||||
my $OID_hrStorageDescr =$oreon{MIB2}{HR_STORAGE_DESCR};
|
||||
my $OID_hrStorageAllocationUnits =$oreon{MIB2}{HR_STORAGE_ALLOCATION_UNITS};
|
||||
my $OID_hrStorageSize =$oreon{MIB2}{HR_STORAGE_SIZE};
|
||||
my $OID_hrStorageUsed =$oreon{MIB2}{HR_STORAGE_USED};
|
||||
|
||||
# create a SNMP session
|
||||
my ( $session, $error ) = Net::SNMP->session(-hostname => $opt_H,-community => $opt_C, -version => $snmp);
|
||||
if ( !defined($session) ) {
|
||||
print("CRITICAL: SNMP Session : $error");
|
||||
exit $ERRORS{'CRITICAL'};
|
||||
}
|
||||
|
||||
#getting partition using its name instead of its oid index
|
||||
if ($opt_n) {
|
||||
my $result = $session->get_table(Baseoid => $OID_hrStorageDescr);
|
||||
if (!defined($result)) {
|
||||
printf("ERROR: hrStorageDescr Table : %s.\n", $session->error);
|
||||
$session->close;
|
||||
exit $ERRORS{'UNKNOWN'};
|
||||
}
|
||||
my $expr = "";
|
||||
if ($opt_d =~ m/^[A-Za-z]:/) {
|
||||
$opt_d =~ s/\\/\\\\/g;
|
||||
$expr = "^$opt_d";
|
||||
}elsif ($opt_d =~ m/^\//) {
|
||||
$expr = "$opt_d\$";
|
||||
}else {
|
||||
$expr = "$opt_d";
|
||||
}
|
||||
foreach my $key ( oid_lex_sort(keys %$result)) {
|
||||
if ($result->{$key} =~ m/$expr/) {
|
||||
my @oid_list = split (/\./,$key);
|
||||
$partition = pop (@oid_list) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($opt_s) {
|
||||
# Get description table
|
||||
my $result = $session->get_table(
|
||||
Baseoid => $OID_hrStorageDescr
|
||||
);
|
||||
|
||||
if (!defined($result)) {
|
||||
printf("ERROR: hrStorageDescr Table : %s.\n", $session->error);
|
||||
$session->close;
|
||||
exit $ERRORS{'UNKNOWN'};
|
||||
}
|
||||
|
||||
foreach my $key ( oid_lex_sort(keys %$result)) {
|
||||
my @oid_list = split (/\./,$key);
|
||||
my $index = pop (@oid_list) ;
|
||||
print "hrStorage $index :: $$result{$key}\n";
|
||||
}
|
||||
exit $ERRORS{'OK'};
|
||||
}
|
||||
|
||||
my $result = $session->get_request(
|
||||
-varbindlist => [$OID_hrStorageDescr.".".$partition ,
|
||||
$OID_hrStorageAllocationUnits.".".$partition ,
|
||||
$OID_hrStorageSize.".".$partition,
|
||||
$OID_hrStorageUsed.".".$partition
|
||||
]
|
||||
);
|
||||
if (!defined($result)) {
|
||||
printf("ERROR: %s", $session->error);
|
||||
if ($opt_n) { print(" - You must specify the disk name when option -n is used");}
|
||||
print ".\n";
|
||||
$session->close;
|
||||
exit $ERRORS{'UNKNOWN'};
|
||||
}
|
||||
$hrStorageDescr = $result->{$OID_hrStorageDescr.".".$partition };
|
||||
$AllocationUnits = $result->{$OID_hrStorageAllocationUnits.".".$partition };
|
||||
$Size = $result->{$OID_hrStorageSize.".".$partition };
|
||||
$Used = $result->{$OID_hrStorageUsed.".".$partition };
|
||||
|
||||
|
||||
# Plugins var treatment
|
||||
|
||||
if (!$Size){
|
||||
print "Disk CRITICAL - no output (-p number expected... it doesn't exist, try another disk - number\n";
|
||||
exit $ERRORS{'CRITICAL'};
|
||||
}
|
||||
|
||||
if (($Size =~ /([0-9]+)/) && ($AllocationUnits =~ /([0-9]+)/)){
|
||||
if (!$Size){
|
||||
print "The number of the option -p is not a hard drive\n";
|
||||
exit $ERRORS{'CRITICAL'};
|
||||
}
|
||||
$tot = 1;
|
||||
$tot = $Size * $AllocationUnits;
|
||||
if (!$tot){$tot = 1;}
|
||||
$used = $Used * $AllocationUnits;
|
||||
$pourcent = ($used * 100) / $tot;
|
||||
|
||||
if (length($pourcent) > 2){
|
||||
@test = split (/\./, $pourcent);
|
||||
$pourcent = $test[0];
|
||||
}
|
||||
$tot = $tot / 1073741824;
|
||||
$Used = ($Used * $AllocationUnits) / 1073741824;
|
||||
|
||||
# Plugin return code
|
||||
|
||||
if ($pourcent >= $critical){
|
||||
print "Disk CRITICAL - ";
|
||||
$return_code = 2;
|
||||
} elsif ($pourcent >= $warning){
|
||||
print "Disk WARNING - ";
|
||||
$return_code = 1;
|
||||
} else {
|
||||
print "Disk OK - ";
|
||||
$return_code = 0;
|
||||
}
|
||||
|
||||
if ($hrStorageDescr){
|
||||
print $hrStorageDescr . " TOTAL: ";
|
||||
printf("%.3f", $tot);
|
||||
print " Go USED: " . $pourcent . "% : ";
|
||||
printf("%.3f", $Used);
|
||||
print " Go";
|
||||
if ($opt_f){
|
||||
my $size_o = $Used * 1073741824;
|
||||
my $warn = $opt_w * $size_o;
|
||||
my $crit = $opt_c * $size_o;
|
||||
print "|size=".$totrrd."o used=".$size_o.";".$warn.";".$crit;
|
||||
}
|
||||
print "\n";
|
||||
exit $return_code;
|
||||
} else {
|
||||
print "TOTAL: ";
|
||||
printf("%.3f", $tot);
|
||||
print " Go USED: " . $pourcent . "% : ";
|
||||
printf("%.3f", $Used);
|
||||
print " Go\n";
|
||||
exit $return_code;
|
||||
}
|
||||
} else {
|
||||
print "Disk CRITICAL - no output (-d number expected... it doesn't exist, try another disk - number\n";
|
||||
exit $ERRORS{'CRITICAL'};
|
||||
}
|
||||
|
||||
sub print_usage () {
|
||||
print "\nUsage:\n";
|
||||
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 " -d (--disk) Set the disk (number expected) ex: 1, 2,... (defaults to 2 )\n";
|
||||
print " -n (--name) Allows to use disk name with option -d instead of disk oid index\n";
|
||||
print " (ex: -d \"C:\" -n, -d \"E:\" -n, -d \"Swap Memory\" -n, -d \"Real Memory\" -n\n";
|
||||
print " (choose an unique expression for each disk)\n";
|
||||
print " -s (--show) Describes all disk (debug mode)\n";
|
||||
print " -w (--warn) Signal strength at which a warning message will be generated\n";
|
||||
print " (default 80)\n";
|
||||
print " -c (--crit) Signal strength at which a critical message will be generated\n";
|
||||
print " (default 95)\n";
|
||||
print " -V (--version) Plugin version\n";
|
||||
print " -h (--help) usage help\n";
|
||||
|
||||
}
|
||||
|
||||
sub print_help () {
|
||||
print "######################################################\n";
|
||||
print "# Copyright (c) 2004-2007 Oreon-project #\n";
|
||||
print "# Bugs to http://www.oreon-project.org/ #\n";
|
||||
print "######################################################\n";
|
||||
print_usage();
|
||||
print "\n";
|
||||
}
|
||||
|
Loading…
Reference in New Issue