checks if var is defined
git-svn-id: http://svn.centreon.com/trunk/plugins-2.x@8398 6bcd3966-0018-0410-8128-fd23d134de7e
This commit is contained in:
parent
6d160acabf
commit
7e47745fab
|
@ -122,6 +122,7 @@ if (!defined($OPTION{'id'})) {
|
|||
sub calculate_meta() {
|
||||
my $result;
|
||||
my $val;
|
||||
my $total;
|
||||
|
||||
if ($calculation eq "MIN") {
|
||||
@metric_value_tab = sort(@metric_value_tab);
|
||||
|
@ -152,7 +153,11 @@ sub calculate_meta() {
|
|||
foreach $val (@metric_value_tab) {
|
||||
$result += $val;
|
||||
}
|
||||
$result = $result / scalar(@metric_value_tab);
|
||||
$total = scalar(@metric_value_tab);
|
||||
if (!$total) {
|
||||
$total = 1;
|
||||
}
|
||||
$result = $result / $total;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
@ -198,16 +203,17 @@ sub retrieve_by_list() {
|
|||
$DBRES3 = $db_centstorage->prepare($query3);
|
||||
if (!$DBRES3->execute) {die "Error:" . $DBRES3->errstr . "\n";}
|
||||
$row3 = $DBRES3->fetchrow_hashref();
|
||||
|
||||
$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();
|
||||
$row4->{'perfdata'} =~ m/$row3->{'metric_name'}=([0-9\.]+)/;
|
||||
if (defined($1)) {
|
||||
$metric_value_tab[$i] = $1;
|
||||
$i++;
|
||||
}
|
||||
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();
|
||||
$row4->{'perfdata'} =~ m/$row3->{'metric_name'}=([0-9\.]+)/;
|
||||
if (defined($1)) {
|
||||
$metric_value_tab[$i] = $1;
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue