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 DBI;
|
||||||
use vars qw($PROGNAME);
|
use vars qw($PROGNAME);
|
||||||
use Getopt::Long;
|
use Getopt::Long;
|
||||||
use vars qw($opt_V $opt_H $opt_h $opt_i);
|
use vars qw($opt_V $opt_d $opt_H $opt_h $opt_i);
|
||||||
use lib "@NAGIOS_PLUGINS@";
|
use lib "/srv/nagios/libexec";
|
||||||
use utils qw($TIMEOUT %ERRORS &print_revision &support);
|
use utils qw($TIMEOUT %ERRORS &print_revision &support);
|
||||||
|
|
||||||
## For Debug mode = 1
|
## For Debug mode = 1
|
||||||
|
@ -38,23 +38,9 @@ sub print_usage ();
|
||||||
Getopt::Long::Configure('bundling');
|
Getopt::Long::Configure('bundling');
|
||||||
GetOptions
|
GetOptions
|
||||||
("h" => \$opt_h,
|
("h" => \$opt_h,
|
||||||
"help" => \$opt_h,
|
|
||||||
"V" => \$opt_V,
|
"V" => \$opt_V,
|
||||||
"H" => \$opt_H,
|
|
||||||
"i=s" => \$opt_i);
|
"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) {
|
if ($opt_V) {
|
||||||
print_revision($PROGNAME,'$Revision: 0.1 $');
|
print_revision($PROGNAME,'$Revision: 0.1 $');
|
||||||
exit $ERRORS{'OK'};
|
exit $ERRORS{'OK'};
|
||||||
|
@ -65,6 +51,17 @@ if ($opt_h) {
|
||||||
exit $ERRORS{'OK'};
|
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 $result;
|
||||||
my $warning;
|
my $warning;
|
||||||
my $critical;
|
my $critical;
|
||||||
|
@ -73,31 +70,61 @@ my $metric_id;
|
||||||
sub return_value($$$){
|
sub return_value($$$){
|
||||||
|
|
||||||
#print "warning : ".$warning."-Critical : ".$critical.":$result\b";
|
#print "warning : ".$warning."-Critical : ".$critical.":$result\b";
|
||||||
|
if ($opt_d) {
|
||||||
|
$opt_d =~ s/\%d/$result/g;
|
||||||
|
}
|
||||||
if ($warning ne $critical){
|
if ($warning ne $critical){
|
||||||
if ($warning < $critical){ # Bon sens
|
if ($warning < $critical){ # Bon sens
|
||||||
if ($result < $warning){
|
if ($result < $warning){
|
||||||
print "OK result : " . $result . "|OMS=" . $result . ";".$warning.";".$critical."\n";
|
if ($opt_d) {
|
||||||
|
print "$opt_d|OMS=" . $result . ";".$warning.";".$critical."\n";
|
||||||
|
}else {
|
||||||
|
print "OK result : " . $result . "|OMS=" . $result . ";".$warning.";".$critical."\n";
|
||||||
|
}
|
||||||
exit $ERRORS{'OK'};
|
exit $ERRORS{'OK'};
|
||||||
} elsif (($result >= $warning) && ($result < $critical)){
|
} elsif (($result >= $warning) && ($result < $critical)){
|
||||||
print "WARNING result : " . $result . "|OMS=" . $result . ";".$warning.";".$critical."\n";
|
if ($opt_d) {
|
||||||
|
print "$opt_d|OMS=" . $result . ";".$warning.";".$critical."\n";
|
||||||
|
}else {
|
||||||
|
print "WARNING result : " . $result . "|OMS=" . $result . ";".$warning.";".$critical."\n";
|
||||||
|
}
|
||||||
exit $ERRORS{'WARNING'};
|
exit $ERRORS{'WARNING'};
|
||||||
} elsif ($result >= $critical){
|
} elsif ($result >= $critical){
|
||||||
print "CRITICAL result : " . $result . "|OMS=" . $result . ";".$warning.";".$critical."\n";
|
if ($opt_d) {
|
||||||
|
print "$opt_d|OMS=" . $result . ";".$warning.";".$critical."\n";
|
||||||
|
}else {
|
||||||
|
print "CRITICAL result : " . $result . "|OMS=" . $result . ";".$warning.";".$critical."\n";
|
||||||
|
}
|
||||||
exit $ERRORS{'CRITICAL'};
|
exit $ERRORS{'CRITICAL'};
|
||||||
}
|
}
|
||||||
} else { # sens inverse
|
} else { # sens inverse
|
||||||
if ($result < $critical){
|
if ($result < $critical){
|
||||||
print "CRITICAL result : " . $result . "|OMS=" . $result . ";".$warning.";".$critical."\n";
|
if ($opt_d) {
|
||||||
|
print "$opt_d|OMS=" . $result . ";".$warning.";".$critical."\n";
|
||||||
|
}else {
|
||||||
|
print "CRITICAL result : " . $result . "|OMS=" . $result . ";".$warning.";".$critical."\n";
|
||||||
|
}
|
||||||
exit $ERRORS{'CRITICAL'};
|
exit $ERRORS{'CRITICAL'};
|
||||||
} elsif ($result >= $critical && $result < $warning){
|
} elsif ($result >= $critical && $result < $warning){
|
||||||
print "WARNING result : " . $result . "|OMS=" . $result . ";".$warning.";".$critical."\n";
|
if ($opt_d) {
|
||||||
|
print "$opt_d|OMS=" . $result . ";".$warning.";".$critical."\n";
|
||||||
|
}else {
|
||||||
|
print "WARNING result : " . $result . "|OMS=" . $result . ";".$warning.";".$critical."\n";
|
||||||
|
}
|
||||||
exit $ERRORS{'WARNING'};
|
exit $ERRORS{'WARNING'};
|
||||||
} elsif ($result >= $warning){
|
} elsif ($result >= $warning){
|
||||||
print "OK result : " . $result . "|OMS=" . $result . ";".$warning.";".$critical."\n";
|
if ($opt_d) {
|
||||||
|
print "$opt_d|OMS=" . $result . ";".$warning.";".$critical."\n";
|
||||||
|
}else {
|
||||||
|
print "OK result : " . $result . "|OMS=" . $result . ";".$warning.";".$critical."\n";
|
||||||
|
}
|
||||||
exit $ERRORS{'OK'};
|
exit $ERRORS{'OK'};
|
||||||
} else{
|
} else{
|
||||||
print "OK result : " . $result . "|OMS=" . $result . ";".$warning.";".$critical."\n";
|
if ($opt_d) {
|
||||||
|
print "$opt_d|OMS=" . $result . ";".$warning.";".$critical."\n";
|
||||||
|
}else {
|
||||||
|
print "OK result : " . $result . "|OMS=" . $result . ";".$warning.";".$critical."\n";
|
||||||
|
}
|
||||||
exit $ERRORS{'OK'};
|
exit $ERRORS{'OK'};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -204,94 +231,92 @@ my $svc_relation2;
|
||||||
|
|
||||||
if ($opt_i){
|
if ($opt_i){
|
||||||
my $str;
|
my $str;
|
||||||
|
|
||||||
# get osl info
|
# 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";}
|
if (!$sth->execute) {die "Error:" . $sth->errstr . "\n";}
|
||||||
$ref = $sth->fetchrow_hashref();
|
$ref = $sth->fetchrow_hashref();
|
||||||
if (!defined($ref->{'calcul_type'})){
|
if (!defined($ref->{'calcul_type'})){
|
||||||
print "Unvalidate Meta Service\n";
|
print "Unvalidate Meta Service\n";
|
||||||
exit $ERRORS{'CRITICAL'};
|
exit $ERRORS{'CRITICAL'};
|
||||||
}
|
}
|
||||||
|
|
||||||
$warning = $ref->{'warning'};
|
$warning = $ref->{'warning'};
|
||||||
$critical = $ref->{'critical'};
|
$critical = $ref->{'critical'};
|
||||||
|
$opt_d = $ref->{'meta_display'};
|
||||||
|
|
||||||
# Get Service List by regexp
|
# Get Service List by regexp
|
||||||
if ($ref->{'meta_select_mode'} eq '2'){
|
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'";
|
$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";}
|
if ($debug) {print $str . "\n";}
|
||||||
$sth = $dbh->prepare($str);
|
$sth = $dbh->prepare($str);
|
||||||
if (!$sth->execute) {die "Error:" . $sth->errstr . "\n";}
|
if (!$sth->execute) {die "Error:" . $sth->errstr . "\n";}
|
||||||
while ($svc = $sth->fetchrow_hashref()){
|
while ($svc = $sth->fetchrow_hashref()){
|
||||||
my $sth2 = $dbh->prepare("SELECT * FROM host_service_relation WHERE service_service_id = '".$svc->{'service_id'}."'");
|
my $sth2 = $dbh->prepare("SELECT * FROM host_service_relation WHERE service_service_id = '".$svc->{'service_id'}."'");
|
||||||
if (!$sth2->execute) {die "Error:" . $sth2->errstr . "\n";}
|
if (!$sth2->execute) {die "Error:" . $sth2->errstr . "\n";}
|
||||||
my $svc_relation = $sth2->fetchrow_hashref();
|
my $svc_relation = $sth2->fetchrow_hashref();
|
||||||
if (defined($svc_relation->{'host_host_id'}) && $svc_relation->{'host_host_id'}){
|
if (defined($svc_relation->{'host_host_id'}) && $svc_relation->{'host_host_id'}){
|
||||||
#### Par Host
|
#### Par Host
|
||||||
if (defined($svc->{'service_id'})){$svc_id = $svc->{'service_id'};} else {$svc_id = $svc->{'svc_id'};}
|
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'};}
|
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);
|
$value = get_value_in_database_by_host($dbh,$dbh2,$svc_id,$metric,$debug);
|
||||||
if ($ref->{'calcul_type'} =~ "AVE"){
|
if ($ref->{'calcul_type'} =~ "AVE"){
|
||||||
if (defined($value) && $value){$total += $value;}
|
if (defined($value) && $value){$total += $value;}
|
||||||
if ($debug) {print "total = " . $total . " value = ".$value."\n";}
|
if ($debug) {print "total = " . $total . " value = ".$value."\n";}
|
||||||
$cpt++;
|
$cpt++;
|
||||||
$result = $total / $cpt;
|
$result = $total / $cpt;
|
||||||
} elsif ($ref->{'calcul_type'} =~ "SOM"){
|
} elsif ($ref->{'calcul_type'} =~ "SOM"){
|
||||||
if ($value){$total += $value;}
|
if ($value){$total += $value;}
|
||||||
if ($debug){print "total = " . $total . " value = ".$value."\n";}
|
if ($debug){print "total = " . $total . " value = ".$value."\n";}
|
||||||
$result = $total;
|
$result = $total;
|
||||||
} elsif ($ref->{'calcul_type'} =~ "MIN"){
|
} elsif ($ref->{'calcul_type'} =~ "MIN"){
|
||||||
if ($debug){print " min : " . $min . " value = ".$value."\n";}
|
if ($debug){print " min : " . $min . " value = ".$value."\n";}
|
||||||
if ($value && $value <= $min){$min = $value;}
|
if ($value && $value <= $min){$min = $value;}
|
||||||
$result = $min;
|
$result = $min;
|
||||||
} elsif ($ref->{'calcul_type'} =~ "MAX"){
|
} elsif ($ref->{'calcul_type'} =~ "MAX"){
|
||||||
if ($debug){print "max = " . $max . " value = ".$value."\n";}
|
if ($debug){print "max = " . $max . " value = ".$value."\n";}
|
||||||
if ($value && $value >= $max){$max = $value;}
|
if ($value && $value >= $max){$max = $value;}
|
||||||
$result = $max;
|
$result = $max;
|
||||||
}
|
}
|
||||||
} elsif (defined($svc_relation->{'hostgroup_hg_id'}) && $svc_relation->{'hostgroup_hg_id'}) {
|
} elsif (defined($svc_relation->{'hostgroup_hg_id'}) && $svc_relation->{'hostgroup_hg_id'}) {
|
||||||
### Par Hostgroup
|
### Par Hostgroup
|
||||||
my $sth3 = $dbh->prepare("SELECT host_host_id FROM hostgroup_relation WHERE hostgroup_hg_id = '".$svc_relation->{'hostgroup_hg_id'}."'");
|
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";}
|
if (!$sth3->execute) {die "Error:" . $sth3->errstr . "\n";}
|
||||||
while ($svc_relation2 = $sth3->fetchrow_hashref()){
|
while ($svc_relation2 = $sth3->fetchrow_hashref()){
|
||||||
if (defined($svc->{'service_id'})){
|
if (defined($svc->{'service_id'})){
|
||||||
$svc_id = $svc->{'service_id'};
|
$svc_id = $svc->{'service_id'};
|
||||||
} else {
|
} else {
|
||||||
$svc_id = $svc->{'svc_id'};
|
$svc_id = $svc->{'svc_id'};
|
||||||
}
|
}
|
||||||
if (defined($ref->{'regexp_str'})){
|
if (defined($ref->{'regexp_str'})){
|
||||||
$metric = $ref->{'metric'};
|
$metric = $ref->{'metric'};
|
||||||
} else {
|
} else {
|
||||||
$metric = $svc->{'metric'};
|
$metric = $svc->{'metric'};
|
||||||
}
|
}
|
||||||
$host_id = $svc_relation2->{'host_host_id'};
|
$host_id = $svc_relation2->{'host_host_id'};
|
||||||
$value = get_value_in_database_by_hg($dbh,$dbh2,$svc_id, $host_id, $metric, $debug);
|
$value = get_value_in_database_by_hg($dbh,$dbh2,$svc_id, $host_id, $metric, $debug);
|
||||||
if ($ref->{'calcul_type'} =~ "AVE"){
|
if ($ref->{'calcul_type'} =~ "AVE"){
|
||||||
if (defined($value) && $value){
|
if (defined($value) && $value){
|
||||||
$total += $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 ($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"){
|
if ($ref->{'calcul_type'} =~ "AVE"){
|
||||||
$result = $total / $cpt;
|
$result = $total / $cpt;
|
||||||
|
@ -316,6 +341,10 @@ if ($opt_i){
|
||||||
if (defined($value) && $value){$total += $value;}
|
if (defined($value) && $value){$total += $value;}
|
||||||
$cpt++;
|
$cpt++;
|
||||||
}
|
}
|
||||||
|
if (!$sth->rows) {
|
||||||
|
print "no result in table meta_service_relation for id $opt_i\n";
|
||||||
|
exit $ERRORS{'UNKNOWN'};
|
||||||
|
}
|
||||||
$result = $total / $cpt;
|
$result = $total / $cpt;
|
||||||
} elsif ($ref->{'calcul_type'} =~ "SOM"){
|
} elsif ($ref->{'calcul_type'} =~ "SOM"){
|
||||||
while ($svc = $sth->fetchrow_hashref()){
|
while ($svc = $sth->fetchrow_hashref()){
|
||||||
|
@ -341,7 +370,7 @@ if ($opt_i){
|
||||||
if ($value && $value >= $max){$max = $value;}
|
if ($value && $value >= $max){$max = $value;}
|
||||||
}
|
}
|
||||||
$result = $max;
|
$result = $max;
|
||||||
}
|
}
|
||||||
return_value($result, $warning, $critical);
|
return_value($result, $warning, $critical);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -349,8 +378,7 @@ if ($opt_i){
|
||||||
|
|
||||||
sub print_usage () {
|
sub print_usage () {
|
||||||
print "Usage:\n";
|
print "Usage:\n";
|
||||||
print " check_osl.pl\n";
|
print " check_meta_service.pl\n";
|
||||||
print " -H Hostname to query (Required)\n";
|
|
||||||
print " -i OSL id\n";
|
print " -i OSL id\n";
|
||||||
print " -V (--version) Plugin version\n";
|
print " -V (--version) Plugin version\n";
|
||||||
print " -h (--help) usage help\n";
|
print " -h (--help) usage help\n";
|
||||||
|
|
Loading…
Reference in New Issue