mirror of
https://github.com/centreon/centreon-plugins.git
synced 2025-04-07 20:35:27 +02:00
git-svn-id: http://svn.centreon.com/Plugins/Dev@1705 6bcd3966-0018-0410-8128-fd23d134de7e
This commit is contained in:
commit
7d2aeed93a
218
centreon-plugins/src/check_graph_dell_temperature.pl
Normal file
218
centreon-plugins/src/check_graph_dell_temperature.pl
Normal file
@ -0,0 +1,218 @@
|
||||
#! /usr/bin/perl -w
|
||||
#
|
||||
# $Id: check_graph_dell_temperature.pl,v 1.1 2005/07/27 22:22:48 wistof Exp $
|
||||
#
|
||||
# Oreon's plugins are developped with GPL Licence :
|
||||
# http://www.fsf.org/licenses/gpl.txt
|
||||
# Developped by : Wistof
|
||||
#
|
||||
# Modified for Oreon Project by : Mathieu Chateau - Christophe Coraboeuf
|
||||
#
|
||||
# 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.
|
||||
|
||||
# based on "graph plugins" developped by Oreon Team. See http://www.oreon.org.
|
||||
##
|
||||
## Plugin init
|
||||
##
|
||||
use strict;
|
||||
use Net::SNMP qw(:snmp oid_lex_sort);
|
||||
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 vars qw($PROGNAME $VERSION);
|
||||
use Getopt::Long;
|
||||
use vars qw($opt_h $opt_V $opt_g $opt_D $opt_S $opt_H $opt_C $opt_v $opt_s $opt_t $opt_step $step $sensor $OID $OID_DESC);
|
||||
|
||||
##
|
||||
## Plugin var init
|
||||
##
|
||||
|
||||
|
||||
$VERSION = '$Revision: 1.1 $';
|
||||
$VERSION =~ s/^\$.*:\W(.*)\W.+?$/$1/;
|
||||
|
||||
my $pathtorrdbase = $oreon{GLOBAL}{DIR_RRDTOOL};
|
||||
$PROGNAME = $0;
|
||||
sub print_help ();
|
||||
sub print_usage ();
|
||||
|
||||
Getopt::Long::Configure('bundling');
|
||||
GetOptions
|
||||
("h" => \$opt_h, "help" => \$opt_h,
|
||||
"V" => \$opt_V, "version" => \$opt_V,
|
||||
"g" => \$opt_g, "rrdgraph" => \$opt_g,
|
||||
"rrd_step=s" => \$opt_step,
|
||||
"v=s" => \$opt_v, "snmp=s" => \$opt_v,
|
||||
"C=s" => \$opt_C, "community=s" => \$opt_C,
|
||||
"S=s" => \$opt_S, "ServiceId=s" => \$opt_S,
|
||||
"s" => \$opt_s, "show" => \$opt_s,
|
||||
"t=s" => \$opt_t, "sensor=s" => \$opt_t,
|
||||
"H=s" => \$opt_H, "hostname=s" => \$opt_H);
|
||||
|
||||
if ($opt_V) {
|
||||
print_revision($PROGNAME,'$Revision: 1.1 $');
|
||||
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);
|
||||
|
||||
($opt_v) || ($opt_v = shift) || ($opt_v = "1");
|
||||
my $snmp = $1 if ($opt_v =~ /(\d)/);
|
||||
|
||||
($opt_t) || ($opt_t = shift) || ($opt_t = "1");
|
||||
my $sensor = $1 if ($opt_t =~ /(\d)/);
|
||||
|
||||
($opt_S) || ($opt_S = shift) || ($opt_S = "1_1");
|
||||
my $ServiceId = is_valid_serviceid($opt_S);
|
||||
|
||||
($opt_C) || ($opt_C = shift) || ($opt_C = "public");
|
||||
|
||||
($opt_step) || ($opt_step = shift) || ($opt_step = "300");
|
||||
$step = $1 if ($opt_step =~ /(\d+)/);
|
||||
|
||||
|
||||
my $rrd = $pathtorrdbase.$ServiceId.".rrd";
|
||||
|
||||
my $start=time;
|
||||
my $name = $0;
|
||||
$name =~ s/\.pl.*//g;
|
||||
|
||||
##
|
||||
## RRDTools create rrd
|
||||
##
|
||||
if ($opt_g) {
|
||||
if (! -e $rrd) {
|
||||
oreon::create_rrd ($rrd,1,$start,$step,"U","U","GAUGE");
|
||||
}
|
||||
}
|
||||
|
||||
##
|
||||
## Plugin snmp requests
|
||||
##
|
||||
my $OID = ".1.3.6.1.4.1.674.10892.1.700.20.1.6.1";
|
||||
my $OID_DESC = ".1.3.6.1.4.1.674.10892.1.700.20.1.8.1";
|
||||
|
||||
|
||||
# create a SNMP session
|
||||
my ( $session, $error ) = Net::SNMP->session(-hostname => $opt_H,-community => $opt_C, -version => $snmp);
|
||||
if ( !defined($session) ) {
|
||||
print("UNKNOWN: $error");
|
||||
exit $ERRORS{'UNKNOWN'};
|
||||
}
|
||||
|
||||
if ($opt_s) {
|
||||
# Get desctiption table
|
||||
my $result = $session->get_table(
|
||||
Baseoid => $OID_DESC
|
||||
);
|
||||
|
||||
if (!defined($result)) {
|
||||
printf("ERROR: Description 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 "Temperature Sensor $index :: $$result{$key}\n";
|
||||
}
|
||||
exit $ERRORS{'OK'};
|
||||
}
|
||||
|
||||
|
||||
my $result = $session->get_request(
|
||||
-varbindlist => [$OID.".".$sensor,
|
||||
$OID_DESC.".".$sensor]
|
||||
);
|
||||
if (!defined($result)) {
|
||||
printf("UNKNOWN: %s.\n", $session->error);
|
||||
$session->close;
|
||||
exit $ERRORS{'UNKNOWN'};
|
||||
}
|
||||
|
||||
my $return_result = $result->{$OID.".".$sensor};
|
||||
my $un = 0;
|
||||
if ($return_result =~ /(\d+)/ ) {
|
||||
$un = $1;
|
||||
} else {
|
||||
printf("UNKNOWN: Unable to parse SNMP Output :: %s", $return_result );
|
||||
$session->close;
|
||||
exit $ERRORS{'UNKNOWN'};
|
||||
}
|
||||
|
||||
$un = sprintf("%02.2f", $un / 10);
|
||||
|
||||
##
|
||||
## RRDtools update
|
||||
##
|
||||
if ($opt_g) {
|
||||
$start=time;
|
||||
oreon::update_rrd ($rrd,$start,$un);
|
||||
}
|
||||
|
||||
##
|
||||
## Plugin return code
|
||||
##
|
||||
if ($un || ( $un == 0) ){
|
||||
print "OK - ". $result->{$OID_DESC.".".$sensor} ." : $un\n";
|
||||
exit $ERRORS{'OK'};
|
||||
}
|
||||
else{
|
||||
print "CRITICAL Host unavailable\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 " -g (--rrdgraph) create a rrd base and add datas into this one\n";
|
||||
print " --rrd_step Specifies the base interval in seconds with which data will be fed into the RRD (300 by default)\n";
|
||||
print " -D (--directory) Path to rrdatabase (or create the .rrd in this directory)\n";
|
||||
print " by default: ".$pathtorrdbase."\n";
|
||||
print " (The path is valid with spaces '/my\ path/...')\n";
|
||||
print " -S (--ServiceId) Oreon Service Id\n";
|
||||
print " -t (--sensor) Set the sensor number (1 by default)\n";
|
||||
print " -s (--show) Describes all sensors \n";
|
||||
print " -V (--version) Plugin version\n";
|
||||
print " -h (--help) usage help\n";
|
||||
|
||||
}
|
||||
|
||||
sub print_help () {
|
||||
print "Copyright (c) 2005 Oreon\n";
|
||||
print "Bugs to http://www.oreon.org/\n";
|
||||
print "\n";
|
||||
print_usage();
|
||||
print "\n";
|
||||
}
|
218
centreon-plugins/src/check_graph_http.pl
Normal file
218
centreon-plugins/src/check_graph_http.pl
Normal file
@ -0,0 +1,218 @@
|
||||
#! /usr/bin/perl -w
|
||||
#
|
||||
# $Id: check_graph_http.pl,v 1.3 2005/08/01 18:03:52 gollum123 Exp $
|
||||
#
|
||||
# This plugin is developped under GPL Licence:
|
||||
# http://www.fsf.org/licenses/gpl.txt
|
||||
|
||||
# Developped by Linagora SA: http://www.linagora.com
|
||||
|
||||
# Modified for Oreon Project by : Mathieu Chateau - Christophe Coraboeuf
|
||||
|
||||
# The Software is provided to you AS IS and WITH ALL FAULTS.
|
||||
# LINAGORA 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 LINAGORA web site.
|
||||
# In no event will LINAGORA be liable for any direct, indirect, punitive, special,
|
||||
# incidental or consequential damages however they may arise and even if LINAGORA has
|
||||
# been previously advised of the possibility of such damages.
|
||||
|
||||
# based on "graph plugins" developped by Oreon Team. See http://www.oreon.org.
|
||||
|
||||
##
|
||||
## Plugin init
|
||||
##
|
||||
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_h $opt_V $opt_g $opt_D $opt_S $opt_H $opt_I $opt_e $opt_s $opt_u $opt_p $opt_P $opt_w $opt_c
|
||||
$opt_t $opt_a $opt_L $opt_f $opt_l $opt_r $opt_R $opt_z $opt_C $opt_step $step);
|
||||
use vars qw($PROGNAME);
|
||||
|
||||
##
|
||||
## Plugin var init
|
||||
##
|
||||
my $pathtorrdbase = $oreon{GLOBAL}{DIR_RRDTOOL};
|
||||
my $pathtolibexechttp = $oreon{GLOBAL}{ NAGIOS_LIBEXEC}."check_http";
|
||||
|
||||
$PROGNAME = "$0";
|
||||
sub print_help ();
|
||||
sub print_usage ();
|
||||
|
||||
Getopt::Long::Configure('bundling');
|
||||
GetOptions
|
||||
("h" => \$opt_h, "help" => \$opt_h,
|
||||
"V" => \$opt_V, "version" => \$opt_V,
|
||||
"g" => \$opt_g, "rrdgraph" => \$opt_g,
|
||||
"rrd_step=s" => \$opt_step,
|
||||
"S=s" => \$opt_S, "ServiceId=s" => \$opt_S,
|
||||
"H=s" => \$opt_H, "hostname=s" => \$opt_H,
|
||||
"I=s" => \$opt_I, "IP-address=s" => \$opt_I,
|
||||
"e=s" => \$opt_e, "expect=s" => \$opt_e,
|
||||
"s=s" => \$opt_s, "string=s" => \$opt_s,
|
||||
"u=s" => \$opt_u, "url=s" => \$opt_u,
|
||||
"p=s" => \$opt_p, "port=s" => \$opt_p,
|
||||
"P=s" => \$opt_P, "post=s" => \$opt_P,
|
||||
"w=s" => \$opt_w, "warning=s" => \$opt_w,
|
||||
"c=s" => \$opt_c, "critical=s" => \$opt_c,
|
||||
"t=s" => \$opt_t, "timeout=s" => \$opt_t,
|
||||
"a=s" => \$opt_a, "authorization=s" => \$opt_a,
|
||||
"L=s" => \$opt_L, "link=s" => \$opt_L,
|
||||
"f=s" => \$opt_f, "onredirect=s" => \$opt_f,
|
||||
"l=s" => \$opt_l, "linespan=s" => \$opt_l,
|
||||
"r=s" => \$opt_r, "regex=s" => \$opt_r,
|
||||
"R=s" => \$opt_R, "eregi=s" => \$opt_R,
|
||||
"C=s" => \$opt_C, "certificate=s" => \$opt_C,
|
||||
"z" => \$opt_R, "ssl" => \$opt_z
|
||||
|
||||
);
|
||||
|
||||
if ($opt_V) {
|
||||
print_revision($PROGNAME,'$Revision: 1.3 $');
|
||||
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);
|
||||
|
||||
($opt_S) || ($opt_S = shift) || ($opt_S = "1_1");
|
||||
my $ServiceId = is_valid_serviceid($opt_S);
|
||||
|
||||
($opt_step) || ($opt_step = shift) || ($opt_step = "300");
|
||||
$step = $1 if ($opt_step =~ /(\d+)/);
|
||||
|
||||
my $args_check_http = "";
|
||||
if ( $opt_H ) {
|
||||
$args_check_http .= " -H $opt_H";
|
||||
}
|
||||
if ( $opt_I ) {
|
||||
$args_check_http .= " -I $opt_I";
|
||||
}
|
||||
if ( $opt_e ) {
|
||||
$args_check_http .= " -e $opt_e";
|
||||
}
|
||||
if ( $opt_s ) {
|
||||
$args_check_http .= " -s $opt_s";
|
||||
}
|
||||
if ( $opt_u ) {
|
||||
$args_check_http .= " -u $opt_u";
|
||||
}
|
||||
if ( $opt_p ) {
|
||||
$args_check_http .= " -p $opt_p";
|
||||
}
|
||||
if ( $opt_P ) {
|
||||
$args_check_http .= " -P $opt_P";
|
||||
}
|
||||
if ( $opt_I ) {
|
||||
$args_check_http .= " -I $opt_I";
|
||||
}
|
||||
if ( $opt_e ) {
|
||||
$args_check_http .= " -e $opt_e";
|
||||
}
|
||||
if ( $opt_w ) {
|
||||
$args_check_http .= " -w $opt_w";
|
||||
}
|
||||
if ( $opt_c ) {
|
||||
$args_check_http .= " -c $opt_c";
|
||||
}
|
||||
if ( $opt_t ) {
|
||||
$args_check_http .= " -t $opt_t";
|
||||
}
|
||||
if ( $opt_a ) {
|
||||
$args_check_http .= " -a $opt_a";
|
||||
}
|
||||
if ( $opt_L ) {
|
||||
$args_check_http .= " -L $opt_L";
|
||||
}
|
||||
if ( $opt_f ) {
|
||||
$args_check_http .= " -f $opt_f";
|
||||
}
|
||||
if ( $opt_l ) {
|
||||
$args_check_http .= " -l $opt_l";
|
||||
}
|
||||
if ( $opt_r ) {
|
||||
$args_check_http .= " -r $opt_r";
|
||||
}
|
||||
if ( $opt_R ) {
|
||||
$args_check_http .= " -R $opt_R";
|
||||
}
|
||||
if ( $opt_C ) {
|
||||
$args_check_http .= " -C $opt_C";
|
||||
}
|
||||
if ( $opt_z ) {
|
||||
$args_check_http .= " --ssl";
|
||||
}
|
||||
|
||||
|
||||
my $rrd = $pathtorrdbase.$ServiceId.".rrd";
|
||||
|
||||
my $start=time;
|
||||
my $name = $0;
|
||||
$name =~ s/\.pl.*//g;
|
||||
|
||||
##
|
||||
## RRDTools create rrd
|
||||
##
|
||||
if ($opt_g) {
|
||||
if (! -e $rrd) {
|
||||
create_rrd ($rrd,1,$start,$step,"U","U","GAUGE");
|
||||
}
|
||||
}
|
||||
##
|
||||
## Plugin requests
|
||||
##
|
||||
# print "args: $args_check_http \n";
|
||||
my $result = `$pathtolibexechttp $args_check_http`;
|
||||
my $return_code = $? / 256;
|
||||
|
||||
$_ = $result;
|
||||
m/time=\s*(\d*\.\d*)/;
|
||||
my $time = $1;
|
||||
|
||||
##
|
||||
## RRDtools update
|
||||
##
|
||||
if ($opt_g && $time ) {
|
||||
$start=time;
|
||||
update_rrd ($rrd,$start,$time);
|
||||
}
|
||||
|
||||
print "$result";
|
||||
exit $return_code;
|
||||
|
||||
##
|
||||
## Plugin return code
|
||||
##
|
||||
sub print_usage () {
|
||||
my $screen = `$pathtolibexechttp -h`;
|
||||
$screen =~ s/check_http/check_graph_http/g;
|
||||
$screen =~ s/-S/-Z/;
|
||||
print $screen;
|
||||
}
|
||||
|
||||
sub print_help () {
|
||||
print "Copyright (c) 2005 LINAGORA SA\n";
|
||||
print "Bugs to http://www.linagora.com/\n";
|
||||
print "\n";
|
||||
print_usage();
|
||||
print "\n";
|
||||
}
|
185
centreon-plugins/src/check_graph_load_average.pl
Normal file
185
centreon-plugins/src/check_graph_load_average.pl
Normal file
@ -0,0 +1,185 @@
|
||||
#! /usr/bin/perl -w
|
||||
#
|
||||
# $Id: check_graph_load_average.pl,v 1.2 2005/07/27 22:21:49 wistof 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
|
||||
#
|
||||
# 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.
|
||||
|
||||
##
|
||||
## Plugin init
|
||||
##
|
||||
use strict;
|
||||
use Net::SNMP qw(:snmp);
|
||||
use FindBin;
|
||||
use lib "$FindBin::Bin";
|
||||
#use lib "@NAGIOS_PLUGINS@";
|
||||
use lib "/usr/local/nagios/libexec/";
|
||||
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 vars qw($PROGNAME);
|
||||
use Getopt::Long;
|
||||
use vars qw($opt_V $opt_h $opt_g $opt_v $opt_C $opt_H $opt_D $opt_S $opt_step $step $snmp $opt_f);
|
||||
|
||||
|
||||
##
|
||||
## Plugin var init
|
||||
##
|
||||
my($return_code);
|
||||
|
||||
my $pathtorrdbase = $oreon{GLOBAL}{DIR_RRDTOOL};
|
||||
|
||||
$PROGNAME = "check_graph_load_average";
|
||||
sub print_help ();
|
||||
sub print_usage ();
|
||||
|
||||
Getopt::Long::Configure('bundling');
|
||||
GetOptions
|
||||
("h" => \$opt_h, "help" => \$opt_h,
|
||||
"V" => \$opt_V, "version" => \$opt_V,
|
||||
"g" => \$opt_g, "rrdgraph" => \$opt_g,
|
||||
"rrd_step=s" => \$opt_step,
|
||||
"v=s" => \$opt_v, "snmp=s" => \$opt_v,
|
||||
"C=s" => \$opt_C, "community=s" => \$opt_C,
|
||||
"S=s" => \$opt_S, "ServiceId=s" => \$opt_S,
|
||||
"H=s" => \$opt_H, "hostname=s" => \$opt_H,
|
||||
"f" => \$opt_f);
|
||||
|
||||
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);
|
||||
|
||||
($opt_S) || ($opt_S = shift) || ($opt_S = "1_1");
|
||||
my $ServiceId = is_valid_serviceid($opt_S);
|
||||
|
||||
($opt_v) || ($opt_v = shift) || ($opt_v = "2");
|
||||
$snmp = $1 if ($opt_v =~ /(\d)/);
|
||||
|
||||
($opt_C) || ($opt_C = shift) || ($opt_C = "public");
|
||||
|
||||
($opt_step) || ($opt_step = shift) || ($opt_step = "300");
|
||||
$step = $1 if ($opt_step =~ /(\d+)/);
|
||||
|
||||
my $rrd = $pathtorrdbase.$ServiceId.".rrd";
|
||||
|
||||
my $start=time;
|
||||
my $name = $0;
|
||||
$name =~ s/\.pl.*//g;
|
||||
|
||||
##
|
||||
## RRDTools create rrd
|
||||
##
|
||||
if ($opt_g) {
|
||||
if (! -e $rrd) {
|
||||
create_rrd ($rrd,3,$start,$step,"U","U","GAUGE");
|
||||
}
|
||||
}
|
||||
|
||||
##
|
||||
## Plugin snmp requests
|
||||
##
|
||||
$return_code = 0;
|
||||
|
||||
my $OID_CPULOAD_1 =$oreon{UNIX}{CPU_LOAD_1M};
|
||||
my $OID_CPULOAD_5 =$oreon{UNIX}{CPU_LOAD_5M};
|
||||
my $OID_CPULOAD_15 =$oreon{UNIX}{CPU_LOAD_15M};
|
||||
|
||||
my ( $session, $error ) = Net::SNMP->session(-hostname => $opt_H,-community => $opt_C, -version => $snmp);
|
||||
if ( !defined($session) ) {
|
||||
print("UNKNOWN: $error");
|
||||
exit $ERRORS{'UNKNOWN'};
|
||||
}
|
||||
|
||||
my $result = $session->get_request(
|
||||
-varbindlist => [$OID_CPULOAD_1, $OID_CPULOAD_5, $OID_CPULOAD_15 ]
|
||||
);
|
||||
if (!defined($result)) {
|
||||
printf("UNKNOWN: %s.\n", $session->error);
|
||||
$session->close;
|
||||
exit $ERRORS{'UNKNOWN'};
|
||||
}
|
||||
|
||||
my $un = $result->{$OID_CPULOAD_1};
|
||||
my $cinq = $result->{$OID_CPULOAD_5};
|
||||
my $quinze = $result->{$OID_CPULOAD_15};
|
||||
|
||||
##
|
||||
## RRDtools update
|
||||
##
|
||||
if ($opt_g && ( $return_code == 0) ) {
|
||||
$start=time;
|
||||
update_rrd ($rrd,$start,$un,$cinq,$quinze);
|
||||
}
|
||||
|
||||
##
|
||||
## Plugin return code
|
||||
##
|
||||
|
||||
my $PERFPARSE = "";
|
||||
|
||||
if ($return_code == 0){
|
||||
if ($opt_f){
|
||||
$PERFPARSE = "|load1=".$un."%;;;0;100 load5=".$cinq."%;;;0;100 load15=".$quinze."%;;;0;100";
|
||||
}
|
||||
print "load average: $un, $cinq, $quinze".$PERFPARSE."\n";
|
||||
exit $ERRORS{'OK'};
|
||||
} else {
|
||||
print "Load Average CRITICAL\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 " -g (--rrdgraph) create à rrd base and add datas into this one\n";
|
||||
print " --rrd_step Specifies the base interval in seconds with which data will be fed into the RRD (300 by default)\n";
|
||||
print " -D (--directory) Path to rrdatabase (or create the .rrd in this directory)\n";
|
||||
print " by default: ".$pathtorrdbase."\n";
|
||||
print " (The path is valid with spaces '/my\ path/...')\n";
|
||||
print " -S (--ServiceId) Oreon Service Id\n";
|
||||
print " -V (--version) Plugin version\n";
|
||||
print " -h (--help) usage help\n";
|
||||
print " -f Perfparse Compatible\n";
|
||||
}
|
||||
|
||||
sub print_help () {
|
||||
print "Copyright (c) 2004-2005 OREON\n";
|
||||
print "Bugs to http://bugs.oreon-project.org/\n";
|
||||
print "\n";
|
||||
print_usage();
|
||||
print "\n";
|
||||
}
|
404
centreon-plugins/src/check_graph_nt.pl
Normal file
404
centreon-plugins/src/check_graph_nt.pl
Normal file
@ -0,0 +1,404 @@
|
||||
#! /usr/bin/perl -w
|
||||
#
|
||||
# $Id: check_graph_nt.pl,v 1.3 2005/08/01 18:04:00 gollum123 Exp $
|
||||
#
|
||||
# Oreon's plugins are developped with GPL Licence :
|
||||
# http://www.fsf.org/licenses/gpl.txt
|
||||
# Developped by : Julien Mathis - Mathieu Mettre
|
||||
# Under control of Flavien Astraud, Jerome Landrieu for Epitech.
|
||||
# Oreon's plugins are developped in partnership with Linagora company.
|
||||
#
|
||||
# Modified for Oreon Project by : Mathieu Chateau - Christophe Coraboeuf
|
||||
#
|
||||
# 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.
|
||||
|
||||
##
|
||||
## Plugin init
|
||||
##
|
||||
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 vars qw($PROGNAME);
|
||||
use Getopt::Long;
|
||||
use vars qw($opt_H $opt_p $opt_s $opt_v $opt_V $opt_h $opt_w $opt_c $opt_S $opt_g $opt_t $opt_l $opt_d $opt_D $opt_step $step $opt_f);
|
||||
|
||||
##
|
||||
## Plugin var init
|
||||
##
|
||||
my $pathtorrdbase = $oreon{GLOBAL}{DIR_RRDTOOL};
|
||||
my $pathtolibexecnt = $oreon{GLOBAL}{NAGIOS_LIBEXEC}."check_nt";
|
||||
|
||||
my($op_v, $op_d, $op_s, $op_t, $op_l, $port, @values, @test, @test2, @test3, @test4, @test5, $warning, $critical, @w, @c, $uptime);
|
||||
my($warning2, $critical2, $warning3, $critical3, $warning4, $critical4, @output);
|
||||
$PROGNAME = "check_graph_nt";
|
||||
sub print_help ();
|
||||
sub print_usage ();
|
||||
|
||||
Getopt::Long::Configure('bundling');
|
||||
GetOptions
|
||||
("h" => \$opt_h, "help" => \$opt_h,
|
||||
"p=s" => \$opt_p, "port=s" => \$opt_p,
|
||||
"V" => \$opt_V, "version" => \$opt_V,
|
||||
"g" => \$opt_g, "rrdgraph" => \$opt_g,
|
||||
"rrd_step=s" => \$opt_step,
|
||||
"s=s" => \$opt_s, "password=s" => \$opt_s,
|
||||
"d=s" => \$opt_d, "showall=s" => \$opt_d,
|
||||
"v=s" => \$opt_v, "variable=s" => \$opt_v,
|
||||
"D=s" => \$opt_D, "directory=s" => \$opt_D,
|
||||
"t=s" => \$opt_t, "timeout=s" => \$opt_t,
|
||||
"l:s" => \$opt_l, "parameter:s" => \$opt_l,
|
||||
"w=s" => \$opt_w, "warning=s" => \$opt_w,
|
||||
"c=s" => \$opt_c, "critical=s" => \$opt_c,
|
||||
"S=s" => \$opt_S, "ServiceId=s" => \$opt_S,
|
||||
"H=s" => \$opt_H, "hostname=s" => \$opt_H);
|
||||
|
||||
if ($opt_h) {
|
||||
print_help();
|
||||
exit $ERRORS{'OK'};
|
||||
}
|
||||
|
||||
if ($opt_V) {
|
||||
$_ = `$pathtolibexecnt -V`;
|
||||
print "$_";
|
||||
exit $ERRORS{'OK'};
|
||||
}
|
||||
|
||||
if ($opt_p) {
|
||||
if ($opt_p =~ /([0-9]+)/){
|
||||
$port = $1;
|
||||
}
|
||||
else{
|
||||
print "Unknown -p number expected... or it doesn't exist, try another port - number\n";
|
||||
exit $ERRORS{'UNKNOWN'};
|
||||
}
|
||||
}
|
||||
|
||||
$opt_H = shift unless ($opt_H);
|
||||
(print_usage() && exit $ERRORS{'OK'}) unless ($opt_H);
|
||||
|
||||
|
||||
if ($opt_c) {
|
||||
($opt_c) || ($opt_c = shift);
|
||||
$critical = $1 if ($opt_c =~ /([0-9]+)/);
|
||||
}
|
||||
|
||||
if ($opt_w) {
|
||||
($opt_w) || ($opt_w = shift);
|
||||
$warning = $1 if ($opt_w =~ /([0-9]+)/);
|
||||
}
|
||||
|
||||
if (($critical && $warning) && ($critical <= $warning)) {
|
||||
print "(--crit) must be superior to (--warn)";
|
||||
print_usage();
|
||||
exit $ERRORS{'OK'};
|
||||
}
|
||||
|
||||
|
||||
if ($opt_t) {
|
||||
($opt_t) || ($opt_t = shift);
|
||||
$op_t = $1 if ($opt_t =~ /([-\.,\w]+)/);
|
||||
}
|
||||
|
||||
if ($opt_l) {
|
||||
($opt_l) || ($opt_l = shift);
|
||||
$op_l = $1 if ($opt_l =~ /(.+)/);
|
||||
}
|
||||
|
||||
if ($opt_s) {
|
||||
($opt_s) || ($opt_s = shift);
|
||||
$op_s = $1 if ($opt_s =~ /([-.,A-Za-z0-9]+)/);
|
||||
}
|
||||
|
||||
if ($opt_d) {
|
||||
($opt_d) || ($opt_d = shift);
|
||||
$op_d = $1 if ($opt_d =~ /([-.,A-Za-z0-9]+)/);
|
||||
}
|
||||
|
||||
if ($opt_v) {
|
||||
($opt_v) || ($opt_v = shift);
|
||||
$op_v = $1 if ($opt_v =~ /([-.,A-Za-z0-9]+)/);
|
||||
}
|
||||
|
||||
($opt_step) || ($opt_step = shift) || ($opt_step = 300);
|
||||
$step = $1 if ($opt_step =~ /(\d+)/);
|
||||
|
||||
($opt_S) || ($opt_S = shift) || ($opt_S = "1_1");
|
||||
my $ServiceId = is_valid_serviceid($opt_S);
|
||||
|
||||
##
|
||||
## RRDTool var init
|
||||
##
|
||||
|
||||
my $rrd = $pathtorrdbase.$ServiceId.".rrd";
|
||||
my $name = $0;
|
||||
$name =~ s/\.pl.*//g;
|
||||
my $return_code;
|
||||
##
|
||||
## Plugin requests
|
||||
##
|
||||
my $start=time;
|
||||
if ($op_v) {
|
||||
if ($op_v) {$op_v = "-v ".$op_v;}
|
||||
if ($port) {$port = "-p ".$port;} else { $port = " ";}
|
||||
if ($warning) {$warning = "-w ".$warning;} else { $warning = " ";}
|
||||
if ($critical) {$critical = "-c ".$critical;} else { $critical = " ";}
|
||||
if ($op_l) {$op_l = "-l \"".$op_l ."\"";} else { $op_l = " ";}
|
||||
if ($op_t) {$op_t = "-t ".$op_t;} else { $op_t = " ";}
|
||||
if ($op_s) {$op_s = "-s ".$op_s;} else { $op_s = " ";}
|
||||
if ($op_d) {$op_d = "-d ".$op_d;} else { $op_d = " ";}
|
||||
# print "$pathtolibexecnt -H $opt_H $op_v $port $warning $critical $op_l $op_t $op_s $op_d\n";
|
||||
$_ = `$pathtolibexecnt -H $opt_H $op_v $port $warning $critical $op_l $op_t $op_s $op_d 2>/dev/null`;
|
||||
my $return = $_;
|
||||
$return =~ s/\\//g;
|
||||
$return_code = $? / 256;
|
||||
|
||||
##
|
||||
## CLIENTVERSION
|
||||
##
|
||||
if ($op_v =~ /CLIENTVERSION/){
|
||||
print "CLIENTVERSION impossible to Graph!\n";
|
||||
exit $ERRORS{'UNKNOWN'};
|
||||
}
|
||||
|
||||
if (($op_v =~ /CPULOAD/) && ($op_l =~ /([-\.,\w]+)/)){ ## CPULOAD
|
||||
@output = split(/\|/,$_);
|
||||
@values = $output[0] =~ /(\d*)\%/g ;
|
||||
$start=time;
|
||||
if ($opt_g) {
|
||||
unless (-e $rrd) {
|
||||
create_rrd ($rrd,$#values +1,$start,$step,"U","U","GAUGE");
|
||||
}
|
||||
update_rrd ($rrd,$start,@values);
|
||||
}
|
||||
## Print Plugins Output
|
||||
$return =~ s/\n/ /g;
|
||||
if (@values){
|
||||
if (defined($opt_c) && defined($opt_w)){
|
||||
print $return . "|cpu=@values;$opt_w;$opt_c\n";
|
||||
} else {
|
||||
print $return . "|cpu=@values\n";
|
||||
}
|
||||
} else {
|
||||
print $return . "\n";
|
||||
}
|
||||
exit $return_code;
|
||||
} elsif ($op_v =~ /UPTIME/){ ## UPTIME
|
||||
if ($_ =~ /.*[-:]+\s(\d+)\s.*$/ ) {
|
||||
$uptime = $1;
|
||||
} else {
|
||||
print "unable to parse check_nt output: $_\n" ;
|
||||
exit $ERRORS{'UNKNOWN'};
|
||||
}
|
||||
if ($opt_g) {
|
||||
if (! -e $rrd) {
|
||||
create_rrd ($rrd,1,$start,$step,"U","U","GAUGE");
|
||||
} else {
|
||||
update_rrd ($rrd,$start,$uptime);
|
||||
}
|
||||
}
|
||||
$_ =~ s/\n/ /g;
|
||||
if (defined($uptime)){
|
||||
print $_ . "|uptime=".$uptime."d\n";
|
||||
} else {
|
||||
print $_ . "\n";
|
||||
}
|
||||
exit $return_code;
|
||||
} elsif (($op_v =~ /USEDDISKSPACE/) && ($op_l =~ /([-\.,\w]+)/)){ ## USEDDISKSPACE
|
||||
my @test = split(/ /,$_);
|
||||
if (defined($test[9]) && defined($test2[1])){
|
||||
@test2 = split(/\(/, $test[9]);
|
||||
@test3 = split(/\%/, $test2[1]);
|
||||
}
|
||||
@c = split(/ /, $critical);
|
||||
$critical = $c[1];
|
||||
@w = split(/ /, $warning);
|
||||
$warning = $w[1];
|
||||
if ($opt_g) {
|
||||
unless (-e $rrd) {
|
||||
create_rrd ($rrd,3,$start,$step,"U","U","GAUGE");
|
||||
}
|
||||
if (defined($test[3]) && defined($test[7]) && defined($test[12])){
|
||||
$test[3] =~ s/,/\./ ;
|
||||
$test[7] =~ s/,/\./ ;
|
||||
$test[12] =~ s/,/\./ ;
|
||||
update_rrd ($rrd,$start,$test[3],$test[7],$test[12]);
|
||||
}
|
||||
}
|
||||
## Print Plugins Output
|
||||
$return =~ s/\n/ /g;
|
||||
$return =~ s/%/ pct/g;
|
||||
if (defined($test[3]) && defined($test[7]) && defined($test[12])){
|
||||
print $return . "|total=".$test[3]."Mo used=".$test[7]."Mo free=".$test[12]."Mo\n";
|
||||
} else {
|
||||
print $return . "\n";
|
||||
}
|
||||
exit $return_code;
|
||||
} elsif ($op_v =~ /MEMUSE/){ ## MEMUSE
|
||||
$start=time;
|
||||
my @test = split(/ /,$_);
|
||||
if (defined($test[2])){
|
||||
@test4 = split(/:/, $test[2]);
|
||||
}
|
||||
@c = split(/ /, $critical);
|
||||
$critical = $c[1];
|
||||
@w = split(/ /, $warning);
|
||||
$warning = $w[1];
|
||||
if ($opt_g) {
|
||||
unless (-e $rrd) {
|
||||
create_rrd ($rrd,3,$start,$step,"U","U","GAUGE");
|
||||
}
|
||||
if (defined($test4[1]) && defined($test[6]) && defined($test[11])){
|
||||
# Replace , by . to convert in real float number (for rrdtool)
|
||||
$test4[1] =~ s/,/\./ ;
|
||||
$test[6] =~ s/,/\./ ;
|
||||
$test[11] =~ s/,/\./ ;
|
||||
update_rrd ($rrd,$start,$test4[1],$test[6],$test[11]);
|
||||
}
|
||||
}
|
||||
## Print Plugins Output
|
||||
$return =~ s/\n/ /g;
|
||||
$return =~ s/%/ pct/g;
|
||||
if ($test4[1] && $test[6] && $test[11]){
|
||||
print $return . "|total=".$test4[1]." used=".$test[6]." free=".$test[11]."\n";
|
||||
} else {
|
||||
print $return . "\n";
|
||||
}
|
||||
exit $return_code;
|
||||
} elsif ($op_v =~ /SERVICESTATE/){## SERVICESTATE
|
||||
my (@tab, $process, $nom, $etat);
|
||||
@tab = split (' - ',$_);
|
||||
foreach $process (@tab) {
|
||||
($nom,$etat) = split (': ', $process);
|
||||
if (defined($etat)) {
|
||||
$etat =~ s/\n//;
|
||||
} else {
|
||||
$etat = "Unknow";
|
||||
}
|
||||
if ($etat =~ /Started/)
|
||||
{$etat=1;}
|
||||
elsif ($etat =~ /Stopped/)
|
||||
{$etat=0;}
|
||||
elsif ($etat =~ /Unknown/)
|
||||
{$etat=-1;}
|
||||
else {
|
||||
print "Unable to get $nom status [$etat]: \n\t$_\n";
|
||||
exit $ERRORS{'UNKNOWN'};
|
||||
}
|
||||
}
|
||||
if ($opt_g) {
|
||||
if (! -e $rrd) {
|
||||
create_rrd ($rrd,1,$start,$step,"U","U","GAUGE");
|
||||
} else {
|
||||
update_rrd ($rrd,$start,$etat);
|
||||
}
|
||||
}
|
||||
$return =~ s/%/ pct/g;
|
||||
print $return;
|
||||
exit $return_code;
|
||||
} elsif ($op_v =~ /PROCSTATE/){## PROCSTATE
|
||||
print "PROCSTATE not graphed\n";
|
||||
exit $ERRORS{'UNKNOWN'};
|
||||
} elsif (($op_v =~ /COUNTER/) && ($op_l =~ /(.+)/)) { ## COUNTER
|
||||
@output = split(/\|/,$_);
|
||||
@values = $output[0] =~ /([,\.\d]*)\s?\%/ ;
|
||||
if (!@values) {@values = $output[0] =~ /([\d]*)/;}
|
||||
$start=time;
|
||||
if ($opt_g) {
|
||||
unless (-e $rrd) {
|
||||
create_rrd ($rrd,$#values +1,$start,$step,"U","U","GAUGE");
|
||||
}
|
||||
update_rrd ($rrd,$start,@values);
|
||||
}
|
||||
## Print Plugins Output
|
||||
$return =~ s/\n/ /g;
|
||||
$return =~ s/%/ pct/g;
|
||||
print $return . "|counter=".@values."\n";
|
||||
exit $return_code;
|
||||
}
|
||||
} else {
|
||||
print "Could not parse arguments\n";
|
||||
exit $ERRORS{'UNKNOWN'};
|
||||
}
|
||||
|
||||
##
|
||||
## Plugin return code
|
||||
##
|
||||
|
||||
sub print_usage () {
|
||||
print "\nUsage:\n";
|
||||
print "$PROGNAME\n";
|
||||
print " Usage: check_graph_nt -H host -v variable [-p port] [-s password] [-w warning] [-c critical] [-l params] [-d SHOWALL] [-t timeout] [-D rrd directory] -g -S ServiceID\n";
|
||||
print " Options:\n";
|
||||
print " -H, --hostname=HOST\n";
|
||||
print " Name of the host to check\n";
|
||||
print " -p, --port=INTEGER\n";
|
||||
print " Optional port number (default: 1248)\n";
|
||||
print " -s <password>\n";
|
||||
print " Password needed for the request\n";
|
||||
print " -v, --variable=STRING\n";
|
||||
print " Variable to check. Valid variables are:\n";
|
||||
print " CLIENTVERSION = Not Graphed. Get the NSClient version\n";
|
||||
print " CPULOAD = Average CPU load on last x minutes. Request a -l parameter with the following syntax:\n";
|
||||
print " -l <minutes range>,<warning threshold>,<critical threshold>. <minute range> should be less than 24*60.\n";
|
||||
print " Thresholds are percentage and up to 10 requests can be done in one shot. ie: -l 60,90,95,120,90,95\n";
|
||||
print " and 4 requests can be graphed.\n";
|
||||
print " UPTIME = Only Days are graphed. Get the uptime of the machine. No specific parameters. No warning or critical threshold.\n";
|
||||
print " USEDDISKSPACE = Size and percentage of disk use. Request a -l parameter containing the drive letter only.\n";
|
||||
print " Warning and critical thresholds can be specified with -w and -c.\n";
|
||||
print " MEMUSE = Memory use. Warning and critical thresholds can be specified with -w and -c.\n";
|
||||
print " SERVICESTATE = Check and graph the state of one service. Request a -l parameters with the following syntax:\n";
|
||||
print " -l <service1>... You MUST specify -d SHOWALL in the input command.\n";
|
||||
print " 1: Service Started - 0: Service Stopped - -1: Service Unknown.\n";
|
||||
# print " SERVICESTATE = Not Graphed. Check the state of one or several services. Request a -l parameters with the following syntax:\n";
|
||||
# print " -l <service1>,<service2>,<service3>,... You can specify -d SHOWALL in case you want to see working services\n";
|
||||
# print " in the returned string.\n";
|
||||
print " PROCSTATE = Not Graphed. Check if one or several process are running. Same syntax as SERVICESTATE.\n";
|
||||
print " COUNTER = Check any performance counter of Windows NT/2000. Request a -l parameters with the following syntax:\n";
|
||||
print " -l \"<performance object>counter\",\"<description>\" The <description> parameter is optional and\n";
|
||||
print " is given to a printf output command which require a float parameters. Some examples:\n";
|
||||
print " \"Paging file usage is %.2f %%\" or \"%.f %% paging file used.\"\n";
|
||||
print " -w, --warning=INTEGER\n";
|
||||
print " Threshold which will result in a warning status\n";
|
||||
print " -c, --critical=INTEGER\n";
|
||||
print " Threshold which will result in a critical status\n";
|
||||
print " -t, --timeout=INTEGER\n";
|
||||
print " Seconds before connection attempt times out (default: 10)\n";
|
||||
print " -h, --help\n";
|
||||
print " Print this help screen\n";
|
||||
print " -V, --version\n";
|
||||
print " Print version information\n";
|
||||
print " -g (--rrdgraph) create à rrd base and add datas into this one\n";
|
||||
print " --rrd_step Specifies the base interval in seconds with which data will be fed into the RRD (300 by default)\n";
|
||||
print " -D (--directory) Path to rrdatabase (or create the .rrd in this directory)\n";
|
||||
print " by default: ".$pathtorrdbase."\n";
|
||||
print " (The path is valid with spaces '/my\ path/...')\n";
|
||||
print " -S (--ServiceId) Oreon Service Id\n";
|
||||
}
|
||||
|
||||
sub print_help () {
|
||||
print "Copyright (c) 2004 OREON\n";
|
||||
print "Bugs to http://www.oreon.org/\n";
|
||||
print "\n";
|
||||
print_usage();
|
||||
print "\n";
|
||||
}
|
215
centreon-plugins/src/check_graph_ping.pl
Normal file
215
centreon-plugins/src/check_graph_ping.pl
Normal file
@ -0,0 +1,215 @@
|
||||
#! /usr/bin/perl -w
|
||||
#
|
||||
# $Id: check_graph_ping.pl,v 1.2 2006/04/28 10:21:49 Julien Mathis $
|
||||
#
|
||||
# Oreon's plugins are developped with GPL Licence :
|
||||
# http://www.fsf.org/licenses/gpl.txt
|
||||
# Developped by : Julien Mathis - Mathieu Mettre - 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.
|
||||
|
||||
#
|
||||
# Plugin init
|
||||
#
|
||||
|
||||
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 vars qw($PROGNAME);
|
||||
use Getopt::Long;
|
||||
use vars qw($opt_V $opt_h $opt_g $opt_H $opt_D $opt_w $opt_c $opt_n $opt_f $opt_S $rta_critical $rta_warning $pl_critical $pl_warning $opt_s $opt_step $step );
|
||||
|
||||
#
|
||||
# Plugin var init
|
||||
#
|
||||
|
||||
my $pathtorrdbase = $oreon{GLOBAL}{DIR_RRDTOOL};
|
||||
|
||||
my $ping = `whereis -b ping`;
|
||||
$ping =~ /^.*:\s(.*)$/;
|
||||
$ping = $1;
|
||||
|
||||
$PROGNAME = "check_graph_ping";
|
||||
sub print_help ();
|
||||
sub print_usage ();
|
||||
|
||||
Getopt::Long::Configure('bundling');
|
||||
GetOptions
|
||||
("h" => \$opt_h, "help" => \$opt_h,
|
||||
"V" => \$opt_V, "version" => \$opt_V,
|
||||
"rrd_step=s" => \$opt_step,"f" => \$opt_f,
|
||||
"g" => \$opt_g, "rrdgraph" => \$opt_g,
|
||||
"w=s" => \$opt_w, "warning=s" => \$opt_w,
|
||||
"c=s" => \$opt_c, "critical=s" => \$opt_c,
|
||||
"n=s" => \$opt_n, "number=s" => \$opt_n,
|
||||
"S=s" => \$opt_S, "ServiceId=s" => \$opt_S,
|
||||
"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);
|
||||
|
||||
($opt_c) || ($opt_c = shift) || ($opt_c = "500,40%");
|
||||
if ($opt_c =~ /([0-9]+),([0-9]+)%/) {
|
||||
$rta_critical = $1;
|
||||
$pl_critical = $2;
|
||||
}
|
||||
|
||||
($opt_w) || ($opt_w = shift) || ($opt_w = "200,20%");
|
||||
if ($opt_w =~ /([0-9]+),([0-9]+)%/) {
|
||||
$rta_warning = $1;
|
||||
$pl_warning = $2;
|
||||
}
|
||||
|
||||
if ( ($rta_critical <= $rta_warning) || ($pl_critical <= $pl_warning) ) {
|
||||
print "critical must be superior to warning\n";
|
||||
print_usage();
|
||||
exit $ERRORS{'OK'};
|
||||
}
|
||||
|
||||
($opt_n) || ($opt_n = shift) || ($opt_n = 1);
|
||||
my $NbPing;
|
||||
if ($opt_n =~ /([0-9]+)/){
|
||||
$NbPing = $1;
|
||||
} else{
|
||||
print "Unknown ping number\n";
|
||||
exit $ERRORS{'UNKNOWN'};
|
||||
}
|
||||
|
||||
($opt_S) || ($opt_S = shift) || ($opt_S = 1);
|
||||
my $rrd = $pathtorrdbase.is_valid_serviceid($opt_S).".rrd";
|
||||
|
||||
|
||||
($opt_step) || ($opt_step = shift) || ($opt_step = "300");
|
||||
$step = $1 if ($opt_step =~ /(\d+)/);
|
||||
|
||||
|
||||
my $start=time;
|
||||
|
||||
#
|
||||
# RRDTools create rrd
|
||||
#
|
||||
|
||||
if ($opt_g) {
|
||||
create_rrd($rrd,1,$start,$step,0,"U","GAUGE") if (! -e $rrd);}
|
||||
|
||||
#
|
||||
# Plugin requests
|
||||
#
|
||||
|
||||
$_ = `$ping -n -c $NbPing $opt_H 2>/dev/null`;
|
||||
my $return = $? / 256;
|
||||
|
||||
#
|
||||
# Get Data From Ping Result
|
||||
#
|
||||
|
||||
my $ping_result = $_;
|
||||
my @ping_result_array = split(/\n/,$ping_result);
|
||||
my @ping_subresult1_array;
|
||||
my @ping_subresult2_array;
|
||||
my $rta = 0;
|
||||
my $pl;
|
||||
my $time_answer;
|
||||
|
||||
if( ( $return != 0 ) || $ping_result_array[@ping_result_array -2 ] =~ /100% packet loss/) {
|
||||
$rta = -1;
|
||||
$time_answer = 0;
|
||||
} else {
|
||||
@ping_subresult1_array = split(/=/,$ping_result_array[@ping_result_array -1 ]);
|
||||
@ping_subresult2_array = split(/,/,$ping_result_array[@ping_result_array -2 ]);
|
||||
@ping_subresult1_array = split(/\//,$ping_subresult1_array[1]);
|
||||
@ping_subresult2_array = split(/ /,$ping_subresult2_array[2]);
|
||||
$rta = $ping_subresult1_array[1];
|
||||
$pl = $ping_subresult2_array[1];
|
||||
$time_answer = $ping_subresult1_array[1];
|
||||
$pl =~ /([0-9]+)\%/;
|
||||
$pl = $1;
|
||||
}
|
||||
|
||||
#
|
||||
# Update RRDTool Database.
|
||||
#
|
||||
|
||||
update_rrd($rrd,$start,$rta) if ($opt_g);
|
||||
|
||||
#
|
||||
# Plugin return code
|
||||
#
|
||||
|
||||
my $result_str = "";
|
||||
|
||||
if( $rta == -1 ) {
|
||||
$ping_result_array[@ping_result_array -2 ] =~ s/\%/percent/g;
|
||||
print "GPING CRITICAL - ".$ping_result_array[@ping_result_array -2 ]."|time=0 ok=0\n";
|
||||
exit $ERRORS{'CRITICAL'};
|
||||
} 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 "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) ) {
|
||||
$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";
|
||||
exit $ERRORS{'WARNING'};
|
||||
} else {
|
||||
$ping_result_array[@ping_result_array -1 ] =~ s/\%/percent/g;
|
||||
my @tab = split(/,/,$ping_result_array[@ping_result_array -1 ]);
|
||||
print "GPING OK - ".$tab[0]."|time=".$time_answer."ms;$pl_warning;$pl_critical;; ok=1\n";
|
||||
exit $ERRORS{'OK'};
|
||||
}
|
||||
|
||||
sub print_usage () {
|
||||
print "Usage:\n";
|
||||
print "$PROGNAME\n";
|
||||
print " -H (--hostname) Hostname to query (Required)\n";
|
||||
print " -g (--rrdgraph) Create a rrd base if necessary and add datas into this one\n";
|
||||
print " --rrd_step Specifies the base interval in seconds with which data will be fed into the RRD (300 by default)\n";
|
||||
print " -S (--ServiceId) Oreon Service Id\n";
|
||||
print " -w (--warning) Threshold pair (Default: 200,20%)\n";
|
||||
print " -c (--critical) Threshold pair (Default: 500,40%)\n";
|
||||
print " -n (--number) number of ICMP ECHO packets to send (Default: 1)\n";
|
||||
print " -V (--version) Plugin version\n";
|
||||
print " -h (--help) usage help\n";
|
||||
}
|
||||
|
||||
sub print_help () {
|
||||
print "######################################################\n";
|
||||
print "# Copyright (c) 2004-2006 Oreon-project #\n";
|
||||
print "# Bugs to http://www.oreon-project.org/ #\n";
|
||||
print "######################################################\n";
|
||||
print_usage();
|
||||
print "\n";
|
||||
}
|
232
centreon-plugins/src/check_graph_process.pl
Normal file
232
centreon-plugins/src/check_graph_process.pl
Normal file
@ -0,0 +1,232 @@
|
||||
#! /usr/bin/perl -w
|
||||
#
|
||||
# $Id: check_graph_process.pl,v 1.2 2005/07/27 22:21:49 wistof Exp $
|
||||
#
|
||||
# Oreon's plugins are developped with GPL Licence :
|
||||
# http://www.fsf.org/licenses/gpl.txt
|
||||
# Developped by : Julien Mathis - Mathieu Mettre - Romain Le Merlus
|
||||
#
|
||||
# Modified for Oreon Project by : Mathieu Chateau - Christophe Coraboeuf
|
||||
#
|
||||
# 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.
|
||||
|
||||
##
|
||||
## Plugin init
|
||||
##
|
||||
use strict;
|
||||
use Net::SNMP qw(:snmp oid_lex_sort);
|
||||
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 vars qw($PROGNAME);
|
||||
use Getopt::Long;
|
||||
use vars qw($opt_V $opt_h $opt_g $opt_v $opt_C $opt_p $opt_H $opt_D $opt_n $opt_S $opt_step $step $result @result %process_list %STATUS $opt_f);
|
||||
my $pathtorrdbase = $oreon{GLOBAL}{DIR_RRDTOOL};
|
||||
|
||||
##
|
||||
## Plugin var init
|
||||
##
|
||||
|
||||
my($proc, $proc_run);
|
||||
|
||||
$PROGNAME = "check_graph_process";
|
||||
sub print_help ();
|
||||
sub print_usage ();
|
||||
|
||||
|
||||
%STATUS=(1=>'running',2=>'runnable',3=>'notRunnable',4=>'invalid');
|
||||
|
||||
Getopt::Long::Configure('bundling');
|
||||
GetOptions
|
||||
("h" => \$opt_h, "help" => \$opt_h,
|
||||
"V" => \$opt_V, "version" => \$opt_V,
|
||||
"g" => \$opt_g, "rrdgraph" => \$opt_g,
|
||||
"rrd_step=s" => \$opt_step, "f" => \$opt_f,
|
||||
"n" => \$opt_n, "number" => \$opt_n,
|
||||
"v=s" => \$opt_v, "snmp=s" => \$opt_v,
|
||||
"C=s" => \$opt_C, "community=s" => \$opt_C,
|
||||
"p=s" => \$opt_p, "process=s" => \$opt_p,
|
||||
"S=s" => \$opt_S, "ServiceId=s" => \$opt_S,
|
||||
"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);
|
||||
|
||||
($opt_v) || ($opt_v = shift) || ($opt_v = "1");
|
||||
my $snmp = $1 if ($opt_v =~ /(\d)/);
|
||||
|
||||
($opt_S) || ($opt_S = shift) || ($opt_S = 1);
|
||||
my $ServiceId = is_valid_serviceid($opt_S);
|
||||
|
||||
($opt_C) || ($opt_C = shift) || ($opt_C = "public");
|
||||
|
||||
my $process = "";
|
||||
if ($opt_p){
|
||||
$process = $1 if ($opt_p =~ /([-.A-Za-z0-9]+)/);
|
||||
}
|
||||
|
||||
($opt_step) || ($opt_step = shift) || ($opt_step = "300");
|
||||
$step = $1 if ($opt_step =~ /(\d+)/);
|
||||
|
||||
|
||||
my $rrd = $pathtorrdbase.$ServiceId.".rrd";
|
||||
my $start=time;
|
||||
my $name = $0;
|
||||
$name =~ s/\.pl.*//g;
|
||||
|
||||
##
|
||||
## RRDTools create rrd
|
||||
##
|
||||
|
||||
if ( $opt_g && $opt_n && (! -e $rrd)) {
|
||||
create_rrd ($rrd,1,$start,$step,"U","U","GAUGE");
|
||||
}
|
||||
|
||||
##
|
||||
## Plugin snmp requests
|
||||
##
|
||||
my $OID_SW_RunName = $oreon{MIB2}{SW_RUNNAME};
|
||||
my $OID_SW_RunIndex =$oreon{MIB2}{SW_RUNINDEX};
|
||||
my $OID_SW_RunStatus =$oreon{MIB2}{SW_RUNSTATUS};
|
||||
|
||||
my ( $session, $error ) = Net::SNMP->session(-hostname => $opt_H,-community => $opt_C, -version => $snmp);
|
||||
if ( !defined($session) ) {
|
||||
print("UNKNOWN: $error");
|
||||
exit $ERRORS{'UNKNOWN'};
|
||||
}
|
||||
|
||||
$result = $session->get_table(Baseoid => $OID_SW_RunName);
|
||||
if (!defined($result)) {
|
||||
printf("UNKNOWN: %s.\n", $session->error);
|
||||
$session->close;
|
||||
exit $ERRORS{'UNKNOWN'};
|
||||
}
|
||||
|
||||
$proc = 0;
|
||||
foreach my $key (oid_lex_sort(keys %$result)) {
|
||||
my @oid_list = split (/\./,$key);
|
||||
$process_list{$$result{$key}} = pop (@oid_list) ;
|
||||
if (defined($opt_p) && $opt_p ne ""){
|
||||
if ($$result{$key} eq $opt_p){
|
||||
$proc++;
|
||||
}
|
||||
} else {
|
||||
$proc++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (!($opt_n))
|
||||
{
|
||||
if ($process_list{$process}) {
|
||||
$result = $session->get_request(-varbindlist => [$OID_SW_RunStatus . "." . $process_list{$process}]);
|
||||
if (!defined($result)) {
|
||||
printf("UNKNOWN: %s.\n", $session->error);
|
||||
$session->close;
|
||||
exit $ERRORS{'UNKNOWN'};
|
||||
}
|
||||
$proc_run = $result->{$OID_SW_RunStatus . "." . $process_list{$process} };
|
||||
print $proc_run;
|
||||
}
|
||||
}
|
||||
|
||||
##
|
||||
## RRDtools update
|
||||
##
|
||||
|
||||
if ( $opt_g && $opt_n) {
|
||||
$start=time;
|
||||
my $totrrd;
|
||||
if ($opt_n){$totrrd = $proc;}
|
||||
else{
|
||||
if ( ($proc_run == "3") || ($proc_run == "4") ){$totrrd = 0;}
|
||||
else{$totrrd = 1;}
|
||||
}
|
||||
update_rrd ($rrd,$start,$totrrd);
|
||||
}
|
||||
|
||||
##
|
||||
## Plugin return code
|
||||
##
|
||||
|
||||
my $PERFPARSE = "";
|
||||
|
||||
if ($opt_n){
|
||||
if ($opt_f){
|
||||
$PERFPARSE = "|nbproc=$proc";
|
||||
}
|
||||
print "Processes OK - Number of current processes: $proc".$PERFPARSE."\n";
|
||||
exit $ERRORS{'OK'};
|
||||
} else {
|
||||
if ($proc_run){
|
||||
if ($opt_f){
|
||||
$PERFPARSE = "|procstatus=$proc_run";
|
||||
}
|
||||
print "Process OK - $process: $STATUS{$proc_run}".$PERFPARSE."\n";
|
||||
exit $ERRORS{'OK'};
|
||||
} else {
|
||||
print "Process CRITICAL - $process not in 'running' state\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 " -g (--rrdgraph) create à rrd base and add datas into this one\n";
|
||||
print " --rrd_step Specifies the base interval in seconds with which data will be fed into the RRD (300 by default)\n";
|
||||
print " -D (--directory) Path to rrdatabase (or create the .rrd in this directory)\n";
|
||||
print " by default: ".$pathtorrdbase."\n";
|
||||
print " (The path is valid with spaces '/my\ path/...')\n";
|
||||
print " -n (--number) Return the number of current running processes. \n";
|
||||
print " -p (--process) Set the process name ex: by default smbd\n";
|
||||
print " -S (--ServiceId) Oreon Service Id\n";
|
||||
print " -V (--version) Plugin version\n";
|
||||
print " -h (--help) usage help\n";
|
||||
print " -f Perfparse Compatible\n";
|
||||
}
|
||||
|
||||
|
||||
sub print_help () {
|
||||
print "##########################################\n";
|
||||
print "# Copyright (c) 2004-2006 Oreon #\n";
|
||||
print "# Bugs to http://www.oreon-project.org/ #\n";
|
||||
print "##########################################\n";
|
||||
print_usage();
|
||||
print "\n";
|
||||
}
|
||||
|
333
centreon-plugins/src/check_graph_remote_storage.pl
Normal file
333
centreon-plugins/src/check_graph_remote_storage.pl
Normal file
@ -0,0 +1,333 @@
|
||||
#! /usr/bin/perl -w
|
||||
#
|
||||
# $Id: check_graph_remote_storage.pl,v 1.2 2005/07/27 22:21:49 wistof Exp $
|
||||
#
|
||||
# Oreon's plugins are developped with GPL Licence :
|
||||
# http://www.fsf.org/licenses/gpl.txt
|
||||
# Developped by : Julien Mathis - Mathieu Mettre - Romain Le Merlus - Yohann Lecarpentier
|
||||
#
|
||||
# Modified for Oreon Project by : Mathieu Chateau - Christophe Coraboeuf
|
||||
#
|
||||
# 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.
|
||||
|
||||
##
|
||||
## Plugin init
|
||||
##
|
||||
|
||||
use strict;
|
||||
use Net::SNMP qw(:snmp);
|
||||
use FindBin;
|
||||
use lib "$FindBin::Bin";
|
||||
use lib "/srv/nagios/libexec";
|
||||
#use lib "/usr/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 vars qw($PROGNAME);
|
||||
use Getopt::Long;
|
||||
use vars qw($opt_V $opt_h $opt_g $opt_v $opt_C $opt_d $opt_n $opt_w $opt_c $opt_H $opt_S $opt_D $opt_s $opt_step $step @test $opt_f);
|
||||
my $pathtorrdbase = $oreon{GLOBAL}{DIR_RRDTOOL};
|
||||
|
||||
##
|
||||
## 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,
|
||||
"g" => \$opt_g, "rrdgraph" => \$opt_g,
|
||||
"rrd_step=s" => \$opt_step, "f" => \$opt_f,
|
||||
"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,
|
||||
"S=s" => \$opt_S, "ServiceId=s" => \$opt_S,
|
||||
"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_S) || ($opt_S = shift) || ($opt_S = "1_1");
|
||||
my $ServiceId = is_valid_serviceid($opt_S);
|
||||
|
||||
($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 $rrd = $pathtorrdbase.$ServiceId.".rrd";
|
||||
my $start=time;
|
||||
my $name = $0;
|
||||
$name =~ s/\.pl.*//g;
|
||||
|
||||
##
|
||||
## RRDTools create rrd
|
||||
##
|
||||
if ($opt_g) {
|
||||
if (! -e $rrd) {
|
||||
create_rrd ($rrd,2,$start,$step,"U","U","GAUGE");
|
||||
}
|
||||
}
|
||||
|
||||
##
|
||||
## 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;
|
||||
|
||||
##
|
||||
## RRDtools update
|
||||
##
|
||||
|
||||
$start=time;
|
||||
my $totrrd = $tot * 1073741824;
|
||||
|
||||
if ($opt_g) {
|
||||
update_rrd ($rrd,$start,$totrrd,$used);
|
||||
}
|
||||
|
||||
##
|
||||
## 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 " -g (--rrdgraph) create a rrd base and add datas into this one\n";
|
||||
print " --rrd_step Specifies the base interval in seconds with which data will be fed into the RRD (300 by default)\n";
|
||||
print " -D (--directory) Path to rrdatabase (or create the .rrd in this directory)\n";
|
||||
print " by default: ".$pathtorrdbase."\n";
|
||||
print " (The path is valid with spaces '/my\ path/...')\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 " -f Perfparse Compatible\n";
|
||||
print " -S (--ServiceId) Oreon Service Id\n";
|
||||
print " -V (--version) Plugin version\n";
|
||||
print " -h (--help) usage help\n";
|
||||
|
||||
}
|
||||
|
||||
sub print_help () {
|
||||
print "##########################################\n";
|
||||
print "# Copyright (c) 2004-2006 Oreon #\n";
|
||||
print "# Bugs to http://www.oreon-project.org/ #\n";
|
||||
print "##########################################\n";
|
||||
print_usage();
|
||||
print "\n";
|
||||
}
|
195
centreon-plugins/src/check_graph_snmp_value.pl
Normal file
195
centreon-plugins/src/check_graph_snmp_value.pl
Normal file
@ -0,0 +1,195 @@
|
||||
#! /usr/bin/perl -w
|
||||
#
|
||||
# $Id: check_snmp_value.pl,v 1.2 2005/11/17 10:21:49 Julien Mathis $
|
||||
#
|
||||
# This plugin is developped under GPL Licence:
|
||||
# http://www.fsf.org/licenses/gpl.txt
|
||||
#
|
||||
# Developped by Merethis SARL : http://www.merethis.com
|
||||
#
|
||||
# The Software is provided to you AS IS and WITH ALL FAULTS.
|
||||
# MERETHIS 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 LINAGORA web site.
|
||||
# In no event will MERETHIS be liable for any direct, indirect, punitive, special,
|
||||
# incidental or consequential damages however they may arise and even if MERETHIS has
|
||||
# been previously advised of the possibility of such damages.
|
||||
|
||||
##
|
||||
## Plugin 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);
|
||||
|
||||
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 vars qw($PROGNAME);
|
||||
use Getopt::Long;
|
||||
use vars qw($opt_h $opt_V $opt_g $opt_D $opt_S $opt_H $opt_C $opt_v $opt_o $opt_c $opt_w $opt_f $opt_t);
|
||||
use vars qw($ServiceId $rrd $snmp $DS_type);
|
||||
my $pathtorrdbase = $oreon{GLOBAL}{DIR_RRDTOOL};
|
||||
|
||||
$PROGNAME = $0;
|
||||
sub print_help ();
|
||||
sub print_usage ();
|
||||
|
||||
Getopt::Long::Configure('bundling');
|
||||
GetOptions
|
||||
("h" => \$opt_h, "help" => \$opt_h,
|
||||
"V" => \$opt_V, "version" => \$opt_V,
|
||||
"g" => \$opt_g, "rrdgraph" => \$opt_g,
|
||||
"f" => \$opt_f,
|
||||
"v=s" => \$opt_v, "snmp=s" => \$opt_v,
|
||||
"C=s" => \$opt_C, "community=s" => \$opt_C,
|
||||
"S=s" => \$opt_S, "ServiceId=s" => \$opt_S,
|
||||
"o=s" => \$opt_o, "oid=s" => \$opt_o,
|
||||
"t=s" => \$opt_t, "type=s" => \$opt_t,
|
||||
"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);
|
||||
|
||||
($opt_v) || ($opt_v = shift) || ($opt_v = "1");
|
||||
my $snmp = $1 if ($opt_v =~ /(\d)/);
|
||||
|
||||
($opt_S) || ($opt_S = shift) || ($opt_S = "1_1");
|
||||
my $ServiceId = is_valid_serviceid($opt_S);
|
||||
|
||||
($opt_C) || ($opt_C = shift) || ($opt_C = "public");
|
||||
my $rrd = $pathtorrdbase.$ServiceId.".rrd";
|
||||
|
||||
($opt_t) || ($opt_t = shift) || ($opt_t = "GAUGE");
|
||||
my $DS_type = $1 if ($opt_t =~ /(GAUGE)/ || $opt_t =~ /(COUNTER)/);
|
||||
|
||||
($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'};
|
||||
}
|
||||
|
||||
|
||||
|
||||
my $start=time;
|
||||
my $name = $0;
|
||||
$name =~ s/\.pl.*//g;
|
||||
my $day = 0;
|
||||
|
||||
|
||||
#=== RRDTools create rrd ====
|
||||
|
||||
|
||||
if ($opt_g) {
|
||||
if (! -e $rrd) {
|
||||
create_rrd($rrd,1,$start,300,"U","U",$DS_type);
|
||||
}
|
||||
}
|
||||
|
||||
#=== create a SNMP session ====
|
||||
|
||||
my ($session, $error) = Net::SNMP->session(-hostname => $opt_H,-community => $opt_C, -version => $snmp);
|
||||
if (!defined($session)) {
|
||||
print("CRITICAL: $error");
|
||||
exit $ERRORS{'CRITICAL'};
|
||||
}
|
||||
|
||||
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};
|
||||
|
||||
#=== RRDtools update ====
|
||||
|
||||
if ($opt_g) {
|
||||
$start=time;
|
||||
update_rrd($rrd,$start,$return_result);
|
||||
}
|
||||
|
||||
#=== Plugin return code ====
|
||||
if (defined($return_result)){
|
||||
if ($opt_w && $opt_c && $return_result < $opt_w){
|
||||
print "Ok value : " . $return_result;
|
||||
if ($opt_f){ print "|value=".$return_result.";".$opt_w.";".$opt_c.";;";}
|
||||
print "\n";
|
||||
exit $ERRORS{'OK'};
|
||||
} elsif ($opt_w && $opt_c && $return_result >= $opt_w && $return_result < $opt_c){
|
||||
print "Warning value : " . $return_result;
|
||||
if ($opt_f){ print "|value=$return_result;".$opt_w.";".$opt_c.";;";}
|
||||
print "\n";
|
||||
exit $ERRORS{'WARNING'};
|
||||
} elsif ($opt_w && $opt_c && $return_result >= $opt_c){
|
||||
print "Critical value : " . $return_result;
|
||||
if ($opt_f){ print "|value=".$return_result.";".$opt_w.";".$opt_c.";;";}
|
||||
print "\n";
|
||||
exit $ERRORS{'CRITICAL'};
|
||||
}
|
||||
} else {
|
||||
print "CRITICAL Host unavailable\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 " -t (--type) Data Source Type (GAUGE or COUNTER) (GAUGE by default)\n";
|
||||
print " -g (--rrdgraph) create a rrd base and add datas into this one\n";
|
||||
print " -D (--directory) Path to rrdatabase (or create the .rrd in this directory)\n";
|
||||
print " by default: ".$pathtorrdbase."\n";
|
||||
print " (The path is valid with spaces '/my\ path/...')\n";
|
||||
print " -S (--ServiceId) Oreon Service Id\n";
|
||||
print " -o (--oid) OID to check\n";
|
||||
print " -w (--warning) Warning level\n";
|
||||
print " -c (--critical) Critical level\n";
|
||||
print " -V (--version) Plugin version\n";
|
||||
print " -h (--help) usage help\n";
|
||||
print " -f Perfparse Compatible\n";
|
||||
}
|
||||
|
||||
sub print_help () {
|
||||
print "#=========================================\n";
|
||||
print "# Copyright (c) 2005 Merethis SARL =\n";
|
||||
print "# Developped by Julien Mathis =\n";
|
||||
print "# Bugs to http://www.oreon-project.org/ =\n";
|
||||
print "#=========================================\n";
|
||||
print_usage();
|
||||
print "\n";
|
||||
}
|
135
centreon-plugins/src/check_graph_tcp.pl
Normal file
135
centreon-plugins/src/check_graph_tcp.pl
Normal file
@ -0,0 +1,135 @@
|
||||
#! /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 lib "/usr/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";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
451
centreon-plugins/src/check_graph_traffic.pl
Normal file
451
centreon-plugins/src/check_graph_traffic.pl
Normal file
@ -0,0 +1,451 @@
|
||||
#! /usr/bin/perl -w
|
||||
#
|
||||
# $Id: check_graph_traffic.pl,v 1.2 2005/07/27 22:21:49 Julio $
|
||||
#
|
||||
# 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.
|
||||
|
||||
#
|
||||
# Plugin init
|
||||
#
|
||||
|
||||
use strict;
|
||||
use Net::SNMP qw(:snmp oid_lex_sort);
|
||||
use FindBin;
|
||||
use lib "$FindBin::Bin";
|
||||
use lib "/srv/nagios/libexec";
|
||||
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 vars qw($VERSION %oreon);
|
||||
use vars qw(%oreon);
|
||||
$VERSION = '$Revision: 1.2 $';
|
||||
$VERSION =~ s/^\$.*:\W(.*)\W.+?$/$1/;
|
||||
|
||||
use vars qw($PROGNAME);
|
||||
use Getopt::Long;
|
||||
use vars qw($opt_V $opt_h $opt_g $opt_v $opt_C $opt_b $opt_H $opt_D $opt_i $opt_n $opt_w $opt_c $opt_s $opt_S $opt_T $opt_step $step);
|
||||
|
||||
my $pathtorrdbase = $oreon{GLOBAL}{DIR_RRDTOOL};
|
||||
|
||||
#
|
||||
# Plugin var init
|
||||
#
|
||||
|
||||
my($proc, $proc_run, @test, $row, @laste_values, $last_check_time, $last_in_bits, $last_out_bits, @last_values, $update_time, $db_file, $in_traffic, $out_traffic, $in_usage, $out_usage);
|
||||
my $pathtolibexecnt = $oreon{NAGIOS_LIBEXEC};
|
||||
|
||||
$PROGNAME = "check_graph_traffic";
|
||||
sub print_help ();
|
||||
sub print_usage ();
|
||||
|
||||
Getopt::Long::Configure('bundling');
|
||||
GetOptions
|
||||
("h" => \$opt_h, "help" => \$opt_h,
|
||||
"s" => \$opt_s, "show" => \$opt_s,
|
||||
"V" => \$opt_V, "version" => \$opt_V,
|
||||
"g" => \$opt_g, "rrdgraph" => \$opt_g,
|
||||
"rrd_step=s" => \$opt_step,
|
||||
"i=s" => \$opt_i, "interface=s" => \$opt_i,
|
||||
"n" => \$opt_n, "name" => \$opt_n,
|
||||
"v=s" => \$opt_v, "snmp=s" => \$opt_v,
|
||||
"C=s" => \$opt_C, "community=s" => \$opt_C,
|
||||
"b=s" => \$opt_b, "bps=s" => \$opt_b,
|
||||
"w=s" => \$opt_w, "warning=s" => \$opt_w,
|
||||
"c=s" => \$opt_c, "critical=s" => \$opt_c,
|
||||
"S=s" => \$opt_S, "ServiceId=s" => \$opt_S,
|
||||
"T=s" => \$opt_T,
|
||||
"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'};
|
||||
}
|
||||
|
||||
##################################################
|
||||
##### Verify Options
|
||||
##
|
||||
|
||||
$opt_H = shift unless ($opt_H);
|
||||
(print_usage() && exit $ERRORS{'OK'}) unless ($opt_H);
|
||||
|
||||
($opt_v) || ($opt_v = shift) || ($opt_v = "1");
|
||||
my $snmp = $1 if ($opt_v =~ /(\d)/);
|
||||
|
||||
if ($opt_n && !$opt_i) {
|
||||
print "Option -n (--name) need option -i (--interface)\n";
|
||||
exit $ERRORS{'UNKNOWN'};
|
||||
}
|
||||
|
||||
($opt_C) || ($opt_C = shift) || ($opt_C = "public");
|
||||
($opt_i) || ($opt_i = shift) || ($opt_i = 2);
|
||||
($opt_S) || ($opt_S = shift) || ($opt_S = 1);
|
||||
my $ServiceId = is_valid_serviceid($opt_S);
|
||||
|
||||
($opt_b) || ($opt_b = shift) || ($opt_b = 95);
|
||||
my $bps = $1 if ($opt_b =~ /([0-9]+)/);
|
||||
|
||||
($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]+)/);
|
||||
|
||||
my $interface = 0;
|
||||
if ($opt_i =~ /([0-9]+)/ && !$opt_n){
|
||||
$interface = $1;
|
||||
} elsif (!$opt_n) {
|
||||
print "Unknown -i number expected... or it doesn't exist, try another interface - number\n";
|
||||
exit $ERRORS{'UNKNOWN'};
|
||||
}
|
||||
|
||||
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+)/);
|
||||
|
||||
##################################################
|
||||
##### RRDTool var init
|
||||
##
|
||||
|
||||
my $rrd = $pathtorrdbase.$ServiceId.".rrd";
|
||||
my $start=time;
|
||||
|
||||
##################################################
|
||||
##### RRDTool create rrd
|
||||
##
|
||||
|
||||
if ($opt_g) {
|
||||
if (! -e $rrd) {
|
||||
create_rrd ($rrd,2,$start,$step,"U","U","GAUGE");
|
||||
}
|
||||
}
|
||||
|
||||
#################################################
|
||||
##### Plugin snmp requests
|
||||
##
|
||||
|
||||
my $OID_DESC =$oreon{MIB2}{IF_DESC};
|
||||
|
||||
# create a SNMP session
|
||||
|
||||
my ($session, $error) = Net::SNMP->session(-hostname => $opt_H, -community => $opt_C, -version => $snmp);
|
||||
if (!defined($session)) {
|
||||
print("UNKNOWN: SNMP Session : $error");
|
||||
exit $ERRORS{'UNKNOWN'};
|
||||
}
|
||||
|
||||
#getting interface using its name instead of its oid index
|
||||
|
||||
if ($opt_n) {
|
||||
my $result = $session->get_table(Baseoid => $OID_DESC);
|
||||
if (!defined($result)) {
|
||||
printf("ERROR: Description Table : %s.\n", $session->error);
|
||||
$session->close;
|
||||
exit $ERRORS{'UNKNOWN'};
|
||||
}
|
||||
foreach my $key ( oid_lex_sort(keys %$result)) {
|
||||
if ($result->{$key} =~ m/$opt_i/) {
|
||||
my @oid_list = split (/\./,$key);
|
||||
$interface = pop (@oid_list) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
my $OID_IN =$oreon{MIB2}{IF_IN_OCTET}.".".$interface;
|
||||
my $OID_OUT = $oreon{MIB2}{IF_OUT_OCTET}.".".$interface;
|
||||
my $OID_SPEED = $oreon{MIB2}{IF_SPEED}.".".$interface;
|
||||
|
||||
# Get desctiption table
|
||||
|
||||
if ($opt_s) {
|
||||
my $result = $session->get_table(Baseoid => $OID_DESC);
|
||||
if (!defined($result)) {
|
||||
printf("ERROR: Description 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 "Interface $index :: $$result{$key}\n";
|
||||
}
|
||||
exit $ERRORS{'OK'};
|
||||
}
|
||||
|
||||
|
||||
####### Get IN bytes
|
||||
|
||||
my $in_bits;
|
||||
my $result = $session->get_request(-varbindlist => [$OID_IN]);
|
||||
if (!defined($result)) {
|
||||
printf("ERROR: IN Bits : %s", $session->error);
|
||||
if ($opt_n) { print " - You must specify interface name when option -n is used";}
|
||||
print ".\n";
|
||||
$session->close;
|
||||
exit $ERRORS{'UNKNOWN'};
|
||||
}
|
||||
$in_bits = $result->{$OID_IN} * 8;
|
||||
|
||||
|
||||
####### Get OUT bytes
|
||||
|
||||
my $out_bits;
|
||||
$result = $session->get_request(-varbindlist => [$OID_OUT]);
|
||||
if (!defined($result)) {
|
||||
printf("ERROR: Out Bits : %s", $session->error);
|
||||
if ($opt_n) { print " - You must specify interface name when option -n is used";}
|
||||
print ".\n";
|
||||
$session->close;
|
||||
exit $ERRORS{'UNKNOWN'};
|
||||
}
|
||||
$out_bits = $result->{$OID_OUT} * 8;
|
||||
|
||||
|
||||
####### Get SPEED of interface
|
||||
|
||||
my $speed_card;
|
||||
$result = $session->get_request(-varbindlist => [$OID_SPEED]);
|
||||
if (!defined($result)) {
|
||||
printf("ERROR: Interface Speed : %s", $session->error);
|
||||
if ($opt_n) { print " - You must specify interface name when option -n is used";}
|
||||
print ".\n";
|
||||
$session->close;
|
||||
exit $ERRORS{'UNKNOWN'};
|
||||
}
|
||||
|
||||
if (defined($opt_T)){
|
||||
$speed_card = $opt_T * 1000000;
|
||||
} else {
|
||||
$speed_card = $result->{$OID_SPEED};
|
||||
}
|
||||
#############################################
|
||||
##### Plugin return code
|
||||
##
|
||||
|
||||
$last_in_bits = 0;
|
||||
$last_out_bits = 0;
|
||||
|
||||
my $flg_created;
|
||||
|
||||
if (-e "/tmp/traffic_if".$interface."_".$opt_H) {
|
||||
open(FILE,"<"."/tmp/traffic_if".$interface."_".$opt_H);
|
||||
while($row = <FILE>){
|
||||
@last_values = split(":",$row);
|
||||
$last_check_time = $last_values[0];
|
||||
$last_in_bits = $last_values[1];
|
||||
$last_out_bits = $last_values[2];
|
||||
$flg_created = 1;
|
||||
}
|
||||
close(FILE);
|
||||
} else {
|
||||
$flg_created = 0;
|
||||
}
|
||||
|
||||
$update_time = time;
|
||||
|
||||
unless (open(FILE,">"."/tmp/traffic_if".$interface."_".$opt_H)){
|
||||
print "Unknown - /tmp/traffic_if".$interface."_".$opt_H. " !\n";
|
||||
exit $ERRORS{"UNKNOWN"};
|
||||
}
|
||||
print FILE "$update_time:$in_bits:$out_bits";
|
||||
close(FILE);
|
||||
|
||||
if ($flg_created eq 0){
|
||||
print "First execution : Buffer in creation.... \n";
|
||||
exit($ERRORS{"UNKNOWN"});
|
||||
}
|
||||
|
||||
|
||||
## Bandwith = IN + OUT / Delta(T) = 6 Mb/s
|
||||
## (100 * Bandwith) / (2(si full duplex) * Ispeed)
|
||||
## Count must round at 4294967296
|
||||
##
|
||||
|
||||
if (($in_bits - $last_in_bits > 0) && defined($last_in_bits)) {
|
||||
my $total = 0;
|
||||
if ($in_bits - $last_in_bits < 0){
|
||||
$total = 4294967296 - $last_in_bits + $in_bits;
|
||||
} else {
|
||||
$total = $in_bits - $last_in_bits;
|
||||
}
|
||||
my $pct_in_traffic = $in_traffic = abs($total / (time - $last_check_time));
|
||||
} else {
|
||||
$in_traffic = 0;
|
||||
}
|
||||
|
||||
if ($out_bits - $last_out_bits > 0 && defined($last_out_bits)) {
|
||||
my $total = 0;
|
||||
if ($out_bits - $last_out_bits < 0){
|
||||
$total = 4294967296 - $last_out_bits + $out_bits;
|
||||
} else {
|
||||
$total = $out_bits - $last_out_bits;
|
||||
}
|
||||
my $pct_out_traffic = $out_traffic = abs($total / (time - $last_check_time));
|
||||
} else {
|
||||
$out_traffic = 0;
|
||||
}
|
||||
|
||||
if ( $speed_card != 0 ) {
|
||||
$in_usage = sprintf("%.1f",($in_traffic*100) / $speed_card);
|
||||
$out_usage = sprintf("%.1f",($out_traffic*100) / $speed_card);
|
||||
## RRDtools update
|
||||
if ($opt_g) {
|
||||
$start = time;
|
||||
update_rrd($rrd,$start, sprintf("%.1f",abs($in_traffic)), sprintf("%.1f",abs($out_traffic)));
|
||||
}
|
||||
}
|
||||
|
||||
my $in_prefix = "";
|
||||
my $out_prefix = "";
|
||||
|
||||
my $in_perfparse_traffic = $in_traffic;
|
||||
my $out_perfparse_traffic = $out_traffic;
|
||||
|
||||
if ($in_traffic > 1000) {
|
||||
$in_traffic = $in_traffic / 1000;
|
||||
$in_prefix = "k";
|
||||
if($in_traffic > 1000){
|
||||
$in_traffic = $in_traffic / 1000;
|
||||
$in_prefix = "M";
|
||||
}
|
||||
if($in_traffic > 1000){
|
||||
$in_traffic = $in_traffic / 1000;
|
||||
$in_prefix = "G";
|
||||
}
|
||||
}
|
||||
|
||||
if ($out_traffic > 1000){
|
||||
$out_traffic = $out_traffic / 1000;
|
||||
$out_prefix = "k";
|
||||
if ($out_traffic > 1000){
|
||||
$out_traffic = $out_traffic / 1000;
|
||||
$out_prefix = "M";
|
||||
}
|
||||
if ($out_traffic > 1000){
|
||||
$out_traffic = $out_traffic / 1000;
|
||||
$out_prefix = "G";
|
||||
}
|
||||
}
|
||||
|
||||
my $in_bits_unit = "";
|
||||
$in_bits = $in_bits/1048576;
|
||||
if ($in_bits > 1000){
|
||||
$in_bits = $in_bits / 1000;
|
||||
$in_bits_unit = "G";
|
||||
} else {
|
||||
$in_bits_unit = "M";
|
||||
}
|
||||
|
||||
my $out_bits_unit = "";
|
||||
$out_bits = $out_bits/1048576;
|
||||
if ($out_bits > 1000){
|
||||
$out_bits = $out_bits / 1000;
|
||||
$out_bits_unit = "G";
|
||||
} else {
|
||||
$out_bits_unit = "M";
|
||||
}
|
||||
|
||||
|
||||
if ( $speed_card == 0 ) {
|
||||
print "CRITICAL: Interface speed equal 0! Interface must be down.|traffic_in=0B/s traffic_out=0B/s\n";
|
||||
exit($ERRORS{"CRITICAL"});
|
||||
}
|
||||
|
||||
#####################################
|
||||
##### Display result
|
||||
##
|
||||
|
||||
|
||||
my $in_perfparse_traffic_str = sprintf("%.1f",abs($in_perfparse_traffic));
|
||||
my $out_perfparse_traffic_str = sprintf("%.1f",abs($out_perfparse_traffic));
|
||||
|
||||
$in_perfparse_traffic_str =~ s/\./,/g;
|
||||
$out_perfparse_traffic_str =~ s/\./,/g;
|
||||
|
||||
my $status = "OK";
|
||||
|
||||
if (($in_usage > $critical) or ($out_usage > $critical)){
|
||||
$status = "CRITICAL";
|
||||
}
|
||||
|
||||
if(($in_usage > $warning) or ($out_usage > $warning)){
|
||||
$status = "WARNING";
|
||||
}
|
||||
|
||||
|
||||
printf("Traffic In : %.2f ".$in_prefix."b/s (".$in_usage." %%), Out : %.2f ".$out_prefix."b/s (".$out_usage." %%) - ", $in_traffic, $out_traffic);
|
||||
printf("Total RX Bits In : %.2f ".$in_bits_unit."B, Out : %.2f ".$out_bits_unit."b", $in_bits, $out_bits);
|
||||
printf("|traffic_in=".$in_perfparse_traffic_str."Bits/s traffic_out=".$out_perfparse_traffic_str."Bits/s\n");
|
||||
exit($ERRORS{$status});
|
||||
|
||||
|
||||
|
||||
|
||||
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 " -g (--rrdgraph) create a rrd base and add datas into this one\n";
|
||||
print " --rrd_step Specifies the base interval in seconds with which data will be fed into the RRD (300 by default)\n";
|
||||
print " -D (--directory) Path to rrdatabase (or create the .rrd in this directory)\n";
|
||||
print " by default: ".$pathtorrdbase."\n";
|
||||
print " (The path is valid with spaces '/my\ path/...')\n";
|
||||
print " (The path is valid with spaces '/my\ path/...')\n";
|
||||
print " -s (--show) Describes all interfaces number (debug mode)\n";
|
||||
print " -i (--interface) Set the interface number (2 by default)\n";
|
||||
print " -n (--name) Allows to use interface name with option -d instead of interface oid index\n";
|
||||
print " (ex: -i \"eth0\" -n, -i \"VMware Virtual Ethernet Adapter for VMnet8\" -n\n";
|
||||
print " (choose an unique expression for each interface)\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 " -T Max Banwidth\n";
|
||||
print " (default 95)\n";
|
||||
print " -S (--ServiceId) Oreon Service Id\n";
|
||||
print " -V (--version) Plugin version\n";
|
||||
print " -h (--help) usage help\n";
|
||||
}
|
||||
|
||||
sub print_help () {
|
||||
print "##########################################\n";
|
||||
print "# Copyright (c) 2004-2006 Oreon #\n";
|
||||
print "# Bugs to http://www.oreon-project.org/ #\n";
|
||||
print "##########################################\n";
|
||||
print_usage();
|
||||
print "\n";
|
||||
}
|
316
centreon-plugins/src/check_graph_traffic_rrd.pl
Normal file
316
centreon-plugins/src/check_graph_traffic_rrd.pl
Normal file
@ -0,0 +1,316 @@
|
||||
#! /usr/bin/perl -w
|
||||
#
|
||||
# $Id: check_graph_traffic,v 1.1 2004/10/21 17:00:00 projectOREON $
|
||||
#
|
||||
# Oreon's plugins are developped with GPL Licence :
|
||||
# http://www.fsf.org/licenses/gpl.txt
|
||||
# Last Developpement by : Jean Baptiste Gouret - Julien Mathis - Mathieu Mettre - Romain Le Merlus - Yohann Lecarpentier
|
||||
#
|
||||
# REVISED BY CVF 6/05/05
|
||||
# Modified for Oreon Project by : Christophe Coraboeuf
|
||||
|
||||
##
|
||||
## Plugin init
|
||||
##
|
||||
use strict;
|
||||
use Net::SNMP qw(:snmp oid_lex_sort);
|
||||
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 fetch_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 vars qw($VERSION %oreon);
|
||||
|
||||
use Getopt::Long;
|
||||
use vars qw($opt_V $opt_h $opt_g $opt_v $opt_C $opt_H $opt_D $opt_step $opt_i $opt_w $opt_c $opt_s $opt_S $opt_T $opt_Y);
|
||||
use Data::Dumper;
|
||||
|
||||
Getopt::Long::Configure('bundling');
|
||||
GetOptions ("h" => \$opt_h, "help" => \$opt_h,
|
||||
"s" => \$opt_s, "show" => \$opt_s,
|
||||
"V" => \$opt_V, "version" => \$opt_V,
|
||||
"g" => \$opt_g, "rrdgraph" => \$opt_g,
|
||||
"D=s" => \$opt_D, "directory=s" => \$opt_D,
|
||||
"i=s" => \$opt_i, "interface=s" => \$opt_i,
|
||||
"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,
|
||||
"S=s" => \$opt_S, "ServiceId=s" => \$opt_S,
|
||||
"H=s" => \$opt_H, "hostname=s" => \$opt_H,
|
||||
"T=s" => \$opt_T, "Speed=s" => \$opt_T,
|
||||
"rrd_step=s" => \$opt_step,
|
||||
);
|
||||
|
||||
my $PROGNAME = "check_graph_traffic_rrd";
|
||||
my $pathtorrdbase = $oreon{GLOBAL}{DIR_RRDTOOL};
|
||||
|
||||
|
||||
sub print_help () {
|
||||
print "\n";
|
||||
print_revision($PROGNAME,'Revision: 1.1 ');
|
||||
print "\n";
|
||||
print_usage();
|
||||
print "\n";
|
||||
support();
|
||||
print "\n";
|
||||
}
|
||||
|
||||
sub main () {
|
||||
|
||||
##
|
||||
## Plugin var init
|
||||
##
|
||||
my ($in_usage, $out_usage, $in_prefix, $out_prefix, $in_traffic, $out_traffic);
|
||||
my ($host, $snmp, $community);
|
||||
my ($interface, $ServiceId, $critical, $warning, $rrd, $start, $name);
|
||||
my $ERROR;
|
||||
my $result;
|
||||
my ($in_bits, $out_bits, $speed, $ds_names, $step, $data);
|
||||
my @valeur;
|
||||
my $i = 0;
|
||||
my ($line, $update_time, $rrdstep, $rrdheartbeat, $bitcounter);
|
||||
my $not_traffic = 1;
|
||||
|
||||
my $OID_IN =$oreon{MIB2}{IF_IN_OCTET};
|
||||
my $OID_OUT = $oreon{MIB2}{IF_OUT_OCTET};
|
||||
my $OID_SPEED = $oreon{MIB2}{IF_SPEED};
|
||||
my $OID_DESC = $oreon{MIB2}{IF_DESC};
|
||||
|
||||
if ($opt_V) { print_revision ($PROGNAME, "Revision: 1.1 "); exit $ERRORS{'OK'}; }
|
||||
if ($opt_h) { print_help(); exit $ERRORS{'OK'}; }
|
||||
if (defined($opt_H) && $opt_H =~ m/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/) { $host = $1; } else { print_usage(); exit $ERRORS{'UNKNOWN'}; }
|
||||
if ($opt_v) { $snmp = $opt_v; } else { $snmp = "2c"; }
|
||||
if ($opt_C) { $community = $opt_C; } else { $community = "public"; }
|
||||
if ($opt_s || (defined($opt_i) && $opt_i =~ /([0-9]+)/)) { $interface = $1;} else { print "\nUnknown -i number expected... or it doesn't exist, try another interface - number\n"; }
|
||||
if ($opt_g) {
|
||||
($opt_S) || ($opt_S = shift) || ($opt_S = "1_1");
|
||||
$ServiceId = is_valid_serviceid($opt_S);
|
||||
}
|
||||
if (defined($opt_step) && $opt_step =~ /([0-9]+)/) { $rrdstep = $1; $rrdheartbeat = $rrdstep * 2; } else { $rrdstep = 300; $rrdheartbeat = $rrdstep * 2; }
|
||||
if (defined($opt_c) && $opt_c =~ /([0-9]+)/) { $critical = $1; } else { $critical = 95; }
|
||||
if (defined($opt_w) && $opt_w =~ /([0-9]+)/) { $warning = $1; } else { $warning = 80; }
|
||||
if (defined($opt_c) && defined($opt_w) && $critical <= $warning){ print "(--crit) must be superior to (--warn)"; print_usage(); exit $ERRORS{'OK'}; }
|
||||
if (defined($opt_D) && $opt_D =~ /([-.\/\_\ A-Za-z0-9]+)/) { $pathtorrdbase = $1; }
|
||||
|
||||
($opt_v) || ($opt_v = shift) || ($opt_v = "1");
|
||||
$snmp = $1 if ($opt_v =~ /(\d)/);
|
||||
|
||||
##
|
||||
## RRDTool var init
|
||||
##
|
||||
if ($opt_i) {
|
||||
$OID_IN .= ".".$interface;
|
||||
$OID_OUT .= ".".$interface;
|
||||
$OID_SPEED .= ".".$interface;
|
||||
}
|
||||
|
||||
if ($opt_g && $opt_S) {
|
||||
$rrd = $pathtorrdbase.$ServiceId.".rrd";
|
||||
$start = time;
|
||||
$name = $0;
|
||||
$name =~ s/\.pl.*//g;
|
||||
|
||||
##
|
||||
## RRDTool create rrd
|
||||
##
|
||||
|
||||
if (!(-e $rrd)) {
|
||||
$_ = `/usr/bin/snmpwalk $host -c $community -v $snmp $OID_IN 2>/dev/null`;
|
||||
if ($_ =~ m/Counter(\d+)/) { $bitcounter = $1; } else { $bitcounter = 32; }
|
||||
$bitcounter = 2 ** $bitcounter;
|
||||
create_rrd ($rrd,2,$start,$rrdstep,0,$bitcounter,"COUNTER");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
##
|
||||
## Plugin snmp requests
|
||||
##
|
||||
|
||||
# if ($opt_s) { $_ = `/usr/bin/snmpwalk $host -c $community -v $snmp $OID_DESC 2>/dev/null`; print $_; exit $ERRORS{'OK'}; }
|
||||
|
||||
|
||||
# create a SNMP session #
|
||||
my ( $session, $error ) = Net::SNMP->session(-hostname => $host,-community => $community, -version => $snmp);
|
||||
if ( !defined($session) ) { print("UNKNOWN: $error"); exit $ERRORS{'UNKNOWN'}; }
|
||||
|
||||
|
||||
if ($opt_s) {
|
||||
# Get desctiption table
|
||||
my $result = $session->get_table(
|
||||
Baseoid => $OID_DESC
|
||||
);
|
||||
|
||||
if (!defined($result)) {
|
||||
printf("ERROR: Description 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 "Interface $index :: $$result{$key}\n";
|
||||
}
|
||||
exit $ERRORS{'OK'};
|
||||
}
|
||||
|
||||
# get IN bits #
|
||||
$result = $session->get_request( -varbindlist => [$OID_IN] );
|
||||
if (!defined($result)) { printf("ERROR : IN : %s.\n", $session->error); $session->close; exit($ERRORS{"CRITICAL"}); }
|
||||
$in_bits = $result->{$OID_IN} * 8;
|
||||
|
||||
|
||||
# get OUT bits #
|
||||
$result = $session->get_request( -varbindlist => [$OID_OUT] );
|
||||
if (!defined($result)) { printf("ERROR : OUT : %s.\n", $session->error); $session->close; exit($ERRORS{"CRITICAL"}); }
|
||||
$out_bits = $result->{$OID_OUT} * 8;
|
||||
|
||||
|
||||
# Get SPEED of interface #
|
||||
if (!defined($opt_T) || $opt_T == 0) {
|
||||
$result = $session->get_request( -varbindlist => [$OID_SPEED] );
|
||||
if (!defined($result)) { printf("ERROR: %s.\n", $session->error); $session->close; exit($ERRORS{"CRITICAL"}); }
|
||||
$speed = $result->{$OID_SPEED};
|
||||
}
|
||||
else {
|
||||
$speed = $opt_T * 1000000;
|
||||
}
|
||||
|
||||
|
||||
##
|
||||
## RRDtools update
|
||||
##
|
||||
|
||||
if ($opt_g) {
|
||||
$start=time;
|
||||
update_rrd ($rrd,$start,$in_bits,$out_bits);
|
||||
|
||||
##
|
||||
## Get the real value in rrdfile
|
||||
##
|
||||
# ($update_time,$step,$ds_names,$data) = RRDs::fetch($rrd, "--resolution=300","--start=now-5min","--end=now","AVERAGE");
|
||||
# foreach $line (@$data) {
|
||||
# foreach $val (@$line) {
|
||||
# if ( defined $val ) { $valeur[$i]=$val; } else { $valeur[$i]="undef"; }
|
||||
# $i++;
|
||||
# }
|
||||
# }*/
|
||||
@valeur = fetch_rrd($rrd,"AVERAGE");
|
||||
$in_traffic = $valeur[0];
|
||||
$out_traffic = $valeur[1];
|
||||
}
|
||||
|
||||
if (!(defined($in_traffic)) && !(defined($out_traffic))) {
|
||||
$not_traffic = 0;
|
||||
} else {
|
||||
$in_prefix = " ";
|
||||
$out_prefix = " ";
|
||||
|
||||
if (!($in_traffic eq "undef")) {
|
||||
if ($in_traffic > 1000000) {
|
||||
$in_usage = sprintf("%.2f",($in_traffic/($speed))*100);
|
||||
$in_traffic = sprintf("%.2f",$in_traffic/1000000);
|
||||
$in_prefix = "M";
|
||||
}
|
||||
elsif ($in_traffic > 1000) {
|
||||
$in_usage = sprintf("%.2f",($in_traffic/($speed))*100);
|
||||
$in_traffic = sprintf("%.2f",$in_traffic/1000);
|
||||
$in_prefix = "K";
|
||||
}
|
||||
elsif ($in_traffic < 1000) {
|
||||
$in_usage = sprintf("%.2f",($in_traffic/($speed))*100);
|
||||
$in_traffic = sprintf("%.2f",$in_traffic);
|
||||
$in_prefix = " ";
|
||||
}
|
||||
else {
|
||||
print "ERROR\n"; exit 1;
|
||||
}
|
||||
|
||||
} else {
|
||||
$in_usage = 0 ;
|
||||
}
|
||||
|
||||
if (!($out_traffic eq "undef")) {
|
||||
if ($out_traffic > 1000000) {
|
||||
$out_usage = sprintf("%.2f",($out_traffic/($speed))*100);
|
||||
$out_traffic = sprintf("%.2f",$out_traffic/1000000);
|
||||
$out_prefix = "M";
|
||||
}
|
||||
elsif ($out_traffic > 1000) {
|
||||
$out_usage = sprintf("%.2f",($out_traffic/($speed))*100);
|
||||
$out_traffic = sprintf("%.2f",$out_traffic/1000);
|
||||
$out_prefix = "K";
|
||||
}
|
||||
elsif ($out_traffic < 1000) {
|
||||
$out_usage = sprintf("%.2f",($out_traffic/($speed))*100);
|
||||
$out_traffic = sprintf("%.2f",$out_traffic);
|
||||
$out_prefix = " ";
|
||||
}
|
||||
} else {
|
||||
$out_usage = 0 ;
|
||||
}
|
||||
}
|
||||
|
||||
##
|
||||
## Plugin return code && Status
|
||||
##
|
||||
|
||||
if ( $speed == 0 ) {
|
||||
print "CRITICAL: Interface speed equal 0! Interface must be down.\n";
|
||||
exit($ERRORS{"CRITICAL"});
|
||||
}
|
||||
else {
|
||||
$speed = sprintf("%.2f",($speed/1000000));
|
||||
}
|
||||
|
||||
if ($not_traffic != 1) {
|
||||
print "Counter: IN = $in_bits bits and OUT = $out_bits bits - Traffic cannot be calculated when the last value from the rrdfile is `undef' (check if the `-g' option is enabled)\n"; exit($ERRORS{"OK"});
|
||||
} else {
|
||||
if(($in_usage > $critical) || ($out_usage > $critical)) {
|
||||
print "CRITICAL: (".$critical."%) depassed threshold. Traffic: $in_traffic ".$in_prefix."b/s (".$in_usage."%) in, $out_traffic ".$out_prefix."b/s (".$out_usage."%) out - Speed Interface = ".$speed." Mb/s \n";
|
||||
exit($ERRORS{"CRITICAL"});
|
||||
}
|
||||
if(($in_usage > $warning) || ($out_usage > $warning)) {
|
||||
print "WARNING: (".$warning."%) depassed threshold. Traffic: $in_traffic ".$in_prefix."b/s (".$in_usage."%) in, $out_traffic ".$out_prefix."b/s (".$out_usage."%) out - Speed Interface = ".$speed." Mb/s\n";
|
||||
exit($ERRORS{"WARNING"});
|
||||
}
|
||||
print "OK: Traffic: $in_traffic ".$in_prefix."b/s (".$in_usage."%) in, $out_traffic ".$out_prefix."b/s (".$out_usage."%) out - Speed Interface = ".$speed." Mb/s\n $opt_g"; exit($ERRORS{"OK"});
|
||||
}
|
||||
}
|
||||
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 " -g (--rrdgraph) create à rrd base and add datas into this one\n";
|
||||
print " -D (--directory) Path to rrdatabase (or create the .rrd in this directory)\n";
|
||||
print " by default: ".$pathtorrdbase."\n";
|
||||
print " (The path is valid with spaces '/my\ path/...')\n";
|
||||
print " -s (--show) Describes all interfaces number (debug mode)\n";
|
||||
print " -i (--interface) Set the interface number (2 by default)\n";
|
||||
print " -T (--speed) Set the speed interface in Mbit/s (by default speed interface capacity)\n";
|
||||
print " --rrdstep Set the rrdstep in second (5 minuntes by default)\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 " -S (--ServiceId) Oreon Service Id\n";
|
||||
print " -V (--version) Plugin version\n";
|
||||
print " -h (--help) usage help\n\n";
|
||||
}
|
||||
|
||||
main ();
|
212
centreon-plugins/src/check_graph_uptime.pl
Normal file
212
centreon-plugins/src/check_graph_uptime.pl
Normal file
@ -0,0 +1,212 @@
|
||||
#! /usr/bin/perl -w
|
||||
#
|
||||
# $Id: check_graph_uptime.pl,v 1.2 2005/07/27 22:21:49 wistof Exp $
|
||||
#
|
||||
# This plugin is developped under GPL Licence:
|
||||
# http://www.fsf.org/licenses/gpl.txt
|
||||
|
||||
# Developped by Linagora SA: http://www.linagora.com
|
||||
|
||||
# Modified for Oreon Project by : Mathieu Chateau - Christophe Coraboeuf
|
||||
# Modified For Oreon compatibility by Julien Mathis For Merethis
|
||||
#
|
||||
# The Software is provided to you AS IS and WITH ALL FAULTS.
|
||||
# LINAGORA 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 LINAGORA web site.
|
||||
# In no event will LINAGORA be liable for any direct, indirect, punitive, special,
|
||||
# incidental or consequential damages however they may arise and even if LINAGORA has
|
||||
# been previously advised of the possibility of such damages.
|
||||
|
||||
# based on "graph plugins" developped by Oreon Team. See http://www.oreon.org.
|
||||
##
|
||||
## Plugin 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);
|
||||
|
||||
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 vars qw($PROGNAME);
|
||||
use Getopt::Long;
|
||||
use vars qw($opt_h $opt_V $opt_g $opt_D $opt_S $opt_H $opt_C $opt_v $opt_d $day $opt_step);
|
||||
my $pathtorrdbase = $oreon{GLOBAL}{DIR_RRDTOOL};
|
||||
|
||||
$PROGNAME = $0;
|
||||
sub print_help ();
|
||||
sub print_usage ();
|
||||
|
||||
Getopt::Long::Configure('bundling');
|
||||
GetOptions
|
||||
("h" => \$opt_h, "help" => \$opt_h,
|
||||
"V" => \$opt_V, "version" => \$opt_V,
|
||||
"g" => \$opt_g, "rrdgraph" => \$opt_g,
|
||||
"rrd_step=s" => \$opt_step,
|
||||
"v=s" => \$opt_v, "snmp=s" => \$opt_v,
|
||||
"C=s" => \$opt_C, "community=s" => \$opt_C,
|
||||
"S=s" => \$opt_S, "ServiceId=s" => \$opt_S,
|
||||
"d" => \$opt_d, "day" => \$opt_d,
|
||||
"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);
|
||||
|
||||
|
||||
($opt_v) || ($opt_v = shift) || ($opt_v = "1");
|
||||
my $snmp = $1 if ($opt_v =~ /(\d)/);
|
||||
|
||||
($opt_S) || ($opt_S = shift) || ($opt_S = "1_1");
|
||||
my $ServiceId = is_valid_serviceid($opt_S);
|
||||
|
||||
($opt_C) || ($opt_C = shift) || ($opt_C = "public");
|
||||
|
||||
my $rrd = $pathtorrdbase.$ServiceId.".rrd";
|
||||
|
||||
my $start=time;
|
||||
my $name = $0;
|
||||
$name =~ s/\.pl.*//g;
|
||||
my $day = 0;
|
||||
|
||||
##
|
||||
## RRDTools create rrd
|
||||
##
|
||||
if ($opt_g) {
|
||||
if (! -e $rrd) {
|
||||
create_rrd($rrd,1,$start,300,"U","U","GAUGE");
|
||||
}
|
||||
}
|
||||
|
||||
##
|
||||
## Plugin snmp requests
|
||||
##
|
||||
|
||||
my $OID_OBJECTID =$oreon{MIB2}{OBJECTID};
|
||||
my $OID_UPTIME_WINDOWS =$oreon{MIB2}{UPTIME_WINDOWS};
|
||||
my $OID_UPTIME_OTHER =$oreon{MIB2}{UPTIME_OTHER};
|
||||
|
||||
# create a SNMP session
|
||||
my ( $session, $error ) = Net::SNMP->session(-hostname => $opt_H,-community => $opt_C, -version => $snmp);
|
||||
if ( !defined($session) ) {
|
||||
print("CRITICAL: $error");
|
||||
exit $ERRORS{'CRITICAL'};
|
||||
}
|
||||
|
||||
my $result = $session->get_request(
|
||||
-varbindlist => [$OID_OBJECTID]
|
||||
);
|
||||
if (!defined($result)) {
|
||||
printf("UNKNOWN: %s.\n", $session->error);
|
||||
$session->close;
|
||||
exit $ERRORS{'UNKNOWN'};
|
||||
}
|
||||
|
||||
my $return_result = $result->{$OID_OBJECTID};
|
||||
my $OID = "";
|
||||
if ($return_result =~ /.*Windows.*/i ) {
|
||||
$OID = $OID_UPTIME_WINDOWS;
|
||||
} else {
|
||||
$OID = $OID_UPTIME_OTHER;
|
||||
}
|
||||
|
||||
$result = $session->get_request(
|
||||
-varbindlist => [$OID]
|
||||
);
|
||||
if (!defined($result)) {
|
||||
printf("UNKNOWN: %s.\n", $session->error);
|
||||
$session->close;
|
||||
exit $ERRORS{'UNKNOWN'};
|
||||
}
|
||||
|
||||
my $un = 0;
|
||||
|
||||
$return_result = $result->{$OID};
|
||||
if ( $return_result =~ m/(\d*) day[s]?,\s*(\d*):(\d*):(\d*).(\d*)/ ) {
|
||||
$un = $5 + $4 * 100 + $3 * 100 * 60 + $2 * 100 * 60 * 60 + $1 * 100 * 60 * 60 * 24;
|
||||
$day = $1;
|
||||
}
|
||||
|
||||
if ( $return_result =~ m/(\d*) hour.*(\d*):(\d*).(\d*)/ ) {
|
||||
$un = $4 + $3 * 100 + $3 * 100 * 60 + $1 * 100 * 60 * 60 ;
|
||||
}
|
||||
|
||||
if ($opt_d) {
|
||||
$un = $day;
|
||||
}
|
||||
|
||||
#print "un : $un\n";
|
||||
|
||||
##
|
||||
## RRDtools update
|
||||
##
|
||||
if ($opt_g) {
|
||||
$start=time;
|
||||
update_rrd($rrd,$start,$un);
|
||||
}
|
||||
|
||||
##
|
||||
## Plugin return code
|
||||
##
|
||||
|
||||
if ($un || ( $un == 0) ){
|
||||
if ($opt_d) {
|
||||
print "OK - Uptime (in day): $un|uptime=".$un."hs\n";
|
||||
} else {
|
||||
print "OK - Uptime (in hundredths of a second): $un|uptime=".$un."hs\n";
|
||||
}
|
||||
exit $ERRORS{'OK'};
|
||||
}
|
||||
else{
|
||||
print "CRITICAL Host unavailable\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 " -g (--rrdgraph) create a rrd base and add datas into this one\n";
|
||||
print " -D (--directory) Path to rrdatabase (or create the .rrd in this directory)\n";
|
||||
print " by default: ".$pathtorrdbase."\n";
|
||||
print " (The path is valid with spaces '/my\ path/...')\n";
|
||||
print " -S (--ServiceId) Oreon Service Id\n";
|
||||
print " -d (--day) Uptime in day\n";
|
||||
print " -V (--version) Plugin version\n";
|
||||
print " -h (--help) usage help\n";
|
||||
|
||||
}
|
||||
|
||||
sub print_help () {
|
||||
print "Copyright (c) 2005 Linagora\n";
|
||||
print "Modified by Merethis \n";
|
||||
print "Bugs to http://www.linagora.com/\n";
|
||||
print "\n";
|
||||
print_usage();
|
||||
print "\n";
|
||||
}
|
369
centreon-plugins/src/check_meta_service.pl
Normal file
369
centreon-plugins/src/check_meta_service.pl
Normal file
@ -0,0 +1,369 @@
|
||||
#! /usr/bin/perl -w
|
||||
#
|
||||
# $Id: check_meta_service.pl,v 1.2 2005/07/27 22:21:49 Julio $
|
||||
#
|
||||
# Oreon's plugins are developped with GPL Licence :
|
||||
# http://www.fsf.org/licenses/gpl.txt
|
||||
# Developped by : Julien Mathis - Romain Le Merlus
|
||||
#
|
||||
# Developped by Julien Mathis for Merethis SARL
|
||||
#
|
||||
# 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.
|
||||
|
||||
##
|
||||
## Plugin init
|
||||
##
|
||||
|
||||
use strict;
|
||||
use DBI;
|
||||
use vars qw($PROGNAME);
|
||||
use Getopt::Long;
|
||||
use vars qw($opt_V $opt_H $opt_h $opt_i);
|
||||
use lib "@NAGIOS_PLUGINS@";
|
||||
use utils qw($TIMEOUT %ERRORS &print_revision &support);
|
||||
|
||||
## For Debug mode = 1
|
||||
my $debug = 0;
|
||||
|
||||
sub print_help ();
|
||||
sub print_usage ();
|
||||
|
||||
Getopt::Long::Configure('bundling');
|
||||
GetOptions
|
||||
("h" => \$opt_h,
|
||||
"help" => \$opt_h,
|
||||
"V" => \$opt_V,
|
||||
"H" => \$opt_H,
|
||||
"i=s" => \$opt_i);
|
||||
|
||||
|
||||
my $dbh = DBI->connect("DBI:mysql:database=oreon;host=localhost",
|
||||
"oreon", "oreon",
|
||||
{'RaiseError' => 1});
|
||||
|
||||
my $sth1 = $dbh->prepare("SELECT * FROM `cfg_perfparse`");
|
||||
if (!$sth1->execute) {die "Error:" . $sth1->errstr . "\n";}
|
||||
my $ref1 = $sth1->fetchrow_hashref();
|
||||
my $dbh2 = DBI->connect("DBI:".$ref1->{'Storage_Modules_Load'}.":database=".$ref1->{'DB_Name'}.";host=".$ref1->{'DB_Host'},
|
||||
$ref1->{'DB_User'}, $ref1->{'DB_Pass'},
|
||||
{'RaiseError' => 1});
|
||||
|
||||
if ($opt_V) {
|
||||
print_revision($PROGNAME,'$Revision: 0.1 $');
|
||||
exit $ERRORS{'OK'};
|
||||
}
|
||||
|
||||
if ($opt_h) {
|
||||
print_help();
|
||||
exit $ERRORS{'OK'};
|
||||
}
|
||||
|
||||
my $result;
|
||||
my $warning;
|
||||
my $critical;
|
||||
my $metric_id;
|
||||
|
||||
sub return_value($$$){
|
||||
|
||||
#print "warning : ".$warning."-Critical : ".$critical.":$result\b";
|
||||
|
||||
if ($warning ne $critical){
|
||||
if ($warning < $critical){ # Bon sens
|
||||
if ($result < $warning){
|
||||
print "OK result : " . $result . "|OMS=" . $result . ";".$warning.";".$critical."\n";
|
||||
exit $ERRORS{'OK'};
|
||||
} elsif (($result >= $warning) && ($result < $critical)){
|
||||
print "WARNING result : " . $result . "|OMS=" . $result . ";".$warning.";".$critical."\n";
|
||||
exit $ERRORS{'WARNING'};
|
||||
} elsif ($result >= $critical){
|
||||
print "CRITICAL result : " . $result . "|OMS=" . $result . ";".$warning.";".$critical."\n";
|
||||
exit $ERRORS{'CRITICAL'};
|
||||
}
|
||||
} else { # sens inverse
|
||||
if ($result < $critical){
|
||||
print "CRITICAL result : " . $result . "|OMS=" . $result . ";".$warning.";".$critical."\n";
|
||||
exit $ERRORS{'CRITICAL'};
|
||||
} elsif ($result >= $critical && $result < $warning){
|
||||
print "WARNING result : " . $result . "|OMS=" . $result . ";".$warning.";".$critical."\n";
|
||||
exit $ERRORS{'WARNING'};
|
||||
} elsif ($result >= $warning){
|
||||
print "OK result : " . $result . "|OMS=" . $result . ";".$warning.";".$critical."\n";
|
||||
exit $ERRORS{'OK'};
|
||||
} else{
|
||||
print "OK result : " . $result . "|OMS=" . $result . ";".$warning.";".$critical."\n";
|
||||
exit $ERRORS{'OK'};
|
||||
}
|
||||
}
|
||||
} else {
|
||||
print "ERROR : warnig level = critical level";
|
||||
exit $ERRORS{'CRITICAL'};
|
||||
}
|
||||
}
|
||||
|
||||
my $ref;
|
||||
my $svc_id;
|
||||
my $metric;
|
||||
my $host_id;
|
||||
|
||||
## Get Value by metric Option
|
||||
|
||||
sub get_value_in_database_metric_id($$$$){
|
||||
## Get last entry in perfparse database for this service
|
||||
my $str = "SELECT value FROM perfdata_service_metric,perfdata_service_bin WHERE perfdata_service_metric.metric_id = '".$metric_id."' AND perfdata_service_metric.last_perfdata_bin = perfdata_service_bin.id";
|
||||
if ($debug) {print $str . "\n";}
|
||||
my $sth_deb2 = $dbh2->prepare($str);
|
||||
if (!$sth_deb2->execute) {die "Error:" . $sth_deb2->errstr . "\n";}
|
||||
my $sth_deb2_data = $sth_deb2->fetchrow_hashref();
|
||||
return $sth_deb2_data->{'value'};
|
||||
}
|
||||
|
||||
## Get value For Regexp Options
|
||||
|
||||
sub get_value_in_database($$$$$){
|
||||
|
||||
my $str;
|
||||
## Get hostname and service description for perfparse request
|
||||
|
||||
$str = "SELECT host_name,service_description FROM host,host_service_relation,service WHERE host.host_id = host_service_relation.host_host_id AND
|
||||
service.service_id = host_service_relation.service_service_id AND service.service_id = '".$svc_id."'";
|
||||
|
||||
if ($debug) {print $str . "\n";}
|
||||
my $host_data = $dbh->prepare($str);
|
||||
if (!$host_data->execute) {die "Error:" . $host_data->errstr . "\n";}
|
||||
my $data = $host_data->fetchrow_hashref();
|
||||
|
||||
## Get last entry in perfparse database for this service
|
||||
my $sth_deb2 = $dbh2->prepare("SELECT value FROM perfdata_service_metric,perfdata_service_bin WHERE perfdata_service_metric.host_name = '".$data->{'host_name'}."' AND perfdata_service_metric.service_description = '".$data->{'service_description'}."' AND perfdata_service_metric.last_perfdata_bin = perfdata_service_bin.id AND perfdata_service_metric.metric = '".$metric."'");
|
||||
if (!$sth_deb2->execute) {die "Error:" . $sth_deb2->errstr . "\n";}
|
||||
my $sth_deb2_data = $sth_deb2->fetchrow_hashref();
|
||||
return $sth_deb2_data->{'value'};
|
||||
}
|
||||
|
||||
sub get_value_in_database_by_host($$$$$){
|
||||
|
||||
my $str;
|
||||
|
||||
## Get hostname and service description for perfparse request
|
||||
|
||||
$str = "SELECT host_name,service_description FROM host,host_service_relation,service WHERE host.host_id = host_service_relation.host_host_id AND service.service_id = host_service_relation.service_service_id AND service.service_id = '".$svc_id."'";
|
||||
if ($debug) {print $str . "\n";}
|
||||
my $host_data = $dbh->prepare($str);
|
||||
if (!$host_data->execute) {die "Error:" . $host_data->errstr . "\n";}
|
||||
my $data = $host_data->fetchrow_hashref();
|
||||
|
||||
## Get last entry in perfparse database for this service
|
||||
|
||||
my $sth_deb2 = $dbh2->prepare("SELECT value FROM perfdata_service_metric,perfdata_service_bin WHERE perfdata_service_metric.host_name = '".$data->{'host_name'}."' AND perfdata_service_metric.service_description = '".$data->{'service_description'}."' AND perfdata_service_metric.last_perfdata_bin = perfdata_service_bin.id AND perfdata_service_metric.metric = '".$metric."'");
|
||||
if (!$sth_deb2->execute) {die "Error:" . $sth_deb2->errstr . "\n";}
|
||||
my $sth_deb2_data = $sth_deb2->fetchrow_hashref();
|
||||
return $sth_deb2_data->{'value'};
|
||||
}
|
||||
|
||||
sub get_value_in_database_by_hg($$$$$$){
|
||||
|
||||
my $str;
|
||||
|
||||
## Get hostname
|
||||
|
||||
$str = "SELECT host_name FROM host WHERE host.host_id = '".$host_id."'";
|
||||
if ($debug) {print $str . "\n";}
|
||||
my $hd = $dbh->prepare($str);
|
||||
if (!$hd->execute) {die "Error:" . $hd->errstr . "\n";}
|
||||
my $host_data = $hd->fetchrow_hashref();
|
||||
|
||||
## Get service description
|
||||
|
||||
$str = "SELECT service_description FROM service WHERE service.service_id = '".$svc_id."'";
|
||||
if ($debug) {print $str . "\n";}
|
||||
my $sd = $dbh->prepare($str);
|
||||
if (!$sd->execute) {die "Error:" . $sd->errstr . "\n";}
|
||||
my $service_data = $sd->fetchrow_hashref();
|
||||
|
||||
## Get last entry in perfparse database for this service
|
||||
|
||||
my $sth_deb2 = $dbh2->prepare("SELECT value FROM perfdata_service_metric,perfdata_service_bin WHERE perfdata_service_metric.host_name = '".$host_data->{'host_name'}."' AND perfdata_service_metric.service_description = '".$service_data->{'service_description'}."' AND perfdata_service_metric.last_perfdata_bin = perfdata_service_bin.id AND perfdata_service_metric.metric = '".$metric."'");
|
||||
if (!$sth_deb2->execute) {die "Error:" . $sth_deb2->errstr . "\n";}
|
||||
my $sth_deb2_data = $sth_deb2->fetchrow_hashref();
|
||||
return $sth_deb2_data->{'value'};
|
||||
}
|
||||
|
||||
my $cpt = 0;
|
||||
my $total = 0;
|
||||
my $max = 0;
|
||||
my $min = 999999999;
|
||||
my $svc;
|
||||
my $value = 0;
|
||||
my $svc_relation2;
|
||||
|
||||
if ($opt_i){
|
||||
my $str;
|
||||
|
||||
# get osl info
|
||||
my $sth = $dbh->prepare("SELECT calcul_type,regexp_str,warning,critical,metric, meta_select_mode FROM meta_service WHERE meta_id = '".$opt_i."'");
|
||||
if (!$sth->execute) {die "Error:" . $sth->errstr . "\n";}
|
||||
$ref = $sth->fetchrow_hashref();
|
||||
if (!defined($ref->{'calcul_type'})){
|
||||
print "Unvalidate Meta Service\n";
|
||||
exit $ERRORS{'CRITICAL'};
|
||||
}
|
||||
|
||||
$warning = $ref->{'warning'};
|
||||
$critical = $ref->{'critical'};
|
||||
|
||||
# Get Service List by regexp
|
||||
if ($ref->{'meta_select_mode'} eq '2'){
|
||||
|
||||
###############################################
|
||||
|
||||
$str = "SELECT service_id FROM service WHERE `service_description` LIKE '".$ref->{'regexp_str'}."' AND service_activate = '1' AND service_register = '1'";
|
||||
if ($debug) {print $str . "\n";}
|
||||
$sth = $dbh->prepare($str);
|
||||
if (!$sth->execute) {die "Error:" . $sth->errstr . "\n";}
|
||||
while ($svc = $sth->fetchrow_hashref()){
|
||||
my $sth2 = $dbh->prepare("SELECT * FROM host_service_relation WHERE service_service_id = '".$svc->{'service_id'}."'");
|
||||
if (!$sth2->execute) {die "Error:" . $sth2->errstr . "\n";}
|
||||
my $svc_relation = $sth2->fetchrow_hashref();
|
||||
if (defined($svc_relation->{'host_host_id'}) && $svc_relation->{'host_host_id'}){
|
||||
#### Par Host
|
||||
if (defined($svc->{'service_id'})){$svc_id = $svc->{'service_id'};} else {$svc_id = $svc->{'svc_id'};}
|
||||
if (defined($ref->{'regexp_str'})){$metric = $ref->{'metric'};} else {$metric = $svc->{'metric'};}
|
||||
$value = get_value_in_database_by_host($dbh,$dbh2,$svc_id,$metric,$debug);
|
||||
if ($ref->{'calcul_type'} =~ "AVE"){
|
||||
if (defined($value) && $value){$total += $value;}
|
||||
if ($debug) {print "total = " . $total . " value = ".$value."\n";}
|
||||
$cpt++;
|
||||
$result = $total / $cpt;
|
||||
} elsif ($ref->{'calcul_type'} =~ "SOM"){
|
||||
if ($value){$total += $value;}
|
||||
if ($debug){print "total = " . $total . " value = ".$value."\n";}
|
||||
$result = $total;
|
||||
} elsif ($ref->{'calcul_type'} =~ "MIN"){
|
||||
if ($debug){print " min : " . $min . " value = ".$value."\n";}
|
||||
if ($value && $value <= $min){$min = $value;}
|
||||
$result = $min;
|
||||
} elsif ($ref->{'calcul_type'} =~ "MAX"){
|
||||
if ($debug){print "max = " . $max . " value = ".$value."\n";}
|
||||
if ($value && $value >= $max){$max = $value;}
|
||||
$result = $max;
|
||||
}
|
||||
} elsif (defined($svc_relation->{'hostgroup_hg_id'}) && $svc_relation->{'hostgroup_hg_id'}) {
|
||||
### Par Hostgroup
|
||||
my $sth3 = $dbh->prepare("SELECT host_host_id FROM hostgroup_relation WHERE hostgroup_hg_id = '".$svc_relation->{'hostgroup_hg_id'}."'");
|
||||
if (!$sth3->execute) {die "Error:" . $sth3->errstr . "\n";}
|
||||
while ($svc_relation2 = $sth3->fetchrow_hashref()){
|
||||
if (defined($svc->{'service_id'})){
|
||||
$svc_id = $svc->{'service_id'};
|
||||
} else {
|
||||
$svc_id = $svc->{'svc_id'};
|
||||
}
|
||||
if (defined($ref->{'regexp_str'})){
|
||||
$metric = $ref->{'metric'};
|
||||
} else {
|
||||
$metric = $svc->{'metric'};
|
||||
}
|
||||
$host_id = $svc_relation2->{'host_host_id'};
|
||||
$value = get_value_in_database_by_hg($dbh,$dbh2,$svc_id, $host_id, $metric, $debug);
|
||||
if ($ref->{'calcul_type'} =~ "AVE"){
|
||||
if (defined($value) && $value){
|
||||
$total += $value;
|
||||
}
|
||||
if ($debug) {print "total = " . $total . " value = ".$value."\n";}
|
||||
$cpt++;
|
||||
} elsif ($ref->{'calcul_type'} =~ "SOM"){
|
||||
if ($value){
|
||||
$total += $value;
|
||||
}
|
||||
if ($debug){print "total = " . $total . " value = ".$value."\n";}
|
||||
} elsif ($ref->{'calcul_type'} =~ "MIN"){
|
||||
if ($debug){print " min : " . $min . " value = ".$value."\n";}
|
||||
if ($value && $value <= $min){
|
||||
$min = $value;
|
||||
}
|
||||
} elsif ($ref->{'calcul_type'} =~ "MAX"){
|
||||
if ($debug){print "max = " . $max . " value = ".$value."\n";}
|
||||
if ($value && $value >= $max){
|
||||
$max = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($ref->{'calcul_type'} =~ "AVE"){
|
||||
$result = $total / $cpt;
|
||||
} elsif ($ref->{'calcul_type'} =~ "SOM"){
|
||||
$result = $total;
|
||||
} elsif ($ref->{'calcul_type'} =~ "MIN"){
|
||||
$result = $min;
|
||||
} elsif ($ref->{'calcul_type'} =~ "MAX"){
|
||||
$result = $max;
|
||||
}
|
||||
}
|
||||
}
|
||||
return_value($result, $warning, $critical);
|
||||
###############################################
|
||||
} else {
|
||||
$sth = $dbh->prepare("SELECT metric_id FROM `meta_service_relation` WHERE meta_id = '".$opt_i."'");
|
||||
if (!$sth->execute) {die "Error:" . $sth->errstr . "\n";}
|
||||
if ($ref->{'calcul_type'} =~ "AVE"){
|
||||
while ($svc = $sth->fetchrow_hashref()){
|
||||
if (defined($svc->{'metric_id'})){$metric_id = $svc->{'metric_id'};}
|
||||
$value = get_value_in_database_metric_id($dbh,$dbh2,$metric_id,$debug);
|
||||
if (defined($value) && $value){$total += $value;}
|
||||
$cpt++;
|
||||
}
|
||||
$result = $total / $cpt;
|
||||
} elsif ($ref->{'calcul_type'} =~ "SOM"){
|
||||
while ($svc = $sth->fetchrow_hashref()){
|
||||
if (defined($svc->{'metric_id'})){$metric_id = $svc->{'metric_id'};}
|
||||
$value = get_value_in_database_metric_id($dbh,$dbh2,$metric_id,$debug);
|
||||
if ($value){$total += $value;}
|
||||
if ($debug){print "total = " . $total . " value = ".$value."\n";}
|
||||
}
|
||||
$result = $total;
|
||||
} elsif ($ref->{'calcul_type'} =~ "MIN"){
|
||||
while ($svc = $sth->fetchrow_hashref()){
|
||||
if (defined($svc->{'metric_id'})){$metric_id = $svc->{'metric_id'};}
|
||||
$value = get_value_in_database_metric_id($dbh,$dbh2,$metric_id,$debug);
|
||||
if ($debug){print " min : " . $min . " value = ".$value."\n";}
|
||||
if ($value && $value <= $min){$min = $value;}
|
||||
}
|
||||
$result = $min;
|
||||
} elsif ($ref->{'calcul_type'} =~ "MAX"){
|
||||
while ($svc = $sth->fetchrow_hashref()){
|
||||
if (defined($svc->{'metric_id'})){$metric_id = $svc->{'metric_id'};}
|
||||
$value = get_value_in_database_metric_id($dbh,$dbh2,$metric_id,$debug);
|
||||
if ($debug){print "max = " . $max . " value = ".$value."\n";}
|
||||
if ($value && $value >= $max){$max = $value;}
|
||||
}
|
||||
$result = $max;
|
||||
}
|
||||
return_value($result, $warning, $critical);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
sub print_usage () {
|
||||
print "Usage:\n";
|
||||
print " check_osl.pl\n";
|
||||
print " -H Hostname to query (Required)\n";
|
||||
print " -i OSL id\n";
|
||||
print " -V (--version) Plugin version\n";
|
||||
print " -h (--help) usage help\n";
|
||||
}
|
||||
|
||||
sub print_help ()
|
||||
{
|
||||
print "###########################################\n";
|
||||
print "# #\n";
|
||||
print "# Copyright (c) 2004-2006 Merethis #\n";
|
||||
print "# Bugs to http://www.oreon-services.com #\n";
|
||||
print "# #\n";
|
||||
print "###########################################\n";
|
||||
print_usage();
|
||||
print "\n";
|
||||
}
|
337
centreon-plugins/src/check_nt_oreon.pl
Normal file
337
centreon-plugins/src/check_nt_oreon.pl
Normal file
@ -0,0 +1,337 @@
|
||||
#! /usr/bin/perl -w
|
||||
#
|
||||
# $Id: check_graph_nt.pl,v 1.3 2005/08/01 18:04:00 gollum123 Exp $
|
||||
#
|
||||
# Oreon's plugins are developped with GPL Licence :
|
||||
# http://www.fsf.org/licenses/gpl.txt
|
||||
# Developped by : Julien Mathis - Mathieu Mettre
|
||||
# Under control of Flavien Astraud, Jerome Landrieu for Epitech.
|
||||
# Oreon's plugins are developped in partnership with Linagora company.
|
||||
#
|
||||
# Modified for Oreon Project by : Mathieu Chateau - Christophe Coraboeuf
|
||||
#
|
||||
# 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.
|
||||
|
||||
## Plugin init
|
||||
|
||||
use strict;
|
||||
use FindBin;
|
||||
use lib "$FindBin::Bin";
|
||||
use lib "/srv/nagios/libexec";
|
||||
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 vars qw($PROGNAME);
|
||||
use Getopt::Long;
|
||||
use vars qw($opt_H $opt_p $opt_s $opt_v $opt_V $opt_h $opt_w $opt_c $opt_S $opt_g $opt_t $opt_l $opt_d $opt_D $opt_step $step $opt_f);
|
||||
|
||||
## Plugin var init
|
||||
|
||||
my $pathtolibexecnt = $oreon{GLOBAL}{NAGIOS_LIBEXEC}."check_nt";
|
||||
my($op_v, $op_d, $op_s, $op_t, $op_l, $port, @values, @test, @test2, @test3, @test4, @test5, $warning, $critical, @w, @c, $uptime);
|
||||
my($warning2, $critical2, $warning3, $critical3, $warning4, $critical4, @output);
|
||||
$PROGNAME = "check_nt_oreon";
|
||||
|
||||
sub print_help ();
|
||||
sub print_usage ();
|
||||
|
||||
Getopt::Long::Configure('bundling');
|
||||
GetOptions
|
||||
("h" => \$opt_h, "help" => \$opt_h,
|
||||
"p=s" => \$opt_p, "port=s" => \$opt_p,
|
||||
"V" => \$opt_V, "version" => \$opt_V,
|
||||
"s=s" => \$opt_s, "password=s" => \$opt_s,
|
||||
"d=s" => \$opt_d, "showall=s" => \$opt_d,
|
||||
"v=s" => \$opt_v, "variable=s" => \$opt_v,
|
||||
"D=s" => \$opt_D, "directory=s" => \$opt_D,
|
||||
"t=s" => \$opt_t, "timeout=s" => \$opt_t,
|
||||
"l:s" => \$opt_l, "parameter:s" => \$opt_l,
|
||||
"w=s" => \$opt_w, "warning=s" => \$opt_w,
|
||||
"c=s" => \$opt_c, "critical=s" => \$opt_c,
|
||||
"S=s" => \$opt_S, "ServiceId=s" => \$opt_S,
|
||||
"H=s" => \$opt_H, "hostname=s" => \$opt_H);
|
||||
|
||||
if ($opt_h) {
|
||||
print_help();
|
||||
exit $ERRORS{'OK'};
|
||||
}
|
||||
|
||||
if ($opt_V) {
|
||||
$_ = `$pathtolibexecnt -V`;
|
||||
print "$_";
|
||||
exit $ERRORS{'OK'};
|
||||
}
|
||||
|
||||
if ($opt_p) {
|
||||
if ($opt_p =~ /([0-9]+)/){
|
||||
$port = $1;
|
||||
} else {
|
||||
print "Unknown -p number expected... or it doesn't exist, try another port - number\n";
|
||||
exit $ERRORS{'UNKNOWN'};
|
||||
}
|
||||
}
|
||||
|
||||
$opt_H = shift unless ($opt_H);
|
||||
(print_usage() && exit $ERRORS{'OK'}) unless ($opt_H);
|
||||
|
||||
|
||||
if ($opt_c) {
|
||||
($opt_c) || ($opt_c = shift);
|
||||
$critical = $1 if ($opt_c =~ /([0-9]+)/);
|
||||
}
|
||||
|
||||
if ($opt_w) {
|
||||
($opt_w) || ($opt_w = shift);
|
||||
$warning = $1 if ($opt_w =~ /([0-9]+)/);
|
||||
}
|
||||
|
||||
if (($critical && $warning) && ($critical <= $warning)) {
|
||||
print "(--crit) must be superior to (--warn)";
|
||||
print_usage();
|
||||
exit $ERRORS{'OK'};
|
||||
}
|
||||
|
||||
if ($opt_t) {
|
||||
($opt_t) || ($opt_t = shift);
|
||||
$op_t = $1 if ($opt_t =~ /([-\.,\w]+)/);
|
||||
}
|
||||
|
||||
if ($opt_l) {
|
||||
($opt_l) || ($opt_l = shift);
|
||||
$op_l = $1 if ($opt_l =~ /(.+)/);
|
||||
}
|
||||
|
||||
if ($opt_d) {
|
||||
($opt_d) || ($opt_d = shift);
|
||||
$op_d = $1 if ($opt_d =~ /([-.,A-Za-z0-9]+)/);
|
||||
}
|
||||
|
||||
if ($opt_s) {
|
||||
($opt_s) || ($opt_s = shift);
|
||||
$op_s = $1 if ($opt_s =~ /([\_\-\.\,A-Za-z0-9]+)/);
|
||||
}
|
||||
|
||||
if ($opt_v) {
|
||||
($opt_v) || ($opt_v = shift);
|
||||
$op_v = $1 if ($opt_v =~ /([-.,A-Za-z0-9]+)/);
|
||||
}
|
||||
|
||||
my $name = $0;
|
||||
$name =~ s/\.pl.*//g;
|
||||
my $return_code;
|
||||
|
||||
## Plugin requests
|
||||
|
||||
my $start=time;
|
||||
if ($op_v) {
|
||||
if ($op_v) {$op_v = "-v ".$op_v;}
|
||||
if ($port) {$port = "-p ".$port;} else { $port = " ";}
|
||||
if ($warning) {$warning = "-w ".$warning;} else { $warning = " ";}
|
||||
if ($critical) {$critical = "-c ".$critical;} else { $critical = " ";}
|
||||
if ($op_l) {$op_l = "-l \"".$op_l ."\"";} else { $op_l = " ";}
|
||||
if ($op_t) {$op_t = "-t ".$op_t;} else { $op_t = " ";}
|
||||
if ($op_s) {$op_s = "-s ".$op_s;} else { $op_s = " ";}
|
||||
if ($op_d) {$op_d = "-d ".$op_d;} else { $op_d = " ";}
|
||||
# print "$pathtolibexecnt -H $opt_H $op_v $port $warning $critical $op_l $op_t $op_s $op_d\n";
|
||||
$_ = `$pathtolibexecnt -H $opt_H $op_v $port $warning $critical $op_l $op_t $op_s $op_d 2>/dev/null`;
|
||||
my $return = $_;
|
||||
$return =~ s/\\//g;
|
||||
$return_code = $? / 256;
|
||||
|
||||
## CLIENTVERSION
|
||||
if ($op_v =~ /CLIENTVERSION/){
|
||||
print "CLIENTVERSION impossible to Graph!\n";
|
||||
exit $ERRORS{'UNKNOWN'};
|
||||
}
|
||||
|
||||
if (($op_v =~ /CPULOAD/) && ($op_l =~ /([-\.,\w]+)/)){ ## CPULOAD
|
||||
@output = split(/\|/,$_);
|
||||
@values = $output[0] =~ /(\d*)\%/g ;
|
||||
$start = time;
|
||||
## Print Plugins Output
|
||||
$return =~ s/\n//g;
|
||||
my @return_data = split(/\|/,$return);
|
||||
if (@values){
|
||||
if (defined($opt_c) && defined($opt_w)){
|
||||
print $return_data[0] . "|cpu=@values%;$opt_w;$opt_c\n";
|
||||
} else {
|
||||
print $return_data[0] . "|cpu=@values%\n";
|
||||
}
|
||||
} else {
|
||||
print $return . "\n";
|
||||
}
|
||||
exit $return_code;
|
||||
} elsif ($op_v =~ /UPTIME/){ ## UPTIME
|
||||
if ($_ =~ /.*[-:]+\s(\d+)\s.*$/ ) {
|
||||
$uptime = $1;
|
||||
} else {
|
||||
print "unable to parse check_nt output: $_\n" ;
|
||||
exit $ERRORS{'UNKNOWN'};
|
||||
}
|
||||
$_ =~ s/\n/ /g;
|
||||
if (defined($uptime)){
|
||||
print $_ . "|uptime=".$uptime."d\n";
|
||||
} else {
|
||||
print $_ . "\n";
|
||||
}
|
||||
exit $return_code;
|
||||
} elsif (($op_v =~ /USEDDISKSPACE/) && ($op_l =~ /([-\.,\w]+)/)){ ## USEDDISKSPACE
|
||||
my @test = split(/ /,$_);
|
||||
if (defined($test[9]) && defined($test2[1])){
|
||||
@test2 = split(/\(/, $test[9]);
|
||||
@test3 = split(/\%/, $test2[1]);
|
||||
}
|
||||
@c = split(/ /, $critical);
|
||||
$critical = $c[1];
|
||||
@w = split(/ /, $warning);
|
||||
$warning = $w[1];
|
||||
## Print Plugins Output
|
||||
$return =~ s/\n/ /g;
|
||||
my @return_part = split(/\|/, $return);
|
||||
#$return =~ s/%/ pct/g;
|
||||
## Put value in octets : Mo -> o
|
||||
if (defined($test[3]) && defined($test[7]) && defined($test[12])){
|
||||
$test[3] = $test[3] * 1024 * 1024;
|
||||
$test[7] = $test[7] * 1024 * 1024;
|
||||
print $return_part[0] . "|total=".$test[3]."o used=".$test[7]."o\n";
|
||||
} else {
|
||||
print $return_part[0] . "\n";
|
||||
}
|
||||
exit $return_code;
|
||||
} elsif ($op_v =~ /MEMUSE/){ ## MEMUSE
|
||||
$start = time;
|
||||
my @test = split(/ /,$_);
|
||||
if (defined($test[2])){
|
||||
@test4 = split(/:/, $test[2]);
|
||||
}
|
||||
@c = split(/ /, $critical);
|
||||
$critical = $c[1];
|
||||
@w = split(/ /, $warning);
|
||||
$warning = $w[1];
|
||||
## Print Plugins Output
|
||||
my @return_data = split(/\|/,$return);
|
||||
$return =~ s/\n/ /g;
|
||||
#$return =~ s/%/ pct/g;
|
||||
if ($test4[1] && $test[6] && $test[11]){
|
||||
## Put value in octets : Mo -> o
|
||||
$test4[1] = $test4[1] * 1024 * 1024;
|
||||
$test[6] = $test[6] * 1024 * 1024;
|
||||
print $return_data[0] . "|total=".$test4[1]."o used=".$test[6]."o\n";
|
||||
} else {
|
||||
print $return_data[0] . "\n";
|
||||
}
|
||||
exit $return_code;
|
||||
} elsif ($op_v =~ /SERVICESTATE/){## SERVICESTATE
|
||||
my (@tab, $process, $nom, $etat);
|
||||
@tab = split (' - ',$_);
|
||||
foreach $process (@tab) {
|
||||
($nom,$etat) = split (': ', $process);
|
||||
if (defined($etat)) {
|
||||
$etat =~ s/\n//;
|
||||
} else {
|
||||
$etat = "Unknow";
|
||||
}
|
||||
if ($etat =~ /Started/)
|
||||
{$etat=1;}
|
||||
elsif ($etat =~ /Stopped/)
|
||||
{$etat=0;}
|
||||
elsif ($etat =~ /Unknown/)
|
||||
{$etat=-1;}
|
||||
else {
|
||||
print "Unable to get $nom status [$etat]: \n\t$_\n";
|
||||
exit $ERRORS{'UNKNOWN'};
|
||||
}
|
||||
}
|
||||
$return =~ s/%/ pct/g;
|
||||
print $return;
|
||||
exit $return_code;
|
||||
} elsif ($op_v =~ /PROCSTATE/){## PROCSTATE
|
||||
print "PROCSTATE not graphed\n";
|
||||
exit $ERRORS{'UNKNOWN'};
|
||||
} elsif (($op_v =~ /COUNTER/) && ($op_l =~ /(.+)/)) { ## COUNTER
|
||||
@output = split(/\|/,$_);
|
||||
@values = $output[0] =~ /([,\.\d]*)\s?\%/ ;
|
||||
if (!@values) {@values = $output[0] =~ /([\d]*)/;}
|
||||
$start=time;
|
||||
## Print Plugins Output
|
||||
$return =~ s/\n/ /g;
|
||||
$return =~ s/%/ pct/g;
|
||||
print $return . "|counter=".@values."\n";
|
||||
exit $return_code;
|
||||
}
|
||||
} else {
|
||||
print "Could not parse arguments\n";
|
||||
exit $ERRORS{'UNKNOWN'};
|
||||
}
|
||||
|
||||
##
|
||||
## Plugin return code
|
||||
##
|
||||
|
||||
sub print_usage () {
|
||||
print "\nUsage:\n";
|
||||
print "$PROGNAME\n";
|
||||
print " Usage: check_graph_nt -H host -v variable [-p port] [-s password] [-w warning] [-c critical] [-l params] [-d SHOWALL] [-t timeout] [-D rrd directory] -g -S ServiceID\n";
|
||||
print " Options:\n";
|
||||
print " -H, --hostname=HOST\n";
|
||||
print " Name of the host to check\n";
|
||||
print " -p, --port=INTEGER\n";
|
||||
print " Optional port number (default: 1248)\n";
|
||||
print " -s <password>\n";
|
||||
print " Password needed for the request\n";
|
||||
print " -v, --variable=STRING\n";
|
||||
print " Variable to check. Valid variables are:\n";
|
||||
print " CLIENTVERSION = Not Graphed. Get the NSClient version\n";
|
||||
print " CPULOAD = Average CPU load on last x minutes. Request a -l parameter with the following syntax:\n";
|
||||
print " -l <minutes range>,<warning threshold>,<critical threshold>. <minute range> should be less than 24*60.\n";
|
||||
print " Thresholds are percentage and up to 10 requests can be done in one shot. ie: -l 60,90,95,120,90,95\n";
|
||||
print " and 4 requests can be graphed.\n";
|
||||
print " UPTIME = Only Days are graphed. Get the uptime of the machine. No specific parameters. No warning or critical threshold.\n";
|
||||
print " USEDDISKSPACE = Size and percentage of disk use. Request a -l parameter containing the drive letter only.\n";
|
||||
print " Warning and critical thresholds can be specified with -w and -c.\n";
|
||||
print " MEMUSE = Memory use. Warning and critical thresholds can be specified with -w and -c.\n";
|
||||
print " SERVICESTATE = Check and graph the state of one service. Request a -l parameters with the following syntax:\n";
|
||||
print " -l <service1>... You MUST specify -d SHOWALL in the input command.\n";
|
||||
print " 1: Service Started - 0: Service Stopped - -1: Service Unknown.\n";
|
||||
# print " SERVICESTATE = Not Graphed. Check the state of one or several services. Request a -l parameters with the following syntax:\n";
|
||||
# print " -l <service1>,<service2>,<service3>,... You can specify -d SHOWALL in case you want to see working services\n";
|
||||
# print " in the returned string.\n";
|
||||
print " PROCSTATE = Not Graphed. Check if one or several process are running. Same syntax as SERVICESTATE.\n";
|
||||
print " COUNTER = Check any performance counter of Windows NT/2000. Request a -l parameters with the following syntax:\n";
|
||||
print " -l \"<performance object>counter\",\"<description>\" The <description> parameter is optional and\n";
|
||||
print " is given to a printf output command which require a float parameters. Some examples:\n";
|
||||
print " \"Paging file usage is %.2f %%\" or \"%.f %% paging file used.\"\n";
|
||||
print " -w, --warning=INTEGER\n";
|
||||
print " Threshold which will result in a warning status\n";
|
||||
print " -c, --critical=INTEGER\n";
|
||||
print " Threshold which will result in a critical status\n";
|
||||
print " -t, --timeout=INTEGER\n";
|
||||
print " Seconds before connection attempt times out (default: 10)\n";
|
||||
print " -h, --help\n";
|
||||
print " Print this help screen\n";
|
||||
print " -V, --version\n";
|
||||
print " Print version information\n";
|
||||
}
|
||||
|
||||
sub print_help () {
|
||||
print "Copyright (c) 2004 OREON\n";
|
||||
print "Bugs to http://www.oreon.org/\n";
|
||||
print "\n";
|
||||
print_usage();
|
||||
print "\n";
|
||||
}
|
534
centreon-plugins/src/check_snmp_cpfw.pl
Normal file
534
centreon-plugins/src/check_snmp_cpfw.pl
Normal file
@ -0,0 +1,534 @@
|
||||
#!/usr/bin/perl -w
|
||||
############################## check_snmp_cpfw ##############
|
||||
# Version : 0.7
|
||||
# Date : Oct 02 2004
|
||||
# Author : Patrick Proy (patrick at proy.org)
|
||||
# Help : http://www.manubulon.com/nagios/
|
||||
# Licence : GPL - http://www.fsf.org/licenses/gpl.txt
|
||||
# TODO :
|
||||
# - check sync method
|
||||
#################################################################
|
||||
#
|
||||
# Help : ./check_snmp_cpfw.pl -h
|
||||
#
|
||||
|
||||
use strict;
|
||||
use Net::SNMP;
|
||||
use Getopt::Long;
|
||||
|
||||
# Nagios specific
|
||||
|
||||
use lib "@NAGIOS_PLUGINS@";
|
||||
use utils qw(%ERRORS $TIMEOUT);
|
||||
#my $TIMEOUT = 15;
|
||||
#my %ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3,'DEPENDENT'=>4);
|
||||
|
||||
# Oreon specific
|
||||
|
||||
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'};
|
||||
}
|
||||
|
||||
my $pathtorrdbase = $oreon{GLOBAL}{DIR_RRDTOOL};
|
||||
|
||||
|
||||
########### SNMP Datas ###########
|
||||
|
||||
###### FW data
|
||||
my $policy_state = "1.3.6.1.4.1.2620.1.1.1.0"; # "Installed"
|
||||
my $policy_name = "1.3.6.1.4.1.2620.1.1.2.0"; # Installed policy name
|
||||
my $connections = "1.3.6.1.4.1.2620.1.1.25.3.0"; # number of connections
|
||||
#my $connections_peak = "1.3.6.1.4.1.2620.1.1.25.4.0"; # peak number of connections
|
||||
my @fw_checks = ($policy_state,$policy_name,$connections);
|
||||
|
||||
###### SVN data
|
||||
my $svn_status = "1.3.6.1.4.1.2620.1.6.102.0"; # "OK" svn status
|
||||
my %svn_checks = ($svn_status,"OK");
|
||||
my %svn_checks_n = ($svn_status,"SVN status");
|
||||
my @svn_checks_oid = ($svn_status);
|
||||
|
||||
###### HA data
|
||||
|
||||
my $ha_active = "1.3.6.1.4.1.2620.1.5.5.0"; # "yes"
|
||||
my $ha_state = "1.3.6.1.4.1.2620.1.5.6.0"; # "active"
|
||||
my $ha_block_state = "1.3.6.1.4.1.2620.1.5.7.0"; #"OK" : ha blocking state
|
||||
my $ha_status = "1.3.6.1.4.1.2620.1.5.102.0"; # "OK" : ha status
|
||||
|
||||
my %ha_checks =( $ha_active,"yes",$ha_state,"active",$ha_block_state,"OK",$ha_status,"OK");
|
||||
my %ha_checks_n =( $ha_active,"HA active",$ha_state,"HA state",$ha_block_state,"HA block state",$ha_status,"ha_status");
|
||||
my @ha_checks_oid =( $ha_active,$ha_state,$ha_block_state,$ha_status);
|
||||
|
||||
my $ha_mode = "1.3.6.1.4.1.2620.1.5.11.0"; # "Sync only" : ha Working mode
|
||||
|
||||
my $ha_tables = "1.3.6.1.4.1.2620.1.5.13.1"; # ha status table
|
||||
my $ha_tables_index = ".1";
|
||||
my $ha_tables_name = ".2";
|
||||
my $ha_tables_state = ".3"; # "OK"
|
||||
my $ha_tables_prbdesc = ".6"; # Description if state is != "OK"
|
||||
|
||||
#my @ha_table_check = ("Synchronization","Filter","cphad","fwd"); # process to check
|
||||
|
||||
####### MGMT data
|
||||
|
||||
my $mgmt_status = "1.3.6.1.4.1.2620.1.7.5.0"; # "active" : management status
|
||||
my $mgmt_alive = "1.3.6.1.4.1.2620.1.7.6.0"; # 1 : management is alive if 1
|
||||
my $mgmt_stat_desc = "1.3.6.1.4.1.2620.1.7.102.0"; # Management status description
|
||||
my $mgmt_stats_desc_l = "1.3.6.1.4.1.2620.1.7.103.0"; # Management status long description
|
||||
|
||||
my %mgmt_checks = ($mgmt_status,"active",$mgmt_alive,"1");
|
||||
my %mgmt_checks_n = ($mgmt_status,"Mgmt status",$mgmt_alive,"Mgmt alive");
|
||||
my @mgmt_checks_oid = ($mgmt_status,$mgmt_alive);
|
||||
|
||||
#################################### Globals ##############################""
|
||||
|
||||
my $Version='0.7';
|
||||
|
||||
my $o_host = undef; # hostname
|
||||
my $o_community = undef; # community
|
||||
my $o_port = 161; # port
|
||||
my $o_help= undef; # wan't some help ?
|
||||
my $o_verb= undef; # verbose mode
|
||||
my $o_version= undef; # print version
|
||||
my $o_warn= undef; # Warning for connections
|
||||
my $o_crit= undef; # Crit for connections
|
||||
my $o_svn= undef; # Check for SVN status
|
||||
my $o_fw= undef; # Check for FW status
|
||||
my $o_ha= undef; # Check for HA status
|
||||
my $o_mgmt= undef; # Check for management status
|
||||
my $o_policy= undef; # Check for policy name
|
||||
my $o_conn= undef; # Check for connexions
|
||||
my $o_perf= undef; # Performance data output
|
||||
|
||||
# SNMPv3 specific
|
||||
my $o_login= undef; # Login for snmpv3
|
||||
my $o_passwd= undef; # Pass for snmpv3
|
||||
|
||||
# Oreon specific
|
||||
my $o_step= undef;
|
||||
my $o_g= undef;
|
||||
my $o_S= undef;
|
||||
my $step= undef;
|
||||
my $rrd= undef;
|
||||
my $start= undef;
|
||||
my $ServiceId= undef;
|
||||
my @rrd_data= undef;
|
||||
|
||||
|
||||
# functions
|
||||
|
||||
sub p_version { print "check_snmp_cpfw version : $Version\n"; }
|
||||
|
||||
sub print_usage {
|
||||
print "Usage: $0 [-v] -H <host> -C <snmp_community> | (-l login -x passwd) [-s] [-w [-p=pol_name] [-c=warn,crit]] [-m] [-a] [-f] [-p <port>] [-t <timeout>] [-V]\n";
|
||||
}
|
||||
|
||||
sub isnnum { # Return true if arg is not a number
|
||||
my $num = shift;
|
||||
if ( $num =~ /^(\d+\.?\d*)|(^\.\d+)$/ ) { return 0 ;}
|
||||
return 1;
|
||||
}
|
||||
|
||||
sub help {
|
||||
print "\nSNMP Checkpoint FW-1 Monitor for Nagios version ",$Version,"\n";
|
||||
print "(c)2004 - to my cat Ratoune\n\n";
|
||||
print_usage();
|
||||
print <<EOT;
|
||||
-v, --verbose
|
||||
print extra debugging information (including interface list on the system)
|
||||
-h, --help
|
||||
print this help message
|
||||
-H, --hostname=HOST
|
||||
name or IP address of host to check
|
||||
-C, --community=COMMUNITY NAME
|
||||
community name for the host's SNMP agent (implies v1 protocol)
|
||||
-s, --svn
|
||||
check for svn status
|
||||
-w, --fw
|
||||
check for fw status
|
||||
-a, --ha
|
||||
check for ha status
|
||||
-m, --mgmt
|
||||
check for management status
|
||||
-p, --policy=POLICY_NAME
|
||||
check if installed policy is POLICY_NAME (must have -w)
|
||||
-c, --connexions=WARN,CRIT
|
||||
check warn and critical number of connexions (must have -w)
|
||||
-f, --perfparse
|
||||
perfparse output (only works with -c)
|
||||
-l, --login=LOGIN
|
||||
Login for snmpv3 authentication (implies v3 protocol with MD5)
|
||||
-x, --passwd=PASSWD
|
||||
Password for snmpv3 authentication
|
||||
-P, --port=PORT
|
||||
SNMP port (Default 161)
|
||||
-t, --timeout=INTEGER
|
||||
timeout for SNMP (Default: Nagios default)
|
||||
-V, --version
|
||||
prints version number
|
||||
-g (--rrdgraph) Create a rrd base if necessary and add datas into this one
|
||||
--rrd_step Specifies the base interval in seconds with which data will be fed into the RRD (300 by default)
|
||||
-S (--ServiceId) Oreon Service Id
|
||||
|
||||
EOT
|
||||
}
|
||||
|
||||
# For verbose output
|
||||
sub verb { my $t=shift; print $t,"\n" if defined($o_verb) ; }
|
||||
|
||||
sub check_options {
|
||||
Getopt::Long::Configure ("bundling");
|
||||
GetOptions(
|
||||
'v' => \$o_verb, 'verbose' => \$o_verb,
|
||||
'h' => \$o_help, 'help' => \$o_help,
|
||||
'H:s' => \$o_host, 'hostname:s' => \$o_host,
|
||||
'P:i' => \$o_port, 'port:i' => \$o_port,
|
||||
'C:s' => \$o_community, 'community:s' => \$o_community,
|
||||
'l:s' => \$o_login, 'login:s' => \$o_login,
|
||||
'x:s' => \$o_passwd, 'passwd:s' => \$o_passwd,
|
||||
't:i' => \$TIMEOUT, 'timeout:i' => \$TIMEOUT,
|
||||
'V' => \$o_version, 'version' => \$o_version,
|
||||
's' => \$o_svn, 'svn' => \$o_svn,
|
||||
'w' => \$o_fw, 'fw' => \$o_fw,
|
||||
'a' => \$o_ha, 'ha' => \$o_ha,
|
||||
'm' => \$o_mgmt, 'mgmt' => \$o_mgmt,
|
||||
'p:s' => \$o_policy, 'policy:s' => \$o_policy,
|
||||
'c:s' => \$o_conn, 'connexions:s' => \$o_conn,
|
||||
'f' => \$o_perf, 'perfparse' => \$o_perf,
|
||||
# For Oreon rrdtool graph
|
||||
"rrd_step:s" => \$o_step,
|
||||
"g" => \$o_g, "rrdgraph" => \$o_g,
|
||||
"S=s" => \$o_S, "ServiceId=s" => \$o_S
|
||||
);
|
||||
if (defined ($o_help) ) { help(); exit $ERRORS{"UNKNOWN"}};
|
||||
if (defined($o_version)) { p_version(); exit $ERRORS{"UNKNOWN"}};
|
||||
if ( ! defined($o_host) ) # check host and filter
|
||||
{ print_usage(); exit $ERRORS{"UNKNOWN"}}
|
||||
# check snmp information
|
||||
if ( !defined($o_community) && (!defined($o_login) || !defined($o_passwd)) )
|
||||
{ print "Put snmp login info!\n"; print_usage(); exit $ERRORS{"UNKNOWN"}}
|
||||
# Check firewall options
|
||||
if ( defined($o_conn)) {
|
||||
if ( ! defined($o_fw))
|
||||
{ print "Cannot check connexions without checking fw\n"; print_usage(); exit $ERRORS{"UNKNOWN"}}
|
||||
my @warncrit=split(/,/ , $o_conn);
|
||||
if ( $#warncrit != 1 )
|
||||
{ print "Put warn,crit levels with -c option\n";print_usage(); exit $ERRORS{"UNKNOWN"}}
|
||||
($o_warn,$o_crit)=@warncrit;
|
||||
if ( isnnum($o_warn) || isnnum($o_crit) )
|
||||
{ print "Numeric values for warning and critical in -c options\n";print_usage(); exit $ERRORS{"UNKNOWN"}}
|
||||
if ($o_warn >= $o_crit)
|
||||
{ print "warning <= critical ! \n";print_usage(); exit $ERRORS{"UNKNOWN"}}
|
||||
}
|
||||
if ( defined($o_policy)) {
|
||||
if (! defined($o_fw))
|
||||
{ print "Cannot check policy name without checking fw\n"; print_usage(); exit $ERRORS{"UNKNOWN"}}
|
||||
if ($o_policy eq "")
|
||||
{ print "Put a policy name !\n"; print_usage(); exit $ERRORS{"UNKNOWN"}}
|
||||
}
|
||||
if (defined($o_perf) && ! defined ($o_conn))
|
||||
{ print "Nothing selected for perfparse !\n";print_usage(); exit $ERRORS{"UNKNOWN"}}
|
||||
if (!defined($o_fw) && !defined($o_ha) && !defined($o_mgmt) && !defined($o_svn))
|
||||
{ print "Must select a product to check !\n";print_usage(); exit $ERRORS{"UNKNOWN"}}
|
||||
|
||||
###### Oreon #######
|
||||
|
||||
if (!defined($o_S)) { $o_S="1_1" }
|
||||
$ServiceId = is_valid_serviceid($o_S);
|
||||
|
||||
if (!defined($o_step)) { $o_step="300" }
|
||||
$step = $1 if ($o_step =~ /(\d+)/);
|
||||
|
||||
}
|
||||
|
||||
########## MAIN #######
|
||||
|
||||
check_options();
|
||||
|
||||
$rrd = $pathtorrdbase.$ServiceId.".rrd";
|
||||
$start=time;
|
||||
|
||||
# Check gobal timeout if snmp screws up
|
||||
alarm($TIMEOUT+15);
|
||||
|
||||
# Connect to host
|
||||
my ($session,$error);
|
||||
if ( defined($o_login) && defined($o_passwd)) {
|
||||
# SNMPv3 login
|
||||
verb("SNMPv3 login");
|
||||
($session, $error) = Net::SNMP->session(
|
||||
-hostname => $o_host,
|
||||
-version => '3',
|
||||
-username => $o_login,
|
||||
-authpassword => $o_passwd,
|
||||
-authprotocol => 'md5',
|
||||
-privpassword => $o_passwd
|
||||
);
|
||||
} else {
|
||||
# SNMPV1 login
|
||||
($session, $error) = Net::SNMP->session(
|
||||
-hostname => $o_host,
|
||||
-community => $o_community,
|
||||
-port => $o_port,
|
||||
-timeout => $TIMEOUT
|
||||
);
|
||||
}
|
||||
if (!defined($session)) {
|
||||
printf("ERROR opening session: %s.\n", $error);
|
||||
exit $ERRORS{"UNKNOWN"};
|
||||
}
|
||||
|
||||
########### Global checks #################
|
||||
|
||||
my $global_status=0; # global status : 0=OK, 1=Warn, 2=Crit
|
||||
my ($resultat,$key)=(undef,undef);
|
||||
|
||||
########## Check SVN status #############
|
||||
my $svn_print="";
|
||||
my $svn_state=0;
|
||||
|
||||
if (defined ($o_svn)) {
|
||||
|
||||
$resultat = $session->get_request(
|
||||
Varbindlist => \@svn_checks_oid
|
||||
);
|
||||
|
||||
if (defined($resultat)) {
|
||||
foreach $key ( keys %svn_checks) {
|
||||
verb("$svn_checks_n{$key} : $svn_checks{$key} / $$resultat{$key}");
|
||||
if ( $$resultat{$key} ne $svn_checks{$key} ) {
|
||||
$svn_print .= $svn_checks_n{$key} . ":" . $$resultat{$key} . " ";
|
||||
$svn_state=2;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$svn_print .= "cannot find oids";
|
||||
#Critical state if not found because it means soft is not activated
|
||||
$svn_state=2;
|
||||
}
|
||||
|
||||
if ($svn_state == 0) {
|
||||
$svn_print="SVN : OK";
|
||||
} else {
|
||||
$svn_print="SVN : " . $svn_print;
|
||||
}
|
||||
verb("$svn_print");
|
||||
}
|
||||
########## Check mgmt status #############
|
||||
my $mgmt_state=0;
|
||||
my $mgmt_print="";
|
||||
|
||||
if (defined ($o_mgmt)) {
|
||||
# Check all states
|
||||
$resultat=undef;
|
||||
$resultat = $session->get_request(
|
||||
Varbindlist => \@mgmt_checks_oid
|
||||
);
|
||||
if (defined($resultat)) {
|
||||
foreach $key ( keys %mgmt_checks) {
|
||||
verb("$mgmt_checks_n{$key} : $mgmt_checks{$key} / $$resultat{$key}");
|
||||
if ( $$resultat{$key} ne $mgmt_checks{$key} ) {
|
||||
$mgmt_print .= $mgmt_checks_n{$key} . ":" . $$resultat{$key} . " ";
|
||||
$mgmt_state=2;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$mgmt_print .= "cannot find oids";
|
||||
#Critical state if not found because it means soft is not activated
|
||||
$mgmt_state=2;
|
||||
}
|
||||
if ($mgmt_state == 0) {
|
||||
$mgmt_print="MGMT : OK";
|
||||
} else {
|
||||
$mgmt_print="MGMT : " . $mgmt_print;
|
||||
}
|
||||
verb("$svn_print");
|
||||
}
|
||||
|
||||
########### Check fw status ##############
|
||||
|
||||
my $fw_state=0;
|
||||
my $fw_print="";
|
||||
my $perf_conn=undef;
|
||||
|
||||
if (defined ($o_fw)) {
|
||||
|
||||
# Check all states
|
||||
|
||||
$resultat = $session->get_request(
|
||||
Varbindlist => \@fw_checks
|
||||
);
|
||||
if (defined($resultat)) {
|
||||
verb("State : $$resultat{$policy_state}");
|
||||
verb("Name : $$resultat{$policy_name}");
|
||||
verb("connections : $$resultat{$connections}");
|
||||
|
||||
if ($$resultat{$policy_state} ne "Installed") {
|
||||
$fw_state=2;
|
||||
$fw_print .= "Policy:". $$resultat{$policy_state}." ";
|
||||
verb("Policy state not installed");
|
||||
}
|
||||
|
||||
if (defined($o_policy)) {
|
||||
if ($$resultat{$policy_name} ne $o_policy) {
|
||||
$fw_state=2;
|
||||
$fw_print .= "Policy installed : $$resultat{$policy_name}";
|
||||
}
|
||||
}
|
||||
|
||||
if (defined($o_conn)) {
|
||||
if ($$resultat{$connections} > $o_crit) {
|
||||
$fw_state=2;
|
||||
$fw_print .= "Connexions : ".$$resultat{$connections}." > ".$o_crit." ";
|
||||
} else {
|
||||
if ($$resultat{$connections} > $o_warn) {
|
||||
$fw_state=1;
|
||||
$fw_print .= "Connexions : ".$$resultat{$connections}." > ".$o_warn." ";
|
||||
}
|
||||
}
|
||||
$perf_conn=$$resultat{$connections};
|
||||
|
||||
##
|
||||
## RRD management
|
||||
##
|
||||
|
||||
if ($o_g) {
|
||||
$start=time;
|
||||
if (! -e $rrd) {
|
||||
create_rrd($rrd,1,$start,$step,0,"U","GAUGE");
|
||||
}
|
||||
update_rrd($rrd,$start, $perf_conn);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$fw_print .= "cannot find oids";
|
||||
#Critical state if not found because it means soft is not activated
|
||||
$fw_state=2;
|
||||
}
|
||||
|
||||
if ($fw_state==0) {
|
||||
$fw_print="FW : OK";
|
||||
} else {
|
||||
$fw_print="FW : " . $fw_print;
|
||||
}
|
||||
|
||||
}
|
||||
########### Check ha status ##############
|
||||
|
||||
my $ha_state_n=0;
|
||||
my $ha_print="";
|
||||
|
||||
if (defined ($o_ha)) {
|
||||
# Check all states
|
||||
|
||||
$resultat = $session->get_request(
|
||||
Varbindlist => \@ha_checks_oid
|
||||
);
|
||||
|
||||
if (defined($resultat)) {
|
||||
foreach $key ( keys %ha_checks) {
|
||||
verb("$ha_checks_n{$key} : $ha_checks{$key} / $$resultat{$key}");
|
||||
if ( $$resultat{$key} ne $ha_checks{$key} ) {
|
||||
$ha_print .= $ha_checks_n{$key} . ":" . $$resultat{$key} . " ";
|
||||
$ha_state_n=2;
|
||||
}
|
||||
}
|
||||
#my $ha_mode = "1.3.6.1.4.1.2620.1.5.11.0"; # "Sync only" : ha Working mode
|
||||
} else {
|
||||
$ha_print .= "cannot find oids";
|
||||
#Critical state if not found because it means soft is not activated
|
||||
$ha_state_n=2;
|
||||
}
|
||||
|
||||
# get ha status table
|
||||
$resultat = $session->get_table(
|
||||
Baseoid => $ha_tables
|
||||
);
|
||||
my %status;
|
||||
my (@index,@oid) = (undef,undef);
|
||||
my $nindex=0;
|
||||
my $index_search= $ha_tables . $ha_tables_index;
|
||||
|
||||
if (defined($resultat)) {
|
||||
foreach $key ( keys %$resultat) {
|
||||
if ( $key =~ /$index_search/) {
|
||||
@oid=split (/\./,$key);
|
||||
pop(@oid);
|
||||
$index[$nindex]=pop(@oid);
|
||||
$nindex++;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$ha_print .= "cannot find oids" if ($ha_state_n ==0);
|
||||
#Critical state if not found because it means soft is not activated
|
||||
$ha_state_n=2;
|
||||
}
|
||||
verb ("found $nindex ha softs");
|
||||
if ( $nindex == 0 )
|
||||
{
|
||||
$ha_print .= " no ha soft found" if ($ha_state_n ==0);
|
||||
$ha_state_n=2;
|
||||
} else {
|
||||
my $ha_soft_name=undef;
|
||||
|
||||
for (my $i=0;$i<$nindex;$i++) {
|
||||
|
||||
$key=$ha_tables . $ha_tables_name . "." . $index[$i] . ".0";
|
||||
$ha_soft_name= $$resultat{$key};
|
||||
|
||||
$key=$ha_tables . $ha_tables_state . "." . $index[$i] . ".0";
|
||||
if (($status{$ha_soft_name} = $$resultat{$key}) ne "OK") {
|
||||
$key=$ha_tables . $ha_tables_prbdesc . "." . $index[$i] . ".0";
|
||||
$status{$ha_soft_name} = $$resultat{$key};
|
||||
$ha_print .= $ha_soft_name . ":" . $status{$ha_soft_name} . " ";
|
||||
$ha_state_n=2
|
||||
}
|
||||
verb ("$ha_soft_name : $status{$ha_soft_name}");
|
||||
}
|
||||
}
|
||||
|
||||
if ($ha_state_n == 0) {
|
||||
$ha_print = "HA : OK";
|
||||
} else {
|
||||
$ha_print = "HA : " . $ha_print;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$session->close;
|
||||
|
||||
########## print results and exit
|
||||
|
||||
my $f_print=undef;
|
||||
|
||||
if (defined ($o_fw)) { $f_print = $fw_print }
|
||||
if (defined ($o_svn)) { $f_print = (defined ($f_print)) ? $f_print . " / ". $svn_print : $svn_print }
|
||||
if (defined ($o_ha)) { $f_print = (defined ($f_print)) ? $f_print . " / ". $ha_print : $ha_print }
|
||||
if (defined ($o_mgmt)) { $f_print = (defined ($f_print)) ? $f_print . " / ". $mgmt_print : $mgmt_print }
|
||||
|
||||
my $exit_status=undef;
|
||||
$f_print .= " / CPFW Status : ";
|
||||
if (($ha_state_n+$svn_state+$fw_state+$mgmt_state) == 0 ) {
|
||||
$f_print .= "OK";
|
||||
$exit_status= $ERRORS{"OK"};
|
||||
} else {
|
||||
if (($fw_state==1) || ($ha_state_n==1) || ($svn_state==1) || ($mgmt_state==1)) {
|
||||
$f_print .= "WARNING";
|
||||
$exit_status= $ERRORS{"WARNING"};
|
||||
} else {
|
||||
$f_print .= "CRITICAL";
|
||||
$exit_status=$ERRORS{"CRITICAL"};
|
||||
}
|
||||
}
|
||||
|
||||
if (defined($o_perf) && defined ($perf_conn)) {
|
||||
$f_print .= " | fw_connexions=" . $perf_conn;
|
||||
}
|
||||
|
||||
print "$f_print\n";
|
||||
exit $exit_status;
|
||||
|
593
centreon-plugins/src/check_snmp_load.pl
Normal file
593
centreon-plugins/src/check_snmp_load.pl
Normal file
@ -0,0 +1,593 @@
|
||||
#!/usr/bin/perl -w
|
||||
############################## check_snmp_load #################
|
||||
# Version : 1.2 / BETA
|
||||
# Date : Aug 27 2005
|
||||
# Author : Patrick Proy ( patrick at proy.org)
|
||||
# Help : http://www.manubulon.com/nagios/
|
||||
# Licence : GPL - http://www.fsf.org/licenses/gpl.txt
|
||||
# Changelog : HP Procurve
|
||||
# TODO :
|
||||
#################################################################
|
||||
#
|
||||
# Help : ./check_snmp_load.pl -h
|
||||
#
|
||||
|
||||
use strict;
|
||||
use Net::SNMP;
|
||||
use Getopt::Long;
|
||||
|
||||
# Nagios specific
|
||||
|
||||
use lib "@NAGIOS_PLUGINS@";
|
||||
use utils qw(%ERRORS $TIMEOUT);
|
||||
#my $TIMEOUT = 15;
|
||||
#my %ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3,'DEPENDENT'=>4);
|
||||
|
||||
# Oreon specific
|
||||
|
||||
|
||||
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'};
|
||||
}
|
||||
|
||||
my $pathtorrdbase = $oreon{GLOBAL}{DIR_RRDTOOL};
|
||||
|
||||
# SNMP Datas
|
||||
|
||||
# Generic with host-ressource-mib
|
||||
my $base_proc = "1.3.6.1.2.1.25.3.3.1"; # oid for all proc info
|
||||
my $proc_id = "1.3.6.1.2.1.25.3.3.1.1"; # list of processors (product ID)
|
||||
my $proc_load = "1.3.6.1.2.1.25.3.3.1.2"; # %time the proc was not idle over last minute
|
||||
|
||||
# Linux load
|
||||
|
||||
my $linload_table= "1.3.6.1.4.1.2021.10.1"; # net-snmp load table
|
||||
my $linload_name = "1.3.6.1.4.1.2021.10.1.2"; # text 'Load-1','Load-5', 'Load-15'
|
||||
my $linload_load = "1.3.6.1.4.1.2021.10.1.3"; # effective load table
|
||||
|
||||
# Cisco cpu/load
|
||||
|
||||
my $cisco_cpu_5m = "1.3.6.1.4.1.9.2.1.58.0"; # Cisco CPU load (5min %)
|
||||
my $cisco_cpu_1m = "1.3.6.1.4.1.9.2.1.57.0"; # Cisco CPU load (1min %)
|
||||
my $cisco_cpu_5s = "1.3.6.1.4.1.9.2.1.56.0"; # Cisco CPU load (5sec %)
|
||||
|
||||
# AS/400 CPU
|
||||
|
||||
my $as400_cpu = "1.3.6.1.4.1.2.6.4.5.1.0"; # AS400 CPU load (10000=100%);
|
||||
|
||||
# Net-SNMP CPU
|
||||
|
||||
my $ns_cpu_idle = "1.3.6.1.4.1.2021.11.11.0"; # Net-snmp cpu idle
|
||||
my $ns_cpu_user = "1.3.6.1.4.1.2021.11.9.0"; # Net-snmp user cpu usage
|
||||
my $ns_cpu_system = "1.3.6.1.4.1.2021.11.10.0"; # Net-snmp system cpu usage
|
||||
|
||||
# Procurve CPU
|
||||
my $procurve_cpu = "1.3.6.1.4.1.11.2.14.11.5.1.9.6.1.0"; # Procurve CPU Counter
|
||||
|
||||
# Nokia CPU
|
||||
my $nokia_cpu = "1.3.6.1.4.1.94.1.21.1.7.1.0"; # Nokia CPU % usage
|
||||
|
||||
# Bluecoat Appliance
|
||||
my $bluecoat_cpu = "1.3.6.1.4.1.3417.2.4.1.1.1.4.1"; # Bluecoat %cpu usage.
|
||||
|
||||
# Linkproof Appliance
|
||||
my $linkproof_cpu= "1.3.6.1.4.1.89.35.1.53.0"; # Ressource utilisation (%) Considers network utilization and internal CPU utilization
|
||||
# 1.3.6.1.4.1.89.35.1.54 : CPU only (%)
|
||||
# 1.3.6.1.4.1.89.35.1.55 : network only (%)
|
||||
|
||||
# CPU OID array
|
||||
my %cpu_oid = ("netsc",$ns_cpu_idle,"as400",$as400_cpu,"bc",$bluecoat_cpu,"nokia",$nokia_cpu,"hp",$procurve_cpu,"lp",$linkproof_cpu);
|
||||
|
||||
# Globals
|
||||
|
||||
my $Version='1.2';
|
||||
|
||||
my $o_host = undef; # hostname
|
||||
my $o_community = undef; # community
|
||||
my $o_port = 161; # port
|
||||
my $o_help= undef; # wan't some help ?
|
||||
my $o_verb= undef; # verbose mode
|
||||
my $o_version= undef; # print version
|
||||
my $o_check_type= "stand"; # check type : stand | netsc | netsl | as400 | cisco | bc | nokia | hp | lp
|
||||
# For backward compatibility
|
||||
my $o_linux= undef; # Check linux load instead of CPU
|
||||
my $o_linuxC= undef; # Check Net-SNMP CPU
|
||||
my $o_as400= undef; # Check for AS 400 load
|
||||
my $o_cisco= undef; # Check for Cisco CPU
|
||||
# End compatibility
|
||||
my $o_warn= undef; # warning level
|
||||
my @o_warnL= undef; # warning levels for Linux Load or Cisco CPU
|
||||
my $o_crit= undef; # critical level
|
||||
my @o_critL= undef; # critical level for Linux Load or Cisco CPU
|
||||
my $o_timeout= 5; # Default 5s Timeout
|
||||
my $o_perf= undef; # Output performance data
|
||||
my $o_version2= undef; # use snmp v2c
|
||||
# SNMPv3 specific
|
||||
my $o_login= undef; # Login for snmpv3
|
||||
my $o_passwd= undef; # Pass for snmpv3
|
||||
# Oreon specific
|
||||
my $o_step= undef;
|
||||
my $o_g= undef;
|
||||
my $o_S= undef;
|
||||
my $step= undef;
|
||||
my $rrd= undef;
|
||||
my $start= undef;
|
||||
my $ServiceId= undef;
|
||||
|
||||
# functions
|
||||
|
||||
sub p_version { print "check_snmp_load version : $Version\n"; }
|
||||
|
||||
sub print_usage {
|
||||
print "Usage: $0 [-v] -H <host> -C <snmp_community> [-2] | (-l login -x passwd) [-p <port>] -w <warn level> -c <crit level> -T=[stand|netsl|netsc|as400|cisco|bc|nokia|hp|lp] [-f] [-t <timeout>] [-V]\n";
|
||||
}
|
||||
|
||||
sub isnnum { # Return true if arg is not a number
|
||||
my $num = shift;
|
||||
if ( $num =~ /^(\d+\.?\d*)|(^\.\d+)$/ ) { return 0 ;}
|
||||
return 1;
|
||||
}
|
||||
|
||||
sub help {
|
||||
print "\nSNMP Load & CPU Monitor for Nagios version ",$Version,"\n";
|
||||
print "(c)2004 to my cat Ratoune - Author : Patrick Proy\n\n";
|
||||
print_usage();
|
||||
print <<EOT;
|
||||
-v, --verbose
|
||||
print extra debugging information
|
||||
-h, --help
|
||||
print this help message
|
||||
-H, --hostname=HOST
|
||||
name or IP address of host to check
|
||||
-C, --community=COMMUNITY NAME
|
||||
community name for the host's SNMP agent (implies v1 protocol)
|
||||
-2, --v2c
|
||||
Use snmp v2c
|
||||
-l, --login=LOGIN
|
||||
Login for snmpv3 authentication (implies v3 protocol with MD5)
|
||||
-x, --passwd=PASSWD
|
||||
Password for snmpv3 authentication
|
||||
-P, --port=PORT
|
||||
SNMP port (Default 161)
|
||||
-w, --warn=INTEGER | INT,INT,INT
|
||||
warning level for cpu in percent (on one minute)
|
||||
if -L switch then comma separated level for load-1,load-5,load-15
|
||||
if -I switch then comma separated level for cpu 5s,cpu 1m,cpu 5m
|
||||
-c, --crit=INTEGER | INT,INT,INT
|
||||
critical level for cpu in percent (on one minute)
|
||||
if -L switch then comma separated level for load-1,load-5,load-15
|
||||
if -I switch then comma separated level for cpu 5s,cpu 1m,cpu 5m
|
||||
-T, --type=stand|netsl|netsc|as400|cisco|bc|nokia|hp|lp
|
||||
CPU check :
|
||||
stand : standard MIBII (works with Windows),
|
||||
can handle multiple CPU.
|
||||
netsl : check linux load provided by Net SNMP
|
||||
netsc : check cpu usage given by net-snmp (100-idle)
|
||||
as400 : check as400 CPU usage
|
||||
cisco : check cisco CPU usage
|
||||
bc : check bluecoat CPU usage
|
||||
nokia : check nokia CPU usage
|
||||
hp : check HP procurve switch CPU usage
|
||||
lp : Linkproof CPU usage
|
||||
-f, --perfparse
|
||||
Perfparse compatible output
|
||||
-t, --timeout=INTEGER
|
||||
timeout for SNMP in seconds (Default: 5)
|
||||
-V, --version
|
||||
prints version number
|
||||
-L, --linux, -A, --as400, -I, --cisco, -N, --netsnmp
|
||||
These options are for backward compatibility (version<1.2)
|
||||
-g (--rrdgraph) Create a rrd base if necessary and add datas into this one
|
||||
--rrd_step Specifies the base interval in seconds with which data will be fed into the RRD (300 by default)
|
||||
-S (--ServiceId) Oreon Service Id
|
||||
EOT
|
||||
}
|
||||
|
||||
# For verbose output
|
||||
sub verb { my $t=shift; print $t,"\n" if defined($o_verb) ; }
|
||||
|
||||
sub check_options {
|
||||
Getopt::Long::Configure ("bundling");
|
||||
GetOptions(
|
||||
'v' => \$o_verb, 'verbose' => \$o_verb,
|
||||
'h' => \$o_help, 'help' => \$o_help,
|
||||
'H:s' => \$o_host, 'hostname:s' => \$o_host,
|
||||
'p:i' => \$o_port, 'port:i' => \$o_port,
|
||||
'C:s' => \$o_community, 'community:s' => \$o_community,
|
||||
'l:s' => \$o_login, 'login:s' => \$o_login,
|
||||
'x:s' => \$o_passwd, 'passwd:s' => \$o_passwd,
|
||||
't:i' => \$o_timeout, 'timeout:i' => \$o_timeout,
|
||||
'V' => \$o_version, 'version' => \$o_version,
|
||||
|
||||
'2' => \$o_version2, 'v2c' => \$o_version2,
|
||||
'c:s' => \$o_crit, 'critical:s' => \$o_crit,
|
||||
'w:s' => \$o_warn, 'warn:s' => \$o_warn,
|
||||
'f' => \$o_perf, 'perfparse' => \$o_perf,
|
||||
'T:s' => \$o_check_type, 'type:s' => \$o_check_type,
|
||||
# For backward compatibility
|
||||
'L' => \$o_linux, 'linux' => \$o_linux,
|
||||
'A' => \$o_as400, 'as400' => \$o_as400,
|
||||
'I' => \$o_cisco, 'cisco' => \$o_cisco,
|
||||
'N' => \$o_linuxC, 'netsnmp' => \$o_linuxC,
|
||||
# For Oreon rrdtool graph
|
||||
"rrd_step:s" => \$o_step,
|
||||
"g" => \$o_g, "rrdgraph" => \$o_g,
|
||||
"S=s" => \$o_S, "ServiceId=s" => \$o_S
|
||||
);
|
||||
# For backward compat
|
||||
if (defined($o_linux)) { $o_check_type="netsl" }
|
||||
if (defined($o_linuxC)) { $o_check_type="netsc" }
|
||||
if (defined($o_as400)) { $o_check_type="as400"}
|
||||
if (defined($o_cisco)) { $o_check_type="cisco"}
|
||||
# TODO : check the -T option
|
||||
if (defined ($o_help) ) { help(); exit $ERRORS{"UNKNOWN"}};
|
||||
if (defined($o_version)) { p_version(); exit $ERRORS{"UNKNOWN"}};
|
||||
if ( ! defined($o_host) ) # check host and filter
|
||||
{ print_usage(); exit $ERRORS{"UNKNOWN"}}
|
||||
# check snmp information
|
||||
if ( !defined($o_community) && (!defined($o_login) || !defined($o_passwd)) )
|
||||
{ print "Put snmp login info!\n"; print_usage(); exit $ERRORS{"UNKNOWN"}}
|
||||
# Check warnings and critical
|
||||
if (!defined($o_warn) || !defined($o_crit))
|
||||
{ print "put warning and critical info!\n"; print_usage(); exit $ERRORS{"UNKNOWN"}}
|
||||
# Get rid of % sign
|
||||
$o_warn =~ s/\%//g;
|
||||
$o_crit =~ s/\%//g;
|
||||
# Check for multiple warning and crit in case of -L
|
||||
if (($o_warn =~ /,/) || ($o_crit =~ /,/)) {
|
||||
if (($o_check_type ne "netsl") && ($o_check_type ne "cisco")) { print "Multiple warning without -L or -I switch\n";print_usage(); exit $ERRORS{"UNKNOWN"}}
|
||||
@o_warnL=split(/,/ , $o_warn);
|
||||
@o_critL=split(/,/ , $o_crit);
|
||||
if (($#o_warnL != 2) || ($#o_critL != 2))
|
||||
{ print "3 warnings and critical !\n";print_usage(); exit $ERRORS{"UNKNOWN"}}
|
||||
for (my $i=0;$i<3;$i++) {
|
||||
if ( isnnum($o_warnL[$i]) || isnnum($o_critL[$i]))
|
||||
{ print "Numeric value for warning or critical !\n";print_usage(); exit $ERRORS{"UNKNOWN"}}
|
||||
if ($o_warnL[$i] > $o_critL[$i])
|
||||
{ print "warning <= critical ! \n";print_usage(); exit $ERRORS{"UNKNOWN"}}
|
||||
}
|
||||
} else {
|
||||
if (($o_check_type eq "netsl") || ($o_check_type eq "cisco")) { print "Multiple warn and crit levels needed with -L or -I switch\n";print_usage(); exit $ERRORS{"UNKNOWN"}}
|
||||
if ( isnnum($o_warn) || isnnum($o_crit) )
|
||||
{ print "Numeric value for warning or critical !\n";print_usage(); exit $ERRORS{"UNKNOWN"}}
|
||||
if ($o_warn > $o_crit)
|
||||
{ print "warning <= critical ! \n";print_usage(); exit $ERRORS{"UNKNOWN"}}
|
||||
}
|
||||
|
||||
###### Oreon #######
|
||||
|
||||
if (!defined($o_S)) { $o_S="1_1" }
|
||||
$ServiceId = is_valid_serviceid($o_S);
|
||||
|
||||
if (!defined($o_step)) { $o_step="300" }
|
||||
$step = $1 if ($o_step =~ /(\d+)/);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
########## MAIN #######
|
||||
|
||||
check_options();
|
||||
|
||||
$rrd = $pathtorrdbase.$ServiceId.".rrd";
|
||||
$start=time;
|
||||
|
||||
# Check gobal timeout if snmp screws up
|
||||
if (defined($TIMEOUT)) {
|
||||
verb("Alarm at $TIMEOUT + 5");
|
||||
alarm($TIMEOUT+5);
|
||||
} else {
|
||||
verb("no timeout defined : $o_timeout + 10");
|
||||
alarm ($o_timeout+10);
|
||||
}
|
||||
|
||||
# Connect to host
|
||||
my ($session,$error);
|
||||
if ( defined($o_login) && defined($o_passwd)) {
|
||||
# SNMPv3 login
|
||||
verb("SNMPv3 login");
|
||||
($session, $error) = Net::SNMP->session(
|
||||
-hostname => $o_host,
|
||||
-version => '3',
|
||||
-username => $o_login,
|
||||
-authpassword => $o_passwd,
|
||||
-authprotocol => 'md5',
|
||||
-privpassword => $o_passwd,
|
||||
-timeout => $o_timeout
|
||||
);
|
||||
} else {
|
||||
if (defined ($o_version2)) {
|
||||
# SNMPv2 Login
|
||||
($session, $error) = Net::SNMP->session(
|
||||
-hostname => $o_host,
|
||||
-version => 2,
|
||||
-community => $o_community,
|
||||
-port => $o_port,
|
||||
-timeout => $o_timeout
|
||||
);
|
||||
} else {
|
||||
# SNMPV1 login
|
||||
($session, $error) = Net::SNMP->session(
|
||||
-hostname => $o_host,
|
||||
-community => $o_community,
|
||||
-port => $o_port,
|
||||
-timeout => $o_timeout
|
||||
);
|
||||
}
|
||||
}
|
||||
if (!defined($session)) {
|
||||
printf("ERROR opening session: %s.\n", $error);
|
||||
exit $ERRORS{"UNKNOWN"};
|
||||
}
|
||||
|
||||
my $exit_val=undef;
|
||||
########### Linux load check ##############
|
||||
|
||||
if ($o_check_type eq "netsl") {
|
||||
|
||||
verb("Checking linux load");
|
||||
# Get load table
|
||||
my $resultat = (Net::SNMP->VERSION < 4) ?
|
||||
$session->get_table($linload_table)
|
||||
: $session->get_table(Baseoid => $linload_table);
|
||||
|
||||
if (!defined($resultat)) {
|
||||
printf("ERROR: Description table : %s.\n", $session->error);
|
||||
$session->close;
|
||||
exit $ERRORS{"UNKNOWN"};
|
||||
}
|
||||
$session->close;
|
||||
|
||||
my @load = undef;
|
||||
my @iload = undef;
|
||||
my @oid=undef;
|
||||
foreach my $key ( keys %$resultat) {
|
||||
verb("OID : $key, Desc : $$resultat{$key}");
|
||||
if ( $key =~ /$linload_name/ ) {
|
||||
@oid=split (/\./,$key);
|
||||
$iload[0]= pop(@oid) if ($$resultat{$key} eq "Load-1");
|
||||
$iload[1]= pop(@oid) if ($$resultat{$key} eq "Load-5");
|
||||
$iload[2]= pop(@oid) if ($$resultat{$key} eq "Load-15");
|
||||
}
|
||||
}
|
||||
|
||||
for (my $i=0;$i<3;$i++) { $load[$i] = $$resultat{$linload_load . "." . $iload[$i]}};
|
||||
|
||||
##
|
||||
## RRD management
|
||||
##
|
||||
|
||||
if ($o_g) {
|
||||
$start=time;
|
||||
if (! -e $rrd) {
|
||||
create_rrd($rrd,3,$start,$step,0,"U","GAUGE");
|
||||
}
|
||||
update_rrd($rrd,$start, $load[0] ,$load[1], $load[2]);
|
||||
}
|
||||
|
||||
|
||||
print "Load : $load[0] $load[1] $load[2] :";
|
||||
|
||||
$exit_val=$ERRORS{"OK"};
|
||||
for (my $i=0;$i<3;$i++) {
|
||||
if ( $load[$i] > $o_critL[$i] ) {
|
||||
print " $load[$i] > $o_critL[$i] : CRITICAL";
|
||||
$exit_val=$ERRORS{"CRITICAL"};
|
||||
}
|
||||
if ( $load[$i] > $o_warnL[$i] ) {
|
||||
# output warn error only if no critical was found
|
||||
if ($exit_val eq $ERRORS{"OK"}) {
|
||||
print " $load[$i] > $o_warnL[$i] : WARNING";
|
||||
$exit_val=$ERRORS{"WARNING"};
|
||||
}
|
||||
}
|
||||
}
|
||||
print " OK" if ($exit_val eq $ERRORS{"OK"});
|
||||
if (defined($o_perf)) {
|
||||
print " | load_1_min=$load[0];$o_warnL[0];$o_critL[0],";
|
||||
print "load_5_min=$load[1];$o_warnL[1];$o_critL[1],";
|
||||
print "load_15_min=$load[2];$o_warnL[2];$o_critL[2]\n";
|
||||
} else {
|
||||
print "\n";
|
||||
}
|
||||
exit $exit_val;
|
||||
}
|
||||
|
||||
############## Cisco CPU check ################
|
||||
|
||||
if ($o_check_type eq "cisco") {
|
||||
my @oidlists = ($cisco_cpu_5m, $cisco_cpu_1m, $cisco_cpu_5s);
|
||||
my $resultat = (Net::SNMP->VERSION < 4) ?
|
||||
$session->get_request(@oidlists)
|
||||
: $session->get_request(-varbindlist => \@oidlists);
|
||||
|
||||
if (!defined($resultat)) {
|
||||
printf("ERROR: Description table : %s.\n", $session->error);
|
||||
$session->close;
|
||||
exit $ERRORS{"UNKNOWN"};
|
||||
}
|
||||
|
||||
$session->close;
|
||||
|
||||
if (!defined ($$resultat{$cisco_cpu_5s})) {
|
||||
print "No CPU information : UNKNOWN\n";
|
||||
exit $ERRORS{"UNKNOWN"};
|
||||
}
|
||||
|
||||
my @load = undef;
|
||||
|
||||
$load[0]=$$resultat{$cisco_cpu_5s};
|
||||
$load[1]=$$resultat{$cisco_cpu_1m};
|
||||
$load[2]=$$resultat{$cisco_cpu_5m};
|
||||
|
||||
##
|
||||
## RRD management
|
||||
##
|
||||
|
||||
if ($o_g) {
|
||||
$start=time;
|
||||
if (! -e $rrd) {
|
||||
create_rrd($rrd,3,$start,$step,0,"U","GAUGE");
|
||||
}
|
||||
update_rrd($rrd,$start,$load[0] ,$load[1], $load[2]);
|
||||
}
|
||||
|
||||
print "CPU : $load[0] $load[1] $load[2] :";
|
||||
|
||||
$exit_val=$ERRORS{"OK"};
|
||||
for (my $i=0;$i<3;$i++) {
|
||||
if ( $load[$i] > $o_critL[$i] ) {
|
||||
print " $load[$i] > $o_critL[$i] : CRITICAL";
|
||||
$exit_val=$ERRORS{"CRITICAL"};
|
||||
}
|
||||
if ( $load[$i] > $o_warnL[$i] ) {
|
||||
# output warn error only if no critical was found
|
||||
if ($exit_val eq $ERRORS{"OK"}) {
|
||||
print " $load[$i] > $o_warnL[$i] : WARNING";
|
||||
$exit_val=$ERRORS{"WARNING"};
|
||||
}
|
||||
}
|
||||
}
|
||||
print " OK" if ($exit_val eq $ERRORS{"OK"});
|
||||
if (defined($o_perf)) {
|
||||
print " | load_5_sec=$load[0]%;$o_warnL[0];$o_critL[0],";
|
||||
print "load_1_min=$load[1]%;$o_warnL[1];$o_critL[1],";
|
||||
print "load_5_min=$load[2]%;$o_warnL[2];$o_critL[2]\n";
|
||||
} else {
|
||||
print "\n";
|
||||
}
|
||||
|
||||
exit $exit_val;
|
||||
}
|
||||
|
||||
################## CPU for : AS/400 , Netsnmp, HP, Bluecoat, linkproof ###########
|
||||
if ( $o_check_type =~ /netsc|as400|bc|nokia|hp|lp/ ) {
|
||||
|
||||
# Get load table
|
||||
my @oidlist = $cpu_oid{$o_check_type};
|
||||
verb("Checking OID : @oidlist");
|
||||
my $resultat = (Net::SNMP->VERSION < 4) ?
|
||||
$session->get_request(@oidlist)
|
||||
: $session->get_request(-varbindlist => \@oidlist);
|
||||
if (!defined($resultat)) {
|
||||
printf("ERROR: Description table : %s.\n", $session->error);
|
||||
$session->close;
|
||||
exit $ERRORS{"UNKNOWN"};
|
||||
}
|
||||
$session->close;
|
||||
|
||||
if (!defined ($$resultat{$cpu_oid{$o_check_type}})) {
|
||||
print "No CPU information : UNKNOWN\n";
|
||||
exit $ERRORS{"UNKNOWN"};
|
||||
}
|
||||
|
||||
my $load=$$resultat{$cpu_oid{$o_check_type}};
|
||||
verb("OID returned $load");
|
||||
# for AS400, divide by 100
|
||||
if ($o_check_type eq "as400") {$load /= 100; };
|
||||
# for Net-snmp : oid returned idle time so load = 100-idle.
|
||||
if ($o_check_type eq "netsc") {$load = 100 - $load; };
|
||||
|
||||
##
|
||||
## RRD management
|
||||
##
|
||||
|
||||
if ($o_g) {
|
||||
$start=time;
|
||||
if (! -e $rrd) {
|
||||
create_rrd($rrd,1,$start,$step,0,"U","GAUGE");
|
||||
}
|
||||
update_rrd($rrd,$start,$load);
|
||||
}
|
||||
|
||||
|
||||
printf("CPU used %.1f%% (",$load);
|
||||
|
||||
$exit_val=$ERRORS{"OK"};
|
||||
if ($load > $o_crit) {
|
||||
print ">$o_crit) : CRITICAL";
|
||||
$exit_val=$ERRORS{"CRITICAL"};
|
||||
} else {
|
||||
if ($load > $o_warn) {
|
||||
print ">$o_warn) : WARNING";
|
||||
$exit_val=$ERRORS{"WARNING"};
|
||||
}
|
||||
}
|
||||
print "<$o_warn) : OK" if ($exit_val eq $ERRORS{"OK"});
|
||||
(defined($o_perf)) ?
|
||||
print " | cpu_prct_used=$load%;$o_warn;$o_crit\n"
|
||||
: print "\n";
|
||||
exit $exit_val;
|
||||
|
||||
}
|
||||
|
||||
########## Standard cpu usage check ############
|
||||
# Get desctiption table
|
||||
my $resultat = (Net::SNMP->VERSION < 4) ?
|
||||
$session->get_table($base_proc)
|
||||
: $session->get_table(Baseoid => $base_proc);
|
||||
|
||||
if (!defined($resultat)) {
|
||||
printf("ERROR: Description table : %s.\n", $session->error);
|
||||
$session->close;
|
||||
exit $ERRORS{"UNKNOWN"};
|
||||
}
|
||||
|
||||
$session->close;
|
||||
|
||||
my ($cpu_used,$ncpu)=(0,0);
|
||||
foreach my $key ( keys %$resultat) {
|
||||
verb("OID : $key, Desc : $$resultat{$key}");
|
||||
if ( $key =~ /$proc_load/) {
|
||||
$cpu_used += $$resultat{$key};
|
||||
$ncpu++;
|
||||
}
|
||||
}
|
||||
|
||||
if ($ncpu==0) {
|
||||
print "Can't find CPU usage information : UNKNOWN\n";
|
||||
exit $ERRORS{"UNKNOWN"};
|
||||
}
|
||||
|
||||
$cpu_used /= $ncpu;
|
||||
|
||||
##
|
||||
## RRD management
|
||||
##
|
||||
|
||||
if ($o_g) {
|
||||
$start=time;
|
||||
if (! -e $rrd) {
|
||||
create_rrd($rrd,1,$start,$step,0,"U","GAUGE");
|
||||
}
|
||||
update_rrd($rrd,$start,$cpu_used);
|
||||
}
|
||||
|
||||
print "$ncpu CPU, ", $ncpu==1 ? "load" : "average load";
|
||||
printf(" %.1f",$cpu_used);
|
||||
$exit_val=$ERRORS{"OK"};
|
||||
|
||||
if ($cpu_used > $o_crit) {
|
||||
print " > $o_crit : CRITICAL";
|
||||
$exit_val=$ERRORS{"CRITICAL"};
|
||||
} else {
|
||||
if ($cpu_used > $o_warn) {
|
||||
print " > $o_warn : WARNING";
|
||||
$exit_val=$ERRORS{"WARNING"};
|
||||
}
|
||||
}
|
||||
print " < $o_warn : OK" if ($exit_val eq $ERRORS{"OK"});
|
||||
(defined($o_perf)) ?
|
||||
print " | cpu_prct_used=$cpu_used%;$o_warn;$o_crit\n"
|
||||
: print "\n";
|
||||
exit $exit_val;
|
||||
|
543
centreon-plugins/src/check_snmp_mem.pl
Normal file
543
centreon-plugins/src/check_snmp_mem.pl
Normal file
@ -0,0 +1,543 @@
|
||||
#!/usr/bin/perl -w
|
||||
############################## check_snmp_mem ##############
|
||||
# Version : 0.9
|
||||
# Date : Jul 20 2005
|
||||
# Author : Patrick Proy (patrick at proy.org)
|
||||
# Help : http://www.manubulon.com/nagios/
|
||||
# Licence : GPL - http://www.fsf.org/licenses/gpl.txt
|
||||
# TODO : snmpv3
|
||||
#################################################################
|
||||
#
|
||||
# Help : ./check_snmp_mem.pl -h
|
||||
#
|
||||
|
||||
use strict;
|
||||
use Net::SNMP;
|
||||
use Getopt::Long;
|
||||
|
||||
# Nagios specific
|
||||
|
||||
use lib "@NAGIOS_PLUGINS@";
|
||||
use utils qw(%ERRORS $TIMEOUT);
|
||||
#my $TIMEOUT = 15;
|
||||
#my %ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3,'DEPENDENT'=>4);
|
||||
|
||||
# Oreon specific
|
||||
|
||||
#use lib "@NAGIOS_PLUGINS@";
|
||||
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'};
|
||||
}
|
||||
|
||||
my $pathtorrdbase = $oreon{GLOBAL}{DIR_RRDTOOL};
|
||||
|
||||
# SNMP Datas
|
||||
|
||||
# Net-snmp memory
|
||||
|
||||
my $nets_ram_free = "1.3.6.1.4.1.2021.4.6.0"; # Real memory free
|
||||
my $nets_ram_total = "1.3.6.1.4.1.2021.4.5.0"; # Real memory total
|
||||
my $nets_swap_free = "1.3.6.1.4.1.2021.4.4.0"; # swap memory free
|
||||
my $nets_swap_total = "1.3.6.1.4.1.2021.4.3.0"; # Swap memory total
|
||||
my @nets_oids = ($nets_ram_free,$nets_ram_total,$nets_swap_free,$nets_swap_total);
|
||||
|
||||
# Cisco
|
||||
|
||||
my $cisco_mem_pool = "1.3.6.1.4.1.9.9.48.1.1.1"; # Cisco memory pool
|
||||
my $cisco_index = "1.3.6.1.4.1.9.9.48.1.1.1.2"; # memory pool name and index
|
||||
my $cisco_valid = "1.3.6.1.4.1.9.9.48.1.1.1.4"; # Valid memory if 1
|
||||
my $cisco_used = "1.3.6.1.4.1.9.9.48.1.1.1.5"; # Used memory
|
||||
my $cisco_free = "1.3.6.1.4.1.9.9.48.1.1.1.6"; # Used memory
|
||||
# .1 : type, .2 : name, .3 : alternate, .4 : valid, .5 : used, .6 : free, .7 : max free
|
||||
|
||||
# HP Procurve
|
||||
|
||||
my $hp_mem_pool = "1.3.6.1.4.1.11.2.14.11.5.1.1.2.2.1.1"; # HP memory pool
|
||||
my $hp_mem_index = "1.3.6.1.4.1.11.2.14.11.5.1.1.2.2.1.1.1"; # memory slot index
|
||||
my $hp_mem_total = "1.3.6.1.4.1.11.2.14.11.5.1.1.2.2.1.1.5"; # Total Bytes
|
||||
my $hp_mem_free = "1.3.6.1.4.1.11.2.14.11.5.1.1.2.2.1.1.6"; # Free Bytes
|
||||
my $hp_mem_free_seg = "1.3.6.1.4.1.11.2.14.11.5.1.1.2.2.1.1.3"; # Free segments
|
||||
|
||||
# AS/400
|
||||
|
||||
# Windows NT/2K/(XP?)
|
||||
|
||||
# check_snmp_storage.pl -C <community> -H <hostIP> -m "^Virtual Memory$" -w <warn %> -c <crit %>
|
||||
|
||||
|
||||
# Globals
|
||||
|
||||
my $Version='0.9';
|
||||
|
||||
my $o_host = undef; # hostname
|
||||
my $o_community = undef; # community
|
||||
my $o_port = 161; # port
|
||||
my $o_help= undef; # wan't some help ?
|
||||
my $o_verb= undef; # verbose mode
|
||||
my $o_version= undef; # print version
|
||||
my $o_netsnmp= 1; # Check with netsnmp (default)
|
||||
my $o_cisco= undef; # Check cisco router mem
|
||||
my $o_hp= undef; # Check hp procurve mem
|
||||
my $o_warn= undef; # warning level option
|
||||
my $o_warnR= undef; # warning level for Real memory
|
||||
my $o_warnS= undef; # warning levels for swap
|
||||
my $o_crit= undef; # Critical level option
|
||||
my $o_critR= undef; # critical level for Real memory
|
||||
my $o_critS= undef; # critical level for swap
|
||||
my $o_perf= undef; # Performance data option
|
||||
my $o_timeout= 5; # Default 5s Timeout
|
||||
my $o_version2= undef; # use snmp v2c
|
||||
# SNMPv3 specific
|
||||
my $o_login= undef; # Login for snmpv3
|
||||
my $o_passwd= undef; # Pass for snmpv3
|
||||
|
||||
# Oreon specific
|
||||
my $o_step= undef;
|
||||
my $o_g= undef;
|
||||
my $o_S= undef;
|
||||
my $step= undef;
|
||||
my $rrd= undef;
|
||||
my $start= undef;
|
||||
my $ServiceId= undef;
|
||||
|
||||
|
||||
# functions
|
||||
|
||||
sub p_version { print "check_snmp_mem version : $Version\n"; }
|
||||
|
||||
sub print_usage {
|
||||
print "Usage: $0 [-v] -H <host> -C <snmp_community> [-2] | (-l login -x passwd) [-p <port>] -w <warn level> -c <crit level> [-I|-N|-E] [-f] [-t <timeout>] [-V]\n";
|
||||
}
|
||||
|
||||
sub isnnum { # Return true if arg is not a number
|
||||
my $num = shift;
|
||||
if ( $num =~ /^(\d+\.?\d*)|(^\.\d+)$/ ) { return 0 ;}
|
||||
return 1;
|
||||
}
|
||||
|
||||
sub round ($$) {
|
||||
sprintf "%.$_[1]f", $_[0];
|
||||
}
|
||||
|
||||
sub help {
|
||||
print "\nSNMP Memory Monitor for Nagios version ",$Version,"\n";
|
||||
print "(c)2004 to my cat Ratoune - Author: Patrick Proy\n\n";
|
||||
print_usage();
|
||||
print <<EOT;
|
||||
-v, --verbose
|
||||
print extra debugging information (including interface list on the system)
|
||||
-h, --help
|
||||
print this help message
|
||||
-H, --hostname=HOST
|
||||
name or IP address of host to check
|
||||
-C, --community=COMMUNITY NAME
|
||||
community name for the host's SNMP agent (implies SNMP v1 or v2c with option)
|
||||
-2, --v2c
|
||||
Use snmp v2c
|
||||
-l, --login=LOGIN
|
||||
Login for snmpv3 authentication (implies v3 protocol with MD5)
|
||||
-x, --passwd=PASSWD
|
||||
Password for snmpv3 authentication
|
||||
-P, --port=PORT
|
||||
SNMP port (Default 161)
|
||||
-w, --warn=INTEGER | INT,INT
|
||||
warning level for memory in percent (0 for no checks)
|
||||
Default (-N switch) : comma separated level for Real Memory and Swap
|
||||
-I switch : warning level
|
||||
-c, --crit=INTEGER | INT,INT
|
||||
critical level for memory in percent (0 for no checks)
|
||||
Default (-N switch) : comma separated level for Real Memory and Swap
|
||||
-I switch : critical level
|
||||
-N, --netsnmp (default)
|
||||
check linux memory & swap provided by Net SNMP
|
||||
-I, --cisco
|
||||
check cisco memory (sum of all memory pools)
|
||||
-E, --hp
|
||||
check HP proccurve memory
|
||||
-f, --perfdata
|
||||
Performance data output
|
||||
-t, --timeout=INTEGER
|
||||
timeout for SNMP in seconds (Default: 5)
|
||||
-V, --version
|
||||
prints version number
|
||||
-g (--rrdgraph) Create a rrd base if necessary and add datas into this one
|
||||
--rrd_step Specifies the base interval in seconds with which data will be fed into the RRD (300 by default)
|
||||
-S (--ServiceId) Oreon Service Id
|
||||
EOT
|
||||
}
|
||||
|
||||
# For verbose output
|
||||
sub verb { my $t=shift; print $t,"\n" if defined($o_verb) ; }
|
||||
|
||||
# Get the alarm signal (just in case snmp timout screws up)
|
||||
$SIG{'ALRM'} = sub {
|
||||
print ("ERROR: Alarm signal (Nagios time-out)\n");
|
||||
exit $ERRORS{"UNKNOWN"};
|
||||
};
|
||||
|
||||
sub check_options {
|
||||
Getopt::Long::Configure ("bundling");
|
||||
GetOptions(
|
||||
'v' => \$o_verb, 'verbose' => \$o_verb,
|
||||
'h' => \$o_help, 'help' => \$o_help,
|
||||
'H:s' => \$o_host, 'hostname:s' => \$o_host,
|
||||
'p:i' => \$o_port, 'port:i' => \$o_port,
|
||||
'C:s' => \$o_community, 'community:s' => \$o_community,
|
||||
'l:s' => \$o_login, 'login:s' => \$o_login,
|
||||
'x:s' => \$o_passwd, 'passwd:s' => \$o_passwd,
|
||||
't:i' => \$o_timeout, 'timeout:i' => \$o_timeout,
|
||||
'V' => \$o_version, 'version' => \$o_version,
|
||||
'I' => \$o_cisco, 'cisco' => \$o_cisco,
|
||||
'N' => \$o_netsnmp, 'netsnmp' => \$o_netsnmp,
|
||||
'E' => \$o_hp, 'hp' => \$o_hp,
|
||||
'2' => \$o_version2, 'v2c' => \$o_version2,
|
||||
'c:s' => \$o_crit, 'critical:s' => \$o_crit,
|
||||
'w:s' => \$o_warn, 'warn:s' => \$o_warn,
|
||||
'f' => \$o_perf, 'perfdata' => \$o_perf,
|
||||
# For Oreon rrdtool graph
|
||||
"rrd_step:s" => \$o_step,
|
||||
"g" => \$o_g, "rrdgraph" => \$o_g,
|
||||
"S=s" => \$o_S, "ServiceId=s" => \$o_S
|
||||
);
|
||||
if (defined ($o_help) ) { help(); exit $ERRORS{"UNKNOWN"}};
|
||||
if (defined($o_version)) { p_version(); exit $ERRORS{"UNKNOWN"}};
|
||||
if ( ! defined($o_host) ) # check host and filter
|
||||
{ print "No host defined!\n";print_usage(); exit $ERRORS{"UNKNOWN"}}
|
||||
# check snmp information
|
||||
if ( !defined($o_community) && (!defined($o_login) || !defined($o_passwd)) )
|
||||
{ print "Put snmp login info!\n"; print_usage(); exit $ERRORS{"UNKNOWN"}}
|
||||
#Check Warning and crit are present
|
||||
if ( ! defined($o_warn) || ! defined($o_crit))
|
||||
{ print "Put warning and critical values!\n"; print_usage(); exit $ERRORS{"UNKNOWN"}}
|
||||
# Get rid of % sign
|
||||
$o_warn =~ s/\%//g;
|
||||
$o_crit =~ s/\%//g;
|
||||
# if -N or -E switch , undef $o_netsnmp
|
||||
if (defined($o_cisco) || defined($o_hp) ) {
|
||||
$o_netsnmp=undef;
|
||||
if ( isnnum($o_warn) || isnnum($o_crit))
|
||||
{ print "Numeric value for warning or critical !\n";print_usage(); exit $ERRORS{"UNKNOWN"} }
|
||||
if ( ($o_crit != 0) && ($o_warn > $o_crit) )
|
||||
{ print "warning <= critical ! \n";print_usage(); exit $ERRORS{"UNKNOWN"}}
|
||||
}
|
||||
if (defined($o_netsnmp)) {
|
||||
my @o_warnL=split(/,/ , $o_warn);
|
||||
my @o_critL=split(/,/ , $o_crit);
|
||||
if (($#o_warnL != 1) || ($#o_critL != 1))
|
||||
{ print "2 warnings and critical !\n";print_usage(); exit $ERRORS{"UNKNOWN"}}
|
||||
for (my $i=0;$i<2;$i++) {
|
||||
if ( isnnum($o_warnL[$i]) || isnnum($o_critL[$i]))
|
||||
{ print "Numeric value for warning or critical !\n";print_usage(); exit $ERRORS{"UNKNOWN"} }
|
||||
if (($o_critL[$i]!= 0) && ($o_warnL[$i] > $o_critL[$i]))
|
||||
{ print "warning <= critical ! \n";print_usage(); exit $ERRORS{"UNKNOWN"}}
|
||||
if ( $o_critL[$i] > 100)
|
||||
{ print "critical percent must be < 100 !\n";print_usage(); exit $ERRORS{"UNKNOWN"}}
|
||||
}
|
||||
$o_warnR=$o_warnL[0];$o_warnS=$o_warnL[1];
|
||||
$o_critR=$o_critL[0];$o_critS=$o_critL[1];
|
||||
}
|
||||
|
||||
###### Oreon #######
|
||||
|
||||
if (!defined($o_S)) { $o_S="1_1" }
|
||||
$ServiceId = is_valid_serviceid($o_S);
|
||||
|
||||
if (!defined($o_step)) { $o_step="300" }
|
||||
$step = $1 if ($o_step =~ /(\d+)/);
|
||||
|
||||
}
|
||||
|
||||
########## MAIN #######
|
||||
|
||||
check_options();
|
||||
|
||||
$rrd = $pathtorrdbase.$ServiceId.".rrd";
|
||||
$start=time;
|
||||
|
||||
# Check gobal timeout if snmp screws up
|
||||
if (defined($TIMEOUT)) {
|
||||
verb("Alarm at $TIMEOUT");
|
||||
alarm($TIMEOUT);
|
||||
} else {
|
||||
verb("no timeout defined : $o_timeout + 10");
|
||||
alarm ($o_timeout+10);
|
||||
}
|
||||
|
||||
# Connect to host
|
||||
my ($session,$error);
|
||||
if ( defined($o_login) && defined($o_passwd)) {
|
||||
# SNMPv3 login
|
||||
verb("SNMPv3 login");
|
||||
($session, $error) = Net::SNMP->session(
|
||||
-hostname => $o_host,
|
||||
-version => '3',
|
||||
-username => $o_login,
|
||||
-authpassword => $o_passwd,
|
||||
-authprotocol => 'md5',
|
||||
-privpassword => $o_passwd,
|
||||
-timeout => $o_timeout
|
||||
);
|
||||
} else {
|
||||
if (defined ($o_version2)) {
|
||||
# SNMPv2 Login
|
||||
($session, $error) = Net::SNMP->session(
|
||||
-hostname => $o_host,
|
||||
-version => 2,
|
||||
-community => $o_community,
|
||||
-port => $o_port,
|
||||
-timeout => $o_timeout
|
||||
);
|
||||
} else {
|
||||
|
||||
# SNMPV1 login
|
||||
($session, $error) = Net::SNMP->session(
|
||||
-hostname => $o_host,
|
||||
-community => $o_community,
|
||||
-port => $o_port,
|
||||
-timeout => $o_timeout
|
||||
);
|
||||
}
|
||||
}
|
||||
if (!defined($session)) {
|
||||
printf("ERROR opening session: %s.\n", $error);
|
||||
exit $ERRORS{"UNKNOWN"};
|
||||
}
|
||||
|
||||
# Global variable
|
||||
my $resultat=undef;
|
||||
|
||||
########### Cisco memory check ############
|
||||
if (defined ($o_cisco)) {
|
||||
|
||||
# Get Cisco memory table
|
||||
$resultat = (Net::SNMP->VERSION < 4) ?
|
||||
$session->get_table($cisco_mem_pool)
|
||||
:$session->get_table(Baseoid => $cisco_mem_pool);
|
||||
|
||||
if (!defined($resultat)) {
|
||||
printf("ERROR: Description table : %s.\n", $session->error);
|
||||
$session->close;
|
||||
exit $ERRORS{"UNKNOWN"};
|
||||
}
|
||||
my (@oid,@index)=(undef,undef);
|
||||
my $nindex=0;
|
||||
foreach my $key ( keys %$resultat) {
|
||||
verb("OID : $key, Desc : $$resultat{$key}");
|
||||
if ( $key =~ /$cisco_index/ ) {
|
||||
@oid=split (/\./,$key);
|
||||
$index[$nindex++] = pop(@oid);
|
||||
}
|
||||
}
|
||||
|
||||
# Check if at least 1 memory pool exists
|
||||
if ($nindex == 0) {
|
||||
printf("ERROR: No memory pools found");
|
||||
$session->close;
|
||||
exit $ERRORS{"UNKNOWN"};
|
||||
}
|
||||
|
||||
# Consolidate the datas
|
||||
my ($used,$free)=(0,0);
|
||||
my ($c_output,$prct_free)=(undef,undef);
|
||||
foreach (@index) {
|
||||
if ( $$resultat{$cisco_valid . "." . $_} == 1 ) {
|
||||
$c_output .="," if defined ($c_output);
|
||||
$used += $$resultat{$cisco_used . "." . $_};
|
||||
$free += $$resultat{$cisco_free . "." . $_};
|
||||
$c_output .= $$resultat{$cisco_index . "." . $_} . ":"
|
||||
.round($$resultat{$cisco_used . "." . $_}*100/($$resultat{$cisco_free . "." . $_}+$$resultat{$cisco_used . "." . $_}) ,0)
|
||||
. "%";
|
||||
}
|
||||
}
|
||||
my $total=$used+$free;
|
||||
$prct_free=round($used*100/($total),0);
|
||||
verb("Used : $used, Free: $free, Output : $c_output");
|
||||
|
||||
##
|
||||
## RRD management
|
||||
##
|
||||
|
||||
if ($o_g) {
|
||||
$start=time;
|
||||
if (! -e $rrd) {
|
||||
create_rrd($rrd,1,$start,$step,0,100,"GAUGE");
|
||||
}
|
||||
update_rrd($rrd,$start,$prct_free);
|
||||
}
|
||||
|
||||
my $c_status="OK";
|
||||
$c_output .=" : " . $prct_free ."% : ";
|
||||
if (($o_crit!=0)&&($o_crit <= $prct_free)) {
|
||||
$c_output .= " > " . $o_crit ;
|
||||
$c_status="CRITICAL";
|
||||
} else {
|
||||
if (($o_warn!=0)&&($o_warn <= $prct_free)) {
|
||||
$c_output.=" > " . $o_warn;
|
||||
$c_status="WARNING";
|
||||
}
|
||||
}
|
||||
$c_output .= " ; ".$c_status;
|
||||
if (defined ($o_perf)) {
|
||||
$c_output .= " | ram_used=" . $used.";";
|
||||
$c_output .= ($o_warn ==0)? ";" : round($o_warn * $total/100,0).";";
|
||||
$c_output .= ($o_crit ==0)? ";" : round($o_crit * $total/100,0).";";
|
||||
$c_output .= "0;" . $total ;
|
||||
}
|
||||
$session->close;
|
||||
print "$c_output \n";
|
||||
exit $ERRORS{$c_status};
|
||||
}
|
||||
|
||||
########### HP Procurve memory check ############
|
||||
if (defined ($o_hp)) {
|
||||
|
||||
# Get hp memory table
|
||||
$resultat = (Net::SNMP->VERSION < 4) ?
|
||||
$session->get_table($hp_mem_pool)
|
||||
:$session->get_table(Baseoid => $hp_mem_pool);
|
||||
|
||||
if (!defined($resultat)) {
|
||||
printf("ERROR: Description table : %s.\n", $session->error);
|
||||
$session->close;
|
||||
exit $ERRORS{"UNKNOWN"};
|
||||
}
|
||||
my (@oid,@index)=(undef,undef);
|
||||
my $nindex=0;
|
||||
foreach my $key ( keys %$resultat) {
|
||||
verb("OID : $key, Desc : $$resultat{$key}");
|
||||
if ( $key =~ /$hp_mem_index/ ) {
|
||||
@oid=split (/\./,$key);
|
||||
$index[$nindex++] = pop(@oid);
|
||||
}
|
||||
}
|
||||
|
||||
# Check if at least 1 memory slots exists
|
||||
if ($nindex == 0) {
|
||||
printf("ERROR: No memory slots found");
|
||||
$session->close;
|
||||
exit $ERRORS{"UNKNOWN"};
|
||||
}
|
||||
|
||||
# Consolidate the datas
|
||||
my ($total,$free)=(0,0);
|
||||
my ($c_output,$prct_free)=(undef,undef);
|
||||
foreach (@index) {
|
||||
$c_output .="," if defined ($c_output);
|
||||
$total += $$resultat{$hp_mem_total . "." . $_};
|
||||
$free += $$resultat{$hp_mem_free . "." . $_};
|
||||
$c_output .= "Slot " . $$resultat{$hp_mem_index . "." . $_} . ":"
|
||||
.round(
|
||||
100 - ($$resultat{$hp_mem_free . "." . $_} *100 /
|
||||
$$resultat{$hp_mem_total . "." . $_}) ,0)
|
||||
. "%";
|
||||
}
|
||||
my $used = $total - $free;
|
||||
$prct_free=round($used*100/($total),0);
|
||||
verb("Used : $used, Free: $free, Output : $c_output");
|
||||
|
||||
##
|
||||
## RRD management
|
||||
##
|
||||
|
||||
if ($o_g) {
|
||||
$start=time;
|
||||
if (! -e $rrd) {
|
||||
create_rrd($rrd,1,$start,$step,0,100,"GAUGE");
|
||||
}
|
||||
update_rrd($rrd,$start,$prct_free);
|
||||
}
|
||||
|
||||
my $c_status="OK";
|
||||
$c_output .=" : " . $prct_free ."% : ";
|
||||
if (($o_crit!=0)&&($o_crit <= $prct_free)) {
|
||||
$c_output .= " > " . $o_crit ;
|
||||
$c_status="CRITICAL";
|
||||
} else {
|
||||
if (($o_warn!=0)&&($o_warn <= $prct_free)) {
|
||||
$c_output.=" > " . $o_warn;
|
||||
$c_status="WARNING";
|
||||
}
|
||||
}
|
||||
$c_output .= " ; ".$c_status;
|
||||
if (defined ($o_perf)) {
|
||||
$c_output .= " | ram_used=" . $used.";";
|
||||
$c_output .= ($o_warn ==0)? ";" : round($o_warn * $total/100,0).";";
|
||||
$c_output .= ($o_crit ==0)? ";" : round($o_crit * $total/100,0).";";
|
||||
$c_output .= "0;" . $total ;
|
||||
}
|
||||
$session->close;
|
||||
print "$c_output \n";
|
||||
exit $ERRORS{$c_status};
|
||||
}
|
||||
|
||||
########### Net snmp memory check ############
|
||||
if (defined ($o_netsnmp)) {
|
||||
|
||||
# Get NetSNMP memory values
|
||||
$resultat = (Net::SNMP->VERSION < 4) ?
|
||||
$session->get_request(@nets_oids)
|
||||
:$session->get_request(-varbindlist => \@nets_oids);
|
||||
|
||||
if (!defined($resultat)) {
|
||||
printf("ERROR: netsnmp : %s.\n", $session->error);
|
||||
$session->close;
|
||||
exit $ERRORS{"UNKNOWN"};
|
||||
}
|
||||
|
||||
my ($realused,$swapused)=(undef,undef);
|
||||
|
||||
$realused= ($$resultat{$nets_ram_total} == 0) ? 0 :
|
||||
($$resultat{$nets_ram_total}-$$resultat{$nets_ram_free})/$$resultat{$nets_ram_total};
|
||||
$swapused= ($$resultat{$nets_swap_total} == 0) ? 0 :
|
||||
($$resultat{$nets_swap_total}-$$resultat{$nets_swap_free})/$$resultat{$nets_swap_total};
|
||||
$realused=round($realused*100,0);
|
||||
$swapused=round($swapused*100,0);
|
||||
verb ("Ram : $$resultat{$nets_ram_free} / $$resultat{$nets_ram_total} : $realused");
|
||||
verb ("Swap : $$resultat{$nets_swap_free} / $$resultat{$nets_swap_total} : $swapused");
|
||||
|
||||
##
|
||||
## RRD management
|
||||
##
|
||||
|
||||
if ($o_g) {
|
||||
$start=time;
|
||||
if (! -e $rrd) {
|
||||
create_rrd($rrd,2,$start,$step,0,100,"GAUGE");
|
||||
}
|
||||
update_rrd($rrd,$start,$realused, $swapused );
|
||||
}
|
||||
|
||||
|
||||
|
||||
my $n_status="OK";
|
||||
my $n_output="Ram : " . $realused . "%, Swap : " . $swapused . "% :";
|
||||
if ((($o_critR!=0)&&($o_critR <= $realused)) || (($o_critS!=0)&&($o_critS <= $swapused))) {
|
||||
$n_output .= " > " . $o_critR . ", " . $o_critS;
|
||||
$n_status="CRITICAL";
|
||||
} else {
|
||||
if ((($o_warnR!=0)&&($o_warnR <= $realused)) || (($o_warnS!=0)&&($o_warnS <= $swapused))) {
|
||||
$n_output.=" > " . $o_warnR . ", " . $o_warnS;
|
||||
$n_status="WARNING";
|
||||
}
|
||||
}
|
||||
$n_output .= " ; ".$n_status;
|
||||
if (defined ($o_perf)) {
|
||||
$n_output .= " | ram_used=" . ($$resultat{$nets_ram_total}-$$resultat{$nets_ram_free}).";";
|
||||
$n_output .= ($o_warnR ==0)? ";" : round($o_warnR * $$resultat{$nets_ram_total}/100,0).";";
|
||||
$n_output .= ($o_critR ==0)? ";" : round($o_critR * $$resultat{$nets_ram_total}/100,0).";";
|
||||
$n_output .= "0;" . $$resultat{$nets_ram_total}. " ";
|
||||
$n_output .= "swap_used=" . ($$resultat{$nets_swap_total}-$$resultat{$nets_swap_free}).";";
|
||||
$n_output .= ($o_warnS ==0)? ";" : round($o_warnS * $$resultat{$nets_swap_total}/100,0).";";
|
||||
$n_output .= ($o_critS ==0)? ";" : round($o_critS * $$resultat{$nets_swap_total}/100,0).";";
|
||||
$n_output .= "0;" . $$resultat{$nets_swap_total};
|
||||
}
|
||||
$session->close;
|
||||
print "$n_output \n";
|
||||
exit $ERRORS{$n_status};
|
||||
|
||||
}
|
602
centreon-plugins/src/check_snmp_process.pl
Normal file
602
centreon-plugins/src/check_snmp_process.pl
Normal file
@ -0,0 +1,602 @@
|
||||
#!/usr/bin/perl -w
|
||||
############################## check_snmp_process ##############
|
||||
# Version : 1.2.1
|
||||
# Date : Dec 12 2004
|
||||
# Author : Patrick Proy (patrick at proy.org)
|
||||
# Help : http://www.manubulon.com/nagios/
|
||||
# Licence : GPL - http://www.fsf.org/licenses/gpl.txt
|
||||
# TODO : put $o_delta as an option
|
||||
###############################################################
|
||||
#
|
||||
# help : ./check_snmp_process -h
|
||||
|
||||
############### BASE DIRECTORY FOR TEMP FILE ########
|
||||
my $o_base_dir="/tmp/tmp_Nagios_proc.";
|
||||
my $file_history=200; # number of data to keep in files.
|
||||
my $delta_of_time_to_make_average=300; # 5minutes by default
|
||||
|
||||
use strict;
|
||||
use Net::SNMP;
|
||||
use Getopt::Long;
|
||||
|
||||
# Nagios specific
|
||||
|
||||
use lib "@NAGIOS_PLUGINS@";
|
||||
use utils qw(%ERRORS $TIMEOUT);
|
||||
#my $TIMEOUT = 5;
|
||||
#my %ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3,'DEPENDENT'=>4);
|
||||
|
||||
# Oreon specific
|
||||
|
||||
#use lib "@NAGIOS_PLUGINS@";
|
||||
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'};
|
||||
}
|
||||
|
||||
my $pathtorrdbase = $oreon{GLOBAL}{DIR_RRDTOOL};
|
||||
|
||||
|
||||
# SNMP Datas
|
||||
my $process_table= '1.3.6.1.2.1.25.4.2.1';
|
||||
my $index_table = '1.3.6.1.2.1.25.4.2.1.1';
|
||||
my $run_name_table = '1.3.6.1.2.1.25.4.2.1.2';
|
||||
my $run_path_table = '1.3.6.1.2.1.25.4.2.1.4';
|
||||
my $proc_mem_table = '1.3.6.1.2.1.25.5.1.1.2'; # Kbytes
|
||||
my $proc_cpu_table = '1.3.6.1.2.1.25.5.1.1.1'; # Centi sec of CPU
|
||||
my $proc_run_state = '1.3.6.1.2.1.25.4.2.1.7';
|
||||
|
||||
# Globals
|
||||
|
||||
my $Version='1.2.1';
|
||||
|
||||
my $o_host = undef; # hostname
|
||||
my $o_community =undef; # community
|
||||
my $o_port = 161; # port
|
||||
my $o_descr = undef; # description filter
|
||||
my $o_warn = 0; # warning limit
|
||||
my @o_warnL= undef; # warning limits (min,max)
|
||||
my $o_crit= 0; # critical limit
|
||||
my @o_critL= undef; # critical limits (min,max)
|
||||
my $o_help= undef; # wan't some help ?
|
||||
my $o_verb= undef; # verbose mode
|
||||
my $o_version= undef; # print version
|
||||
my $o_noreg= undef; # Do not use Regexp for name
|
||||
my $o_path= undef; # check path instead of name
|
||||
my $o_inverse= undef; # checks max instead of min number of process
|
||||
my $o_timeout= 5; # Default 5s Timeout
|
||||
# SNMP V3 specific
|
||||
my $o_login= undef; # snmp v3 login
|
||||
my $o_passwd= undef; # snmp v3 passwd
|
||||
# Memory & CPU
|
||||
my $o_mem= undef; # checks memory (max)
|
||||
my @o_memL= undef; # warn and crit level for mem
|
||||
my $o_mem_avg= undef; # cheks memory average
|
||||
my $o_cpu= undef; # checks CPU usage
|
||||
my @o_cpuL= undef; # warn and crit level for cpu
|
||||
my $o_delta= $delta_of_time_to_make_average; # delta time for CPU check
|
||||
# Oreon specific
|
||||
my $o_step= undef;
|
||||
my $o_g= undef;
|
||||
my $o_S= undef;
|
||||
my $step= undef;
|
||||
my $rrd= undef;
|
||||
my $start= undef;
|
||||
my $ServiceId= undef;
|
||||
my @rrd_data= undef;
|
||||
|
||||
# functions
|
||||
|
||||
sub p_version { print "check_snmp_process version : $Version\n"; }
|
||||
|
||||
sub print_usage {
|
||||
print "Usage: $0 [-v] -H <host> -C <snmp_community> | (-l login -x passwd) [-p <port>] -n <name> [-w <min_proc>[,<max_proc>] -c <min_proc>[,max_proc] ] [-m<warn Mb>,<crit Mb> -a -u<warn %>,<crit%> ] [-t <timeout>] [-f ] [-r] [-V]\n";
|
||||
}
|
||||
|
||||
sub isnotnum { # Return true if arg is not a number
|
||||
my $num = shift;
|
||||
if ( $num =~ /^(\d+\.?\d*)|(^\.\d+)$/ ) { return 0 ;}
|
||||
return 1;
|
||||
}
|
||||
|
||||
# Get the alarm signal (just in case snmp timout screws up)
|
||||
$SIG{'ALRM'} = sub {
|
||||
print ("ERROR: Alarm signal (Nagios time-out)\n");
|
||||
exit $ERRORS{"UNKNOWN"};
|
||||
};
|
||||
|
||||
sub read_file {
|
||||
# Input : File, items_number
|
||||
# Returns : array of value : [line][item]
|
||||
my ($traffic_file,$items_number)=@_;
|
||||
my ($ligne,$n_rows)=(undef,0);
|
||||
my (@last_values,@file_values,$i);
|
||||
open(FILE,"<".$traffic_file) || return (1,0,0);
|
||||
|
||||
while($ligne = <FILE>)
|
||||
{
|
||||
chomp($ligne);
|
||||
@file_values = split(":",$ligne);
|
||||
#verb("@file_values");
|
||||
if ($#file_values >= ($items_number-1)) {
|
||||
# check if there is enough data, else ignore line
|
||||
for ( $i=0 ; $i< $items_number ; $i++ ) {$last_values[$n_rows][$i]=$file_values[$i]; }
|
||||
$n_rows++;
|
||||
}
|
||||
}
|
||||
close FILE;
|
||||
if ($n_rows != 0) {
|
||||
return (0,$n_rows,@last_values);
|
||||
} else {
|
||||
return (1,0,0);
|
||||
}
|
||||
}
|
||||
|
||||
sub write_file {
|
||||
# Input : file , rows, items, array of value : [line][item]
|
||||
# Returns : 0 / OK, 1 / error
|
||||
my ($file_out,$rows,$item,@file_values)=@_;
|
||||
my $start_line= ($rows > $file_history) ? $rows - $file_history : 0;
|
||||
if ( open(FILE2,">".$file_out) ) {
|
||||
for (my $i=$start_line;$i<$rows;$i++) {
|
||||
for (my $j=0;$j<$item;$j++) {
|
||||
print FILE2 $file_values[$i][$j];
|
||||
if ($j != ($item -1)) { print FILE2 ":" };
|
||||
}
|
||||
print FILE2 "\n";
|
||||
}
|
||||
close FILE2;
|
||||
return 0;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
sub help {
|
||||
print "\nSNMP Process Monitor for Nagios version ",$Version,"\n";
|
||||
print "(c)2004 to my cat Ratoune - Author: Patrick Proy\n\n";
|
||||
print_usage();
|
||||
print <<EOT;
|
||||
-v, --verbose
|
||||
print extra debugging information (and lists all storages)
|
||||
-h, --help
|
||||
print this help message
|
||||
-H, --hostname=HOST
|
||||
name or IP address of host to check
|
||||
-C, --community=COMMUNITY NAME
|
||||
community name for the host's SNMP agent (implies SNMP v1)
|
||||
-l, --login=LOGIN
|
||||
Login for snmpv3 authentication (implies v3 protocol with MD5)
|
||||
-x, --passwd=PASSWD
|
||||
Password for snmpv3 authentication
|
||||
-p, --port=PORT
|
||||
SNMP port (Default 161)
|
||||
-n, --name=NAME
|
||||
Name of the process (regexp)
|
||||
No trailing slash !
|
||||
-r, --noregexp
|
||||
Do not use regexp to match NAME in description OID
|
||||
-f, --fullpath
|
||||
Use full path name instead of process name
|
||||
(Windows doesn't provide full path name)
|
||||
-w, --warn=MIN[,MAX]
|
||||
Number of process that will cause a warning
|
||||
-c, --critical=MIN[,MAX]
|
||||
number of process that will cause an error
|
||||
Notes on warning and critical :
|
||||
with the following options : -w m1,x1 -c m2,x2
|
||||
you must have : m2 <= m1 < x1 <= x2
|
||||
you can omit x1 or x2 or both
|
||||
-m, --memory=WARN,CRIT
|
||||
checks memory usage (default max of all process)
|
||||
values are warning and critical values in Mb
|
||||
-a, --average
|
||||
makes an average of memory used by process instead of max
|
||||
-u, --cpu=WARN,CRIT
|
||||
checks cpu usage of all process
|
||||
values are warning and critical values in % of CPU usage
|
||||
if more than one CPU, value can be > 100% : 100%=1 CPU
|
||||
-t, --timeout=INTEGER
|
||||
timeout for SNMP in seconds (Default: 5)
|
||||
-V, --version
|
||||
prints version number
|
||||
-g (--rrdgraph) Create a rrd base if necessary and add datas into this one
|
||||
--rrd_step Specifies the base interval in seconds with which data will be fed into the RRD (300 by default)
|
||||
-S (--ServiceId) Oreon Service Id
|
||||
|
||||
Note :
|
||||
CPU usage is in % of one cpu, so maximum can be 100% * number of CPU
|
||||
example :
|
||||
Browse process list : <script> -C <community> -H <host> -n <anything> -v
|
||||
the -n option allows regexp in perl format :
|
||||
All process of /opt/soft/bin : -n /opt/soft/bin/ -f
|
||||
All 'named' process : -n named
|
||||
|
||||
EOT
|
||||
}
|
||||
|
||||
sub verb { my $t=shift; print $t,"\n" if defined($o_verb) ; }
|
||||
|
||||
sub check_options {
|
||||
my $compat_o_cpu_sum;
|
||||
Getopt::Long::Configure ("bundling");
|
||||
GetOptions(
|
||||
'v' => \$o_verb, 'verbose' => \$o_verb,
|
||||
'h' => \$o_help, 'help' => \$o_help,
|
||||
'H:s' => \$o_host, 'hostname:s' => \$o_host,
|
||||
'p:i' => \$o_port, 'port:i' => \$o_port,
|
||||
'C:s' => \$o_community, 'community:s' => \$o_community,
|
||||
'l:s' => \$o_login, 'login:s' => \$o_login,
|
||||
'x:s' => \$o_passwd, 'passwd:s' => \$o_passwd,
|
||||
'c:s' => \$o_crit, 'critical:s' => \$o_crit,
|
||||
'w:s' => \$o_warn, 'warn:s' => \$o_warn,
|
||||
't:i' => \$o_timeout, 'timeout:i' => \$o_timeout,
|
||||
'n:s' => \$o_descr, 'name:s' => \$o_descr,
|
||||
'r' => \$o_noreg, 'noregexp' => \$o_noreg,
|
||||
'f' => \$o_path, 'fullpath' => \$o_path,
|
||||
'm:s' => \$o_mem, 'memory:s' => \$o_mem,
|
||||
'a' => \$o_mem_avg, 'average' => \$o_mem_avg,
|
||||
'u:s' => \$o_cpu, 'cpu' => \$o_cpu,
|
||||
#### To be compatible with version 1.2, will be removed... ####
|
||||
's' => \$compat_o_cpu_sum, 'cpusum' => \$compat_o_cpu_sum,
|
||||
##########
|
||||
'V' => \$o_version, 'version' => \$o_version,
|
||||
# For Oreon rrdtool graph
|
||||
"rrd_step:s" => \$o_step,
|
||||
"g" => \$o_g, "rrdgraph" => \$o_g,
|
||||
"S=s" => \$o_S, "ServiceId=s" => \$o_S
|
||||
);
|
||||
if (defined ($o_help)) { help(); exit $ERRORS{"UNKNOWN"}};
|
||||
if (defined($o_version)) { p_version(); exit $ERRORS{"UNKNOWN"}};
|
||||
# check snmp information
|
||||
if ( !defined($o_community) && (!defined($o_login) || !defined($o_passwd)) )
|
||||
{ print "Put snmp login info!\n"; print_usage(); exit $ERRORS{"UNKNOWN"}}
|
||||
# Check compulsory attributes
|
||||
if ( ! defined($o_descr) || ! defined($o_host) ) { print_usage(); exit $ERRORS{"UNKNOWN"}};
|
||||
@o_warnL=split(/,/,$o_warn);
|
||||
@o_critL=split(/,/,$o_crit);
|
||||
verb("$#o_warnL $#o_critL");
|
||||
if ( isnotnum($o_warnL[0]) || isnotnum($o_critL[0]))
|
||||
{ print "Numerical values for warning and critical\n";print_usage(); exit $ERRORS{"UNKNOWN"};}
|
||||
if ((defined($o_warnL[1]) && isnotnum($o_warnL[1])) || (defined($o_critL[1]) && isnotnum($o_critL[1])))
|
||||
{ print "Numerical values for warning and critical\n";print_usage(); exit $ERRORS{"UNKNOWN"};}
|
||||
# Check for positive numbers
|
||||
if (($o_warnL[0] < 0) || ($o_critL[0] < 0))
|
||||
{ print " warn and critical > 0 \n";print_usage(); exit $ERRORS{"UNKNOWN"}};
|
||||
if ((defined($o_warnL[1]) && ($o_warnL[1] < 0)) || (defined($o_critL[1]) && ($o_critL[1] < 0)))
|
||||
{ print " warn and critical > 0 \n";print_usage(); exit $ERRORS{"UNKNOWN"}};
|
||||
# Check min_crit < min warn < max warn < crit warn
|
||||
if ($o_warnL[0] < $o_critL[0]) { print " warn minimum must be >= crit minimum\n";print_usage(); exit $ERRORS{"UNKNOWN"}};
|
||||
if (defined($o_warnL[1])) {
|
||||
if ($o_warnL[1] <= $o_warnL[0])
|
||||
{ print "warn minimum must be < warn maximum\n";print_usage(); exit $ERRORS{"UNKNOWN"}};
|
||||
} elsif ( defined($o_critL[1]) && ($o_critL[1] <= $o_warnL[0]))
|
||||
{ print "warn minimum must be < crit maximum when no crit warning defined\n";print_usage(); exit $ERRORS{"UNKNOWN"};}
|
||||
if ( defined($o_critL[1]) && defined($o_warnL[1]) && ($o_critL[1]<$o_warnL[1]))
|
||||
{ print "warn max must be <= crit maximum\n";print_usage(); exit $ERRORS{"UNKNOWN"};}
|
||||
#### Memory checks
|
||||
if (defined ($o_mem)) {
|
||||
@o_memL=split(/,/,$o_mem);
|
||||
if ($#o_memL != 1)
|
||||
{print "2 values (warning,critical) for memory\n";print_usage(); exit $ERRORS{"UNKNOWN"}};
|
||||
if (isnotnum($o_memL[0]) || isnotnum($o_memL[1]))
|
||||
{print "Numeric values for memory!\n";print_usage(); exit $ERRORS{"UNKNOWN"}};
|
||||
if ($o_memL[0]>$o_memL[1])
|
||||
{print "Warning must be <= Critical for memory!\n";print_usage(); exit $ERRORS{"UNKNOWN"}};
|
||||
}
|
||||
#### CPU checks
|
||||
if (defined ($o_cpu)) {
|
||||
@o_cpuL=split(/,/,$o_cpu);
|
||||
if ($#o_cpuL != 1)
|
||||
{print "2 values (warning,critical) for cpu\n";print_usage(); exit $ERRORS{"UNKNOWN"}};
|
||||
if (isnotnum($o_cpuL[0]) || isnotnum($o_cpuL[1]))
|
||||
{print "Numeric values for cpu!\n";print_usage(); exit $ERRORS{"UNKNOWN"}};
|
||||
if ($o_cpuL[0]>$o_cpuL[1])
|
||||
{print "Warning must be <= Critical for cpu!\n";print_usage(); exit $ERRORS{"UNKNOWN"}};
|
||||
}
|
||||
###### Oreon #######
|
||||
|
||||
if (!defined($o_S)) { $o_S="1_1" }
|
||||
$ServiceId = is_valid_serviceid($o_S);
|
||||
|
||||
if (!defined($o_step)) { $o_step="300" }
|
||||
$step = $1 if ($o_step =~ /(\d+)/);
|
||||
|
||||
}
|
||||
|
||||
########## MAIN #######
|
||||
|
||||
check_options();
|
||||
|
||||
$rrd = $pathtorrdbase.$ServiceId.".rrd";
|
||||
$start=time;
|
||||
|
||||
# Check gobal timeout if snmp screws up
|
||||
if (defined($TIMEOUT)) {
|
||||
verb("Alarm at $TIMEOUT");
|
||||
alarm($TIMEOUT);
|
||||
} else {
|
||||
verb("no timeout defined : $o_timeout + 10");
|
||||
alarm ($o_timeout+10);
|
||||
}
|
||||
|
||||
# Connect to host
|
||||
my ($session,$error);
|
||||
if ( defined($o_login) && defined($o_passwd)) {
|
||||
# SNMPv3 login
|
||||
verb("SNMPv3 login");
|
||||
($session, $error) = Net::SNMP->session(
|
||||
-hostname => $o_host,
|
||||
-version => '3',
|
||||
-username => $o_login,
|
||||
-authpassword => $o_passwd,
|
||||
-authprotocol => 'md5',
|
||||
-privpassword => $o_passwd,
|
||||
-timeout => $o_timeout
|
||||
);
|
||||
} else {
|
||||
# SNMPV1 login
|
||||
($session, $error) = Net::SNMP->session(
|
||||
-hostname => $o_host,
|
||||
-community => $o_community,
|
||||
-port => $o_port,
|
||||
-timeout => $o_timeout
|
||||
);
|
||||
}
|
||||
|
||||
if (!defined($session)) {
|
||||
printf("ERROR: %s.\n", $error);
|
||||
exit $ERRORS{"UNKNOWN"};
|
||||
}
|
||||
|
||||
# Look for process in name or path name table
|
||||
my $resultat=undef;
|
||||
if ( !defined ($o_path) ) {
|
||||
$resultat = $session->get_table(
|
||||
Baseoid => $run_name_table
|
||||
);
|
||||
} else {
|
||||
$resultat = $session->get_table(
|
||||
Baseoid => $run_path_table
|
||||
);
|
||||
}
|
||||
|
||||
if (!defined($resultat)) {
|
||||
printf("ERROR: Process name table : %s.\n", $session->error);
|
||||
$session->close;
|
||||
exit $ERRORS{"UNKNOWN"};
|
||||
}
|
||||
|
||||
my @tindex = undef;
|
||||
my @oids = undef;
|
||||
my @descr = undef;
|
||||
my $num_int = 0;
|
||||
my $count_oid = 0;
|
||||
# Select storage by regexp of exact match
|
||||
# and put the oid to query in an array
|
||||
|
||||
verb("Filter : $o_descr");
|
||||
|
||||
foreach my $key ( keys %$resultat) {
|
||||
verb("OID : $key, Desc : $$resultat{$key}");
|
||||
# test by regexp or exact match
|
||||
my $test = defined($o_noreg)
|
||||
? $$resultat{$key} eq $o_descr
|
||||
: $$resultat{$key} =~ /$o_descr/;
|
||||
if ($test) {
|
||||
# get the index number of the interface
|
||||
my @oid_list = split (/\./,$key);
|
||||
$tindex[$num_int] = pop (@oid_list);
|
||||
# get the full description
|
||||
$descr[$num_int]=$$resultat{$key};
|
||||
# put the oid of running and mem (check this maybe ?) in an array.
|
||||
$oids[$count_oid++]=$proc_mem_table . "." . $tindex[$num_int];
|
||||
$oids[$count_oid++]=$proc_cpu_table . "." . $tindex[$num_int];
|
||||
$oids[$count_oid++]=$proc_run_state . "." . $tindex[$num_int];
|
||||
#verb("Name : $descr[$num_int], Index : $tindex[$num_int]");
|
||||
verb($oids[$count_oid-1]);
|
||||
$num_int++;
|
||||
}
|
||||
}
|
||||
|
||||
if ( $num_int == 0) {
|
||||
print "No process ",(defined ($o_noreg)) ? "named " : "matching ", $o_descr, " found : CRITICAL\n";
|
||||
exit $ERRORS{"CRITICAL"};
|
||||
}
|
||||
|
||||
my $result=undef;
|
||||
my $num_int_ok=0;
|
||||
my %result_cons=();
|
||||
#$session->max_msg_size([214748]);
|
||||
if ( $count_oid >= 50) {
|
||||
my @toid=undef;
|
||||
my $tmp_num=0;
|
||||
my $tmp_index=0;
|
||||
my $tmp_count=$count_oid;
|
||||
my $tmp_result=undef;
|
||||
verb("More than 50 oid, splitting");
|
||||
while ( $tmp_count != 0 ) {
|
||||
$tmp_num = ($tmp_count >=50) ? 50 : $tmp_count;
|
||||
for (my $i=0; $i<$tmp_num;$i++) {
|
||||
$toid[$i]=$oids[$i+$tmp_index];
|
||||
#verb("$i : $toid[$i] : $oids[$i+$tmp_index]");
|
||||
}
|
||||
$tmp_result = $session->get_request(
|
||||
Varbindlist => \@toid
|
||||
);
|
||||
if (!defined($tmp_result)) { printf("ERROR: running table : %s.\n", $session->error); $session->close;
|
||||
exit $ERRORS{"UNKNOWN"};
|
||||
}
|
||||
foreach (@toid) { $result_cons{$_}=$$tmp_result{$_}; }
|
||||
$tmp_count-=$tmp_num;
|
||||
$tmp_index+=$tmp_num;
|
||||
}
|
||||
|
||||
} else {
|
||||
$result = $session->get_request(
|
||||
Varbindlist => \@oids
|
||||
);
|
||||
if (!defined($result)) { printf("ERROR: running table : %s.\n", $session->error); $session->close;
|
||||
exit $ERRORS{"UNKNOWN"};
|
||||
}
|
||||
foreach (@oids) {$result_cons{$_}=$$result{$_};}
|
||||
}
|
||||
|
||||
#Check if process are in running or runnable state
|
||||
for (my $i=0; $i< $num_int; $i++) {
|
||||
my $state=$result_cons{$proc_run_state . "." . $tindex[$i]};
|
||||
my $tmpmem=$result_cons{$proc_mem_table . "." . $tindex[$i]};
|
||||
my $tmpcpu=$result_cons{$proc_cpu_table . "." . $tindex[$i]};
|
||||
verb ("Process $tindex[$i] in state $state using $tmpmem, and $tmpcpu CPU");
|
||||
$num_int_ok++ if (($state == 1) || ($state ==2));
|
||||
}
|
||||
|
||||
$session->close;
|
||||
|
||||
$rrd_data[0] = $num_int_ok;
|
||||
|
||||
my $final_status=0;
|
||||
my ($res_memory,$res_cpu)=(0,0);
|
||||
my $memory_print="";
|
||||
my $cpu_print="";
|
||||
###### Checks memory usage
|
||||
if (defined ($o_mem) ) {
|
||||
if (defined ($o_mem_avg)) {
|
||||
for (my $i=0; $i< $num_int; $i++) { $res_memory += $result_cons{$proc_mem_table . "." . $tindex[$i]};}
|
||||
$res_memory /= ($num_int_ok*1024);
|
||||
verb("Memory average : $res_memory");
|
||||
} else {
|
||||
for (my $i=0; $i< $num_int; $i++) {
|
||||
$res_memory = ($result_cons{$proc_mem_table . "." . $tindex[$i]} > $res_memory) ? $result_cons{$proc_mem_table . "." . $tindex[$i]} : $res_memory;
|
||||
}
|
||||
$res_memory /=1024;
|
||||
verb("Memory max : $res_memory");
|
||||
}
|
||||
if ($res_memory > $o_memL[1]) {
|
||||
$final_status=2;
|
||||
$memory_print=", Mem : ".sprintf("%.1f",$res_memory)."Mb > ".$o_memL[1]." CRITICAL";
|
||||
} elsif ( $res_memory > $o_memL[0]) {
|
||||
$final_status=1;
|
||||
$memory_print=", Mem : ".sprintf("%.1f",$res_memory)."Mb > ".$o_memL[0]." WARNING";
|
||||
} else {
|
||||
$memory_print=", Mem : ".sprintf("%.1f",$res_memory)."Mb OK";
|
||||
}
|
||||
|
||||
push @rrd_data, $res_memory;
|
||||
|
||||
}
|
||||
|
||||
######## Checks CPU usage
|
||||
|
||||
if (defined ($o_cpu) ) {
|
||||
my $timenow=time;
|
||||
my $temp_file_name;
|
||||
my ($return,@file_values)=(undef,undef);
|
||||
my $n_rows=0;
|
||||
my $n_items_check=2;
|
||||
my $trigger=$timenow - ($o_delta - ($o_delta/10));
|
||||
my $trigger_low=$timenow - 3*$o_delta;
|
||||
my ($old_value,$old_time)=undef;
|
||||
my $found_value=undef;
|
||||
|
||||
#### Get the current values
|
||||
for (my $i=0; $i< $num_int; $i++) { $res_cpu += $result_cons{$proc_cpu_table . "." . $tindex[$i]};}
|
||||
|
||||
verb("Time: $timenow , cpu (centiseconds) : $res_cpu");
|
||||
|
||||
#### Read file
|
||||
$temp_file_name=$o_descr;
|
||||
$temp_file_name =~ s/ /_/g;
|
||||
$temp_file_name = $o_base_dir . $o_host ."." . $temp_file_name;
|
||||
# First, read entire file
|
||||
my @ret_array=read_file($temp_file_name,$n_items_check);
|
||||
$return = shift(@ret_array);
|
||||
$n_rows = shift(@ret_array);
|
||||
if ($n_rows != 0) { @file_values = @ret_array };
|
||||
verb ("File read returns : $return with $n_rows rows");
|
||||
#make the checks if the file is OK
|
||||
if ($return ==0) {
|
||||
my $j=$n_rows-1;
|
||||
do {
|
||||
if ($file_values[$j][0] < $trigger) {
|
||||
if ($file_values[$j][0] > $trigger_low) {
|
||||
# found value = centiseconds / seconds = %cpu
|
||||
$found_value= ($res_cpu-$file_values[$j][1]) / ($timenow - $file_values[$j][0] );
|
||||
}
|
||||
}
|
||||
$j--;
|
||||
} while ( ($j>=0) && (!defined($found_value)) );
|
||||
}
|
||||
###### Write file
|
||||
$file_values[$n_rows][0]=$timenow;
|
||||
$file_values[$n_rows][1]=$res_cpu;
|
||||
$n_rows++;
|
||||
$return=write_file($temp_file_name,$n_rows,$n_items_check,@file_values);
|
||||
if ($return != 0) { $cpu_print.="! ERROR writing file $temp_file_name !";$final_status=3;}
|
||||
##### Check values (if something to check...)
|
||||
if (defined($found_value)) {
|
||||
if ($found_value > $o_cpuL[1]) {
|
||||
$final_status=2;
|
||||
$cpu_print.=", Cpu : ".sprintf("%.0f",$found_value)."% > ".$o_cpuL[1]." CRITICAL";
|
||||
} elsif ( $found_value > $o_cpuL[0]) {
|
||||
$final_status=($final_status==2)?2:1;
|
||||
$cpu_print.=", Cpu : ".sprintf("%.0f",$found_value)."% > ".$o_cpuL[0]." WARNING";
|
||||
} else {
|
||||
$cpu_print.=", Cpu : ".sprintf("%.0f",$found_value)."% OK";
|
||||
}
|
||||
push @rrd_data, $found_value;
|
||||
} else {
|
||||
if ($final_status==0) { $final_status=3 };
|
||||
$cpu_print.=", No data for CPU (".$n_rows." line(s)):UNKNOWN";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
##
|
||||
## RRD management
|
||||
##
|
||||
|
||||
if ($o_g) {
|
||||
$start=time;
|
||||
if (! -e $rrd) {
|
||||
create_rrd($rrd,$#rrd_data+1,$start,$step,0,"U","GAUGE");
|
||||
}
|
||||
update_rrd($rrd,$start,@rrd_data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
print $num_int_ok, " process ", (defined ($o_noreg)) ? "named " : "matching ", $o_descr, " ";
|
||||
|
||||
#### Check for min and max number of process
|
||||
if ( $num_int_ok <= $o_critL[0] ) {
|
||||
print "(<= ",$o_critL[0]," : CRITICAL)";
|
||||
$final_status=2;
|
||||
} elsif ( $num_int_ok <= $o_warnL[0] ) {
|
||||
print "(<= ",$o_warnL[0]," : WARNING)";
|
||||
$final_status=($final_status==2)?2:1;
|
||||
} else {
|
||||
print "(> ",$o_warnL[0],")";
|
||||
}
|
||||
if (defined($o_critL[1]) && ($num_int_ok > $o_critL[1])) {
|
||||
print " (> ",$o_critL[1]," : CRITICAL)";
|
||||
$final_status=2;
|
||||
} elsif (defined($o_warnL[1]) && ($num_int_ok > $o_warnL[1])) {
|
||||
print " (> ",$o_warnL[1]," : WARNING)";
|
||||
$final_status=($final_status==2)?2:1;
|
||||
} elsif (defined($o_warnL[1])) {
|
||||
print " (<= ",$o_warnL[1],"):OK";
|
||||
}
|
||||
|
||||
print $memory_print,$cpu_print,"\n";
|
||||
|
||||
if ($final_status==2) { exit $ERRORS{"CRITICAL"};}
|
||||
if ($final_status==1) { exit $ERRORS{"WARNING"};}
|
||||
if ($final_status==3) { exit $ERRORS{"UNKNOWN"};}
|
||||
exit $ERRORS{"OK"};
|
||||
|
662
centreon-plugins/src/check_snmp_storage.pl
Normal file
662
centreon-plugins/src/check_snmp_storage.pl
Normal file
@ -0,0 +1,662 @@
|
||||
#!/usr/bin/perl -w
|
||||
############################## check_snmp_storage ##############
|
||||
# Version : 1.1.1.4 - DEV
|
||||
# Date : Aug 2 2005
|
||||
# Author : Patrick Proy ( patrick at proy.org)
|
||||
# Help : http://www.manubulon.com/nagios/
|
||||
# Licence : GPL - http://www.fsf.org/licenses/gpl.txt
|
||||
# TODO : better options in snmpv3
|
||||
#################################################################
|
||||
#
|
||||
# help : ./check_snmp_storage -h
|
||||
|
||||
use strict;
|
||||
use Net::SNMP;
|
||||
use Getopt::Long;
|
||||
|
||||
# Nagios specific
|
||||
|
||||
use lib "@NAGIOS_PLUGINS@";
|
||||
use utils qw(%ERRORS $TIMEOUT);
|
||||
#my $TIMEOUT = 15;
|
||||
#my %ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3,'DEPENDENT'=>4);
|
||||
|
||||
# Oreon specific
|
||||
|
||||
#use lib "@NAGIOS_PLUGINS@";
|
||||
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'};
|
||||
}
|
||||
|
||||
my $pathtorrdbase = $oreon{GLOBAL}{DIR_RRDTOOL};
|
||||
|
||||
# SNMP Datas
|
||||
my $storage_table= '1.3.6.1.2.1.25.2.3.1';
|
||||
my $storagetype_table = '1.3.6.1.2.1.25.2.3.1.2';
|
||||
my $index_table = '1.3.6.1.2.1.25.2.3.1.1';
|
||||
my $descr_table = '1.3.6.1.2.1.25.2.3.1.3';
|
||||
my $size_table = '1.3.6.1.2.1.25.2.3.1.5.';
|
||||
my $used_table = '1.3.6.1.2.1.25.2.3.1.6.';
|
||||
my $alloc_units = '1.3.6.1.2.1.25.2.3.1.4.';
|
||||
|
||||
#Storage types definition - from /usr/share/snmp/mibs/HOST-RESOURCES-TYPES.txt
|
||||
my %hrStorage;
|
||||
$hrStorage{"Other"} = '1.3.6.1.2.1.25.2.1.1';
|
||||
$hrStorage{"1.3.6.1.2.1.25.2.1.1"} = 'Other';
|
||||
$hrStorage{"Ram"} = '1.3.6.1.2.1.25.2.1.2';
|
||||
$hrStorage{"1.3.6.1.2.1.25.2.1.2"} = 'Ram';
|
||||
$hrStorage{"VirtualMemory"} = '1.3.6.1.2.1.25.2.1.3';
|
||||
$hrStorage{"1.3.6.1.2.1.25.2.1.3"} = 'VirtualMemory';
|
||||
$hrStorage{"FixedDisk"} = '1.3.6.1.2.1.25.2.1.4';
|
||||
$hrStorage{"1.3.6.1.2.1.25.2.1.4"} = 'FixedDisk';
|
||||
$hrStorage{"RemovableDisk"} = '1.3.6.1.2.1.25.2.1.5';
|
||||
$hrStorage{"1.3.6.1.2.1.25.2.1.5"} = 'RemovableDisk';
|
||||
$hrStorage{"FloppyDisk"} = '1.3.6.1.2.1.25.2.1.6';
|
||||
$hrStorage{"1.3.6.1.2.1.25.2.1.6"} = 'FloppyDisk';
|
||||
$hrStorage{"CompactDisk"} = '1.3.6.1.2.1.25.2.1.7';
|
||||
$hrStorage{"1.3.6.1.2.1.25.2.1.7"} = 'CompactDisk';
|
||||
$hrStorage{"RamDisk"} = '1.3.6.1.2.1.25.2.1.8';
|
||||
$hrStorage{"1.3.6.1.2.1.25.2.1.8"} = 'RamDisk';
|
||||
$hrStorage{"FlashMemory"} = '1.3.6.1.2.1.25.2.1.9';
|
||||
$hrStorage{"1.3.6.1.2.1.25.2.1.9"} = 'FlashMemory';
|
||||
$hrStorage{"NetworkDisk"} = '1.3.6.1.2.1.25.2.1.10';
|
||||
$hrStorage{"1.3.6.1.2.1.25.2.1.10"} = 'NetworkDisk';
|
||||
|
||||
# Globals
|
||||
|
||||
my $Name='check_snmp_storage';
|
||||
my $Version='1.1.1.3';
|
||||
|
||||
my $o_host = undef; # hostname
|
||||
my $o_community = undef; # community
|
||||
my $o_port = 161; # port
|
||||
my $o_version2 = undef; #use snmp v2c
|
||||
my $o_descr = undef; # description filter
|
||||
my $o_storagetype = undef; # parse storage type also
|
||||
my $o_warn = undef; # warning limit
|
||||
my $o_crit= undef; # critical limit
|
||||
my $o_help= undef; # wan't some help ?
|
||||
my $o_type= undef; # pl, pu, mbl, mbu
|
||||
my @o_typeok= ("pu","pl","bu","bl"); # valid values for o_type
|
||||
my $o_verb= undef; # verbose mode
|
||||
my $o_version= undef; # print version
|
||||
my $o_noreg= undef; # Do not use Regexp for name
|
||||
my $o_sum= undef; # add all storage before testing
|
||||
my $o_index= undef; # Parse index instead of description
|
||||
my $o_negate= undef; # Negate the regexp if set
|
||||
my $o_timeout= 5; # Default 5s Timeout
|
||||
my $o_perf= undef; # Output performance data
|
||||
my $o_short= undef; # Short output parameters
|
||||
my @o_shortL= undef; # output type,where,cut
|
||||
# SNMP V3 specific
|
||||
my $o_login= undef; # snmp v3 login
|
||||
my $o_passwd= undef; # snmp v3 passwd
|
||||
# Oreon specific
|
||||
my $o_step= undef;
|
||||
my $o_g= undef;
|
||||
my $o_S= undef;
|
||||
my $step= undef;
|
||||
my $rrd= undef;
|
||||
my $rrd_max= undef;
|
||||
my $start= undef;
|
||||
my $ServiceId= undef;
|
||||
my @rrd_data= undef;
|
||||
|
||||
# functions
|
||||
|
||||
sub p_version { print "$Name version : $Version\n"; }
|
||||
|
||||
sub print_usage {
|
||||
print "Usage: $Name [-v] -H <host> -C <snmp_community> [-2] | (-l login -x passwd) [-p <port>] -m <name in desc_oid> [-q storagetype] -w <warn_level> -c <crit_level> [-t <timeout>] [-T pl|pu|bl|bu ] [-r] [-s] [-i] [-e] [-S 0|1[,1,<car>]]\n";
|
||||
}
|
||||
|
||||
sub round ($$) {
|
||||
sprintf "%.$_[1]f", $_[0];
|
||||
}
|
||||
|
||||
sub is_pattern_valid { # Test for things like "<I\s*[^>" or "+5-i"
|
||||
my $pat = shift;
|
||||
if (!defined($pat)) { $pat=" ";} # Just to get rid of compilation time warnings
|
||||
return eval { "" =~ /$pat/; 1 } || 0;
|
||||
}
|
||||
|
||||
# Get the alarm signal (just in case snmp timout screws up)
|
||||
$SIG{'ALRM'} = sub {
|
||||
print ("ERROR: General time-out (Alarm signal)\n");
|
||||
exit $ERRORS{"UNKNOWN"};
|
||||
};
|
||||
|
||||
sub isnnum { # Return true if arg is not a number
|
||||
my $num = shift;
|
||||
if ( $num =~ /^-?(\d+\.?\d*)|(^\.\d+)$/ ) { return 0 ;}
|
||||
return 1;
|
||||
}
|
||||
|
||||
sub help {
|
||||
print "\nSNMP Disk Monitor for Nagios version ",$Version,"\n";
|
||||
print "(c)2004 to my cat Ratoune - Author : Patrick Proy\n\n";
|
||||
print_usage();
|
||||
print <<EOT;
|
||||
By default, plugin will monitor %used on drives :
|
||||
warn if %used > warn and critical if %used > crit
|
||||
-v, --verbose
|
||||
print extra debugging information (and lists all storages)
|
||||
-h, --help
|
||||
print this help message
|
||||
-H, --hostname=HOST
|
||||
name or IP address of host to check
|
||||
-C, --community=COMMUNITY NAME
|
||||
community name for the host's SNMP agent (implies SNMP v1)
|
||||
-2, --v2c
|
||||
Use snmp v2c
|
||||
-l, --login=LOGIN
|
||||
Login for snmpv3 authentication (implies v3 protocol with MD5)
|
||||
-x, --passwd=PASSWD
|
||||
Password for snmpv3 authentication
|
||||
-p, --port=PORT
|
||||
SNMP port (Default 161)
|
||||
-m, --name=NAME
|
||||
Name in description OID (can be mounpoints '/home' or 'Swap Space'...)
|
||||
This is treated as a regexp : -m /var will match /var , /var/log, /opt/var ...
|
||||
Test it before, because there are known bugs (ex : trailling /)
|
||||
No trailing slash for mountpoints !
|
||||
-q, --storagetype=[Other|Ram|VirtualMemory|FixedDisk|RemovableDisk|FloppyDisk
|
||||
CompactDisk|RamDisk|FlashMemory|NetworkDisk]
|
||||
Also check the storage type in addition of the name
|
||||
It is possible to use regular expressions ( "FixedDisk|FloppyDisk" )
|
||||
-r, --noregexp
|
||||
Do not use regexp to match NAME in description OID
|
||||
-s, --sum
|
||||
Add all storages that match NAME (used space and total space)
|
||||
THEN make the tests.
|
||||
-i, --index
|
||||
Parse index table instead of description table to select storage
|
||||
-e, --exclude
|
||||
Select all storages except the one(s) selected by -m
|
||||
No action on storage type selection
|
||||
-T, --type=TYPE
|
||||
pl : calculate percent left
|
||||
pu : calculate percent used (Default)
|
||||
bl : calculate MegaBytes left
|
||||
bu : calculate MegaBytes used
|
||||
-w, --warn=INTEGER
|
||||
percent / MB of disk used to generate WARNING state
|
||||
you can add the % sign
|
||||
-c, --critical=INTEGER
|
||||
percent / MB of disk used to generate CRITICAL state
|
||||
you can add the % sign
|
||||
-f, --perfparse
|
||||
Perfparse compatible output
|
||||
-S, --short=<type>[,<where>,<cut>]
|
||||
<type>: Make the output shorter :
|
||||
0 : only print the global result except the disk in warning or critical
|
||||
ex: "< 80% : OK"
|
||||
1 : Don't print all info for every disk
|
||||
ex : "/ : 66 %used (< 80) : OK"
|
||||
<where>: (optional) if = 1, put the OK/WARN/CRIT at the beginning
|
||||
<cut>: take the <n> first caracters or <n> last if n<0
|
||||
-t, --timeout=INTEGER
|
||||
timeout for SNMP in seconds (Default: 5)
|
||||
-V, --version
|
||||
prints version number
|
||||
-g (--rrdgraph) Create a rrd base if necessary and add datas into this one
|
||||
--rrd_step Specifies the base interval in seconds with which data will be fed into the RRD (300 by default)
|
||||
-S (--ServiceId) Oreon Service Id
|
||||
|
||||
Note :
|
||||
with T=pu or T=bu : OK < warn < crit
|
||||
with T=pl ot T=bl : crit < warn < OK
|
||||
|
||||
If multiple storage are selected, the worse condition will be returned
|
||||
i.e if one disk is critical, the return is critical
|
||||
|
||||
example :
|
||||
Browse storage list : <script> -C <community> -H <host> -m <anything> -w 1 -c 2 -v
|
||||
the -m option allows regexp in perl format :
|
||||
Test drive C,F,G,H,I on Windows : -m ^[CFGHI]:
|
||||
Test all mounts containing /var : -m /var
|
||||
Test all mounts under /var : -m ^/var
|
||||
Test only /var : -m /var -r
|
||||
Test all swap spaces : -m ^Swap
|
||||
Test all but swap spaces : -m ^Swap -e
|
||||
|
||||
EOT
|
||||
}
|
||||
|
||||
sub verb { my $t=shift; print $t,"\n" if defined($o_verb) ; }
|
||||
|
||||
sub check_options {
|
||||
Getopt::Long::Configure ("bundling");
|
||||
GetOptions(
|
||||
'v' => \$o_verb, 'verbose' => \$o_verb,
|
||||
'h' => \$o_help, 'help' => \$o_help,
|
||||
'H:s' => \$o_host, 'hostname:s' => \$o_host,
|
||||
'p:i' => \$o_port, 'port:i' => \$o_port,
|
||||
'C:s' => \$o_community, 'community:s' => \$o_community,
|
||||
'l:s' => \$o_login, 'login:s' => \$o_login,
|
||||
'x:s' => \$o_passwd, 'passwd:s' => \$o_passwd,
|
||||
'c:s' => \$o_crit, 'critical:s' => \$o_crit,
|
||||
'w:s' => \$o_warn, 'warn:s' => \$o_warn,
|
||||
't:i' => \$o_timeout, 'timeout:i' => \$o_timeout,
|
||||
'm:s' => \$o_descr, 'name:s' => \$o_descr,
|
||||
'T:s' => \$o_type, 'type:s' => \$o_type,
|
||||
'r' => \$o_noreg, 'noregexp' => \$o_noreg,
|
||||
's' => \$o_sum, 'sum' => \$o_sum,
|
||||
'i' => \$o_index, 'index' => \$o_index,
|
||||
'e' => \$o_negate, 'exclude' => \$o_negate,
|
||||
'V' => \$o_version, 'version' => \$o_version,
|
||||
'q:s' => \$o_storagetype, 'storagetype:s'=> \$o_storagetype,
|
||||
'2' => \$o_version2, 'v2c' => \$o_version2,
|
||||
'S:s' => \$o_short, 'short:s' => \$o_short,
|
||||
'f' => \$o_perf, 'perfparse' => \$o_perf,
|
||||
# For Oreon rrdtool graph
|
||||
"rrd_step:s" => \$o_step,
|
||||
"g" => \$o_g, "rrdgraph" => \$o_g,
|
||||
# "S=s" => \$o_S,
|
||||
"ServiceId=s" => \$o_S
|
||||
);
|
||||
if (defined($o_help) ) { help(); exit $ERRORS{"UNKNOWN"}};
|
||||
if (defined($o_version) ) { p_version(); exit $ERRORS{"UNKNOWN"}};
|
||||
# check mount point regexp
|
||||
if (!is_pattern_valid($o_descr))
|
||||
{ print "Bad pattern for mount point !\n"; print_usage(); exit $ERRORS{"UNKNOWN"}}
|
||||
# check snmp information
|
||||
if ( !defined($o_community) && (!defined($o_login) || !defined($o_passwd)) )
|
||||
{ print "Put snmp login info!\n"; print_usage(); exit $ERRORS{"UNKNOWN"}}
|
||||
# Check types
|
||||
if ( !defined($o_type) ) { $o_type="pu" ;}
|
||||
if ( ! grep( /^$o_type$/ ,@o_typeok) ) { print_usage(); exit $ERRORS{"UNKNOWN"}};
|
||||
# Check compulsory attributes
|
||||
if ( ! defined($o_descr) || ! defined($o_host) || !defined($o_warn) ||
|
||||
!defined($o_crit)) { print_usage(); exit $ERRORS{"UNKNOWN"}};
|
||||
# Check for positive numbers
|
||||
|
||||
# check if warn or crit in % and MB is tested
|
||||
if ( ( ( $o_warn =~ /%/ ) || ($o_crit =~ /%/)) && ( ( $o_type eq 'bu' ) || ( $o_type eq 'bl' ) ) ) {
|
||||
print "warning or critical cannot be in % when MB are tested\n";
|
||||
print_usage(); exit $ERRORS{"UNKNOWN"};
|
||||
}
|
||||
# Get rid of % sign
|
||||
$o_warn =~ s/\%//;
|
||||
$o_crit =~ s/\%//;
|
||||
if (($o_warn < 0) || ($o_crit < 0)) { print " warn and critical > 0 \n";print_usage(); exit $ERRORS{"UNKNOWN"}};
|
||||
# Check warning and critical values
|
||||
if ( ( $o_type eq 'pu' ) || ( $o_type eq 'bu' )) {
|
||||
if ($o_warn >= $o_crit) { print " warn < crit if type=",$o_type,"\n";print_usage(); exit $ERRORS{"UNKNOWN"}};
|
||||
}
|
||||
if ( ( $o_type eq 'pl' ) || ( $o_type eq 'bl' )) {
|
||||
if ($o_warn <= $o_crit) { print " warn > crit if type=",$o_type,"\n";print_usage(); exit $ERRORS{"UNKNOWN"}};
|
||||
}
|
||||
if ( ($o_warn < 0 ) || ($o_crit < 0 )) { print "warn and crit must be > 0\n";print_usage(); exit $ERRORS{"UNKNOWN"}};
|
||||
if ( ( $o_type eq 'pl' ) || ( $o_type eq 'pu' )) {
|
||||
if ( ($o_warn > 100 ) || ($o_crit > 100 )) { print "percent must be < 100\n";print_usage(); exit $ERRORS{"UNKNOWN"}};
|
||||
}
|
||||
# Check short values
|
||||
if ( defined ($o_short)) {
|
||||
@o_shortL=split(/,/,$o_short);
|
||||
if ((isnnum($o_shortL[0])) || ($o_shortL[0] !=0) && ($o_shortL[0]!=1)) {
|
||||
print "-S first option must be 0 or 1\n";print_usage(); exit $ERRORS{"UNKNOWN"};
|
||||
}
|
||||
if (defined ($o_shortL[1])&& $o_shortL[1] eq "") {$o_shortL[1]=undef};
|
||||
if (defined ($o_shortL[2]) && isnnum($o_shortL[2]))
|
||||
{print "-S last option must be an integer\n";print_usage(); exit $ERRORS{"UNKNOWN"};}
|
||||
}
|
||||
###### Oreon #######
|
||||
|
||||
if (!defined($o_S)) { $o_S="1_1" }
|
||||
$ServiceId = is_valid_serviceid($o_S);
|
||||
|
||||
if (!defined($o_step)) { $o_step="300" }
|
||||
$step = $1 if ($o_step =~ /(\d+)/);
|
||||
|
||||
|
||||
}
|
||||
|
||||
########## MAIN #######
|
||||
|
||||
check_options();
|
||||
|
||||
$rrd = $pathtorrdbase.$ServiceId.".rrd";
|
||||
$start=time;
|
||||
|
||||
# Check gobal timeout
|
||||
if (defined($TIMEOUT)) {
|
||||
verb("Alarm at $TIMEOUT");
|
||||
alarm($TIMEOUT);
|
||||
} else {
|
||||
verb("no timeout defined : $o_timeout + 10");
|
||||
alarm ($o_timeout+10);
|
||||
}
|
||||
|
||||
# Connect to host
|
||||
my ($session,$error);
|
||||
if ( defined($o_login) && defined($o_passwd)) {
|
||||
# SNMPv3 login
|
||||
verb("SNMPv3 login");
|
||||
($session, $error) = Net::SNMP->session(
|
||||
-hostname => $o_host,
|
||||
-version => '3',
|
||||
-username => $o_login,
|
||||
-authpassword => $o_passwd,
|
||||
-authprotocol => 'md5',
|
||||
-privpassword => $o_passwd,
|
||||
-timeout => $o_timeout
|
||||
);
|
||||
} else {
|
||||
if (defined ($o_version2)) {
|
||||
# SNMPv2 Login
|
||||
($session, $error) = Net::SNMP->session(
|
||||
-hostname => $o_host,
|
||||
-version => 2,
|
||||
-community => $o_community,
|
||||
-port => $o_port,
|
||||
-timeout => $o_timeout
|
||||
);
|
||||
} else { # SNMPV1 login
|
||||
($session, $error) = Net::SNMP->session(
|
||||
-hostname => $o_host,
|
||||
-community => $o_community,
|
||||
-port => $o_port,
|
||||
-timeout => $o_timeout
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (!defined($session)) {
|
||||
printf("ERROR: %s.\n", $error);
|
||||
exit $ERRORS{"UNKNOWN"};
|
||||
}
|
||||
|
||||
my $resultat=undef;
|
||||
my $stype=undef;
|
||||
if (defined ($o_index)){
|
||||
if (Net::SNMP->VERSION < 4) {
|
||||
$resultat = $session->get_table($index_table);
|
||||
} else {
|
||||
$resultat = $session->get_table(Baseoid => $index_table);
|
||||
}
|
||||
} else {
|
||||
if (Net::SNMP->VERSION < 4) {
|
||||
$resultat = $session->get_table($descr_table);
|
||||
} else {
|
||||
$resultat = $session->get_table(Baseoid => $descr_table);
|
||||
}
|
||||
}
|
||||
#get storage typetable for reference
|
||||
if (defined($o_storagetype)){
|
||||
if (Net::SNMP->VERSION < 4) {
|
||||
$stype = $session->get_table($storagetype_table);
|
||||
} else {
|
||||
$stype = $session->get_table(Baseoid => $storagetype_table);
|
||||
}
|
||||
}
|
||||
if (!defined($resultat) | (!defined($stype) && defined($o_storagetype))) {
|
||||
printf("ERROR: Description/Type table : %s.\n", $session->error);
|
||||
$session->close;
|
||||
exit $ERRORS{"UNKNOWN"};
|
||||
}
|
||||
|
||||
my @tindex = undef;
|
||||
my @oids = undef;
|
||||
my @descr = undef;
|
||||
my $num_int = 0;
|
||||
my $count_oid = 0;
|
||||
my $test = undef;
|
||||
my $perf_out= undef;
|
||||
# Select storage by regexp of exact match
|
||||
# and put the oid to query in an array
|
||||
|
||||
verb("Filter : $o_descr");
|
||||
|
||||
foreach my $key ( keys %$resultat) {
|
||||
verb("OID : $key, Desc : $$resultat{$key}");
|
||||
# test by regexp or exact match / include or exclude
|
||||
if (defined($o_negate)) {
|
||||
$test = defined($o_noreg)
|
||||
? $$resultat{$key} ne $o_descr
|
||||
: $$resultat{$key} !~ /$o_descr/;
|
||||
} else {
|
||||
$test = defined($o_noreg)
|
||||
? $$resultat{$key} eq $o_descr
|
||||
: $$resultat{$key} =~ /$o_descr/;
|
||||
}
|
||||
if ($test) {
|
||||
# get the index number of the interface
|
||||
my @oid_list = split (/\./,$key);
|
||||
$tindex[$num_int] = pop (@oid_list);
|
||||
# Check if storage type is OK
|
||||
if (defined($o_storagetype)) {
|
||||
my($skey)=$storagetype_table.".".$tindex[$num_int];
|
||||
verb(" OID : $skey, Storagetype: $hrStorage{$$stype{$skey}} ?= $o_storagetype");
|
||||
if ( $hrStorage{$$stype{$skey}} !~ $o_storagetype) {
|
||||
$test=undef;
|
||||
}
|
||||
}
|
||||
if ($test) {
|
||||
# get the full description
|
||||
$descr[$num_int]=$$resultat{$key};
|
||||
# put the oid in an array
|
||||
$oids[$count_oid++]=$size_table . $tindex[$num_int];
|
||||
$oids[$count_oid++]=$used_table . $tindex[$num_int];
|
||||
$oids[$count_oid++]=$alloc_units . $tindex[$num_int];
|
||||
|
||||
verb(" Name : $descr[$num_int], Index : $tindex[$num_int]");
|
||||
$num_int++;
|
||||
}
|
||||
}
|
||||
}
|
||||
verb("storages selected : $num_int");
|
||||
if ( $num_int == 0 ) { print "Unknown storage : $o_descr : ERROR\n" ; exit $ERRORS{"UNKNOWN"};}
|
||||
|
||||
my $result=undef;
|
||||
|
||||
if (Net::SNMP->VERSION < 4) {
|
||||
$result = $session->get_request(@oids);
|
||||
} else {
|
||||
if ($session->version == 0) {
|
||||
# snmpv1
|
||||
$result = $session->get_request(Varbindlist => \@oids);
|
||||
} else {
|
||||
# snmp v2c or v3 : get_bulk_request is not really good for this, so do simple get
|
||||
$result = $session->get_request(Varbindlist => \@oids);
|
||||
foreach my $key ( keys %$result) { verb("$key : $$result{$key}"); }
|
||||
}
|
||||
}
|
||||
|
||||
if (!defined($result)) { printf("ERROR: Size table :%s.\n", $session->error); $session->close;
|
||||
exit $ERRORS{"UNKNOWN"};
|
||||
}
|
||||
|
||||
$session->close;
|
||||
|
||||
# Only a few ms left...
|
||||
alarm(0);
|
||||
|
||||
# Sum everything if -s and more than one storage
|
||||
if ( defined ($o_sum) && ($num_int > 1) ) {
|
||||
verb("Adding all entries");
|
||||
$$result{$size_table . $tindex[0]} *= $$result{$alloc_units . $tindex[0]};
|
||||
$$result{$used_table . $tindex[0]} *= $$result{$alloc_units . $tindex[0]};
|
||||
$$result{$alloc_units . $tindex[0]} = 1;
|
||||
for (my $i=1;$i<$num_int;$i++) {
|
||||
$$result{$size_table . $tindex[0]} += ($$result{$size_table . $tindex[$i]}
|
||||
* $$result{$alloc_units . $tindex[$i]});
|
||||
$$result{$used_table . $tindex[0]} += ($$result{$used_table . $tindex[$i]}
|
||||
* $$result{$alloc_units . $tindex[$i]});
|
||||
}
|
||||
$num_int=1;
|
||||
$descr[0]="Sum of all $o_descr";
|
||||
}
|
||||
|
||||
my $i=undef;
|
||||
my $warn_state=0;
|
||||
my $crit_state=0;
|
||||
my ($p_warn,$p_crit);
|
||||
my $output=undef;
|
||||
for ($i=0;$i<$num_int;$i++) {
|
||||
verb("Descr : $descr[$i]");
|
||||
verb("Size : $$result{$size_table . $tindex[$i]}");
|
||||
verb("Used : $$result{$used_table . $tindex[$i]}");
|
||||
verb("Alloc : $$result{$alloc_units . $tindex[$i]}");
|
||||
my $to = $$result{$size_table . $tindex[$i]} * $$result{$alloc_units . $tindex[$i]} / 1024**2;
|
||||
my $pu=undef;
|
||||
if ( $$result{$used_table . $tindex[$i]} != 0 ) {
|
||||
$pu = $$result{$used_table . $tindex[$i]}*100 / $$result{$size_table . $tindex[$i]};
|
||||
}else {
|
||||
$pu=0;
|
||||
}
|
||||
my $bu = $$result{$used_table . $tindex[$i]} * $$result{$alloc_units . $tindex[$i]} / 1024**2;
|
||||
my $pl = 100 - $pu;
|
||||
my $bl = ($$result{$size_table . $tindex[$i]}- $$result{$used_table . $tindex[$i]}) * $$result{$alloc_units . $tindex[$i]} / 1024**2;
|
||||
# add a ' ' if some data exists in $perf_out
|
||||
$perf_out .= " " if (defined ($perf_out)) ;
|
||||
##### Ouputs and checks
|
||||
# Keep complete description fot performance output (in MB)
|
||||
my $Pdescr=$descr[$i];
|
||||
$Pdescr =~ s/'/_/g;
|
||||
##### TODO : subs "," with something
|
||||
if (defined($o_shortL[2])) {
|
||||
if ($o_shortL[2] < 0) {$descr[$i]=substr($descr[$i],$o_shortL[2]);}
|
||||
else {$descr[$i]=substr($descr[$i],0,$o_shortL[2]);}
|
||||
}
|
||||
if ($o_type eq "pu") { # Checks % used
|
||||
my $locstate=0;
|
||||
$p_warn=$o_warn*$to/100;$p_crit=$o_crit*$to/100;
|
||||
(($pu >= $o_crit) && ($locstate=$crit_state=1))
|
||||
|| (($pu >= $o_warn) && ($locstate=$warn_state=1));
|
||||
if (defined($o_shortL[2])) {}
|
||||
if (!defined($o_shortL[0]) || ($locstate==1)) { # print full output if warn or critical state
|
||||
$output.=sprintf ("%s: %.0f%%used(%.0fMB/%.0fMB) ",$descr[$i],$pu,$bu,$to);
|
||||
} elsif ($o_shortL[0] == 1) {
|
||||
$output.=sprintf ("%s: %.0f%% ",$descr[$i],$pu);
|
||||
}
|
||||
$rrd_max = 100;
|
||||
if (defined($rrd_data[0])) {
|
||||
push @rrd_data, $pu;
|
||||
} else {
|
||||
$rrd_data[0]= $pu ;
|
||||
}
|
||||
}
|
||||
|
||||
if ($o_type eq 'bu') { # Checks MBytes used
|
||||
my $locstate=0;
|
||||
$p_warn=$o_warn;$p_crit=$o_crit;
|
||||
( ($bu >= $o_crit) && ($locstate=$crit_state=1) )
|
||||
|| ( ($bu >= $o_warn) && ($locstate=$warn_state=1) );
|
||||
if (!defined($o_shortL[0]) || ($locstate==1)) { # print full output if warn or critical state
|
||||
$output.=sprintf("%s: %.0fMBused/%.0fMB (%.0f%%) ",$descr[$i],$bu,$to,$pu);
|
||||
} elsif ($o_shortL[0] == 1) {
|
||||
$output.=sprintf("%s: %.0fMB ",$descr[$i],$bu);
|
||||
}
|
||||
$rrd_max = "U";
|
||||
if (defined($rrd_data[0])) {
|
||||
push @rrd_data, $bu;
|
||||
} else {
|
||||
$rrd_data[0]= $bu ;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ($o_type eq 'bl') {
|
||||
my $locstate=0;
|
||||
$p_warn=$to-$o_warn;$p_crit=$to-$o_crit;
|
||||
( ($bl <= $o_crit) && ($locstate=$crit_state=1) )
|
||||
|| ( ($bl <= $o_warn) && ($locstate=$warn_state=1) );
|
||||
if (!defined($o_shortL[0]) || ($locstate==1)) { # print full output if warn or critical state
|
||||
$output.=sprintf ("%s: %.0fMBleft/%.0fMB (%.0f%%) ",$descr[$i],$bl,$to,$pl);
|
||||
} elsif ($o_shortL[0] == 1) {
|
||||
$output.=sprintf ("%s: %.0fMB ",$descr[$i],$bl);
|
||||
}
|
||||
$rrd_max = "U";
|
||||
if (defined($rrd_data[0])) {
|
||||
push @rrd_data, $pl;
|
||||
} else {
|
||||
$rrd_data[0]= $pl ;
|
||||
}
|
||||
}
|
||||
|
||||
if ($o_type eq 'pl') { # Checks % left
|
||||
my $locstate=0;
|
||||
$p_warn=(100-$o_warn)*$to/100;$p_crit=(100-$o_crit)*$to/100;
|
||||
( ($pl <= $o_crit) && ($locstate=$crit_state=1) )
|
||||
|| ( ($pl <= $o_warn) && ($locstate=$warn_state=1) );
|
||||
if (!defined($o_shortL[0]) || ($locstate==1)) { # print full output if warn or critical state
|
||||
$output.=sprintf ("%s: %.0f%%left(%.0fMB/%.0fMB) ",$descr[$i],$pl,$bl,$to);
|
||||
} elsif ($o_shortL[0] == 1) {
|
||||
$output.=sprintf ("%s: %.0f%% ",$descr[$i],$pl);
|
||||
}
|
||||
$rrd_max = 100;
|
||||
if (defined($rrd_data[0])) {
|
||||
push @rrd_data, $pl;
|
||||
} else {
|
||||
$rrd_data[0]= $pl ;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
# Performance output (in MB)
|
||||
$perf_out .= "'".$Pdescr. "'=" . round($bu,0) . "MB;" . round($p_warn,0)
|
||||
. ";" . round($p_crit,0) . ";0;" . round($to,0);
|
||||
}
|
||||
|
||||
|
||||
##
|
||||
## RRD management
|
||||
##
|
||||
|
||||
if ($o_g) {
|
||||
$start=time;
|
||||
if (! -e $rrd) {
|
||||
create_rrd($rrd,$#rrd_data+1,$start,$step,0,$rrd_max,"GAUGE");
|
||||
}
|
||||
update_rrd($rrd,$start,@rrd_data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
verb ("Perf data : $perf_out");
|
||||
|
||||
my $comp_oper=undef;
|
||||
my $comp_unit=undef;
|
||||
($o_type eq "pu") && ($comp_oper ="<") && ($comp_unit ="%");
|
||||
($o_type eq "pl") && ($comp_oper =">") && ($comp_unit ="%");
|
||||
($o_type eq "bu") && ($comp_oper ="<") && ($comp_unit ="MB");
|
||||
($o_type eq 'bl') && ($comp_oper =">") && ($comp_unit ="MB");
|
||||
|
||||
if (!defined ($output)) { $output="All selected storages "; }
|
||||
|
||||
if ( $crit_state == 1) {
|
||||
$comp_oper = ($comp_oper eq "<") ? ">" : "<"; # Inverse comp operator
|
||||
if (defined($o_shortL[1])) {
|
||||
print "CRITICAL : (",$comp_oper,$o_crit,$comp_unit,") ",$output;
|
||||
} else {
|
||||
print $output,"(",$comp_oper,$o_crit,$comp_unit,") : CRITICAL";
|
||||
}
|
||||
(defined($o_perf)) ? print " | ",$perf_out,"\n" : print "\n";
|
||||
exit $ERRORS{"CRITICAL"};
|
||||
}
|
||||
if ( $warn_state == 1) {
|
||||
$comp_oper = ($comp_oper eq "<") ? ">" : "<"; # Inverse comp operator
|
||||
if (defined($o_shortL[1])) {
|
||||
print "WARNING : (",$comp_oper,$o_warn,$comp_unit,") ",$output;
|
||||
} else {
|
||||
print $output,"(",$comp_oper,$o_warn,$comp_unit,") : WARNING";
|
||||
}
|
||||
(defined($o_perf)) ? print " | ",$perf_out,"\n" : print "\n";
|
||||
exit $ERRORS{"WARNING"};
|
||||
}
|
||||
if (defined($o_shortL[1])) {
|
||||
print "OK : (",$comp_oper,$o_warn,$comp_unit,") ",$output;
|
||||
} else {
|
||||
print $output,"(",$comp_oper,$o_warn,$comp_unit,") : OK";
|
||||
}
|
||||
(defined($o_perf)) ? print " | ",$perf_out,"\n" : print "\n";
|
||||
|
||||
exit $ERRORS{"OK"};
|
||||
|
381
centreon-plugins/src/check_snmp_win.pl
Normal file
381
centreon-plugins/src/check_snmp_win.pl
Normal file
@ -0,0 +1,381 @@
|
||||
#!/usr/bin/perl -w
|
||||
############################## check_snmp_win ##############
|
||||
# Version : 0.5
|
||||
# Date : Aug 22 2005
|
||||
# Author : Patrick Proy (patrick at proy.org)
|
||||
# Help : http://www.manubulon.com/nagios/
|
||||
# Licence : GPL - http://www.fsf.org/licenses/gpl.txt
|
||||
# TODO :
|
||||
###############################################################
|
||||
#
|
||||
# help : ./check_snmp_win.pl -h
|
||||
|
||||
use strict;
|
||||
use Net::SNMP;
|
||||
use Getopt::Long;
|
||||
|
||||
# Nagios specific
|
||||
|
||||
use lib "@NAGIOS_PLUGINS@";
|
||||
use utils qw(%ERRORS $TIMEOUT);
|
||||
#my $TIMEOUT = 5;
|
||||
#my %ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3,'DEPENDENT'=>4);
|
||||
|
||||
# SNMP Datas for processes (MIB II)
|
||||
my $process_table= '1.3.6.1.2.1.25.4.2.1';
|
||||
my $index_table = '1.3.6.1.2.1.25.4.2.1.1';
|
||||
my $run_name_table = '1.3.6.1.2.1.25.4.2.1.2';
|
||||
my $run_path_table = '1.3.6.1.2.1.25.4.2.1.4';
|
||||
my $proc_mem_table = '1.3.6.1.2.1.25.5.1.1.2'; # Kbytes
|
||||
my $proc_cpu_table = '1.3.6.1.2.1.25.5.1.1.1'; # Centi sec of CPU
|
||||
my $proc_run_state = '1.3.6.1.2.1.25.4.2.1.7';
|
||||
|
||||
# Windows SNMP DATA
|
||||
|
||||
my $win_serv_table = '1.3.6.1.4.1.77.1.2.3.1'; # Windows services table
|
||||
my $win_serv_name = '1.3.6.1.4.1.77.1.2.3.1.1'; # Name of the service
|
||||
# Install state : uninstalled(1), install-pending(2), uninstall-pending(3), installed(4)
|
||||
my $win_serv_inst = '1.3.6.1.4.1.77.1.2.3.1.2';
|
||||
# Operating state : active(1), continue-pending(2), pause-pending(3), paused(4)
|
||||
my $win_serv_state = '1.3.6.1.4.1.77.1.2.3.1.3';
|
||||
my %win_serv_state_label = ( 1 => 'active', 2=> 'continue-pending', 3=> 'pause-pending', 4=> 'paused');
|
||||
# Can be uninstalled : cannot-be-uninstalled(1), can-be-uninstalled(2)
|
||||
my $win_serv_uninst = '1.3.6.1.4.1.77.1.2.3.1.4';
|
||||
|
||||
# Globals
|
||||
|
||||
my $Version='0.5';
|
||||
my $Name='check_snmp_win';
|
||||
|
||||
my $o_host = undef; # hostname
|
||||
my $o_community =undef; # community
|
||||
my $o_port = 161; # port
|
||||
my $o_version2 = undef; #use snmp v2c
|
||||
my $o_descr = undef; # description filter
|
||||
my @o_descrL = undef; # Service descriprion list.
|
||||
my $o_showall = undef; # Show all services even if OK
|
||||
my $o_type = "service"; # Check type (service, ...)
|
||||
my $o_number = undef; # Number of service for warn and crit levels
|
||||
my $o_help= undef; # wan't some help ?
|
||||
my $o_verb= undef; # verbose mode
|
||||
my $o_version= undef; # print version
|
||||
my $o_noreg= undef; # Do not use Regexp for name
|
||||
my $o_timeout= 5; # Default 5s Timeout
|
||||
# SNMP V3 specific
|
||||
my $o_login= undef; # snmp v3 login
|
||||
my $o_passwd= undef; # snmp v3 passwd
|
||||
|
||||
# functions
|
||||
|
||||
sub p_version { print "$Name version : $Version\n"; }
|
||||
|
||||
sub print_usage {
|
||||
print "Usage: $Name [-v] -H <host> -C <snmp_community> [-2] | (-l login -x passwd) [-p <port>] -n <name>[,<name2] [-T=service] [-r] [-s] [-N=<n>] [-t <timeout>] [-V]\n";
|
||||
}
|
||||
|
||||
sub isnotnum { # Return true if arg is not a number
|
||||
my $num = shift;
|
||||
if ( $num =~ /^-?(\d+\.?\d*)|(^\.\d+)$/ ) { return 0 ;}
|
||||
return 1;
|
||||
}
|
||||
|
||||
sub is_pattern_valid { # Test for things like "<I\s*[^>" or "+5-i"
|
||||
my $pat = shift;
|
||||
if (!defined($pat)) { $pat=" ";} # Just to get rid of compilation time warnings
|
||||
return eval { "" =~ /$pat/; 1 } || 0;
|
||||
}
|
||||
|
||||
# Get the alarm signal (just in case snmp timout screws up)
|
||||
$SIG{'ALRM'} = sub {
|
||||
print ("ERROR: Alarm signal (Nagios time-out)\n");
|
||||
exit $ERRORS{"UNKNOWN"};
|
||||
};
|
||||
|
||||
sub help {
|
||||
print "\nSNMP Windows Monitor for Nagios version ",$Version,"\n";
|
||||
print "GPL licence, (c)2004-2005 Patrick Proy\n\n";
|
||||
print_usage();
|
||||
print <<EOT;
|
||||
-v, --verbose
|
||||
print extra debugging information (and lists all services)
|
||||
-h, --help
|
||||
print this help message
|
||||
-H, --hostname=HOST
|
||||
name or IP address of host to check
|
||||
-C, --community=COMMUNITY NAME
|
||||
community name for the host's SNMP agent (implies SNMP v1 or v2c with option)
|
||||
-2, --v2c
|
||||
Use snmp v2c
|
||||
-l, --login=LOGIN
|
||||
Login for snmpv3 authentication (implies v3 protocol with MD5)
|
||||
-x, --passwd=PASSWD
|
||||
Password for snmpv3 authentication
|
||||
-p, --port=PORT
|
||||
SNMP port (Default 161)
|
||||
-T, --type=service
|
||||
Check type :
|
||||
- service (default) checks service
|
||||
-n, --name=NAME[,NAME2...]
|
||||
Comma separated names of services (perl regular expressions can be used for every one).
|
||||
By default, it is not case sensitive.
|
||||
-N, --number=<n>
|
||||
Compare matching services with <n> instead of the number of names provided.
|
||||
-s, --showall
|
||||
Show all services in the output, instead of only the non-active ones.
|
||||
-r, --noregexp
|
||||
Do not use regexp to match NAME in service description.
|
||||
-t, --timeout=INTEGER
|
||||
timeout for SNMP in seconds (Default: 5)
|
||||
-V, --version
|
||||
prints version number
|
||||
Note :
|
||||
The script will return
|
||||
OK if ALL services are in active state,
|
||||
WARNING if there is more than specified (ex 2 service specified, 3 active services matching),
|
||||
CRITICAL if at least one of them is non active.
|
||||
The -n option will allows regexp in perl format
|
||||
-n "service" will match 'service WINS' 'sevice DNS' etc...
|
||||
It is not case sensitive by default : WINS = wins
|
||||
EOT
|
||||
}
|
||||
|
||||
sub verb { my $t=shift; print $t,"\n" if defined($o_verb) ; }
|
||||
|
||||
sub decode_utf8 { # just replaces UFT8 caracters by "."
|
||||
my $utfstr=shift;
|
||||
if (substr($utfstr,0,2) ne "0x") { return $utfstr; }
|
||||
my @stringL=split(//,$utfstr);
|
||||
my $newstring="";
|
||||
for (my $i=2;$i<$#stringL;$i+=2) {
|
||||
if ( ($stringL[$i] . $stringL[$i+1]) eq "c3") {
|
||||
$i+=2;$newstring .= ".";
|
||||
} else {
|
||||
$newstring .= chr(hex($stringL[$i] . $stringL[$i+1]));
|
||||
}
|
||||
}
|
||||
return $newstring;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
Getopt::Long::Configure ("bundling");
|
||||
GetOptions(
|
||||
'v' => \$o_verb, 'verbose' => \$o_verb,
|
||||
'h' => \$o_help, 'help' => \$o_help,
|
||||
'H:s' => \$o_host, 'hostname:s' => \$o_host,
|
||||
'p:i' => \$o_port, 'port:i' => \$o_port,
|
||||
'C:s' => \$o_community, 'community:s' => \$o_community,
|
||||
'l:s' => \$o_login, 'login:s' => \$o_login,
|
||||
'x:s' => \$o_passwd, 'passwd:s' => \$o_passwd,
|
||||
't:i' => \$o_timeout, 'timeout:i' => \$o_timeout,
|
||||
'n:s' => \$o_descr, 'name:s' => \$o_descr,
|
||||
'r' => \$o_noreg, 'noregexp' => \$o_noreg,
|
||||
'T:s' => \$o_type, 'type:s' => \$o_type,
|
||||
'N:i' => \$o_number, 'number:i' => \$o_number,
|
||||
'2' => \$o_version2, 'v2c' => \$o_version2,
|
||||
's' => \$o_showall, 'showall' => \$o_showall,
|
||||
'V' => \$o_version, 'version' => \$o_version
|
||||
);
|
||||
if (defined ($o_help)) { help(); exit $ERRORS{"UNKNOWN"}};
|
||||
if (defined($o_version)) { p_version(); exit $ERRORS{"UNKNOWN"}};
|
||||
# check snmp information
|
||||
if ( !defined($o_community) && (!defined($o_login) || !defined($o_passwd)) )
|
||||
{ print "Put snmp login info!\n"; print_usage(); exit $ERRORS{"UNKNOWN"}}
|
||||
# Check compulsory attributes
|
||||
if ( $o_type ne "service" ) {
|
||||
print "Invalid check type !\n"; print_usage(); exit $ERRORS{"UNKNOWN"}
|
||||
}
|
||||
if ( ! defined($o_descr) || ! defined($o_host) ) { print_usage(); exit $ERRORS{"UNKNOWN"}};
|
||||
@o_descrL=split(/,/,$o_descr);
|
||||
foreach my $List (@o_descrL) {
|
||||
if ( ! is_pattern_valid ($List) ) { print "Invalid pattern ! ";print_usage(); exit $ERRORS{"UNKNOWN"} }
|
||||
}
|
||||
if (defined ($o_number)) {
|
||||
if (isnotnum($o_number) || ($o_number<0) )
|
||||
{ print "Invalid number of services!\n";print_usage(); exit $ERRORS{"UNKNOWN"}}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
########## MAIN #######
|
||||
|
||||
check_options();
|
||||
|
||||
# Check gobal timeout if snmp screws up
|
||||
if (defined($TIMEOUT)) {
|
||||
verb("Alarm at $TIMEOUT");
|
||||
alarm($TIMEOUT);
|
||||
} else {
|
||||
verb("no timeout defined : $o_timeout + 10");
|
||||
alarm ($o_timeout+10);
|
||||
}
|
||||
|
||||
# Connect to host
|
||||
my ($session,$error);
|
||||
if ( defined($o_login) && defined($o_passwd)) {
|
||||
# SNMPv3 login
|
||||
verb("SNMPv3 login");
|
||||
($session, $error) = Net::SNMP->session(
|
||||
-hostname => $o_host,
|
||||
-version => '3',
|
||||
-username => $o_login,
|
||||
-authpassword => $o_passwd,
|
||||
-authprotocol => 'md5',
|
||||
-privpassword => $o_passwd,
|
||||
-timeout => $o_timeout
|
||||
);
|
||||
} else {
|
||||
if (defined ($o_version2)) {
|
||||
# SNMPv2 Login
|
||||
($session, $error) = Net::SNMP->session(
|
||||
-hostname => $o_host,
|
||||
-version => 2,
|
||||
-community => $o_community,
|
||||
-port => $o_port,
|
||||
-timeout => $o_timeout
|
||||
);
|
||||
} else {
|
||||
# SNMPV1 login
|
||||
($session, $error) = Net::SNMP->session(
|
||||
-hostname => $o_host,
|
||||
-community => $o_community,
|
||||
-port => $o_port,
|
||||
-timeout => $o_timeout
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$session->max_msg_size(5000);
|
||||
verb($session->max_msg_size);
|
||||
#print $session->max_msg_size(),"\n";
|
||||
|
||||
if (!defined($session)) {
|
||||
printf("ERROR: %s.\n", $error);
|
||||
exit $ERRORS{"UNKNOWN"};
|
||||
}
|
||||
|
||||
# Look for process in name or path name table
|
||||
my $resultat=undef;
|
||||
|
||||
$resultat = (Net::SNMP->VERSION < 4) ?
|
||||
$session->get_table($win_serv_name)
|
||||
: $session->get_table(Baseoid => $win_serv_name);
|
||||
|
||||
if (!defined($resultat)) {
|
||||
printf("ERROR: Process name table : %s.\n", $session->error);
|
||||
$session->close;
|
||||
exit $ERRORS{"UNKNOWN"};
|
||||
}
|
||||
|
||||
my @tindex = undef;
|
||||
my @oids = undef;
|
||||
my @descr = undef;
|
||||
my $num_int = 0;
|
||||
my $count_oid = 0;
|
||||
# Select storage by regexp of exact match
|
||||
# and put the oid to query in an array
|
||||
|
||||
verb("Filter : $o_descr");
|
||||
|
||||
foreach my $key ( keys %$resultat) {
|
||||
my $descr_d=decode_utf8($$resultat{$key});
|
||||
verb("Desc : $descr_d");
|
||||
# test by regexp or exact match
|
||||
my $test=undef;
|
||||
foreach my $List (@o_descrL) {
|
||||
if (!($test)) {
|
||||
$test = defined($o_noreg)
|
||||
? $descr_d eq $List
|
||||
: $descr_d =~ /$List/i;
|
||||
}
|
||||
}
|
||||
if ($test) {
|
||||
# get the full description
|
||||
$descr[$num_int]=$descr_d;
|
||||
# get the index number of the process
|
||||
$key =~ s/$win_serv_name\.//;
|
||||
$tindex[$num_int] = $key;
|
||||
# put the oid of running state in an array.
|
||||
$oids[$count_oid++]=$win_serv_state . "." . $tindex[$num_int];
|
||||
verb("Name : $descr[$num_int], Index : $tindex[$num_int]");
|
||||
$num_int++;
|
||||
}
|
||||
}
|
||||
|
||||
if ( $num_int == 0) {
|
||||
if (defined ($o_number) && ($o_number ==0)) {
|
||||
print "No services ",(defined ($o_noreg)) ? "named \"" : "matching \"", $o_descr, "\" found : OK\n";
|
||||
exit $ERRORS{"OK"};
|
||||
} else {
|
||||
print "No services ",(defined ($o_noreg)) ? "named \"" : "matching \"", $o_descr, "\" found : CRITICAL\n";
|
||||
exit $ERRORS{"CRITICAL"};
|
||||
}
|
||||
}
|
||||
|
||||
my $result=undef;
|
||||
my $num_int_ok=0;
|
||||
|
||||
$result = (Net::SNMP->VERSION < 4) ?
|
||||
$session->get_request(@oids)
|
||||
: $session->get_request(Varbindlist => \@oids);
|
||||
|
||||
if (!defined($result)) { printf("ERROR: running table : %s.\n", $session->error); $session->close;
|
||||
exit $ERRORS{"UNKNOWN"};
|
||||
}
|
||||
|
||||
$session->close;
|
||||
|
||||
my $output=undef;
|
||||
#Check if service are in active state
|
||||
for (my $i=0; $i< $num_int; $i++) {
|
||||
my $state=$$result{$win_serv_state . "." . $tindex[$i]};
|
||||
verb ("Process $tindex[$i] in state $state");
|
||||
if ($state == 1) {
|
||||
$num_int_ok++
|
||||
} else {
|
||||
$output .= ", " if defined($output);
|
||||
$output .= $descr[$i] . " : " . $win_serv_state_label{$state};
|
||||
}
|
||||
}
|
||||
|
||||
my $force_critical=0;
|
||||
|
||||
# Show the services that are not present
|
||||
# Or all of them with -s option
|
||||
foreach my $List (@o_descrL) {
|
||||
my $test=0;
|
||||
for (my $i=0; $i< $num_int; $i++) {
|
||||
if ( $descr[$i] =~ /$List/i ) { $test++; }
|
||||
}
|
||||
if ($test==0) {
|
||||
$output .= ", " if defined($output);
|
||||
$output .= "\"" . $List . "\" not active";
|
||||
# Force a critical state (could otherwise lead to false OK)
|
||||
$force_critical=1;
|
||||
} elsif ( defined ($o_showall) ) {
|
||||
$output .= ", " if defined($output);
|
||||
$output .= "\"" . $List . "\" active";
|
||||
if ($test != 1) {
|
||||
$output .= "(" .$test . " services)";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (defined ($output) ) {
|
||||
print $output, " : ";
|
||||
} else {
|
||||
print $num_int_ok, " services active (", (defined ($o_noreg)) ? "named \"" : "matching \"", $o_descr, "\") : ";
|
||||
}
|
||||
|
||||
$o_number = $#o_descrL+1 if (!defined($o_number));
|
||||
|
||||
if (($num_int_ok < $o_number)||($force_critical == 1)) {
|
||||
print "CRITICAL\n";
|
||||
exit $ERRORS{"CRITICAL"};
|
||||
} elsif ($num_int_ok > $o_number) {
|
||||
print "WARNING\n";
|
||||
exit $ERRORS{"WARNING"};
|
||||
}
|
||||
print "OK\n";
|
||||
exit $ERRORS{"OK"};
|
||||
|
||||
|
49
centreon-plugins/src/oreon.conf
Normal file
49
centreon-plugins/src/oreon.conf
Normal file
@ -0,0 +1,49 @@
|
||||
[GLOBAL]
|
||||
DIR_OREON=@INSTALL_DIR_OREON@/
|
||||
DIR_TRAFFICMAP=@INSTALL_DIR_OREON@/include/trafficMap/average/
|
||||
DIR_NAGIOS=@INSTALL_DIR_NAGIOS@/
|
||||
DIR_RRDTOOL=@INSTALL_DIR_OREON@/rrd/
|
||||
NAGIOS_LIBEXEC=@NAGIOS_PLUGINS@/
|
||||
NAGIOS_ETC=@NAGIOS_ETC@/
|
||||
|
||||
[NT]
|
||||
CPU=.1.3.6.1.2.1.25.3.3.1.2
|
||||
HD_USED=.1.3.6.1.2.1.25.2.3.1.6
|
||||
HD_NAME=.1.3.6.1.2.1.25.2.3.1.3
|
||||
|
||||
[CISCO]
|
||||
NB_CONNECT=.1.3.6.1.4.1.9.9.147.1.2.2.2.1.5.40.6
|
||||
|
||||
[UNIX]
|
||||
CPU_USER=.1.3.6.1.4.1.2021.11.50.0
|
||||
CPU_SYSTEM=.1.3.6.1.4.1.2021.11.52.0
|
||||
CPU_LOAD_1M =.1.3.6.1.4.1.2021.10.1.3.1
|
||||
CPU_LOAD_5M =.1.3.6.1.4.1.2021.10.1.3.2
|
||||
CPU_LOAD_15M =.1.3.6.1.4.1.2021.10.1.3.3
|
||||
|
||||
[DELL]
|
||||
TEMP=.1.3.6.1.4.1.674.10892.1.700.20.1.6.1
|
||||
|
||||
[ALTEON]
|
||||
VIRT=1.3.6.1.4.1.1872.2.1.8.2.7.1.3.1
|
||||
FRONT=1.3.6.1.4.1.1872.2.1.8.2.5.1.3.1
|
||||
|
||||
[MIB2]
|
||||
SW_RUNNAME=.1.3.6.1.2.1.25.4.2.1.2
|
||||
SW_RUNINDEX=.1.3.6.1.2.1.25.4.2.1.1
|
||||
SW_RUNSTATUS=.1.3.6.1.2.1.25.4.2.1.7
|
||||
HR_STORAGE_DESCR=.1.3.6.1.2.1.25.2.3.1.3
|
||||
HR_STORAGE_ALLOCATION_UNITS=.1.3.6.1.2.1.25.2.3.1.4
|
||||
HR_STORAGE_SIZE=.1.3.6.1.2.1.25.2.3.1.5
|
||||
HR_STORAGE_USED=.1.3.6.1.2.1.25.2.3.1.6
|
||||
OBJECTID=.1.3.6.1.2.1.1.1.0
|
||||
UPTIME_WINDOWS=.1.3.6.1.2.1.1.3.0
|
||||
UPTIME_OTHER=.1.3.6.1.2.1.25.1.1.0
|
||||
IF_IN_OCTET=.1.3.6.1.2.1.2.2.1.10
|
||||
IF_OUT_OCTET=.1.3.6.1.2.1.2.2.1.16
|
||||
IF_SPEED=.1.3.6.1.2.1.2.2.1.5
|
||||
IF_DESC=.1.3.6.1.2.1.2.2.1.2
|
||||
IF_IN_ERROR=.1.3.6.1.2.1.2.2.1.14
|
||||
IF_OUT_ERROR=.1.3.6.1.2.1.2.2.1.20
|
||||
|
||||
|
218
centreon-plugins/src/oreon.pm
Normal file
218
centreon-plugins/src/oreon.pm
Normal file
@ -0,0 +1,218 @@
|
||||
#
|
||||
# $Id: check_graph_ping.pl,v 1.2 2005/07/27 22:21:49 wistof Exp $
|
||||
#
|
||||
# Oreon's plugins are developped with GPL Licence :
|
||||
# http://www.fsf.org/licenses/gpl.txt
|
||||
# Developped by : Mathieu Chateau - Christophe Coraboeuf
|
||||
#
|
||||
# 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.
|
||||
package oreon;
|
||||
|
||||
use Exporter ();
|
||||
use FindBin qw($Bin);
|
||||
use lib "$FindBin::Bin";
|
||||
use lib "@NAGIOS_PLUGINS@";
|
||||
|
||||
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
|
||||
use utils qw($TIMEOUT %ERRORS &print_revision &support);
|
||||
|
||||
if (eval "require Config::IniFiles" ) {
|
||||
use Config::IniFiles;
|
||||
} else {
|
||||
print "Unable to load Config::IniFiles\n";
|
||||
exit $ERRORS{'UNKNOWN'};
|
||||
}
|
||||
|
||||
### RRDTOOL Module
|
||||
use lib qw(@RRDTOOL_PERL_LIB@ ../lib/perl);
|
||||
if (eval "require RRDs" ) {
|
||||
use RRDs;
|
||||
} else {
|
||||
print "Unable to load RRDs perl module\n";
|
||||
exit $ERRORS{'UNKNOWN'};
|
||||
}
|
||||
|
||||
# On défini une version pour les vérifications
|
||||
#$VERSION = do { my @r = (q$Revision: XXX $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
|
||||
|
||||
our @ISA = qw(Exporter);
|
||||
our @EXPORT_OK = qw(get_parameters create_rrd update_rrd fetch_rrd &is_valid_serviceid);
|
||||
our @EXPORT = @EXPORT_OK;
|
||||
|
||||
my $params_file="oreon.conf";
|
||||
my @ds = ("a","b","c","d","e","f","g","h","i","j","k","l");
|
||||
|
||||
###############################################################################
|
||||
# Get all parameters from the ini file
|
||||
###############################################################################
|
||||
sub get_parameters
|
||||
{
|
||||
|
||||
$params_file = "@NAGIOS_PLUGINS@/$params_file";
|
||||
unless (-e $params_file)
|
||||
{
|
||||
print "Unknown - In oreon.pm :: $params_file :: $!\n";
|
||||
exit $ERRORS{'UNKNOWN'};
|
||||
}
|
||||
my %oreon;
|
||||
tie %oreon, 'Config::IniFiles', ( -file => $params_file );
|
||||
return %oreon;
|
||||
}
|
||||
|
||||
|
||||
###############################################################################
|
||||
# Create RRD file
|
||||
###############################################################################
|
||||
sub create_rrd($$$$$$$)
|
||||
{
|
||||
my @rrd_arg;
|
||||
my ($rrd, $nb_ds ,$start, $step, $min, $max, $type) = @_;
|
||||
$nb_ds = 1 unless($nb_ds);
|
||||
$start = time unless($start);
|
||||
$step = 300 unless($step);
|
||||
$min = "U" unless($min);
|
||||
$max = "U" unless($max);
|
||||
$type = "GAUGE" unless($type);
|
||||
|
||||
my $ERROR = RRDs::error;
|
||||
|
||||
@rrd_arg=($rrd,
|
||||
"--start",
|
||||
$start-1,
|
||||
"--step",
|
||||
$step);
|
||||
|
||||
for ($i = 0; $i < $nb_ds; $i++) {
|
||||
push(@rrd_arg,"DS:".$ds[$i].":$type:".($step * 2).":".$min.":".$max);
|
||||
}
|
||||
push(@rrd_arg,"RRA:AVERAGE:0.5:1:8640",
|
||||
"RRA:MIN:0.5:12:8640",
|
||||
"RRA:MAX:0.5:12:8640");
|
||||
RRDs::create (@rrd_arg);
|
||||
$ERROR = RRDs::error;
|
||||
if ($ERROR) {
|
||||
print "unable to create '$rrd' : $ERROR\n" ;
|
||||
exit 3;
|
||||
}
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
# Update RRD file
|
||||
###############################################################################
|
||||
sub update_rrd($$@)
|
||||
{
|
||||
my @rrd_arg;
|
||||
my ($rrd, $start,@values) = @_;
|
||||
$start = time unless($start);
|
||||
|
||||
my $ERROR = RRDs::error;
|
||||
for (@values) {
|
||||
s/,/\./ ;
|
||||
$str_value .= ":" . $_;
|
||||
}
|
||||
RRDs::update ($rrd, "$start$str_value");
|
||||
$ERROR = RRDs::error;
|
||||
if ($ERROR) {
|
||||
print "unable to update '$rrd' : $ERROR\n" ;
|
||||
exit 3;
|
||||
}
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
# Fetch RRD file
|
||||
###############################################################################
|
||||
sub fetch_rrd($$)
|
||||
{
|
||||
my ($line, $val, @valeurs, $update_time, $step, $ds_names, $data, $i) ;
|
||||
my ($rrd, $CF,@values) = @_;
|
||||
$start = time unless($start);
|
||||
|
||||
my $ERROR = RRDs::error;
|
||||
|
||||
($update_time,$step,$ds_names,$data) = RRDs::fetch($rrd, "--resolution=300","--start=now-5min","--end=now",$CF);
|
||||
|
||||
|
||||
$ERROR = RRDs::error;
|
||||
if ($ERROR) {
|
||||
print "unable to update '$rrd' : $ERROR\n" ;
|
||||
exit 3;
|
||||
}
|
||||
foreach $line (@$data) {
|
||||
foreach $val (@$line) {
|
||||
if ( defined $val ) { $valeur[$i]=$val; } else { $valeur[$i]="undef"; }
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
return @valeur;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
###############################################################################
|
||||
# Is a valid ServiceId
|
||||
###############################################################################
|
||||
sub is_valid_serviceid {
|
||||
my $ServiceId = shift;
|
||||
if ($ServiceId && $ServiceId =~ m/^([0-9_]+)$/) {
|
||||
return $ServiceId;
|
||||
}else{
|
||||
print "Unknown -S Service ID expected... or it doesn't exist, try another id - number\n";
|
||||
exit $ERRORS{'UNKNOWN'};
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Oreon - shared module for Oreon plugins
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
use oreon;
|
||||
oreon::get_parameters()
|
||||
oreon::create_rrd( )
|
||||
oreon::update_rrd( )
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
=head2 Functions
|
||||
|
||||
B<oreon::create_rrd> create a rrd database.
|
||||
|
||||
create_rrd($rrd, $nb_ds ,$start, $step, $min, $max, $type );
|
||||
|
||||
$rrd : RRD filename
|
||||
$nb_ds : Number of Data Sources to create
|
||||
$start : Start time of RRD
|
||||
$step : RRD step
|
||||
$min : Minimum value in RRD
|
||||
$max : Maximum value in RRD
|
||||
$type : GAUGE or COUNTER
|
||||
|
||||
update_rrd($rrd, $start,@values);
|
||||
|
||||
$rrd : RRD filename to update
|
||||
$start :
|
||||
@values : update RRD with list values
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
Mathieu Chateau E<lt>mathieu.chateau@lsafrance.comE<gt>
|
||||
Christophe Coraboeuf E<lt>ccoraboeuf@oreon-project.orgE<gt>
|
||||
|
||||
=cut
|
||||
|
||||
|
||||
|
||||
|
10
centreon-plugins/src/process-service-perfdata
Normal file
10
centreon-plugins/src/process-service-perfdata
Normal file
@ -0,0 +1,10 @@
|
||||
# some parameters passed on command line
|
||||
TIMET=$1
|
||||
HOSTNAME=$2
|
||||
SERVICEDESC=$3
|
||||
OUTPUT=$4
|
||||
SERVICESTATE=$5
|
||||
PERFDATA=$6
|
||||
PERFFILE="/var/log/nagios/service-perfdata"
|
||||
|
||||
/usr/bin/printf "%b" "$TIMET\t$HOSTNAME\t$SERVICEDESC\t$OUTPUT\t$SERVICESTATE\t$PERFDATA\n" >> $PERFFILE
|
34
centreon-plugins/src/submit_host_check_result
Normal file
34
centreon-plugins/src/submit_host_check_result
Normal file
@ -0,0 +1,34 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Arguments:
|
||||
# $1 = host_name (Short name of host that the service is
|
||||
# associated with)
|
||||
# $2 = state_string (A string representing the status of
|
||||
# the given service - "UP", "DOWN", "UNREACHABLE"
|
||||
# $3 = plugin_output (A text string that should be used
|
||||
# as the plugin output for the service checks)
|
||||
#
|
||||
|
||||
# pipe the service check info into the send_nsca program, which
|
||||
# in turn transmits the data to the nsca daemon on the central
|
||||
# monitoring server
|
||||
|
||||
|
||||
return_code=-1
|
||||
|
||||
case "$2" in
|
||||
UP)
|
||||
return_code=0
|
||||
;;
|
||||
DOWN)
|
||||
return_code=1
|
||||
;;
|
||||
UNREACHABLE)
|
||||
return_code=2
|
||||
;;
|
||||
esac
|
||||
|
||||
# Test everything works fine
|
||||
#/usr/bin/printf "%s\t%s\t%s\n" "$1" "$2" "$3" >> /tmp/test
|
||||
|
||||
/usr/bin/printf "%s\t%s\t%s\n" "$1" "$return_code" "$3" | /usr/sbin/send_nsca IP -p PORT -c /etc/send_nsca.cfg
|
38
centreon-plugins/src/submit_service_check_result
Normal file
38
centreon-plugins/src/submit_service_check_result
Normal file
@ -0,0 +1,38 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Arguments:
|
||||
# $1 = host_name (Short name of host that the service is
|
||||
# associated with)
|
||||
# $2 = svc_description (Description of the service)
|
||||
# $3 = state_string (A string representing the status of
|
||||
# the given service - "OK", "WARNING", "CRITICAL"
|
||||
# or "UNKNOWN")
|
||||
# $4 = plugin_output (A text string that should be used
|
||||
# as the plugin output for the service checks)
|
||||
#
|
||||
|
||||
# pipe the service check info into the send_nsca program, which
|
||||
# in turn transmits the data to the nsca daemon on the central
|
||||
# monitoring server
|
||||
|
||||
return_code=-1
|
||||
|
||||
case "$3" in
|
||||
OK)
|
||||
return_code=0
|
||||
;;
|
||||
WARNING)
|
||||
return_code=1
|
||||
;;
|
||||
CRITICAL)
|
||||
return_code=2
|
||||
;;
|
||||
UNKNOWN)
|
||||
return_code=-1
|
||||
;;
|
||||
esac
|
||||
|
||||
# Test everything works fine
|
||||
#/usr/bin/printf "%s\t%s\t%s\t%s\n" "$1" "$2" "$3" "$4" >> /tmp/test
|
||||
|
||||
/usr/bin/printf "%s\t%s\t%s\t%s\n" "$1" "$2" "$return_code" "$4" | /usr/sbin/send_nsca IP -p PORT -c /etc/send_nsca.cfg
|
128
centreon-plugins/src/traps/trap_common.pm
Normal file
128
centreon-plugins/src/traps/trap_common.pm
Normal file
@ -0,0 +1,128 @@
|
||||
#
|
||||
# $Id: trap_common.pm,v 1.0 2006/06/30 12:30:00 Nicolas Cordier for Merethis $
|
||||
#
|
||||
# Oreon's plugins are developped with GPL Licence :
|
||||
# http://www.fsf.org/licenses/gpl.txt
|
||||
# Developped by : Nicolas Cordier for Merethis
|
||||
#
|
||||
# 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.
|
||||
|
||||
package trap_common;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use DBI;
|
||||
|
||||
use Exporter();
|
||||
|
||||
our @ISA = qw(Exporter);
|
||||
our @EXPORT_OK = qw(submit_res getTrapsInfos);
|
||||
our @EXPORT = @EXPORT_OK;
|
||||
|
||||
#
|
||||
## configuration for oreon db access
|
||||
#
|
||||
## /!\ you may have to edit this
|
||||
#
|
||||
sub set_db
|
||||
{
|
||||
## part that should be modified
|
||||
my $db_name = "oreondb"; ## name of your database for oreon
|
||||
my $login = "root"; ## user of your database
|
||||
my $mdp = ""; ## password for this user
|
||||
## end of part that should be modified
|
||||
|
||||
my $dsn = "dbi:mysql:$db_name";
|
||||
return $dsn, $login, $mdp;
|
||||
}
|
||||
|
||||
#
|
||||
## send result to nagios using nagios.cmd
|
||||
#
|
||||
## /!\ you may have to edit this
|
||||
#
|
||||
sub submit_res($)
|
||||
{
|
||||
## part that should be modified
|
||||
open(FILE, ">>/var/run/nagios/nagios.cmd") or die ("Can't open"); ## modify this for your nagios.cmd location
|
||||
## end of part that should be modified
|
||||
print FILE $_[0];
|
||||
close(FILE);
|
||||
}
|
||||
|
||||
#
|
||||
## remove useless things to get a good ip
|
||||
#
|
||||
sub epur_ip($)
|
||||
{
|
||||
(my $ip) = split(/:/, $_[0]);
|
||||
$ip = substr($ip, 1, -1);
|
||||
|
||||
return $ip;
|
||||
}
|
||||
|
||||
#
|
||||
## retrieve hostname and hostid from db using the ip
|
||||
#
|
||||
sub get_hostinfos($$)
|
||||
{
|
||||
my $requete = "SELECT host_name, host_id FROM host WHERE host_address='$_[1]' ";
|
||||
my $sth = $_[0]->prepare($requete);
|
||||
$sth->execute();
|
||||
my @host = $sth -> fetchrow_array;
|
||||
$sth -> finish;
|
||||
return @host;
|
||||
}
|
||||
|
||||
#
|
||||
## retrieve servicedescription from db using the ip and host_id
|
||||
#
|
||||
sub get_servicename($$$)
|
||||
{
|
||||
my $requete = "SELECT service_description FROM service WHERE service_id IN";
|
||||
$requete .= " (SELECT service_id FROM traps_service_relation WHERE traps_id='$_[1]')";
|
||||
$requete .= " AND service_id IN";
|
||||
$requete .= " (SELECT service_service_id FROM host_service_relation WHERE host_host_id='$_[2]')";
|
||||
my $sth = $_[0]->prepare($requete);
|
||||
if ($sth->execute() == 0)
|
||||
{
|
||||
$sth -> finish;
|
||||
$requete = "SELECT service_description FROM service WHERE service_id IN";
|
||||
$requete .= " (SELECT service_id FROM traps_service_relation WHERE traps_id='$_[1]')";
|
||||
$requete .= " AND service_id IN";
|
||||
$requete .= " (SELECT service_service_id FROM host_service_relation WHERE hostgroup_hg_id IN";
|
||||
$requete .= " (SELECT hostgroup_hg_id FROM hostgroup_relation WHERE host_host_id='$_[2]')";
|
||||
$requete .= ")";
|
||||
$sth = $_[0]->prepare($requete);
|
||||
$sth->execute();
|
||||
}
|
||||
my $service = $sth -> fetchrow_array;
|
||||
$sth -> finish;
|
||||
return $service;
|
||||
}
|
||||
|
||||
#
|
||||
## return informations about the trap for the generation of the result sent to nagios
|
||||
#
|
||||
sub getTrapsInfos(@)
|
||||
{
|
||||
shift;
|
||||
my $ip = epur_ip($_[0]);
|
||||
shift;
|
||||
my $trap_id = $_[0];
|
||||
shift;
|
||||
|
||||
my @db = set_db();
|
||||
my $dbh = DBI->connect($db[0], $db[1], $db[2]) or die "Echec de la connexion\n";
|
||||
my @host = get_hostinfos($dbh, $ip);
|
||||
my $servicename = get_servicename($dbh, $trap_id, $host[1]);
|
||||
$dbh -> disconnect;
|
||||
return $host[0], $servicename, @_;
|
||||
}
|
37
centreon-plugins/src/traps/trap_handler.sh
Normal file
37
centreon-plugins/src/traps/trap_handler.sh
Normal file
@ -0,0 +1,37 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# $Id: trap_handler.sh,v 1.0 2006/06/30 12:30:00 Nicolas Cordier for Merethis $
|
||||
#
|
||||
# Oreon's plugins are developped with GPL Licence :
|
||||
# http://www.fsf.org/licenses/gpl.txt
|
||||
# Developped by : Nicolas Cordier for Merethis
|
||||
#
|
||||
# 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.
|
||||
|
||||
read host
|
||||
read ip
|
||||
vars=""
|
||||
|
||||
while read oid val
|
||||
do
|
||||
vars="$vars, $oid = $val"
|
||||
done
|
||||
|
||||
exec=$1
|
||||
shift
|
||||
while [ "$1" != "" ]
|
||||
do
|
||||
args="$args $1"
|
||||
shift
|
||||
done
|
||||
|
||||
args="$ip $args $vars"
|
||||
|
||||
$exec $args
|
61
centreon-plugins/src/traps/trap_link.pl
Normal file
61
centreon-plugins/src/traps/trap_link.pl
Normal file
@ -0,0 +1,61 @@
|
||||
#!/usr/bin/perl -w
|
||||
#
|
||||
# $Id: trap_link.pl,v 1.0 2006/06/30 12:30:00 Nicolas Cordier for Merethis $
|
||||
#
|
||||
# Oreon's plugins are developped with GPL Licence :
|
||||
# http://www.fsf.org/licenses/gpl.txt
|
||||
# Developped by : Nicolas Cordier for Merethis
|
||||
#
|
||||
# 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.
|
||||
|
||||
#
|
||||
## to use the common.pm including usefull functions
|
||||
#
|
||||
use DBI;
|
||||
use lib '/usr/lib/nagios/plugins/traps';
|
||||
use trap_common;
|
||||
|
||||
#
|
||||
## get informations about the trap for the generation of the result sent to nagios
|
||||
#
|
||||
(my $hostname, my $servicename, my @args) = getTrapsInfos(@ARGV);
|
||||
|
||||
#
|
||||
## set state for the resul (OK (0)/WARNING (1)/CRITICAL (2)/UNKNOWN (3))
|
||||
#
|
||||
my $state = ($args[0] eq "up" ? 0 : 2);
|
||||
|
||||
#
|
||||
## set the text output of the service check
|
||||
#
|
||||
my $plugin = "";
|
||||
$plugin .= $args[0];
|
||||
|
||||
# parse trap to obtain more information
|
||||
my $i = 0;
|
||||
while ($args[$i])
|
||||
{
|
||||
submit_res("$args[$i]\n");
|
||||
if ("$args[$i]" eq "IF-MIB::ifDescr")
|
||||
{
|
||||
$plugin .= " on $args[$i + 2]";
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
|
||||
#
|
||||
## set the result
|
||||
#
|
||||
$res = "[".time."] PROCESS_SERVICE_CHECK_RESULT;".$hostname.";".$servicename.";".$state.";".$plugin."\n";
|
||||
|
||||
#
|
||||
## send the result
|
||||
#
|
||||
submit_res($res);
|
Loading…
x
Reference in New Issue
Block a user