From d079b3916cbcd628a49e75b2c5dbad5355107fb9 Mon Sep 17 00:00:00 2001 From: Mat Sugumaran Date: Tue, 22 May 2007 16:25:34 +0000 Subject: [PATCH] git-svn-id: http://svn.centreon.com/Plugins/Dev@2352 6bcd3966-0018-0410-8128-fd23d134de7e --- src/check_meta_service.pl | 390 -------------------------------------- 1 file changed, 390 deletions(-) delete mode 100644 src/check_meta_service.pl diff --git a/src/check_meta_service.pl b/src/check_meta_service.pl deleted file mode 100644 index fefb9d9ba..000000000 --- a/src/check_meta_service.pl +++ /dev/null @@ -1,390 +0,0 @@ -#! /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_d $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, - "V" => \$opt_V, - "i=s" => \$opt_i); - -if ($opt_V) { - print_revision($PROGNAME,'$Revision: 0.1 $'); - exit $ERRORS{'OK'}; -} - -if ($opt_h) { - print_help(); - exit $ERRORS{'OK'}; -} - -require("@OREON_PATH@/ODS/etc/conf.pm"); - -my $dbh = DBI->connect("DBI:mysql:database=oreon;host=localhost","oreon", "oreon-pwd",{'RaiseError' => 1}); -my $dbh2 = DBI->connect("DBI:mysql:database=oreon;host=localhost","ods", "oreon-pwd",{'RaiseError' => 1}); - -my $result; -my $warning; -my $critical; -my $metric_id; - -sub return_value($$$){ - - 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){ - 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'}; - } - } - } 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 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'})){ - print "Unvalidate Meta Service\n"; - exit $ERRORS{'CRITICAL'}; - } - - $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); - 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++; - } - 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()){ - 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_meta_service.pl\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"; -}