check_meta_service compatible with centreon broker
git-svn-id: http://svn.centreon.com/trunk/plugins-2.x@12084 6bcd3966-0018-0410-8128-fd23d134de7e
This commit is contained in:
parent
e17af0c94c
commit
6214f770c9
|
@ -46,8 +46,8 @@ use vars qw($mysql_user $mysql_passwd $mysql_host $mysql_database_oreon $mysql_d
|
|||
########################################
|
||||
|
||||
my $PROGNAME = $0;
|
||||
my $VERSION = "2.1";
|
||||
my $MODIF_DATE = "04/05/2009";
|
||||
my $VERSION = "2.3";
|
||||
my $MODIF_DATE = "13/04/2011";
|
||||
|
||||
my %ERRORS = ( "OK" => 0, "WARNING" => 1, "CRITICAL" => 2, "UNKNOWN" => 3);
|
||||
|
||||
|
@ -162,6 +162,39 @@ sub calculate_meta() {
|
|||
return $result;
|
||||
}
|
||||
|
||||
##################################################
|
||||
##
|
||||
## 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."'";
|
||||
|
@ -183,6 +216,61 @@ 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) {
|
||||
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();
|
||||
|
||||
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'}."' LIMIT 1";
|
||||
$DBRES4 = $db_centstorage->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++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
##################################################
|
||||
##
|
||||
## Retrieve by list for ndo
|
||||
##
|
||||
##################################################
|
||||
sub retrieve_by_list() {
|
||||
my $row2;
|
||||
|
||||
|
@ -196,12 +284,16 @@ sub retrieve_by_list() {
|
|||
|
||||
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";}
|
||||
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";}
|
||||
if (!$DBRES3->execute) {
|
||||
die "Error:" . $DBRES3->errstr . "\n";
|
||||
}
|
||||
$row3 = $DBRES3->fetchrow_hashref();
|
||||
|
||||
$row3->{'service_description'} =~ s/\#S\#/\//g;
|
||||
|
@ -210,7 +302,9 @@ sub retrieve_by_list() {
|
|||
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";}
|
||||
if (!$DBRES4->execute) {
|
||||
die "Error:" . $DBRES4->errstr . "\n";
|
||||
}
|
||||
$row4 = $DBRES4->fetchrow_hashref();
|
||||
|
||||
while ($row4->{'perfdata'} =~ m/\'?([a-zA-Z0-9\_\-\/\.\:\ ]+)\'?=([0-9\.\,\-]+)/g) {
|
||||
|
@ -224,6 +318,26 @@ sub retrieve_by_list() {
|
|||
}
|
||||
}
|
||||
|
||||
##################################################
|
||||
##
|
||||
## 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
|
||||
|
@ -237,7 +351,9 @@ sub retrieve_by_list() {
|
|||
##################################################
|
||||
my $query = "SELECT meta_display, calcul_type, regexp_str, warning, critical, metric, meta_select_mode FROM `meta_service` WHERE meta_id = '".$OPTION{'id'}."' LIMIT 1";
|
||||
my $DBRES = $dbh->prepare($query);
|
||||
if (!$DBRES->execute) {die "Error:" . $DBRES->errstr . "\n";}
|
||||
if (!$DBRES->execute) {
|
||||
die "Error:" . $DBRES->errstr . "\n";
|
||||
}
|
||||
$row = $DBRES->fetchrow_hashref();
|
||||
if (!defined($row->{'calcul_type'})){
|
||||
print "Meta Service is not valid\n";
|
||||
|
@ -257,13 +373,20 @@ $metric_select = $row->{'metric'};
|
|||
$display = $row->{'meta_display'};
|
||||
|
||||
my $selection_mode = $row->{'meta_select_mode'};
|
||||
my $db_layer = get_db_layer();
|
||||
|
||||
|
||||
if ($selection_mode eq '2') {
|
||||
retrieve_by_regexp();
|
||||
}
|
||||
else {
|
||||
retrieve_by_list();
|
||||
if ($selection_mode eq '2') {
|
||||
if ($db_layer eq "broker") {
|
||||
retrieve_by_regexp_centreon_broker();
|
||||
} else {
|
||||
retrieve_by_regexp();
|
||||
}
|
||||
} else {
|
||||
if ($db_layer eq "broker") {
|
||||
retrieve_by_list_centreon_broker();
|
||||
} else {
|
||||
retrieve_by_list();
|
||||
}
|
||||
}
|
||||
|
||||
my $res = calculate_meta();
|
||||
|
|
Loading…
Reference in New Issue