Skip to content

Commit

Permalink
#ITC-3043 Host- and service group extended view display wrong status …
Browse files Browse the repository at this point in the history
…count (Servicegroups/extended view: Added global service status overview - usable as a global filter)
  • Loading branch information
ibering committed Jul 12, 2023
1 parent d244055 commit 6c41694
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 20 deletions.
28 changes: 15 additions & 13 deletions src/Controller/ServicegroupsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -781,10 +781,10 @@ public function copy($id = null) {
$sourceServicegroup = $ServicegroupsTable->getSourceServicegroupForCopy($sourceServicegroupId, $MY_RIGHTS);

$newServicegroupData = [
'description' => $servicegroupData['Servicegroup']['description'],
'description' => $servicegroupData['Servicegroup']['description'],
'servicegroup_url' => $sourceServicegroup['servicegroup_url'],
'uuid' => UUID::v4(),
'container' => [
'uuid' => UUID::v4(),
'container' => [
'name' => $servicegroupData['Servicegroup']['container']['name'],
'containertype_id' => CT_SERVICEGROUP,
'parent_id' => $sourceServicegroup['container']['parent_id']
Expand Down Expand Up @@ -943,7 +943,6 @@ public function loadServicegroupWithServicesById($id = null) {
$UserTime = new UserTime($User->getTimezone(), $User->getDateformat());

$serviceIds = $ServicegroupsTable->getServiceIdsByServicegroupId($id);

$ServiceFilter = new ServiceFilter($this->request);
$ServiceConditions = new ServiceConditions($ServiceFilter->indexFilter());

Expand All @@ -956,6 +955,13 @@ public function loadServicegroupWithServicesById($id = null) {
$all_services = [];
$services = [];

$servicegroupServicestatusOverview = [
0 => null,
1 => null,
2 => null,
3 => null
];

if (!empty($serviceIds)) {
if ($this->DbBackend->isNdoUtils()) {
/** @var $ServicesTable ServicesTable */
Expand All @@ -967,8 +973,12 @@ public function loadServicegroupWithServicesById($id = null) {
/** @var $ServicesTable ServicesTable */
$ServicesTable = TableRegistry::getTableLocator()->get('Services');
$services = $ServicesTable->getServiceIndexStatusengine3($ServiceConditions, $PaginateOMat);
$servicegroupServicestatusAllServices = $ServicesTable->getServiceStatusGlobalOverview($ServiceConditions);
foreach ($servicegroupServicestatusAllServices as $servicestatusGroupByState) {
$state = (int)$servicestatusGroupByState['Servicestatus']['current_state'];
$servicegroupServicestatusOverview[$state] = (int)$servicestatusGroupByState['count'];
}
}

if ($this->DbBackend->isCrateDb()) {
throw new MissingDbBackendException('MissingDbBackendException');
}
Expand All @@ -977,12 +987,6 @@ public function loadServicegroupWithServicesById($id = null) {
$ServicestatusFields = new ServicestatusFields($this->DbBackend);
$ServicestatusFields->currentState();

$servicegroupServicestatusOverview = [
0 => 0,
1 => 0,
2 => 0,
3 => 0
];

$hostContainers = [];
if ($this->hasRootPrivileges === false) {
Expand Down Expand Up @@ -1036,8 +1040,6 @@ public function loadServicegroupWithServicesById($id = null) {
];
$tmpRecord['Service']['has_graph'] = $PerfdataChecker->hasPerfdata();
$all_services[] = $tmpRecord;

$servicegroupServicestatusOverview[$Servicestatus->currentState()]++;
}

$statusOverview = array_combine([
Expand Down
68 changes: 68 additions & 0 deletions src/Model/Table/ServicesTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -5093,4 +5093,72 @@ public function getActiveServicesWithServicetemplateByHostId($id, $enableHydrati
->all();
return $query;
}

/**
* @param ServiceConditions $ServiceConditions
* @param $MY_RIGHTS
* @return array
*/
public function getServiceStatusGlobalOverview(ServiceConditions $ServiceConditions, $MY_RIGHTS = []): array {
$where = $ServiceConditions->getConditions();
$where['Services.disabled'] = 0;
if ($ServiceConditions->getServiceIds()) {
$serviceIds = $ServiceConditions->getServiceIds();
if (!is_array($serviceIds)) {
$serviceIds = [$serviceIds];
}

$where['Services.id IN'] = $serviceIds;
}

$query = $this->find();
$query->select([
'Servicestatus.current_state',
'count' => $query->newExpr('COUNT(DISTINCT Servicestatus.service_description)'),
])
->contain('Servicetemplates')
->innerJoin(['Hosts' => 'hosts'], [
'Hosts.id = Services.host_id',
])
->innerJoinWith('Hosts.HostsToContainersSharing', function (Query $q) use ($ServiceConditions) {
if (!empty($ServiceConditions->getContainerIds())) {
$q->where([
'HostsToContainersSharing.id IN ' => $ServiceConditions->getContainerIds()
]);
}
return $q;
})
->innerJoin(['Servicestatus' => 'statusengine_servicestatus'], [
'Servicestatus.service_description = Services.uuid'
]);

if (isset($where['servicename LIKE'])) {
$query->where(new Comparison(
'IF((Services.name IS NULL OR Services.name=""), Servicetemplates.name, Services.name)',
$where['servicename LIKE'],
'string',
'rlike'
));
unset($where['servicename LIKE']);
}
if (isset($where['servicename rlike'])) {
$query->where(new Comparison(
'IF((Services.name IS NULL OR Services.name=""), Servicetemplates.name, Services.name)',
$where['servicename rlike'],
'string',
'rlike'
));
unset($where['servicename rlike']);
}

if (!empty($where)) {
$query->andWhere($where);
}

$query->disableHydration();
$query->group(['Servicestatus.current_state']);

return $this->emptyArrayIfNull($query->toArray());
}

}
12 changes: 8 additions & 4 deletions src/Template/Servicegroups/extended.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@
<div class="panel-hdr">
<h2>
{{(servicegroup.Servicegroup.container.name) && servicegroup.Servicegroup.container.name ||
'<?php echo __('Service Groups (0)'); ?>'}}
'<?php echo __('
Service
Groups(0)
'); ?>'}}
<span class="fw-300"><i><?php echo __('UUID: '); ?>{{servicegroup.Servicegroup.uuid}}</i></span>
</h2>
<div class="panel-toolbar">
Expand Down Expand Up @@ -199,11 +202,12 @@ class="custom-control-input"
name="checkbox"
checked="checked"
ng-model-options="{debounce: 500}"
ng-model="servicegroupsStateFilter[$index]"
ng-value="$index">
ng-value="{{state}}"
ng-model="filter.Servicestatus.current_state[state]">
<label
class="extended-list custom-control-label custom-control-label-{{state}} no-margin"
for="statusFilter{{state}}">{{stateCount}} {{state}}</label>
for="statusFilter{{state}}">{{stateCount}}
</label>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
angular.module('openITCOCKPIT')
.controller('ServicegroupsExtendedController', function($scope, $http, $interval, $stateParams){
.controller('ServicegroupsExtendedController', function($rootScope, $scope, $http, $interval, $stateParams, QueryStringService){

$scope.init = true;
$scope.servicegroupsStateFilter = {};
Expand All @@ -14,7 +14,15 @@ angular.module('openITCOCKPIT')
$scope.useScroll = true;

$scope.filter = {
servicename: ''
servicename: '',
Servicestatus: {
current_state: {
ok: false,
warning: false,
critical: false,
unknown: false
}
}
};

$scope.post = {
Expand Down Expand Up @@ -69,6 +77,7 @@ angular.module('openITCOCKPIT')
'scroll': $scope.useScroll,
'page': $scope.currentPage,
'filter[servicename]': $scope.filter.servicename,
'filter[Servicestatus.current_state][]': $rootScope.currentStateForApi($scope.filter.Servicestatus.current_state)
}
}).then(function(result){
$scope.servicegroup = result.data.servicegroup;
Expand Down Expand Up @@ -187,7 +196,6 @@ angular.module('openITCOCKPIT')
if($scope.init){
return;
}

if($scope.post.Servicegroup.id > 0){
$scope.loadServicesWithStatus('');
}
Expand Down

0 comments on commit 6c41694

Please sign in to comment.