Skip to content

Commit

Permalink
Merge branch 'ITC-3043' of https://github.com/it-novum/openITCOCKPIT
Browse files Browse the repository at this point in the history
…into ITC-3043
  • Loading branch information
nook24 committed Jul 18, 2023
2 parents 0a9daa0 + f0a8105 commit eb009bd
Show file tree
Hide file tree
Showing 8 changed files with 159 additions and 40 deletions.
19 changes: 11 additions & 8 deletions src/Controller/HostgroupsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,12 @@ public function loadHostgroupWithHostsById($id = null) {
$all_hosts = [];
$hosts = [];

$hostgroupHoststatusOverview = [
0 => null,
1 => null,
2 => null
];

if (!empty($hostIds)) {
if ($this->DbBackend->isNdoUtils()) {
/** @var $HostsTable HostsTable */
Expand All @@ -416,6 +422,11 @@ public function loadHostgroupWithHostsById($id = null) {
/** @var $HostsTable HostsTable */
$HostsTable = TableRegistry::getTableLocator()->get('Hosts');
$hosts = $HostsTable->getHostsIndexStatusengine3($HostFilter, $HostConditions, $PaginateOMat);
$hostgroupServicestatusAllHosts = $HostsTable->getHostStatusGlobalOverview($HostFilter, $HostConditions);
foreach ($hostgroupServicestatusAllHosts as $hoststatusGroupByState) {
$state = (int)$hoststatusGroupByState['Hoststatus']['current_state'];
$hostgroupHoststatusOverview[$state] = (int)$hoststatusGroupByState['count'];
}
}

if ($this->DbBackend->isCrateDb()) {
Expand All @@ -426,12 +437,6 @@ public function loadHostgroupWithHostsById($id = null) {
$ServicestatusFields = new ServicestatusFields($this->DbBackend);
$ServicestatusFields->currentState();

$hostgroupHoststatusOverview = [
0 => 0,
1 => 0,
2 => 0
];


foreach ($hosts as $host) {
$Host = new Host($host);
Expand Down Expand Up @@ -464,8 +469,6 @@ public function loadHostgroupWithHostsById($id = null) {
$allowEdit = $ContainerPermissions->hasPermission();
}

$hostgroupHoststatusOverview[$Hoststatus->currentState()]++;

$tmpRecord = [
'Host' => $Host->toArray(),
'Hoststatus' => $Hoststatus->toArray(),
Expand Down
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
45 changes: 43 additions & 2 deletions src/Model/Table/HostsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use Cake\ORM\TableRegistry;
use Cake\Utility\Hash;
use Cake\Validation\Validator;
use itnovum\openITCOCKPIT\Core\FileDebugger;
use itnovum\openITCOCKPIT\Core\HostConditions;
use itnovum\openITCOCKPIT\Core\ValueObjects\User;
use itnovum\openITCOCKPIT\Database\PaginateOMat;
Expand Down Expand Up @@ -4499,7 +4498,7 @@ public function getHostsWithStatusByConditionsStatusengine3($MY_RIGHTS, $conditi
'RLIKE'
);
}
}else{
} else {
$where['Hosts.address LIKE'] = sprintf('%%%s%%', $conditions['Host']['address']);
}
}
Expand Down Expand Up @@ -4913,4 +4912,46 @@ public function getHostsForDesktopWithStatusByConditionsStatusengine3($MY_RIGHTS
private function isValidRegularExpression($regEx) {
return @preg_match('`' . $regEx . '`', '') !== false;
}

/**
* @param HostFilter $HostFilter
* @param HostConditions $HostConditions
* @return array
*/
public function getHostStatusGlobalOverview(HostFilter $HostFilter, HostConditions $HostConditions): array {
$MY_RIGHTS = $HostConditions->getContainerIds();
$where = $HostFilter->indexFilter();
$where['Hosts.disabled'] = 0;
if ($HostConditions->getHostIds()) {
$hostIds = $HostConditions->getHostIds();
if (!is_array($hostIds)) {
$hostIds = [$hostIds];
}

$where['Hosts.id IN'] = $hostIds;
}
$query = $this->find();
$query->select([
'Hoststatus.current_state',
'count' => $query->newExpr('COUNT(DISTINCT Hoststatus.hostname)'),
])
->innerJoin(['Hoststatus' => 'statusengine_hoststatus'], [
'Hoststatus.hostname = Hosts.uuid'
]);
if (!empty($MY_RIGHTS)) {
$query->innerJoin(['HostsToContainersSharing' => 'hosts_to_containers'], [
'HostsToContainersSharing.host_id = Hosts.id'
]);
$query->where([
'HostsToContainersSharing.container_id IN' => $MY_RIGHTS
]);
}
if (!empty($where)) {
$query->andWhere($where);
}

$query->disableHydration();
$query->group(['Hoststatus.current_state']);
return $this->emptyArrayIfNull($query->toArray());
}
}
57 changes: 56 additions & 1 deletion src/Model/Table/ServicesTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use Cake\Utility\Hash;
use Cake\Validation\Validator;
use itnovum\openITCOCKPIT\Core\Comparison\ServiceComparisonForSave;
use itnovum\openITCOCKPIT\Core\FileDebugger;
use itnovum\openITCOCKPIT\Core\ServiceConditions;
use itnovum\openITCOCKPIT\Core\ServicestatusConditions;
use itnovum\openITCOCKPIT\Core\UUID;
Expand Down Expand Up @@ -5093,4 +5092,60 @@ public function getActiveServicesWithServicetemplateByHostId($id, $enableHydrati
->all();
return $query;
}

/**
* @param ServiceConditions $ServiceConditions
* @return array
*/
public function getServiceStatusGlobalOverview(ServiceConditions $ServiceConditions): 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',
'like'
));
unset($where['servicename LIKE']);
}


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

$query->disableHydration();
$query->group(['Servicestatus.current_state']);
return $this->emptyArrayIfNull($query->toArray());
}
}
13 changes: 7 additions & 6 deletions src/Template/Hostgroups/extended.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@
<div id="panel-1" class="panel">
<div class="panel-hdr">
<h2>
{{(hostgroup.Hostgroup.container.name) && hostgroup.Hostgroup.container.name ||
q <span class="fw-300"><i><?php echo __('UUID: '); ?>{{hostgroup.Hostgroup.uuid}}</i></span>
{{hostgroup.Hostgroup.container.name}}
<span class="fw-300"><i><?php echo __('UUID: '); ?>{{hostgroup.Hostgroup.uuid}}</i></span>
</h2>
<div class="panel-toolbar">
<button class="btn btn-xs btn-default mr-1 shadow-0" ng-click="loadHostsWithStatus()">
Expand Down Expand Up @@ -175,7 +175,7 @@ class="dropdown-item"
<div class="frame-wrap">
<table class="table table-striped m-0 table-bordered table-hover table-sm">
<thead>
<tr ng-if="hostgroup.Hosts.length > 0">
<tr>
<td colspan="8" class="no-padding">
<div class="form-group">
<div class="input-group input-group-sm">
Expand All @@ -200,11 +200,12 @@ class="custom-control-input"
name="checkbox"
checked="checked"
ng-model-options="{debounce: 500}"
ng-model="hostgroupsStateFilter[$index]"
ng-value="$index">
ng-value="{{state}}"
ng-model="filter.Hoststatus.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
10 changes: 5 additions & 5 deletions src/Template/Servicegroups/extended.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@
<div id="panel-1" class="panel">
<div class="panel-hdr">
<h2>
{{(servicegroup.Servicegroup.container.name) && servicegroup.Servicegroup.container.name ||
'<?php echo __('Service Groups (0)'); ?>'}}
{{servicegroup.Servicegroup.container.name}}
<span class="fw-300"><i><?php echo __('UUID: '); ?>{{servicegroup.Servicegroup.uuid}}</i></span>
</h2>
<div class="panel-toolbar">
Expand Down Expand Up @@ -199,11 +198,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('HostgroupsExtendedController', function($scope, $http, $interval, $stateParams){
.controller('HostgroupsExtendedController', function($rootScope, $scope, $http, $interval, $stateParams){

$scope.init = true;
$scope.servicegroupsStateFilter = {};
Expand Down Expand Up @@ -29,6 +29,13 @@ angular.module('openITCOCKPIT')
$scope.filter = {
Host: {
name: ''
},
Hoststatus: {
current_state: {
up: false,
down: false,
unreachable: false
}
}
};
};
Expand Down Expand Up @@ -75,7 +82,9 @@ angular.module('openITCOCKPIT')
'scroll': $scope.useScroll,
'page': $scope.currentPage,
'selected': $scope.post.Hostgroup.id,
'filter[Hosts.name]': $scope.filter.Host.name
'filter[Hosts.name]': $scope.filter.Host.name,
'filter[Hoststatus.current_state][]': $rootScope.currentStateForApi($scope.filter.Hoststatus.current_state)

}
}).then(function(result){
$scope.hostgroup = result.data.hostgroup;
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){

$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 eb009bd

Please sign in to comment.