Skip to content
This repository has been archived by the owner on Dec 13, 2022. It is now read-only.

Commit

Permalink
fix(monitoring service): Fix hard_state_duration column (#7506)
Browse files Browse the repository at this point in the history
Fixed statusFilter that changed before the xls call was completed.
Fixed the xls file to display the hard_state_duration column only when the state filter is 'ok' or 'pending'.
  • Loading branch information
callapa authored and loiclau committed May 10, 2019
1 parent 5f010ca commit 075cc27
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 33 deletions.
8 changes: 6 additions & 2 deletions www/include/monitoring/status/Services/service.php
Original file line number Diff line number Diff line change
Expand Up @@ -493,13 +493,14 @@ function setO(_i) {
function updateSelect() {
var oldStatus = jQuery('#statusFilter').val();
var opts = document.getElementById('statusFilter').options;
var newTypeOrder = null;
if (jQuery('#statusService').val() == 'svcpb' || jQuery('#statusService').val() == 'svc_unhandled') {
opts.length = 0;
opts[opts.length] = new Option("", "");
opts[opts.length] = new Option(warning, "warning");
opts[opts.length] = new Option(critical, "critical");
opts[opts.length] = new Option(unknown, "unknown");
change_type_order(tabSortPb['champ']);
newTypeOrder = tabSortPb['champ'];
} else {
opts.length = 0;
opts[opts.length] = new Option("", "");
Expand All @@ -508,14 +509,17 @@ function updateSelect() {
opts[opts.length] = new Option(critical, "critical");
opts[opts.length] = new Option(unknown, "unknown");
opts[opts.length] = new Option(pending, "pending");
change_type_order(tabSortAll['champ']);
newTypeOrder = tabSortAll['champ'];
}

// We define the statusFilter before calling ajax
if (jQuery("#statusFilter option[value='" + oldStatus + "']").length > 0) {
jQuery("#statusFilter option[value='" + oldStatus + "']").prop('selected', true);
} else {
jQuery("#statusFilter option[value='']").prop('selected', true);
}

change_type_order(newTypeOrder);
}


Expand Down
68 changes: 39 additions & 29 deletions www/include/monitoring/status/Services/xml/serviceXML.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,41 +244,45 @@
}
$request .= $instance_filter;

if (preg_match("/^svc_unhandled/", $statusService)) {
if (preg_match("/^svc_unhandled_(warning|critical|unknown)\$/", $statusService, $matches)) {
if (isset($matches[1]) && $matches[1] == 'warning') {
$request .= " AND s.state = 1 ";
}
if (isset($matches[1]) && $matches[1] == "critical") {
$request .= " AND s.state = 2 ";
} elseif (isset($matches[1]) && $matches[1] == "unknown") {
$request .= " AND s.state = 3 ";
} elseif (isset($matches[1]) && $matches[1] == "pending") {
$request .= " AND s.state = 4 ";
} else {
$request .= " AND s.state != 0 ";
}
} else {
$request .= " AND (s.state != 0 AND s.state != 4) ";
}
if ($statusService == 'svc_unhandled') {
$request .= " AND s.state_type = 1";
$request .= " AND s.acknowledged = 0";
$request .= " AND s.scheduled_downtime_depth = 0";
$request .= " AND h.acknowledged = 0 AND h.scheduled_downtime_depth = 0 ";
} elseif ($statusService == "svcpb") {
$request .= " AND s.state != 0 AND s.state != 4 ";
}

if ($statusFilter == "ok") {
$request .= " AND s.state = 0";
} elseif ($statusFilter == "warning") {
$request .= " AND s.state = 1";
} elseif ($statusFilter == "critical") {
$request .= " AND s.state = 2";
} elseif ($statusFilter == "unknown") {
$request .= " AND s.state = 3";
} elseif ($statusFilter == "pending") {
$request .= " AND s.state = 4";
if ($statusService === 'svc_unhandled' || $statusService === 'svcpb') {
switch ($statusFilter) {
case 'warning':
$request .= " AND s.state = 1 ";
break;
case 'critical':
$request .= " AND s.state = 2 ";
break;
case 'unknown':
$request .= " AND s.state = 3 ";
break;
default:
$request .= " AND s.state != 0 AND s.state != 4 ";
}
} elseif ($statusService === 'svc') {
switch ($statusFilter) {
case 'ok':
$request .= " AND s.state = 0";
break;
case 'warning':
$request .= " AND s.state = 1 ";
break;
case 'critical':
$request .= " AND s.state = 2 ";
break;
case 'unknown':
$request .= " AND s.state = 3 ";
break;
case 'pending':
$request .= " AND s.state = 4 ";
break;
}
}

/**
Expand Down Expand Up @@ -334,6 +338,11 @@
}
}

$isHardStateDurationVisible =
!($statusService === 'svc'
&& ($statusFilter === 'ok' || $statusFilter === 'pending')
);

/* * **************************************************
* Create Buffer
*/
Expand All @@ -358,6 +367,7 @@
$obj->XML->writeElement("service_flapping", _("This Service is flapping"));
$obj->XML->writeElement("notif_disabled", _("Notification is disabled"));
$obj->XML->writeElement("use_criticality", $criticalityUsed);
$obj->XML->writeElement("use_hard_state_duration", $isHardStateDurationVisible ? 1 : 0);
$obj->XML->endElement();

$host_prev = "";
Expand Down
4 changes: 2 additions & 2 deletions www/include/monitoring/status/Services/xsl/service.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<td class="ListColHeaderCenter" style="white-space:nowrap;" id="current_state"></td>
<td class="ListColHeaderCenter" style="white-space:nowrap;" id="last_state_change"></td>
<xsl:for-each select="//i">
<xsl:if test="o = 'svc_unhandled' or o = 'svcpb' or o = 'svc_warning' or o = 'svc_critical' or o = 'svc_unknown' or o = 'svc_unhandled_warning' or o = 'svc_unhandled_critical' or o = 'svc_unhandled_unknown'">
<xsl:if test="use_hard_state_duration = 1">
<td class="ListColHeaderCenter" style="white-space:nowrap;" id="last_hard_state_change">
<xsl:value-of select="hard_state_label"/>
</td>
Expand Down Expand Up @@ -309,7 +309,7 @@
<td class="ListColRight" style="white-space:nowrap;">
<xsl:value-of select="d"/>
</td>
<xsl:if test = "//i/o = 'svc_unhandled' or //i/o = 'svcpb' or //i/o = 'svc_warning' or //i/o = 'svc_critical' or //i/o = 'svc_unknown' or //i/o = 'svc_unhandled_warning' or //i/o = 'svc_unhandled_critical' or //i/o = 'svc_unhandled_unknown'">
<xsl:if test = "//i/use_hard_state_duration = 1">
<td class="ListColRight" style="white-space:nowrap;">
<xsl:value-of select="last_hard_state_change"/>
</td>
Expand Down

0 comments on commit 075cc27

Please sign in to comment.