Commit 2b5e9d80 authored by Adrien Morais's avatar Adrien Morais Committed by Adrien Morais
Browse files

enh(feature-switch): fully manage feature switch (#37)



* enh(feature-switch): fully manage feature switch

* Apply suggestions from code review

Co-authored-by: default avatarKevin Duret <kduret@centreon.com>
parent a853d9bc
<?php
/*
* Copyright 2005-2020 Centreon
* Copyright 2005-2021 Centreon
* Centreon is developed by : Julien Mathis and Romain Le Merlus under
* GPL Licence 2.0.
*
......@@ -41,6 +41,13 @@ $dataPEND = array();
$dataList = array();
$db = new CentreonDB("centstorage");
/**
* true: URIs will correspond to deprecated pages
* false: URIs will correspond to new page (Resource Status)
*/
$useDeprecatedPages = $centreon->user->doesShowDeprecatedPages();
$centreonWebPath = trim($centreon->optGen['oreon_web_path'], '/');
$buildHostUri = function (array $states, array $statuses) use ($resourceController, $buildParameter) {
return $resourceController->buildListingUri(
[
......@@ -66,6 +73,8 @@ $unhandledState = $buildParameter('unhandled_problems', 'Unhandled');
$acknowledgedState = $buildParameter('acknowledged', 'Acknowledged');
$inDowntimeState = $buildParameter('in_downtime', 'In downtime');
$deprecatedHostListingUri = '/' . $centreonWebPath . '/main.php?p=20202&search=&o=h_';
// query for DOWN status
$res = $db->query(
"SELECT
......@@ -101,10 +110,25 @@ $res = $db->query(
);
while ($row = $res->fetch()) {
$row['un'] = $row['status'] - ($row['ack'] + $row['down']);
$row['listing_uri'] = $buildHostUri([], [$downStatus]);
$row['listing_ack_uri'] = $buildHostUri([$acknowledgedState], [$downStatus]);
$row['listing_downtime_uri'] = $buildHostUri([$inDowntimeState], [$downStatus]);
$row['listing_unhandled_uri'] = $buildHostUri([$unhandledState], [$downStatus]);
$deprecatedDownHostListingUri = $deprecatedHostListingUri . 'down';
$row['listing_uri'] = $useDeprecatedPages
? $deprecatedDownHostListingUri
: $buildHostUri([], [$downStatus]);
$row['listing_ack_uri'] = $useDeprecatedPages
? $deprecatedDownHostListingUri
: $buildHostUri([$acknowledgedState], [$downStatus]);
$row['listing_downtime_uri'] = $useDeprecatedPages
? $deprecatedDownHostListingUri
: $buildHostUri([$inDowntimeState], [$downStatus]);
$row['listing_unhandled_uri'] = $useDeprecatedPages
? $deprecatedDownHostListingUri
: $buildHostUri([$unhandledState], [$downStatus]);
$dataDO[] = $row;
}
......@@ -143,10 +167,25 @@ $res = $db->query(
);
while ($row = $res->fetch()) {
$row['un'] = $row['status'] - ($row['ack'] + $row['down']);
$row['listing_uri'] = $buildHostUri([], [$unreachableStatus]);
$row['listing_ack_uri'] = $buildHostUri([$acknowledgedState], [$unreachableStatus]);
$row['listing_downtime_uri'] = $buildHostUri([$inDowntimeState], [$unreachableStatus]);
$row['listing_unhandled_uri'] = $buildHostUri([$unhandledState], [$unreachableStatus]);
$deprecatedUnreachableHostListingUri = $deprecatedHostListingUri . 'unreachable';
$row['listing_uri'] = $useDeprecatedPages
? $deprecatedUnreachableHostListingUri
: $buildHostUri([], [$unreachableStatus]);
$row['listing_ack_uri'] = $useDeprecatedPages
? $deprecatedUnreachableHostListingUri
: $buildHostUri([$acknowledgedState], [$unreachableStatus]);
$row['listing_downtime_uri'] = $useDeprecatedPages
? $deprecatedUnreachableHostListingUri
: $buildHostUri([$inDowntimeState], [$unreachableStatus]);
$row['listing_unhandled_uri'] = $useDeprecatedPages
? $deprecatedUnreachableHostListingUri
: $buildHostUri([$unhandledState], [$unreachableStatus]);
$dataUN[] = $row;
}
......@@ -170,7 +209,10 @@ $res = $db->query(
) . ";"
);
while ($row = $res->fetch()) {
$row['listing_uri'] = $buildHostUri([], [$upStatus]);
$row['listing_uri'] = $useDeprecatedPages
? $deprecatedHostListingUri . 'up'
: $buildHostUri([], [$upStatus]);
$dataUP[] = $row;
}
......@@ -194,7 +236,10 @@ $res = $db->query(
) . ";"
);
while ($row = $res->fetch()) {
$row['listing_uri'] = $buildHostUri([], [$pendingStatus]);
$row['listing_uri'] = $useDeprecatedPages
? $deprecatedHostListingUri . 'pending'
: $buildHostUri([], [$pendingStatus]);
$dataPEND[] = $row;
}
......
......@@ -33,16 +33,28 @@
</td>
</tr>
<tr class="line_ack">
<td class='ListColLeft'><span class="badge service_critical margin_right">{$dataCRI[0].ack}</span>Acknowledge</td>
<td class='ListColLeft'><span class="badge service_warning margin_right">{$dataWA[0].ack}</span>Acknowledge</td>
<td class='ListColLeft'><span class="badge service_unknown margin_right">{$dataUNK[0].ack}</span>Acknowledge</td>
<td class='ListColLeft'>
<a href='{$dataCRI[0].listing_ack_uri}' target="_blank"><span class="badge service_critical margin_right">{$dataCRI[0].ack}</span>Acknowledge</a>
</td>
<td class='ListColLeft'>
<a href='{$dataWA[0].listing_ack_uri}' target="_blank"><span class="badge service_warning margin_right">{$dataWA[0].ack}</span>Acknowledge</a>
</td>
<td class='ListColLeft'>
<a href='{$dataUNK[0].listing_ack_uri}' target="_blank"><span class="badge service_unknown margin_right">{$dataUNK[0].ack}</span>Acknowledge</a>
</td>
<td></td>
<td></td>
</tr>
<tr class ="line_downtime">
<td class='ListColLeft'><span class="badge service_critical margin_right">{$dataCRI[0].down}</span>Downtimes</td>
<td class='ListColLeft'><span class="badge service_warning margin_right">{$dataWA[0].down}</span>Downtimes</td>
<td class='ListColLeft'><span class="badge service_unknown margin_right">{$dataUNK[0].down}</span>Downtimes</td>
<td class='ListColLeft'>
<a href='{$dataCRI[0].listing_downtime_uri}' target="_blank"><span class="badge service_critical margin_right">{$dataCRI[0].down}</span>Downtimes</a>
</td>
<td class='ListColLeft'>
<a href='{$dataWA[0].listing_downtime_uri}' target="_blank"><span class="badge service_warning margin_right">{$dataWA[0].down}</span>Downtimes</a>
</td>
<td class='ListColLeft'>
<a href='{$dataUNK[0].listing_downtime_uri}' target="_blank"><span class="badge service_unknown margin_right">{$dataUNK[0].down}</span>Downtimes</a>
</td>
<td></td>
<td></td>
</tr>
......
<?php
/*
* Copyright 2005-2020 Centreon
* Copyright 2005-2021 Centreon
* Centreon is developed by : Julien Mathis and Romain Le Merlus under
* GPL Licence 2.0.
*
......@@ -41,6 +41,13 @@ $dataUNK = array();
$dataPEND = array();
$db = new CentreonDB("centstorage");
/**
* true: URIs will correspond to deprecated pages
* false: URIs will correspond to new page (Resource Status)
*/
$useDeprecatedPages = $centreon->user->doesShowDeprecatedPages();
$centreonWebPath = trim($centreon->optGen['oreon_web_path'], '/');
$buildServiceUri = function (array $states, array $statuses) use ($resourceController, $buildParameter) {
return $resourceController->buildListingUri(
[
......@@ -67,6 +74,8 @@ $unhandledState = $buildParameter('unhandled_problems', 'Unhandled');
$acknowledgedState = $buildParameter('acknowledged', 'Acknowledged');
$inDowntimeState = $buildParameter('in_downtime', 'In downtime');
$deprecatedServiceListingUri = '/' . $centreonWebPath . '/main.php?p=20201&search=';
// query for CRITICAL state
$res = $db->query(
"SELECT
......@@ -124,10 +133,22 @@ $res = $db->query(
) . ";"
);
while ($row = $res->fetch()) {
$row['listing_uri'] = $buildServiceUri([], [$criticalStatus]);
$row['listing_ack_uri'] = $buildServiceUri([$acknowledgedState], [$criticalStatus]);
$row['listing_downtime_uri'] = $buildServiceUri([$inDowntimeState], [$criticalStatus]);
$row['listing_unhandled_uri'] = $buildServiceUri([$unhandledState], [$criticalStatus]);
$row['listing_uri'] = $useDeprecatedPages
? $deprecatedServiceListingUri . '&statusFilter=critical&o=svc'
: $buildServiceUri([], [$criticalStatus]);
$row['listing_ack_uri'] = $useDeprecatedPages
? $deprecatedServiceListingUri . '&statusFilter=critical&statusService=svcpb'
: $buildServiceUri([$acknowledgedState], [$criticalStatus]);
$row['listing_downtime_uri'] = $useDeprecatedPages
? $deprecatedServiceListingUri . '&statusFilter=critical&statusService=svcpb'
: $buildServiceUri([$inDowntimeState], [$criticalStatus]);
$row['listing_unhandled_uri'] = $useDeprecatedPages
? $deprecatedServiceListingUri . '&statusFilter=critical&statusService=svc_unhandled'
: $buildServiceUri([$unhandledState], [$criticalStatus]);
$dataCRI[] = $row;
}
......@@ -188,10 +209,22 @@ $res = $db->query(
) . ";"
);
while ($row = $res->fetch()) {
$row['listing_uri'] = $buildServiceUri([], [$warningStatus]);
$row['listing_ack_uri'] = $buildServiceUri([$acknowledgedState], [$warningStatus]);
$row['listing_downtime_uri'] = $buildServiceUri([$inDowntimeState], [$warningStatus]);
$row['listing_unhandled_uri'] = $buildServiceUri([$unhandledState], [$warningStatus]);
$row['listing_uri'] = $useDeprecatedPages
? $deprecatedServiceListingUri . '&statusFilter=warning&o=svc'
: $buildServiceUri([], [$warningStatus]);
$row['listing_ack_uri'] = $useDeprecatedPages
? $deprecatedServiceListingUri . '&statusFilter=warning&statusService=svcpb'
: $buildServiceUri([$acknowledgedState], [$warningStatus]);
$row['listing_downtime_uri'] = $useDeprecatedPages
? $deprecatedServiceListingUri . '&statusFilter=warning&statusService=svcpb'
: $buildServiceUri([$inDowntimeState], [$warningStatus]);
$row['listing_unhandled_uri'] = $useDeprecatedPages
? $deprecatedServiceListingUri . '&statusFilter=critical&statusService=svc_unhandled'
: $buildServiceUri([$unhandledState], [$warningStatus]);
$dataWA[] = $row;
}
......@@ -218,7 +251,10 @@ $res = $db->query(
) . ";"
);
while ($row = $res->fetch()) {
$row['listing_uri'] = $buildServiceUri([], [$okStatus]);
$row['listing_uri'] = $useDeprecatedPages
? $deprecatedServiceListingUri . '&statusFilter=ok&o=svc'
: $buildServiceUri([], [$okStatus]);
$dataOK[] = $row;
}
......@@ -244,7 +280,10 @@ $res = $db->query(
: "") . ";"
);
while ($row = $res->fetch()) {
$row['listing_uri'] = $buildServiceUri([], [$pendingStatus]);
$row['listing_uri'] = $useDeprecatedPages
? $deprecatedServiceListingUri . '&statusFilter=pending&o=svc'
: $buildServiceUri([], [$pendingStatus]);
$dataPEND[] = $row;
}
......@@ -305,10 +344,22 @@ $res = $db->query(
) . ";"
);
while ($row = $res->fetch()) {
$row['listing_uri'] = $buildServiceUri([], [$unknownStatus]);
$row['listing_ack_uri'] = $buildServiceUri([$acknowledgedState], [$unknownStatus]);
$row['listing_downtime_uri'] = $buildServiceUri([$inDowntimeState], [$unknownStatus]);
$row['listing_unhandled_uri'] = $buildServiceUri([$unhandledState], [$unknownStatus]);
$row['listing_uri'] = $useDeprecatedPages
? $deprecatedServiceListingUri . '&statusFilter=unknown&o=svc'
: $buildServiceUri([], [$unknownStatus]);
$row['listing_ack_uri'] = $useDeprecatedPages
? $deprecatedServiceListingUri . '&statusFilter=unknown&statusService=svcpb'
: $buildServiceUri([$acknowledgedState], [$unknownStatus]);
$row['listing_downtime_uri'] = $useDeprecatedPages
? $deprecatedServiceListingUri . '&statusFilter=unknown&statusService=svcpb'
: $buildServiceUri([$inDowntimeState], [$unknownStatus]);
$row['listing_unhandled_uri'] = $useDeprecatedPages
? $deprecatedServiceListingUri . '&statusFilter=unknown&statusService=svc_unhandled'
: $buildServiceUri([$unhandledState], [$unknownStatus]);
$dataUNK[] = $row;
}
......
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