new option -d
git-svn-id: http://svn.centreon.com/Plugins/Dev@1720 6bcd3966-0018-0410-8128-fd23d134de7e
This commit is contained in:
parent
06638158f5
commit
22e7f809b9
|
@ -25,8 +25,8 @@ 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 vars qw($opt_V $opt_d $opt_H $opt_h $opt_i);
|
||||
use lib "/srv/nagios/libexec";
|
||||
use utils qw($TIMEOUT %ERRORS &print_revision &support);
|
||||
|
||||
## For Debug mode = 1
|
||||
|
@ -38,23 +38,9 @@ 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'};
|
||||
|
@ -65,6 +51,17 @@ if ($opt_h) {
|
|||
exit $ERRORS{'OK'};
|
||||
}
|
||||
|
||||
my $dbh = DBI->connect("DBI:mysql:database=oreon;host=localhost",
|
||||
"oreon", "oreon-pwd",
|
||||
{'RaiseError' => 1});
|
||||
|
||||
my $sth1 = $dbh->prepare("SELECT * FROM `cfg_perfparse`");
|
||||
if (!$sth1->execute) {die "Error: cannot prepare query\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});
|
||||
|
||||
my $result;
|
||||
my $warning;
|
||||
my $critical;
|
||||
|
@ -73,31 +70,61 @@ my $metric_id;
|
|||
sub return_value($$$){
|
||||
|
||||
#print "warning : ".$warning."-Critical : ".$critical.":$result\b";
|
||||
|
||||
if ($opt_d) {
|
||||
$opt_d =~ s/\%d/$result/g;
|
||||
}
|
||||
if ($warning ne $critical){
|
||||
if ($warning < $critical){ # Bon sens
|
||||
if ($result < $warning){
|
||||
if ($opt_d) {
|
||||
print "$opt_d|OMS=" . $result . ";".$warning.";".$critical."\n";
|
||||
}else {
|
||||
print "OK result : " . $result . "|OMS=" . $result . ";".$warning.";".$critical."\n";
|
||||
}
|
||||
exit $ERRORS{'OK'};
|
||||
} elsif (($result >= $warning) && ($result < $critical)){
|
||||
if ($opt_d) {
|
||||
print "$opt_d|OMS=" . $result . ";".$warning.";".$critical."\n";
|
||||
}else {
|
||||
print "WARNING result : " . $result . "|OMS=" . $result . ";".$warning.";".$critical."\n";
|
||||
}
|
||||
exit $ERRORS{'WARNING'};
|
||||
} elsif ($result >= $critical){
|
||||
if ($opt_d) {
|
||||
print "$opt_d|OMS=" . $result . ";".$warning.";".$critical."\n";
|
||||
}else {
|
||||
print "CRITICAL result : " . $result . "|OMS=" . $result . ";".$warning.";".$critical."\n";
|
||||
}
|
||||
exit $ERRORS{'CRITICAL'};
|
||||
}
|
||||
} else { # sens inverse
|
||||
if ($result < $critical){
|
||||
if ($opt_d) {
|
||||
print "$opt_d|OMS=" . $result . ";".$warning.";".$critical."\n";
|
||||
}else {
|
||||
print "CRITICAL result : " . $result . "|OMS=" . $result . ";".$warning.";".$critical."\n";
|
||||
}
|
||||
exit $ERRORS{'CRITICAL'};
|
||||
} elsif ($result >= $critical && $result < $warning){
|
||||
if ($opt_d) {
|
||||
print "$opt_d|OMS=" . $result . ";".$warning.";".$critical."\n";
|
||||
}else {
|
||||
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'};
|
||||
if ($opt_d) {
|
||||
print "$opt_d|OMS=" . $result . ";".$warning.";".$critical."\n";
|
||||
}else {
|
||||
print "OK result : " . $result . "|OMS=" . $result . ";".$warning.";".$critical."\n";
|
||||
}
|
||||
exit $ERRORS{'OK'};
|
||||
} else{
|
||||
if ($opt_d) {
|
||||
print "$opt_d|OMS=" . $result . ";".$warning.";".$critical."\n";
|
||||
}else {
|
||||
print "OK result : " . $result . "|OMS=" . $result . ";".$warning.";".$critical."\n";
|
||||
}
|
||||
exit $ERRORS{'OK'};
|
||||
}
|
||||
}
|
||||
|
@ -204,9 +231,8 @@ 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."'");
|
||||
my $sth = $dbh->prepare("SELECT meta_display,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'})){
|
||||
|
@ -216,12 +242,11 @@ if ($opt_i){
|
|||
|
||||
$warning = $ref->{'warning'};
|
||||
$critical = $ref->{'critical'};
|
||||
$opt_d = $ref->{'meta_display'};
|
||||
|
||||
# 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);
|
||||
|
@ -316,6 +341,10 @@ if ($opt_i){
|
|||
if (defined($value) && $value){$total += $value;}
|
||||
$cpt++;
|
||||
}
|
||||
if (!$sth->rows) {
|
||||
print "no result in table meta_service_relation for id $opt_i\n";
|
||||
exit $ERRORS{'UNKNOWN'};
|
||||
}
|
||||
$result = $total / $cpt;
|
||||
} elsif ($ref->{'calcul_type'} =~ "SOM"){
|
||||
while ($svc = $sth->fetchrow_hashref()){
|
||||
|
@ -349,8 +378,7 @@ if ($opt_i){
|
|||
|
||||
sub print_usage () {
|
||||
print "Usage:\n";
|
||||
print " check_osl.pl\n";
|
||||
print " -H Hostname to query (Required)\n";
|
||||
print " check_meta_service.pl\n";
|
||||
print " -i OSL id\n";
|
||||
print " -V (--version) Plugin version\n";
|
||||
print " -h (--help) usage help\n";
|
||||
|
|
Loading…
Reference in New Issue