Commit d0142cdf authored by Julien Mathis's avatar Julien Mathis
Browse files

remove ndo backend

parent bde4a6cf
......@@ -31,9 +31,6 @@
#
# For more information : contact@centreon.com
#
# SVN : $URL$
# SVN : $Id$
#
####################################################################################
use strict;
......@@ -46,8 +43,8 @@ use vars qw($centreon_config);
########################################
my $PROGNAME = $0;
my $VERSION = "2.5";
my $MODIF_DATE = "07-22-2013";
my $VERSION = "2.7";
my $MODIF_DATE = "12-23-2015";
my %ERRORS = ( "OK" => 0, "WARNING" => 1, "CRITICAL" => 2, "UNKNOWN" => 3);
my %DSTYPE = ( "0" => "g", "1" => "c", "2" => "d", "3" => "a");
......@@ -61,24 +58,6 @@ my $ndo_prefix;
my $db_broker;
my $DBRESULT;
sub get_db_layer();
my $db_layer = get_db_layer();
if ($db_layer eq "ndo") {
$DBRESULT = $dbh->prepare("SELECT * FROM `cfg_ndo2db`");
if (!$DBRESULT->execute) {
die "Error:" . $dbh->errstr . "\n";
}
$row = $DBRESULT->fetchrow_hashref();
if (defined($row)) {
$db_broker = DBI->connect("DBI:mysql:database=".$row->{'db_name'}.";host=".$row->{'db_host'}.":".$row->{'db_port'}, $row->{'db_user'}, $row->{'db_pass'}, {'RaiseError' => 1});
$ndo_prefix = $row->{'db_prefix'};
} else {
print "Could not find broker connection info!\n";
exit $ERRORS{'UNKNOWN'};
}
}
my @metric_value_tab;
my $warning;
my $critical;
......@@ -122,8 +101,8 @@ if (defined($OPTION{'help'})) {
}
if (!defined($OPTION{'id'})) {
print_help;
exit $ERRORS{'UNKNOWN'};
print_help;
exit $ERRORS{'UNKNOWN'};
}
##################################################
......@@ -132,47 +111,47 @@ if (!defined($OPTION{'id'})) {
##
##################################################
sub calculate_meta() {
my $result;
my $val;
my $total;
if ($calculation eq "MIN") {
@metric_value_tab = sort(@metric_value_tab);
if (defined($metric_value_tab[0])) {
$result = $metric_value_tab[0];
} else {
$result = 0;
}
} elsif ($calculation eq "MAX") {
@metric_value_tab = sort(@metric_value_tab);
if (defined($metric_value_tab[0])) {
$result = $metric_value_tab[scalar(@metric_value_tab) - 1];
} else {
$result = 0;
}
} elsif ($calculation eq "SOM") {
$result = 0;
foreach $val (@metric_value_tab) {
if ($val) {
$val =~ s/,/./;
$result += $val;
}
}
} elsif ($calculation eq "AVE") {
$result = 0;
foreach $val (@metric_value_tab) {
if ($val) {
$val =~ s/,/./;
$result = $result + $val;
}
}
$total = scalar(@metric_value_tab);
if (!$total) {
$total = 1;
}
$result = $result / $total;
my $result;
my $val;
my $total;
if ($calculation eq "MIN") {
@metric_value_tab = sort(@metric_value_tab);
if (defined($metric_value_tab[0])) {
$result = $metric_value_tab[0];
} else {
$result = 0;
}
} elsif ($calculation eq "MAX") {
@metric_value_tab = sort(@metric_value_tab);
if (defined($metric_value_tab[0])) {
$result = $metric_value_tab[scalar(@metric_value_tab) - 1];
} else {
$result = 0;
}
} elsif ($calculation eq "SOM") {
$result = 0;
foreach $val (@metric_value_tab) {
if ($val) {
$val =~ s/,/./;
$result += $val;
}
}
} elsif ($calculation eq "AVE") {
$result = 0;
foreach $val (@metric_value_tab) {
if ($val) {
$val =~ s/,/./;
$result = $result + $val;
}
}
return $result;
$total = scalar(@metric_value_tab);
if (!$total) {
$total = 1;
}
$result = $result / $total;
}
return $result;
}
##################################################
......@@ -202,53 +181,26 @@ sub getDataSourceType() {
## Retrieve by regexp for Centreon Broker
##
##################################################
sub retrieve_by_regexp_centreon_broker() {
my $row2;
my $query2 = "SELECT s.perfdata FROM services s WHERE s.description LIKE '".$regexp."'";
my $DBRES2 = $db_centstorage->prepare($query2);
if (!$DBRES2->execute) {
die "Error:" . $DBRES2->errstr . "\n";
}
my $i = 0;
while ($row2 = $DBRES2->fetchrow_hashref()) {
if (defined($metric_select)) {
$row2->{'perfdata'} =~ m/\'?$metric_select\'?=([0-9\.]+)/;
if (defined($1)) {
$metric_value_tab[$i] = $1;
$i++;
}
}
else {
print "No metric defined!\n";
exit $ERRORS{'UNKNOWN'};
}
}
}
##################################################
##
## Retrieve by regexp for ndo
##
##################################################
sub retrieve_by_regexp() {
my $row2;
my $query2 = "SELECT ss.perfdata FROM `".$ndo_prefix."servicestatus` ss, `".$ndo_prefix."services` s WHERE ss.service_object_id = s.service_object_id AND s.display_name LIKE '".$regexp."'";
my $DBRES2 = $db_broker->prepare($query2);
if (!$DBRES2->execute) {die "Error:" . $DBRES2->errstr . "\n";}
my $i = 0;
while ($row2 = $DBRES2->fetchrow_hashref()) {
if (defined($metric_select)) {
$row2->{'perfdata'} =~ m/\'?$metric_select\'?=([0-9\.]+)/;
if (defined($1)) {
$metric_value_tab[$i] = $1;
$i++;
}
}
else {
print "No metric defined!\n";
exit $ERRORS{'UNKNOWN'};
}
my $row2;
my $query2 = "SELECT s.perfdata FROM services s WHERE s.description LIKE '".$regexp."' AND s.enable = 1";
my $DBRES2 = $db_centstorage->prepare($query2);
if (!$DBRES2->execute) {
die "Error:" . $DBRES2->errstr . "\n";
}
my $i = 0;
while ($row2 = $DBRES2->fetchrow_hashref()) {
if (defined($metric_select)) {
$row2->{'perfdata'} =~ m/\'?$metric_select\'?=([0-9\.]+)/;
if (defined($1)) {
$metric_value_tab[$i] = $1;
$i++;
}
} else {
print "No metric defined!\n";
exit $ERRORS{'UNKNOWN'};
}
}
}
##################################################
......@@ -256,38 +208,38 @@ sub retrieve_by_regexp() {
## Retrieve by list for Centreon Broker
##
##################################################
sub retrieve_by_list_centreon_broker() {
my $row2;
my $query3;
my $DBRES3;
my $row3;
my $query4;
my $DBRES4;
my $row4;
my $query2 = "SELECT host_id, metric_id FROM `meta_service_relation` WHERE meta_id = '".$OPTION{'id'}."'";
my $DBRES2 = $dbh->prepare($query2);
if (!$DBRES2->execute) {
sub retrieve_by_list() {
my $row2;
my $query3;
my $DBRES3;
my $row3;
my $query4;
my $DBRES4;
my $row4;
my $query2 = "SELECT host_id, metric_id FROM `meta_service_relation` WHERE meta_id = '".$OPTION{'id'}."'";
my $DBRES2 = $dbh->prepare($query2);
if (!$DBRES2->execute) {
die "Error:" . $DBRES2->errstr . "\n";
}
my $i = 0;
while ($row2 = $DBRES2->fetchrow_hashref()) {
$query3 = "SELECT host_name, service_description, m.metric_name FROM index_data i, metrics m WHERE i.id = m.index_id AND m.metric_id = '".$row2->{'metric_id'}."' LIMIT 1";
$DBRES3 = $db_centstorage->prepare($query3);
if (!$DBRES3->execute) {
die "Error:" . $DBRES3->errstr . "\n";
}
my $i = 0;
while ($row2 = $DBRES2->fetchrow_hashref()) {
$query3 = "SELECT host_name, service_description, m.metric_name FROM index_data i, metrics m WHERE i.id = m.index_id AND m.metric_id = '".$row2->{'metric_id'}."' LIMIT 1";
$DBRES3 = $db_centstorage->prepare($query3);
if (!$DBRES3->execute) {
die "Error:" . $DBRES3->errstr . "\n";
}
$row3 = $DBRES3->fetchrow_hashref();
if (defined($row3->{'service_description'})) {
$query4 = "SELECT s.perfdata FROM services s, hosts h WHERE s.host_id = h.host_id AND h.name = '".$row3->{'host_name'}."' AND s.description = '".$row3->{'service_description'}."' AND s.enabled = '1' AND h.enabled = '1' LIMIT 1";
$DBRES4 = $db_centstorage->prepare($query4);
if (!$DBRES4->execute) {
die "Error:" . $DBRES4->errstr . "\n";
}
$row4 = $DBRES4->fetchrow_hashref();
$row3 = $DBRES3->fetchrow_hashref();
if (defined($row3->{'service_description'})) {
$query4 = "SELECT s.perfdata FROM services s, hosts h WHERE s.host_id = h.host_id AND h.name = '".$row3->{'host_name'}."' AND s.description = '".$row3->{'service_description'}."' AND s.enabled = '1' AND h.enabled = '1' LIMIT 1";
$DBRES4 = $db_centstorage->prepare($query4);
if (!$DBRES4->execute) {
die "Error:" . $DBRES4->errstr . "\n";
}
$row4 = $DBRES4->fetchrow_hashref();
if (defined($OPTION{'legacy'})) {
while ($row4->{'perfdata'} =~ m/\'?([a-zA-Z0-9\_\-\/\.\:\ ]+)\'?=([0-9\.\,\-]+)/g) {
my $value = $2;
......@@ -304,90 +256,12 @@ sub retrieve_by_list_centreon_broker() {
$i++;
}
}
}
}
}
}
##################################################
##
## Retrieve by list for ndo
##
##################################################
sub retrieve_by_list() {
my $row2;
my $query3;
my $DBRES3;
my $row3;
my $query4;
my $DBRES4;
my $row4;
my $query2 = "SELECT host_id, metric_id FROM `meta_service_relation` WHERE meta_id = '".$OPTION{'id'}."'";
my $DBRES2 = $dbh->prepare($query2);
if (!$DBRES2->execute) {
die "Error:" . $DBRES2->errstr . "\n";
}
my $i = 0;
while ($row2 = $DBRES2->fetchrow_hashref()) {
$query3 = "SELECT host_name, service_description, m.metric_name FROM index_data i, metrics m WHERE i.id = m.index_id AND m.metric_id = '".$row2->{'metric_id'}."' LIMIT 1";
$DBRES3 = $db_centstorage->prepare($query3);
if (!$DBRES3->execute) {
die "Error:" . $DBRES3->errstr . "\n";
}
$row3 = $DBRES3->fetchrow_hashref();
$row3->{'service_description'} =~ s/\#S\#/\//g;
$row3->{'service_description'} =~ s/\#BS\#/\\/g;
if (defined($row3->{'service_description'})) {
$query4 = "SELECT ss.perfdata FROM `".$ndo_prefix."servicestatus` ss, `".$ndo_prefix."services` s, `".$ndo_prefix."hosts` h WHERE ss.service_object_id = s.service_object_id AND s.host_object_id = h.host_object_id AND h.display_name = '".$row3->{'host_name'}."' AND s.display_name = '".$row3->{'service_description'}."' LIMIT 1";
$DBRES4 = $db_broker->prepare($query4);
if (!$DBRES4->execute) {
die "Error:" . $DBRES4->errstr . "\n";
}
$row4 = $DBRES4->fetchrow_hashref();
while ($row4->{'perfdata'} =~ m/\'?([a-zA-Z0-9\_\-\/\.\:\ ]+)\'?=([0-9\.\,\-]+)/g) {
my $value = $2;
if (defined($1) && defined($value) && $1 =~ $row3->{'metric_name'}) {
$metric_value_tab[$i] = $value;
$i++;
}
}
}
}
}
##################################################
##
## Get Db Layer
##
##################################################
sub get_db_layer() {
my $query = "SELECT `value` FROM `options` WHERE `key` = 'broker'";
my $res = $dbh->prepare($query);
if (!$res->execute) {
die "Error:" . $res->errstr . "\n";
}
$row = $res->fetchrow_hashref();
if (!defined($row->{'value'})) {
return "ndo";
} else {
return $row->{'value'};
}
}
}
}
##################################################
##
## MAIN
##
##################################################
##################################################
##
## First query
......@@ -419,17 +293,9 @@ $display = $row->{'meta_display'};
my $selection_mode = $row->{'meta_select_mode'};
if ($selection_mode eq '2') {
if ($db_layer eq "broker") {
retrieve_by_regexp_centreon_broker();
} else {
retrieve_by_regexp();
}
retrieve_by_regexp();
} else {
if ($db_layer eq "broker") {
retrieve_by_list_centreon_broker();
} else {
retrieve_by_list();
}
retrieve_by_list();
}
my $res = calculate_meta();
......@@ -438,21 +304,21 @@ $res = sprintf("%02.2f", $res);
my $msg = "";
my $meta_status = $ERRORS{'OK'};
if (defined($warning) && defined($critical)) {
if ($warning <= $critical) {
if ($res >= $warning) {
$meta_status = $ERRORS{'WARNING'};
}
if ($res >= $critical) {
$meta_status = $ERRORS{'CRITICAL'};
}
} elsif ($warning > $critical) {
if ($res <= $warning) {
$meta_status = $ERRORS{'WARNING'};
}
if ($res <= $critical) {
$meta_status = $ERRORS{'CRITICAL'};
}
if ($warning <= $critical) {
if ($res >= $warning) {
$meta_status = $ERRORS{'WARNING'};
}
if ($res >= $critical) {
$meta_status = $ERRORS{'CRITICAL'};
}
} elsif ($warning > $critical) {
if ($res <= $warning) {
$meta_status = $ERRORS{'WARNING'};
}
if ($res <= $critical) {
$meta_status = $ERRORS{'CRITICAL'};
}
}
}
my $metric = "";
......@@ -477,6 +343,7 @@ if (!defined($display) || !$display) {
} else {
$msg = sprintf($display, $res);
}
if (defined($OPTION{'legacy'})) {
$msg .= "|".$metric."=".$res;
} else {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment