Skip to content

Commit

Permalink
Merge pull request #596 from it-novum/ITC-1171
Browse files Browse the repository at this point in the history
ITC-1171 CrateDB
  • Loading branch information
nook24 authored Jun 27, 2017
2 parents 1c5ed66 + 42dce6b commit 2902095
Show file tree
Hide file tree
Showing 57 changed files with 3,526 additions and 2,361 deletions.
74 changes: 52 additions & 22 deletions app/Controller/AcknowledgementsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@
// License agreement and license key will be shipped with the order
// confirmation.

use itnovum\openITCOCKPIT\Core\AcknowledgedServiceConditions;
use itnovum\openITCOCKPIT\Core\AcknowledgedServiceControllerRequest;
use itnovum\openITCOCKPIT\Core\ValueObjects\HostStates;
use itnovum\openITCOCKPIT\Core\AcknowledgedHostControllerRequest;
use itnovum\openITCOCKPIT\Core\AcknowledgedHostConditions;
use itnovum\openITCOCKPIT\Core\ValueObjects\ServiceStates;

class AcknowledgementsController extends AppController {
/*
Expand All @@ -34,6 +37,7 @@ class AcknowledgementsController extends AppController {
*/
public $uses = [
MONITORING_ACKNOWLEDGED_HOST,
MONITORING_ACKNOWLEDGED_SERVICE,
MONITORING_ACKNOWLEDGED,
MONITORING_SERVICESTATUS,
'Host',
Expand All @@ -50,8 +54,8 @@ class AcknowledgementsController extends AppController {
public $listFilters = [
'service' => [
'fields' => [
'Acknowledged.comment_data' => ['label' => 'Comment', 'searchType' => 'wildcard'],
'Acknowledged.author_name' => ['label' => 'Author', 'searchType' => 'wildcard'],
'AcknowledgedService.comment_data' => ['label' => 'Comment', 'searchType' => 'wildcard'],
'AcknowledgedService.author_name' => ['label' => 'Author', 'searchType' => 'wildcard'],
],
],
'host' => [
Expand All @@ -67,10 +71,31 @@ public function service($id = null){
throw new NotFoundException(__('Invalid service'));
}

//Process request and set request settings back to front end
$ServiceStates = new ServiceStates();
$AcknowledgedServiceControllerRequest = new AcknowledgedServiceControllerRequest(
$this->request,
$ServiceStates,
$this->userLimit
);

$service = $this->Service->find('first', [
'recursive' => -1,
'fields' => [
'Service.id',
'Service.uuid',
'Service.name',
'Service.service_type',
'Service.service_url'
],
'contain' => [
'Host' => [
'fields' => [
'Host.id',
'Host.name',
'Host.uuid',
'Host.address'
],
'Container',
],
'Servicetemplate' => [
Expand All @@ -84,10 +109,9 @@ public function service($id = null){
'Service.id' => $id,
],
]);

//Check if user is permitted to see this object
if (!$this->allowedByContainerId(Hash::extract($service, 'Host.Container.{n}.HostsToContainer.container_id'))) {
$this->render403();

return;
}

Expand All @@ -96,29 +120,35 @@ public function service($id = null){
$allowEdit = true;
}

//Process conditions
$Conditions = new AcknowledgedServiceConditions();
$Conditions->setLimit($AcknowledgedServiceControllerRequest->getLimit());
$Conditions->setFrom($AcknowledgedServiceControllerRequest->getFrom());
$Conditions->setTo($AcknowledgedServiceControllerRequest->getTo());
$Conditions->setStates($AcknowledgedServiceControllerRequest->getServiceStates());
$Conditions->setOrder($AcknowledgedServiceControllerRequest->getOrder());
$Conditions->setServiceUuid($service['Service']['uuid']);

//Query state history records
$query = $this->AcknowledgedService->getQuery($Conditions, $this->Paginator->settings['conditions']);
$this->Paginator->settings = array_merge($this->Paginator->settings, $query);
$all_acknowledgements = $this->Paginator->paginate(
$this->AcknowledgedService->alias,
[],
[key($this->Paginator->settings['order'])]
);

$docuExists = $this->Documentation->existsForUuid($service['Service']['uuid']);

//Get meta data and push to front end
$servicestatus = $this->Servicestatus->byUuid($service['Service']['uuid'], [
'fields' => [
'Servicestatus.current_state',
'Servicestatus.is_flapping'
],
]);
$docuExists = $this->Documentation->existsForUuid($service['Service']['uuid']);

$requestSettings = $this->Acknowledged->listSettingsService($this->request, $service['Service']['uuid']);

if (isset($this->Paginator->settings['conditions'])) {
$this->Paginator->settings['conditions'] = Hash::merge($this->Paginator->settings['conditions'], $requestSettings['conditions']);
} else {
$this->Paginator->settings['conditions'] = $requestSettings['conditions'];
}


$this->Paginator->settings['order'] = $requestSettings['paginator']['order'];
$this->Paginator->settings['limit'] = $requestSettings['paginator']['limit'];

$all_acknowledgements = $this->Paginator->paginate($this->Acknowledged->alias);

$this->set('AcknowledgementListsettings', $requestSettings['Listsettings']);
$this->set(compact(['service', 'all_acknowledgements', 'servicestatus', 'allowEdit', 'docuExists']));
$this->set(compact(['service', 'all_acknowledgements', 'servicestatus', 'docuExists', 'allowEdit']));
$this->set('AcknowledgementListsettings', $AcknowledgedServiceControllerRequest->getRequestSettingsForListSettings());
}

public function host($id = null){
Expand Down
1 change: 1 addition & 0 deletions app/Controller/Component/ConstantsComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public function __construct() {
'MONITORING_HOSTCHECK' => $monitoring . 'Module.Hostcheck',
'MONITORING_ACKNOWLEDGED' => $monitoring . 'Module.Acknowledged',
'MONITORING_ACKNOWLEDGED_HOST' => $monitoring . 'Module.AcknowledgedHost',
'MONITORING_ACKNOWLEDGED_SERVICE' => $monitoring . 'Module.AcknowledgedService',
'MONITORING_CONTACTNOTIFICATION' => $monitoring . 'Module.Contactnotification',
'MONITORING_CONTACTNOTIFICATIONMETHOD' => $monitoring . 'Module.Contactnotificationmethod',
'MONITORING_PARENTHOST' => $monitoring . 'Module.Parenthost',
Expand Down
3 changes: 1 addition & 2 deletions app/Controller/HostsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ class HostsController extends AppController {
'Hostcommandargumentvalue',
'Contact',
'Contactgroup',
MONITORING_ACKNOWLEDGED,
MONITORING_ACKNOWLEDGED_HOST,
'DeletedHost',
'DeletedService',
Expand Down Expand Up @@ -133,7 +132,7 @@ class HostsController extends AppController {
[
'0' => [
'name' => 'Downtime',
'value' => 0,
'value' => 1,
'label' => 'In Downtime',
'data' => 'Filter.Hoststatus.scheduled_downtime_depth',
],
Expand Down
13 changes: 13 additions & 0 deletions app/Controller/NotificationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,21 @@ public function serviceNotification($service_id){
//Check if user is permitted to see this object
$service = $this->Service->find('first', [
'recursive' => -1,
'fields' => [
'Service.id',
'Service.uuid',
'Service.name',
'Service.service_type',
'Service.service_url'
],
'contain' => [
'Host' => [
'fields' => [
'Host.id',
'Host.name',
'Host.uuid',
'Host.address'
],
'Container',
],
'Servicetemplate' => [
Expand Down
87 changes: 56 additions & 31 deletions app/Controller/ServicechecksController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@
// License agreement and license key will be shipped with the order
// confirmation.

class ServicechecksController extends AppController
{
use itnovum\openITCOCKPIT\Core\ServicechecksConditions;
use itnovum\openITCOCKPIT\Core\ServicechecksControllerRequest;
use itnovum\openITCOCKPIT\Core\ValueObjects\ServiceStates;

class ServicechecksController extends AppController {
/*
* Attention! In this case we load an external Model from the monitoring plugin! The Controller
* use this external model to fetch the required data out of the database
Expand All @@ -50,16 +53,29 @@ class ServicechecksController extends AppController
],
];

public function index($id = null)
{
public function index($id = null){
if (!$this->Service->exists($id)) {
throw new NotFoundException(__('invalid service'));
throw new NotFoundException(__('Invalid service'));
}

//Check if user is permitted to see this object
$service = $this->Service->find('first', [
'recursive' => -1,
'contain' => [
'Host' => [
'recursive' => -1,
'fields' => [
'Service.id',
'Service.uuid',
'Service.name',
'Service.service_type',
'Service.service_url'
],
'contain' => [
'Host' => [
'fields' => [
'Host.id',
'Host.name',
'Host.uuid',
'Host.address'
],
'Container',
],
'Servicetemplate' => [
Expand All @@ -72,41 +88,50 @@ public function index($id = null)
'conditions' => [
'Service.id' => $id,
],

]);

$containerIdsToCheck = Hash::extract($service, 'Host.Container.{n}.HostsToContainer.container_id');
$containerIdsToCheck[] = $service['Host']['container_id'];

//Check if user is permitted to see this object
if (!$this->allowedByContainerId($containerIdsToCheck, false)) {
if (!$this->allowedByContainerId(Hash::extract($service, 'Host.Container.{n}.HostsToContainer.container_id'))) {
$this->render403();

return;
}

$allowEdit = false;
if ($this->allowedByContainerId($containerIdsToCheck)) {
if ($this->allowedByContainerId(Hash::extract($service, 'Host.Container.{n}.HostsToContainer.container_id'))) {
$allowEdit = true;
}

//Process request and set request settings back to front end
$ServicechecksControllerRequest = new ServicechecksControllerRequest(
$this->request,
new ServiceStates(),
$this->userLimit
);

//Process conditions
$Conditions = new ServicechecksConditions();
$Conditions->setLimit($ServicechecksControllerRequest->getLimit());
$Conditions->setFrom($ServicechecksControllerRequest->getFrom());
$Conditions->setTo($ServicechecksControllerRequest->getTo());
$Conditions->setOrder($ServicechecksControllerRequest->getOrder());
$Conditions->setStates($ServicechecksControllerRequest->getServiceStates());
$Conditions->setServiceUuid($service['Service']['uuid']);

//Query host notification records
$query = $this->Servicecheck->getQuery($Conditions, $this->Paginator->settings['conditions']);
$this->Paginator->settings = array_merge($this->Paginator->settings, $query);
$all_servicechecks = $this->Paginator->paginate(
$this->Servicecheck->alias,
[],
[key($this->Paginator->settings['order'])]
);
$docuExists = $this->Documentation->existsForUuid($service['Service']['uuid']);

//Get meta data and push to front end
$servicestatus = $this->Servicestatus->byUuid($service['Service']['uuid'], [
'fields' => [
'Servicestatus.current_state',
'Servicestatus.is_flapping'
],
]);
$docuExists = $this->Documentation->existsForUuid($service['Service']['uuid']);


$requestSettings = $this->Servicecheck->listSettings($this->request, $service['Service']['uuid']);

$this->Paginator->settings['conditions'] = Hash::merge($this->Paginator->settings['conditions'], $requestSettings['conditions']);
$this->Paginator->settings['order'] = $requestSettings['paginator']['order'];
$this->Paginator->settings['limit'] = $requestSettings['paginator']['limit'];

$all_servicechecks = $this->Paginator->paginate();

$this->set('ServicecheckListsettings', $requestSettings['Listsettings']);
$this->set(compact(['service', 'all_servicechecks', 'servicestatus', 'allowEdit', 'docuExists']));
$this->set(compact(['service', 'all_servicechecks', 'servicestatus', 'docuExists', 'allowEdit']));
$this->set('ServicecheckListsettings', $ServicechecksControllerRequest->getRequestSettingsForListSettings());
}
}
Loading

0 comments on commit 2902095

Please sign in to comment.