git-svn-id: http://svn.centreon.com/trunk/plugins-2.x@9353 6bcd3966-0018-0410-8128-fd23d134de7e
This commit is contained in:
Julien Mathis 2009-11-12 19:07:30 +00:00
parent 19df12614a
commit 57813d469c
5 changed files with 4 additions and 409 deletions

View File

@ -209,9 +209,6 @@ Notes on warning and critical :
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
@ -249,12 +246,7 @@ sub check_options {
#### 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
);
'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
@ -458,8 +450,6 @@ for (my $i=0; $i< $num_int; $i++) {
$session->close;
#$rrd_data[0] = $num_int_ok;
my $final_status=0;
my ($res_memory,$res_cpu)=(0,0);
my $memory_print="";
@ -494,9 +484,6 @@ if (defined ($o_mem) ) {
$res_memory = $res_memory * 1024 * 1024;
$metrics .= " Ramused=".$res_memory."o";
}
#push @rrd_data, $res_memory;
}
######## Checks CPU usage
@ -562,7 +549,6 @@ if (defined ($o_cpu) ) {
$cpu_print.=", Cpu : ".sprintf("%.0f",$found_value)."% OK";
$metrics .= " CpuUsed=$found_value";
}
#push @rrd_data, $found_value;
} else {
if ($final_status==0) { $final_status=3 };
$cpu_print.=", No data for CPU (".$n_rows." line(s)):UNKNOWN";
@ -571,20 +557,6 @@ if (defined ($o_cpu) ) {
}
##
## 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

View File

@ -1,363 +0,0 @@
#! /usr/bin/perl -w
################################################################################
# Copyright 2005-2009 MERETHIS
# Centreon is developped by : Julien Mathis and Romain Le Merlus under
# GPL Licence 2.0.
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation ; either version 2 of the License.
#
# This program is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, see <http://www.gnu.org/licenses>.
#
# Linking this program statically or dynamically with other modules is making a
# combined work based on this program. Thus, the terms and conditions of the GNU
# General Public License cover the whole combination.
#
# As a special exception, the copyright holders of this program give MERETHIS
# permission to link this program with independent modules to produce an executable,
# regardless of the license terms of these independent modules, and to copy and
# distribute the resulting executable under terms of MERETHIS choice, provided that
# MERETHIS also meet, for each linked independent module, the terms and conditions
# of the license of that module. An independent module is a module which is not
# derived from this program. If you modify this program, you may extend this
# exception to your version of the program, but you are not obliged to do so. If you
# do not wish to do so, delete this exception statement from your version.
#
# For more information : contact@centreon.com
#
# SVN : $URL$
# SVN : $Id$
#
####################################################################################
#
# 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 centreon" ) {
use centreon qw(get_parameters create_rrd update_rrd &is_valid_serviceid);
use vars qw($VERSION %centreon);
%centreon=get_parameters();
} else {
print "Unable to load centreon 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 = $centreon{GLOBAL}{NAGIOS_PLUGINS}."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 = $0;
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 `;
my $return = $_;
if (!defined($return) || $return eq "") {
print "Error in command, check your command options\n";
exit (3);
}
$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] =~ s/\,/\./g;
$test[3] = eval($test[3] * 1024 * 1024 * 1024);
$test[7] =~ s/\,/\./g;
$test[7] = eval ($test[7] * 1024 * 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] =~ s/\,/\./g;
$test4[1] = eval($test4[1] * 1024 * 1024);
$test[6] =~ s/\,/\./g;
$test[6] = eval($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 = "Unknown";
}
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 ."---\n";
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 "##############################################\n";
print "# Copyright (c) 2004-2007 Centreon #\n";
print "# Bugs to http://bugs.oreon-project.org/ #\n";
print "##############################################\n";
print_usage();
print "\n";
}

View File

@ -26,7 +26,7 @@ use utils qw(%ERRORS $TIMEOUT);
# Oreon specific
if (eval "require centreon" ) {
use centreon qw(get_parameters create_rrd update_rrd &is_valid_serviceid);
use centreon qw(get_parameters &is_valid_serviceid);
use vars qw($VERSION %centreon);
%centreon=get_parameters();
} else {
@ -249,7 +249,6 @@ sub check_options {
check_options();
$rrd = $pathtorrdbase.$ServiceId.".rrd";
$start=time;
# Check gobal timeout if snmp screws up
@ -391,18 +390,6 @@ if (defined ($o_fw)) {
}
}
$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";

View File

@ -28,7 +28,7 @@ use lib "@NAGIOS_PLUGINS@";
use utils qw($TIMEOUT %ERRORS &print_revision &support);
if (eval "require centreon" ) {
use centreon qw(get_parameters create_rrd update_rrd &is_valid_serviceid);
use centreon qw(get_parameters &is_valid_serviceid);
use vars qw($VERSION %centreon);
%centreon=get_parameters();
} else {
@ -122,7 +122,6 @@ if ($opt_n) {
}
}
if ($scriptname eq "") {
print "No such process, verify your snmpd configuration\n";
exit(3);

View File

@ -28,7 +28,7 @@ use lib "@NAGIOS_PLUGINS@";
use utils qw($TIMEOUT %ERRORS &print_revision &support);
if (eval "require centreon" ) {
use centreon qw(get_parameters create_rrd update_rrd &is_valid_serviceid);
use centreon qw(get_parameters &is_valid_serviceid);
use vars qw($VERSION %centreon);
%centreon=get_parameters();
} else {