diff --git a/app/Controller/AcknowledgementsController.php b/app/Controller/AcknowledgementsController.php index cacfbe0f8d..cd3c9c4986 100644 --- a/app/Controller/AcknowledgementsController.php +++ b/app/Controller/AcknowledgementsController.php @@ -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 { /* @@ -34,6 +37,7 @@ class AcknowledgementsController extends AppController { */ public $uses = [ MONITORING_ACKNOWLEDGED_HOST, + MONITORING_ACKNOWLEDGED_SERVICE, MONITORING_ACKNOWLEDGED, MONITORING_SERVICESTATUS, 'Host', @@ -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' => [ @@ -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' => [ @@ -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; } @@ -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){ diff --git a/app/Controller/Component/ConstantsComponent.php b/app/Controller/Component/ConstantsComponent.php index db25c18f78..4c13c54b34 100644 --- a/app/Controller/Component/ConstantsComponent.php +++ b/app/Controller/Component/ConstantsComponent.php @@ -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', diff --git a/app/Controller/HostsController.php b/app/Controller/HostsController.php index 7dec4f18e7..cb4482b2e8 100644 --- a/app/Controller/HostsController.php +++ b/app/Controller/HostsController.php @@ -78,7 +78,6 @@ class HostsController extends AppController { 'Hostcommandargumentvalue', 'Contact', 'Contactgroup', - MONITORING_ACKNOWLEDGED, MONITORING_ACKNOWLEDGED_HOST, 'DeletedHost', 'DeletedService', @@ -133,7 +132,7 @@ class HostsController extends AppController { [ '0' => [ 'name' => 'Downtime', - 'value' => 0, + 'value' => 1, 'label' => 'In Downtime', 'data' => 'Filter.Hoststatus.scheduled_downtime_depth', ], diff --git a/app/Controller/NotificationsController.php b/app/Controller/NotificationsController.php index 6bbb2ca15d..70fc16302f 100644 --- a/app/Controller/NotificationsController.php +++ b/app/Controller/NotificationsController.php @@ -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' => [ diff --git a/app/Controller/ServicechecksController.php b/app/Controller/ServicechecksController.php index 31bf23bd13..4ba1f38525 100644 --- a/app/Controller/ServicechecksController.php +++ b/app/Controller/ServicechecksController.php @@ -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 @@ -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' => [ @@ -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()); } } diff --git a/app/Controller/ServicesController.php b/app/Controller/ServicesController.php index 30e15b81ed..b8ec1c5cd6 100755 --- a/app/Controller/ServicesController.php +++ b/app/Controller/ServicesController.php @@ -24,6 +24,9 @@ // confirmation. use itnovum\openITCOCKPIT\Core\CustomVariableDiffer; +use itnovum\openITCOCKPIT\Core\ServiceConditions; +use itnovum\openITCOCKPIT\Core\ServiceControllerRequest; +use itnovum\openITCOCKPIT\Core\ValueObjects\User; use itnovum\openITCOCKPIT\Monitoring\QueryHandler; /** @@ -83,7 +86,7 @@ class ServicesController extends AppController { 'Servicetemplateeventcommandargumentvalue', MONITORING_HOSTSTATUS, MONITORING_SERVICESTATUS, - MONITORING_ACKNOWLEDGED, + MONITORING_ACKNOWLEDGED_SERVICE, MONITORING_OBJECTS, 'DeletedService', 'Rrd', @@ -204,144 +207,76 @@ class ServicesController extends AppController { ]; public function index(){ - $this->__unbindAssociations('Host'); - - $this->Service->virtualFields['servicestatus'] = 'Servicestatus.current_state'; - $this->Service->virtualFields['last_hard_state_change'] = 'Servicestatus.last_hard_state_change'; - $this->Service->virtualFields['last_check'] = 'Servicestatus.last_check'; - $this->Service->virtualFields['next_check'] = 'Servicestatus.next_check'; - $this->Service->virtualFields['output'] = 'Servicestatus.output'; - $this->Service->virtualFields['hostname'] = 'Host.name'; - $this->Service->virtualFields['servicename'] = 'IF((Service.name IS NULL OR Service.name=""), Servicetemplate.name, Service.name)'; - $this->Service->virtualFields['keywords'] = 'IF((Service.tags IS NULL OR Service.tags=""), Servicetemplate.tags, Service.tags)'; - - $conditions = [ - 'Service.disabled' => 0, - 'HostsToContainers.container_id' => $this->MY_RIGHTS, - ]; - $conditions = $this->ListFilter->buildConditions($this->request->data, $conditions); - - if (isset($this->request->params['named']['BrowserContainerId'])) { - $containerId = $this->request->params['named']['BrowserContainerId']; - if (!in_array($containerId, $this->MY_RIGHTS)) { - $this->render403(); + $ServiceControllerRequest = new ServiceControllerRequest($this->request); + $ServiceConditions = new ServiceConditions(); + $User = new User($this->Auth); + if ($ServiceControllerRequest->isRequestFromBrowser() === false) { + $ServiceConditions->setIncludeDisabled(false); + $ServiceConditions->setContainerIds($this->MY_RIGHTS); + } + + if ($ServiceControllerRequest->isRequestFromBrowser() === true) { + $browserContainerIds = $ServiceControllerRequest->getBrowserContainerIdsByRequest(); + foreach ($browserContainerIds as $containerIdToCheck) { + if (!in_array($containerIdToCheck, $this->MY_RIGHTS)) { + $this->render403(); + return; + } } - $_conditions = [ - 'Host.disabled' => 0, - //'Host.container_id' => $all_container_ids - 'HostsToContainers.container_id' => $containerId, - ]; - $conditions = Hash::merge($conditions, $_conditions); + $ServiceConditions->setIncludeDisabled(false); + $ServiceConditions->setContainerIds($browserContainerIds); - if ($this->Auth->user('recursive_browser')) { + if ($User->isRecursiveBrowserEnabled()) { //get recursive container ids - $containerIdToResolve = $this->request->params['named']['BrowserContainerId']; - $containerIds = Hash::extract($this->Container->children($containerIdToResolve, false, ['Container.id']), '{n}.Container.id'); + $containerIdToResolve = $browserContainerIds; + $containerIds = Hash::extract($this->Container->children($containerIdToResolve[0], false, ['Container.id']), '{n}.Container.id'); $recursiveContainerIds = []; foreach ($containerIds as $containerId) { if (in_array($containerId, $this->MY_RIGHTS)) { - $recursiveContainerIds['HostsToContainers.container_id'][] = $containerId; + $recursiveContainerIds[] = $containerId; } } - $conditions = array_merge_recursive($conditions, $recursiveContainerIds); + $ServiceConditions->setContainerIds(array_merge($ServiceConditions->getContainerIds(), $recursiveContainerIds)); } } - $all_services = []; - $query = [ - 'recursive' => -1, - 'conditions' => $conditions, - 'contain' => ['Servicetemplate'], - 'fields' => [ - 'Service.id', - 'Service.uuid', - 'Service.name', - 'Service.description', - 'Service.active_checks_enabled', - 'Service.tags', - - 'Servicestatus.current_state', - 'Servicestatus.last_check', - 'Servicestatus.next_check', - 'Servicestatus.last_hard_state_change', - 'Servicestatus.output', - 'Servicestatus.scheduled_downtime_depth', - 'Servicestatus.active_checks_enabled', - 'Servicestatus.state_type', - 'Servicestatus.problem_has_been_acknowledged', - 'Servicestatus.acknowledgement_type', - 'Servicestatus.is_flapping', - - 'Servicetemplate.id', - 'Servicetemplate.uuid', - 'Servicetemplate.name', - 'Servicetemplate.description', - 'Servicetemplate.active_checks_enabled', - 'Servicetemplate.tags', - - 'Host.name', - 'Host.id', - 'Host.uuid', - 'Host.description', - 'Host.address', + //Default order + $ServiceConditions->setOrder($ServiceControllerRequest->getOrder([ + 'Host.name' => 'asc', + 'Service.servicename' => 'asc' + ])); - 'Hoststatus.current_state', + if ($this->DbBackend->isNdoUtils()) { + $query = $this->Service->getServiceIndexQuery($ServiceConditions, $this->ListFilter->buildConditions()); + $this->Service->virtualFieldsForIndexAndServiceList(); + $modelName = 'Service'; + } - 'HostsToContainers.container_id', - ], - 'order' => [ - 'Host.name' => 'asc', - 'Service.servicename' => 'asc', - ], - 'joins' => [[ - 'table' => 'hosts', - 'type' => 'INNER', - 'alias' => 'Host', - 'conditions' => 'Service.host_id = Host.id', - ], [ - 'table' => 'nagios_objects', - 'type' => 'INNER', - 'alias' => 'HostObject', - 'conditions' => 'Host.uuid = HostObject.name1 AND HostObject.objecttype_id = 1', - ], [ - 'table' => 'nagios_hoststatus', - 'type' => 'INNER', - 'alias' => 'Hoststatus', - 'conditions' => 'Hoststatus.host_object_id = HostObject.object_id', - ], [ - 'table' => 'nagios_objects', - 'type' => 'INNER', - 'alias' => 'ServiceObject', - 'conditions' => 'ServiceObject.name1 = Host.uuid AND Service.uuid = ServiceObject.name2 AND ServiceObject.objecttype_id = 2', - ], [ - 'table' => 'nagios_servicestatus', - 'type' => 'LEFT OUTER', - 'alias' => 'Servicestatus', - 'conditions' => 'Servicestatus.service_object_id = ServiceObject.object_id', - ], [ - 'table' => 'hosts_to_containers', - 'alias' => 'HostsToContainers', - 'type' => 'LEFT', - 'conditions' => [ - 'HostsToContainers.host_id = Host.id', - ], - ], - ], - 'group' => [ - 'Service.id', - ], - ]; + if ($this->DbBackend->isCrateDb()) { + $this->Servicestatus->virtualFieldsForIndexAndServiceList(); + $query = $this->Servicestatus->getServiceIndexQuery($ServiceConditions, $this->ListFilter->buildConditions()); + $modelName = 'Servicestatus'; + } if ($this->isApiRequest()) { - unset($query['limit']); - $all_services = $this->Service->find('all', $query); + if(isset($query['limit'])){ + unset($query['limit']); + } + $all_services = $this->{$modelName}->find('all', $query); } else { $this->Paginator->settings = array_merge($this->Paginator->settings, $query); - $all_services = $this->Paginator->paginate(); + $all_services = $this->Paginator->paginate($modelName, [], [key($this->Paginator->settings['order'])]); } + + $this->set('all_services', $all_services); + $this->set('_serialize', ['all_services']); + $this->set('username', $User->getFullName()); + $this->set('QueryHandler', new QueryHandler($this->Systemsetting->getQueryHandlerPath())); + + //lookup host containers for edit permissions $hostContainers = []; - if (!empty($all_services)) { + if (!empty($all_services) && $this->hasRootPrivileges === false) { $hostIds = array_unique(Hash::extract($all_services, '{n}.Host.id')); $_hostContainers = $this->Host->find('all', [ 'contain' => [ @@ -358,25 +293,9 @@ public function index(){ foreach ($_hostContainers as $host) { $hostContainers[$host['Host']['id']] = Hash::extract($host['Container'], '{n}.id'); } - } - $username = $this->Auth->user('full_name'); - - $this->set(compact(['all_services', 'username', 'hostContainers'])); - //Aufruf für json oder xml view: /nagios_module/hosts.json oder /nagios_module/hosts.xml - $this->set('_serialize', ['all_services']); - - if (isset($this->request->data['Filter']) && $this->request->data['Filter'] !== null) { - if (isset($this->request->data['Filter']['ServiceStatus']['current_state'])) { - $this->set('HostStatus.current_state', $this->request->data['Filter']['HostStatus']['current_state']); - } else { - $this->set('ServiceStatus.current_state', []); - } - $this->set('isFilter', true); - } else { - $this->set('isFilter', false); + $this->set('hostContainers', $hostContainers); } - $this->set('QueryHandler', new QueryHandler($this->Systemsetting->getQueryHandlerPath())); } public function view($id = null){ @@ -715,7 +634,6 @@ public function add(){ if (!empty($this->request->params['pass'])) { $hostId = $this->request->params['pass'][0]; } - //debug($hostId); //Fix that we dont lose any unsaved host macros, because of vaildation error if (isset($this->request->data['Customvariable'])) { @@ -1029,9 +947,7 @@ public function edit($id = null){ 'Service.id', ], ]); - //debug($serviceContactsAndContactgroups); $ContactsInherited = $this->__inheritContactsAndContactgroups($service, $serviceContactsAndContactgroups); - //debug($ContactsInherited); $this->Frontend->setJson('ContactsInherited', $ContactsInherited); $this->set(compact( @@ -2132,11 +2048,10 @@ function browser($id = null){ $servicestatus = $this->Servicestatus->byUuid($service['Service']['uuid']); $hoststatus = $this->Hoststatus->byUuid($service['Host']['uuid']); - $acknowledged = []; if (isset($servicestatus['Servicestatus']) && $servicestatus['Servicestatus']['problem_has_been_acknowledged'] > 0) { - $acknowledged = $this->Acknowledged->byUuid($service['Service']['uuid']); - if (!empty($acknowledged[0])) { - $acknowledged = $acknowledged[0]; + $acknowledged = $this->AcknowledgedService->byUuid($service['Service']['uuid']); + if (empty($acknowledged)) { + $acknowledged = []; } } $ticketSystem = $this->Systemsetting->find('first', [ @@ -2242,14 +2157,24 @@ public function serviceList($host_id){ throw new NotFoundException(__('Invalid host')); } - $disabledServices = $this->Service->findAllByHostIdAndDisabled($host_id, 1); - $deletedServices = $this->DeletedService->findAllByHostId($host_id); - $this->Host->unbindModel([ - 'hasAndBelongsToMany' => ['Contactgroup', 'Contact', 'Parenthost', 'Hostgroup'], - 'hasMany' => ['Hostcommandargumentvalue', 'HostescalationHostMembership', 'HostdependencyHostMembership', 'Customvariable'], - 'belongsTo' => ['CheckPeriod', 'NotifyPeriod', 'CheckCommand'], + $host = $this->Host->find('first', [ + 'fields' => [ + 'Host.id', + 'Host.uuid', + 'Host.name', + 'Host.address', + 'Host.host_url', + 'Host.container_id', + ], + 'conditions' => [ + 'Host.id' => $host_id, + ], + 'contain' => [ + 'Container', + ], ]); - $host = $this->Host->findById($host_id); + + //Check if user is permitted to see this object $containerIdsToCheck = Hash::extract($host, 'Container.{n}.HostsToContainer.container_id'); $containerIdsToCheck[] = $host['Host']['container_id']; if (!$this->allowedByContainerId($containerIdsToCheck, false)) { @@ -2258,6 +2183,36 @@ public function serviceList($host_id){ return; } + $disabledServices = $this->Service->find('all', [ + 'recursive' => -1, + 'conditions' => [ + 'Service.host_id' => $host_id, + 'Service.disabled' => 1 + ], + 'contain' => [ + 'Host' => [ + 'fields' => [ + 'Host.id', + 'Host.uuid', + 'Host.name' + ] + ], + 'Servicetemplate' => [ + 'fields' => [ + 'Servicetemplate.id', + 'Servicetemplate.name' + ] + ] + ], + 'fields' => [ + 'Service.id', + 'Service.uuid', + 'Service.name' + ] + ]); + $deletedServices = $this->DeletedService->findAllByHostId($host_id); + + $allowEdit = false; if ($this->allowedByContainerId($containerIdsToCheck)) { $allowEdit = true; @@ -2266,97 +2221,43 @@ public function serviceList($host_id){ $containerIds = $this->Tree->resolveChildrenOfContainerIds($this->MY_RIGHTS); $hosts = $this->Host->hostsByContainerId($containerIds, 'list'); - $this->Service->virtualFields['servicestatus'] = 'Servicestatus.current_state'; - $this->Service->virtualFields['last_hard_state_change'] = 'Servicestatus.last_hard_state_change'; - $this->Service->virtualFields['last_check'] = 'Servicestatus.last_check'; - $this->Service->virtualFields['next_check'] = 'Servicestatus.next_check'; - $this->Service->virtualFields['output'] = 'Servicestatus.output'; - $this->Service->virtualFields['hostname'] = 'Host.name'; - $this->Service->virtualFields['servicename'] = 'IF((Service.name IS NULL OR Service.name=""), Servicetemplate.name, Service.name)'; - $all_services = []; - $query = [ -// 'recursive' => -1, - 'contain' => ['Servicetemplate'], - 'fields' => [ - 'Service.id', - 'Service.uuid', - 'Service.name', - 'Service.description', - 'Service.active_checks_enabled', + $ServiceControllerRequest = new ServiceControllerRequest($this->request); + $ServiceConditions = new ServiceConditions(); + $User = new User($this->Auth); + $ServiceConditions->setIncludeDisabled(false); + $ServiceConditions->setContainerIds($this->MY_RIGHTS); + $ServiceConditions->setHostId($host_id); - 'Servicestatus.current_state', - 'Servicestatus.last_check', - 'Servicestatus.next_check', - 'Servicestatus.last_hard_state_change', - 'Servicestatus.output', - 'Servicestatus.scheduled_downtime_depth', - 'Servicestatus.active_checks_enabled', - 'Servicestatus.state_type', - 'Servicestatus.problem_has_been_acknowledged', - 'Servicestatus.acknowledgement_type', - 'Servicestatus.is_flapping', - 'Servicetemplate.id', - 'Servicetemplate.uuid', - 'Servicetemplate.name', - 'Servicetemplate.description', - 'Servicetemplate.active_checks_enabled', + //Default order + $ServiceConditions->setOrder($ServiceControllerRequest->getOrder([ + 'Service.servicename' => 'asc' + ])); - 'Host.name', - 'Host.id', - 'Host.uuid', - 'Host.description', - 'Host.address', + if ($this->DbBackend->isNdoUtils()) { + $query = $this->Service->getServiceIndexQuery($ServiceConditions, $this->ListFilter->buildConditions()); + $this->Service->virtualFieldsForIndexAndServiceList(); + $modelName = 'Service'; + } - 'Hoststatus.current_state', - ], - 'order' => ['Service.servicename' => 'asc'], - 'joins' => [ - [ - 'table' => 'hosts', - 'type' => 'INNER', - 'alias' => 'Host', - 'conditions' => 'Service.host_id = Host.id', - ], [ - 'table' => 'nagios_objects', - 'type' => 'LEFT OUTER', - 'alias' => 'HostObject', - 'conditions' => 'Host.uuid = HostObject.name1 AND HostObject.objecttype_id = 1', - ], [ - 'table' => 'nagios_hoststatus', - 'type' => 'LEFT OUTER', - 'alias' => 'Hoststatus', - 'conditions' => 'Hoststatus.host_object_id = HostObject.object_id', - ], [ - 'table' => 'nagios_objects', - 'type' => 'LEFT OUTER', - 'alias' => 'ServiceObject', - 'conditions' => 'ServiceObject.name1 = Host.uuid AND Service.uuid = ServiceObject.name2 AND ServiceObject.objecttype_id = 2', - ], [ - 'table' => 'nagios_servicestatus', - 'type' => 'LEFT OUTER', - 'alias' => 'Servicestatus', - 'conditions' => 'Servicestatus.service_object_id = ServiceObject.object_id', - ], - ], - 'conditions' => [ - 'Host.id' => $host_id, - ], - ]; + if ($this->DbBackend->isCrateDb()) { + $this->Servicestatus->virtualFieldsForIndexAndServiceList(); + $query = $this->Servicestatus->getServiceIndexQuery($ServiceConditions, $this->ListFilter->buildConditions()); + $modelName = 'Servicestatus'; + } if ($this->isApiRequest()) { - unset($query['limit']); - $all_services = $this->Service->find('all', $query); + if(isset($query['limit'])){ + unset($query['limit']); + } + $all_services = $this->{$modelName}->find('all', $query); } else { - $activeServices = ['conditions' => [ - 'Host.id' => $host_id, - 'Service.disabled' => 0, - ]]; - $this->Paginator->settings = array_merge($this->Paginator->settings, $query, $activeServices); - $all_services = $this->Paginator->paginate(); + $this->Paginator->settings = array_merge($this->Paginator->settings, $query); + $all_services = $this->Paginator->paginate($modelName, [], [key($this->Paginator->settings['order'])]); } + $this->Frontend->setJson('hostUuid', $host['Host']['uuid']); $username = $this->Auth->user('full_name'); @@ -2366,16 +2267,6 @@ public function serviceList($host_id){ $this->set('_serialize', ['all_services']); } - //public function pnp($id){ - // if(!$this->Service->exists($id)){ - // throw new NotFoundException(__('Invalid service')); - // } - // - // $service = $this->Service->findById($id); - // $servicestatus = $this->Servicestatus->byUuid($service['Service']['uuid']); - // $acknowledged = $this->Acknowledged->byUuid($service['Service']['uuid']); - // $this->set(compact(['service', 'servicestatus', 'acknowledged'])); - //} public function grapherSwitch($id){ if (!$this->Service->exists($id)) { @@ -2430,8 +2321,7 @@ public function grapher($id){ } $servicestatus = $this->Servicestatus->byUuid($service['Service']['uuid']); - $acknowledged = $this->Acknowledged->byUuid($service['Service']['uuid']); - $this->set(compact(['service', 'servicestatus', 'acknowledged', 'allowEdit', 'services', 'docuExists'])); + $this->set(compact(['service', 'servicestatus', 'allowEdit', 'services', 'docuExists'])); } public function grapherTemplate($id){ @@ -2447,7 +2337,6 @@ public function grapherTemplate($id){ $service = $this->Service->findById($id); $docuExists = $this->Documentation->existsForUuid($service['Service']['uuid']); $servicestatus = $this->Servicestatus->byUuid($service['Service']['uuid']); - $acknowledged = $this->Acknowledged->byUuid($service['Service']['uuid']); $commandUuid = $service['CheckCommand']['uuid']; if ($commandUuid == null || $commandUuid == '') { @@ -2455,7 +2344,7 @@ public function grapherTemplate($id){ $commandUuid = $servicetemplate['CheckCommand']['uuid']; } - $this->set(compact(['service', 'servicestatus', 'acknowledged', 'commandUuid', 'docuExists'])); + $this->set(compact(['service', 'servicestatus', 'commandUuid', 'docuExists'])); } public function grapherZoom($id, $ds, $newStart, $newEnd){ diff --git a/app/Controller/StatehistoriesController.php b/app/Controller/StatehistoriesController.php index 5a469e20e5..4e5c0a4111 100644 --- a/app/Controller/StatehistoriesController.php +++ b/app/Controller/StatehistoriesController.php @@ -25,7 +25,10 @@ use itnovum\openITCOCKPIT\Core\StatehistoryControllerRequest; use itnovum\openITCOCKPIT\Core\StatehistoryHostConditions; +use itnovum\openITCOCKPIT\Core\StatehistoryServiceConditions; +use itnovum\openITCOCKPIT\Core\StatehistoryServiceControllerRequest; use itnovum\openITCOCKPIT\Core\ValueObjects\HostStates; +use itnovum\openITCOCKPIT\Core\ValueObjects\ServiceStates; use itnovum\openITCOCKPIT\Core\ValueObjects\StateTypes; class StatehistoriesController extends AppController { @@ -35,6 +38,7 @@ class StatehistoriesController extends AppController { */ public $uses = [ MONITORING_STATEHISTORY_HOST, + MONITORING_STATEHISTORY_SERVICE, MONITORING_STATEHISTORY, MONITORING_SERVICESTATUS, MONITORING_HOSTSTATUS, @@ -51,7 +55,7 @@ class StatehistoriesController extends AppController { public $listFilters = [ 'service' => [ 'fields' => [ - 'Statehistory.output' => ['label' => 'Output', 'searchType' => 'wildcard'], + 'StatehistoryService.output' => ['label' => 'Output', 'searchType' => 'wildcard'], ], ], 'host' => [ @@ -66,10 +70,33 @@ public function service($id = null){ throw new NotFoundException(__('invalid service')); } + //Process request and set request settings back to front end + $ServiceStates = new ServiceStates(); + $StateTypes = new StateTypes(); + $StatehistoryRequest = new StatehistoryServiceControllerRequest( + $this->request, + $ServiceStates, + $StateTypes, + $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' => [ @@ -90,7 +117,6 @@ public function service($id = null){ //Check if user is permitted to see this object if (!$this->allowedByContainerId($containerIdsToCheck, false)) { $this->render403(); - return; } @@ -100,39 +126,36 @@ public function service($id = null){ $allowEdit = true; } + + //Process conditions + $Conditions = new StatehistoryServiceConditions(); + $Conditions->setLimit($StatehistoryRequest->getLimit()); + $Conditions->setOrder($StatehistoryRequest->getOrder()); + $Conditions->setStates($StatehistoryRequest->getServiceStates()); + $Conditions->setStateTypes($StatehistoryRequest->getStateTypes()); + $Conditions->setFrom($StatehistoryRequest->getFrom()); + $Conditions->setTo($StatehistoryRequest->getTo()); + $Conditions->setServiceUuid($service['Service']['uuid']); + + //Query state history records + $query = $this->StatehistoryService->getQuery($Conditions, $this->Paginator->settings['conditions']); + $this->Paginator->settings = array_merge($this->Paginator->settings, $query); + $all_statehistories = $this->Paginator->paginate( + $this->StatehistoryService->alias, + [], + [key($this->Paginator->settings['order'])] + ); + + //Get meta data and push to front end $servicestatus = $this->Servicestatus->byUuid($service['Service']['uuid'], [ 'fields' => [ 'Servicestatus.current_state', + 'Servicestatus.is_flapping' ], ]); - - - $requestSettings = $this->Statehistory->listSettings($this->request, $service['Service']['uuid'], $service['Host']['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['conditions'] = Hash::merge($this->Paginator->settings['conditions'], $requestSettings['conditions']); - - //SQL Clenup - if (isset($this->Paginator->settings['conditions']['Statehistory.state'])) { - $this->Paginator->settings['conditions']['Statehistory.state'] = array_unique($this->Paginator->settings['conditions']['Statehistory.state']); - } - if (isset($this->Paginator->settings['conditions']['Statehistory.state_type'])) { - $this->Paginator->settings['conditions']['Statehistory.state_type'] = array_unique($this->Paginator->settings['conditions']['Statehistory.state_type']); - } - - $this->Paginator->settings['order'] = $requestSettings['paginator']['order']; - $this->Paginator->settings['limit'] = $requestSettings['paginator']['limit']; - - $all_statehistories = $this->Paginator->paginate($this->Statehistory->alias); $docuExists = $this->Documentation->existsForUuid($service['Service']['uuid']); - - $this->set(compact(['service', 'all_statehistories', 'servicestatus', 'allowEdit', 'docuExists'])); - $this->set('StatehistoryListsettings', $requestSettings['Listsettings']); + $this->set(compact(['service', 'all_statehistories', 'servicestatus', 'docuExists', 'allowEdit'])); + $this->set('StatehistoryListsettings', $StatehistoryRequest->getRequestSettingsForListSettings()); } public function host($id = null){ diff --git a/app/Model/Host.php b/app/Model/Host.php index ca140f8070..d1ced8cd15 100755 --- a/app/Model/Host.php +++ b/app/Model/Host.php @@ -1294,6 +1294,7 @@ public function getHostIndexQuery(HostConditions $HostConditions, $conditions = 'Hoststatus.last_check', 'Hoststatus.next_check', 'Hoststatus.last_hard_state_change', + 'Hoststatus.last_state_change', 'Hoststatus.output', 'Hoststatus.scheduled_downtime_depth', 'Hoststatus.active_checks_enabled', diff --git a/app/Model/Service.php b/app/Model/Service.php index a89917b171..88e8e3e095 100755 --- a/app/Model/Service.php +++ b/app/Model/Service.php @@ -23,6 +23,8 @@ // License agreement and license key will be shipped with the order // confirmation. +use itnovum\openITCOCKPIT\Core\ServiceConditions; + class Service extends AppModel { public $hasAndBelongsToMany = [ @@ -1210,4 +1212,108 @@ public function checkUsageFlag($serviceId, $moduleValue) { return false; } } + + public function virtualFieldsForIndexAndServiceList(){ + $this->virtualFields['servicename'] = 'IF((Service.name IS NULL OR Service.name=""), Servicetemplate.name, Service.name)'; + $this->virtualFields['keywords'] = 'IF((Service.tags IS NULL OR Service.tags=""), Servicetemplate.tags, Service.tags)'; + } + + /** + * @param ServiceConditions $ServiceConditions + * @param array $conditions + * @return array + */ + public function getServiceIndexQuery(ServiceConditions $ServiceConditions, $conditions = []){ + $query = [ + 'recursive' => -1, + 'conditions' => $conditions, + 'contain' => ['Servicetemplate'], + 'fields' => [ + 'Service.id', + 'Service.uuid', + 'Service.name', + 'Service.description', + 'Service.active_checks_enabled', + 'Service.tags', + + 'Servicestatus.current_state', + 'Servicestatus.last_check', + 'Servicestatus.next_check', + 'Servicestatus.last_hard_state_change', + 'Servicestatus.last_state_change', + 'Servicestatus.output', + 'Servicestatus.scheduled_downtime_depth', + 'Servicestatus.active_checks_enabled', + 'Servicestatus.state_type', + 'Servicestatus.problem_has_been_acknowledged', + 'Servicestatus.acknowledgement_type', + 'Servicestatus.is_flapping', + + 'Servicetemplate.id', + 'Servicetemplate.uuid', + 'Servicetemplate.name', + 'Servicetemplate.description', + 'Servicetemplate.active_checks_enabled', + 'Servicetemplate.tags', + + 'Host.name', + 'Host.id', + 'Host.uuid', + 'Host.description', + 'Host.address', + + 'Hoststatus.current_state', + + 'HostsToContainers.container_id', + ], + 'order' => $ServiceConditions->getOrder(), + 'joins' => [[ + 'table' => 'hosts', + 'type' => 'INNER', + 'alias' => 'Host', + 'conditions' => 'Service.host_id = Host.id', + ], [ + 'table' => 'nagios_objects', + 'type' => 'INNER', + 'alias' => 'HostObject', + 'conditions' => 'Host.uuid = HostObject.name1 AND HostObject.objecttype_id = 1', + ], [ + 'table' => 'nagios_hoststatus', + 'type' => 'INNER', + 'alias' => 'Hoststatus', + 'conditions' => 'Hoststatus.host_object_id = HostObject.object_id', + ], [ + 'table' => 'nagios_objects', + 'type' => 'INNER', + 'alias' => 'ServiceObject', + 'conditions' => 'ServiceObject.name1 = Host.uuid AND Service.uuid = ServiceObject.name2 AND ServiceObject.objecttype_id = 2', + ], [ + 'table' => 'nagios_servicestatus', + 'type' => 'LEFT OUTER', + 'alias' => 'Servicestatus', + 'conditions' => 'Servicestatus.service_object_id = ServiceObject.object_id', + ], [ + 'table' => 'hosts_to_containers', + 'alias' => 'HostsToContainers', + 'type' => 'LEFT', + 'conditions' => [ + 'HostsToContainers.host_id = Host.id', + ], + ], + ], + 'group' => [ + 'Service.id', + ], + ]; + + $query['conditions']['Service.disabled'] = (int)$ServiceConditions->includeDisabled(); + $query['conditions']['HostsToContainers.container_id'] = $ServiceConditions->getContainerIds(); + + if($ServiceConditions->getHostId()){ + $query['conditions']['Service.host_id'] = $ServiceConditions->getHostId(); + } + + return $query; + + } } diff --git a/app/Plugin/CrateModule/Console/Command/SyncTablesShell.php b/app/Plugin/CrateModule/Console/Command/SyncTablesShell.php index 24ff96de41..43ba716b3b 100644 --- a/app/Plugin/CrateModule/Console/Command/SyncTablesShell.php +++ b/app/Plugin/CrateModule/Console/Command/SyncTablesShell.php @@ -191,11 +191,25 @@ public function syncServices(){ foreach ($services as $service) { $serviceName = $service['Service']['name']; $nameFromTemplate = false; - if($serviceName === null || $serviceName === ''){ + if ($serviceName === null || $serviceName === '') { $serviceName = $service['Servicetemplate']['name']; $nameFromTemplate = true; } + $activeChecksEnabled = $service['Service']['active_checks_enabled']; + $activeChecksEnabledFromTemplate = false; + if ($activeChecksEnabled === null || $activeChecksEnabled === '') { + $activeChecksEnabled = $service['Servicetemplate']['active_checks_enabled']; + $activeChecksEnabledFromTemplate = true; + } + + $tags = $service['Service']['tags']; + $tagFromTemplate = false; + if ($tags === null || $tags === '') { + $tags = $service['Servicetemplate']['tags']; + $tagFromTemplate = true; + } + $crateService[] = [ 'CrateService' => [ 'id' => (int)$service['Service']['id'], @@ -204,6 +218,10 @@ public function syncServices(){ 'servicetemplate_id' => (int)$service['Service']['servicetemplate_id'], 'host_id' => (int)$service['Service']['host_id'], 'name_from_template' => $nameFromTemplate, + 'active_checks_enabled' => $activeChecksEnabled, + 'active_checks_enabled_from_template' => $activeChecksEnabledFromTemplate, + 'tags' => $tags, + 'tags_from_template' => $tagFromTemplate ] ]; } diff --git a/app/Plugin/CrateModule/Model/AcknowledgedService.php b/app/Plugin/CrateModule/Model/AcknowledgedService.php new file mode 100644 index 0000000000..e8d6c51af2 --- /dev/null +++ b/app/Plugin/CrateModule/Model/AcknowledgedService.php @@ -0,0 +1,88 @@ + +// +// This file is dual licensed +// +// 1. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 3 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +// 2. +// If you purchased an openITCOCKPIT Enterprise Edition you can use this file +// under the terms of the openITCOCKPIT Enterprise Edition license agreement. +// License agreement and license key will be shipped with the order +// confirmation. + +use \itnovum\openITCOCKPIT\Core\AcknowledgedServiceConditions; + +class AcknowledgedService extends CrateModuleAppModel { + public $useDbConfig = 'Crate'; + public $useTable = 'service_acknowledgements'; + public $tablePrefix = 'statusengine_'; + + /** + * @param null $uuid + * @return array|null + */ + public function byUuid($uuid = null){ + return $this->byServiceUuid($uuid); + } + /** + * @param string $uuid + * @return array|null + */ + public function byServiceUuid($uuid = null){ + $return = []; + if ($uuid !== null) { + $acknowledged = $this->find('first', [ + 'conditions' => [ + 'service_description' => $uuid, + ], + 'order' => [ + 'AcknowledgedService.entry_time' => 'DESC', + ], + ]); + + return $acknowledged; + + } + + return $return; + } + + /** + * @param AcknowledgedServiceConditions $AcknowledgedServiceConditions + * @param array $paginatorConditions + * @return array + */ + public function getQuery(AcknowledgedServiceConditions $AcknowledgedServiceConditions, $paginatorConditions = []){ + $query = [ + 'conditions' => [ + 'service_description' => $AcknowledgedServiceConditions->getServiceUuid(), + 'entry_time >' => $AcknowledgedServiceConditions->getFrom(), + 'entry_time <' => $AcknowledgedServiceConditions->getTo() + ], + 'order' => $AcknowledgedServiceConditions->getOrder(), + 'limit' => $AcknowledgedServiceConditions->getLimit(), + ]; + + if (!empty($AcknowledgedServiceConditions->getStates())) { + $query['conditions']['state'] = $AcknowledgedServiceConditions->getStates(); + } + + //Merge ListFilter conditions + $query['conditions'] = Hash::merge($paginatorConditions, $query['conditions']); + + return $query; + } +} diff --git a/app/Plugin/CrateModule/Model/CrateService.php b/app/Plugin/CrateModule/Model/CrateService.php index 86bdf32f41..bdf2047093 100644 --- a/app/Plugin/CrateModule/Model/CrateService.php +++ b/app/Plugin/CrateModule/Model/CrateService.php @@ -23,11 +23,11 @@ // confirmation. - class CrateService extends CrateModuleAppModel { public $useDbConfig = 'Crate'; public $useTable = 'services'; public $tablePrefix = 'openitcockpit_'; + } diff --git a/app/Plugin/CrateModule/Model/Datasource/Crate.php b/app/Plugin/CrateModule/Model/Datasource/Crate.php index 225ecadc68..f7ae1147e0 100644 --- a/app/Plugin/CrateModule/Model/Datasource/Crate.php +++ b/app/Plugin/CrateModule/Model/Datasource/Crate.php @@ -75,6 +75,11 @@ class Crate extends DboSource { 'offset' => null ); + /** + * @var array + */ + private $fieldsInQuery = []; + /** * @var array @@ -263,12 +268,14 @@ public function read(Model $Model, $queryData = array(), $recursive = null){ $this->tablePrefix = $Model->tablePrefix; $this->joins = $queryData['joins']; + $this->Model = $Model; if (!isset($this->tableMetaData[$this->modelName])) { $this->getTableMetaInformation($this->tablePrefix . $this->tableName); } + $this->joinedModels = []; foreach ($queryData['joins'] as $join) { $fakeModel = new stdClass(); $fakeModel->alias = $join['alias']; @@ -277,7 +284,9 @@ public function read(Model $Model, $queryData = array(), $recursive = null){ } if (empty($queryData['fields'])) { - $queryData['fields'] = ['*']; + $queryData['fields'] = [ + sprintf('%s.*', $this->modelName) + ]; } if (!empty($this->Model->virtualFields) && $this->findType !== 'count') { @@ -290,10 +299,6 @@ public function read(Model $Model, $queryData = array(), $recursive = null){ } } - //if (!empty($queryData['joins'])) { - // throw new NotImplementedException('joins are not implemented now'); - //} - if (!empty($queryData['sort']) && !empty($queryData['direction'])) { $queryData['order'] = [ $queryData['sort'] => $queryData['direction'] @@ -312,6 +317,39 @@ public function buildSelectQuery($queryData){ $queryTemplate = sprintf($queryTemplate, implode(',', $queryData['fields']), $this->tablePrefix . $this->tableName, $this->modelName); } + $this->fieldsInQuery = []; + if ($this->findType !== 'count') { + $modelsInQuery = array_merge($this->joinedModels, [$this->modelName]); + + foreach ($queryData['fields'] as $fieldInQuery) { + $fieldInQuery = trim($fieldInQuery); + + foreach ($modelsInQuery as $modelInQuery) { + if (strpos($fieldInQuery, $modelInQuery . '.') !== 0) { + continue; + } + if ($fieldInQuery === sprintf('%s.*', $modelInQuery)) { + //User run SELECT * FROM - add all fields + foreach ($this->tableMetaData[$modelInQuery] as $column) { + $this->fieldsInQuery[] = sprintf('%s.%s', $modelInQuery, $column['column_name']); + } + } else { + $isVirtualField = false; + foreach ($this->Model->virtualFields as $virtualField => $realField) { + if ($fieldInQuery === sprintf('%s AS %s', $realField, $virtualField)) { + $isVirtualField = true; + $this->fieldsInQuery[] = sprintf('%s.%s', $this->modelName, $virtualField); + } + } + + if ($isVirtualField === false) { + $this->fieldsInQuery[] = $fieldInQuery; + } + } + } + } + } + foreach ($queryData['joins'] as $join) { //INNER JOIN statusengine_hoststatus as Hoststatus on Hoststatus.hostname = Host.uuid $queryTemplate = sprintf( @@ -330,7 +368,14 @@ public function buildSelectQuery($queryData){ foreach ($queryData['conditions'] as $column => $condition) { $result = $this->_parseKey($column, $condition, $this->Model); $column = $result['key']; - if ($this->columnExists($column)) { + + $isVirtualField = false; + if($this->isVirtualField($column)){ + $isVirtualField = true; + $column = sprintf('%s%s%s', $this->startQuote, $column, $this->endQuote); + } + + if ($this->columnExists($column) || $isVirtualField === true) { if ($i === 1) { if (is_array($result['value'])) { $placeholders = []; @@ -338,14 +383,14 @@ public function buildSelectQuery($queryData){ $placeholders[] = '?'; } $hasWhere = true; - $queryTemplate = sprintf('%s WHERE %s %s (%s)', $queryTemplate, $result['key'], $result['operator'], implode(', ', $placeholders)); + $queryTemplate = sprintf('%s WHERE %s %s (%s)', $queryTemplate, $column, $result['operator'], implode(', ', $placeholders)); } else { $hasWhere = true; if ($result['value'] !== null) { - $queryTemplate = sprintf('%s WHERE %s %s ?', $queryTemplate, $result['key'], $result['operator']); + $queryTemplate = sprintf('%s WHERE %s %s ?', $queryTemplate, $column, $result['operator']); } else { - $queryTemplate = sprintf('%s WHERE %s %s', $queryTemplate, $result['key'], $result['operator']); + $queryTemplate = sprintf('%s WHERE %s %s', $queryTemplate, $column, $result['operator']); } } } else { @@ -354,12 +399,12 @@ public function buildSelectQuery($queryData){ foreach ($result['value'] as $value) { $placeholders[] = '?'; } - $queryTemplate = sprintf('%s AND %s %s (%s)', $queryTemplate, $result['key'], $result['operator'], implode(', ', $placeholders)); + $queryTemplate = sprintf('%s AND %s %s (%s)', $queryTemplate, $column, $result['operator'], implode(', ', $placeholders)); } else { if ($result['value'] !== null) { - $queryTemplate = sprintf('%s AND %s %s ?', $queryTemplate, $result['key'], $result['operator']); + $queryTemplate = sprintf('%s AND %s %s ?', $queryTemplate, $column, $result['operator']); } else { - $queryTemplate = sprintf('%s AND %s %s', $queryTemplate, $result['key'], $result['operator']); + $queryTemplate = sprintf('%s AND %s %s', $queryTemplate, $column, $result['operator']); } } } @@ -404,11 +449,17 @@ public function buildSelectQuery($queryData){ $column = $this->removeModelAlias($column); } - if ($this->columnExists($column)) { $direction = $this->getDirection($direction); $orderBy[] = sprintf('%s %s', $column, $direction); } + + if($this->isVirtualField($column)){ + $column = sprintf('%s%s%s', $this->startQuote, $column, $this->endQuote); + $direction = $this->getDirection($direction); + $orderBy[] = sprintf('%s %s', $column, $direction); + } + } if (!empty($orderBy)) { @@ -432,11 +483,22 @@ public function buildSelectQuery($queryData){ foreach ($queryData['conditions'] as $column => $condition) { $result = $this->_parseKey($column, $condition, $this->Model); $column = $result['key']; - if ($this->columnExists($column)) { + + $isVirtualField = false; + if($this->isVirtualField($column)){ + $isVirtualField = true; + } + + if ($this->columnExists($column) || $isVirtualField === true) { if (is_array($result['value'])) { foreach ($result['value'] as $value) { - $query->bindValue($i++, $value); - $attachedParameters[] = $value; + if (is_bool($value)) { + $query->bindValue($i++, $value, PDO::PARAM_BOOL); + $attachedParameters[] = $value ? 'true' : 'false'; + } else { + $query->bindValue($i++, $value); + $attachedParameters[] = $value; + } } } elseif (is_bool($result['value'])) { $query->bindValue($i++, $result['value'], PDO::PARAM_BOOL); @@ -550,6 +612,20 @@ public function buildInsertQuery($Model, $fields, $values){ * @return bool */ public function isVirtualField($columnName){ + if (isset($this->Model->virtualFields[$columnName])) { + return true; + } + + $columnNameQuoted = sprintf('%s%s%s', + $this->startQuote, + $columnName, + $this->endQuote + ); + if (isset($this->Model->virtualFields[$columnNameQuoted])) { + return true; + } + + $key = $this->modelName . '.'; if (strpos($columnName, $key, 0) === 0) { $columnName = substr($columnName, strlen($key)); @@ -772,7 +848,6 @@ public function executeQuery(PDOStatement $query, $sql, $options = array(), $par $t = microtime(true); $this->_result = $this->__execute($query, $sql); - if ($options['log']) { $this->took = round((microtime(true) - $t) * 1000, 0); $this->numRows = $this->affected = $this->lastAffected(); @@ -787,9 +862,12 @@ public function executeQuery(PDOStatement $query, $sql, $options = array(), $par */ public function fetchAllCrate(){ if ($this->hasResult()) { - $this->_result->setFetchMode(PDO::FETCH_ASSOC); + if ($this->findType === 'count') { + $this->_result->setFetchMode(PDO::FETCH_ASSOC); + } else { + $this->_result->setFetchMode(PDO::FETCH_NUM); + } $dbResult = $this->_result->fetchAll(); - if ($this->findType === 'count') { $count = 0; if (isset($dbResult[0]['count'])) { @@ -804,6 +882,14 @@ public function fetchAllCrate(){ ]; } + $merge = []; + foreach ($dbResult as $record) { + $merge[] = array_combine($this->fieldsInQuery, $record); + } + + $dbResult = $merge; + unset($merge); + if ($this->findType === 'first' && isset($dbResult[0])) { if (!empty($this->joins)) { return $this->formatResultFindAllWithJoins($dbResult); @@ -831,6 +917,7 @@ public function formatResultFindAllWithJoins($dbResult = []){ $results = []; $fields = []; + foreach ($this->tableMetaData[$this->modelName] as $column) { $fields[$this->modelName][] = $column['column_name']; } @@ -841,32 +928,35 @@ public function formatResultFindAllWithJoins($dbResult = []){ } } - foreach ($dbResult as $record) { - foreach ($record as $field => $value) { - $result = []; - foreach ($fields as $modelName => $fieldsFromModel) { - $result[$modelName] = Set::classicExtract($record, '{(' . implode('|', array_values($fieldsFromModel)) . ')}'); - } + foreach ($this->Model->virtualFields as $virtualField => $realField) { + $modelSplit = explode('.', $realField, 2); + $modelName = $this->modelName; + if (sizeof($modelSplit) == 2) { + $modelName = $modelSplit[0]; } - //Check for Joind fields, with same name - if(!empty($this->joins)){ - foreach ($record as $field => $value) { - foreach ($this->joins as $join) { - foreach ($this->tableMetaData[$join['alias']] as $column) { - $ModelNameAndFieldName = sprintf('%s.%s', $join['alias'], $column['column_name']); - if ($field == $ModelNameAndFieldName) { - $result[$join['alias']][$column['column_name']] = $value; - } - } + $key = $modelName . '.'; + $realColumnName = substr($realField, strlen($key)); + + $fields[$modelName][] = sprintf('%s AS %s', $realColumnName, $virtualField); + } + + foreach ($dbResult as $record) { + $result = []; + foreach ($fields as $modelName => $fieldsFromModel) { + foreach ($fieldsFromModel as $column) { + $keyInRecord = sprintf('%s.%s', $modelName, $column); + + if (isset($record[$keyInRecord])) { + $result[$modelName][$column] = $record[$keyInRecord]; } } } - - $results[] = $result; + if (!empty($result)) { + $results[] = $result; + } } - return $results; } @@ -877,10 +967,15 @@ public function formatResultFindAllWithJoins($dbResult = []){ */ public function formatResultFindAll($dbResult = []){ $result = []; - foreach ($dbResult as $dbRecord) { - $result[] = [ - $this->modelName => $dbRecord - ]; + $key = $this->modelName . '.'; + foreach ($dbResult as $i => $dbRecord) { + $record = []; + foreach ($dbRecord as $column => $value) { + $realColumnName = substr($column, strlen($key)); + $record[$this->modelName][$realColumnName] = $value; + } + unset($dbRecord[$i]); + $result[] = $record; } return $result; } diff --git a/app/Plugin/CrateModule/Model/Hoststatus.php b/app/Plugin/CrateModule/Model/Hoststatus.php index d8df139d61..546c19f4dd 100644 --- a/app/Plugin/CrateModule/Model/Hoststatus.php +++ b/app/Plugin/CrateModule/Model/Hoststatus.php @@ -99,7 +99,20 @@ public function getHostIndexQuery(HostConditions $HostConditions, $conditions = unset($conditions['Host.keywords rlike']); $conditions['Host.tags rlike'] = implode('|', $values); } + + if(isset($conditions['Hoststatus.problem_has_been_acknowledged'])){ + $acknowledgedCondition = []; + foreach($conditions['Hoststatus.problem_has_been_acknowledged'] as $condition){ + $acknowledgedCondition[] = (bool)$condition; + } + $conditions['Hoststatus.problem_has_been_acknowledged'] = $acknowledgedCondition; + } + $query = [ + 'fields' => [ + 'Hoststatus.*', + 'Host.*' + ], 'joins' => [ [ 'table' => 'openitcockpit_hosts', diff --git a/app/Plugin/CrateModule/Model/NotificationHost.php b/app/Plugin/CrateModule/Model/NotificationHost.php index 9df7033037..a0ff0479d0 100644 --- a/app/Plugin/CrateModule/Model/NotificationHost.php +++ b/app/Plugin/CrateModule/Model/NotificationHost.php @@ -31,22 +31,6 @@ class NotificationHost extends CrateModuleAppModel { public $tablePrefix = 'statusengine_'; - //See http://nagios.sourceforge.net/docs/ndoutils/NDOUtils_DB_Model.pdf and search for "notifications Table" - public function __construct($id = false, $table = null, $ds = null, $useDynamicAssociations = true){ - parent::__construct($id, $table, $ds, $useDynamicAssociations); - $this->virtualFields['"Host.name"'] = 'Host.name'; - $this->virtualFields['"Contact.name"'] = 'Contact.name'; - $this->virtualFields['"Command.name"'] = 'Command.name'; - - $this->virtualFields['"Host.uuid"'] = 'Host.uuid'; - $this->virtualFields['"Contact.uuid"'] = 'Contact.uuid'; - $this->virtualFields['"Command.uuid"'] = 'Command.uuid'; - - $this->virtualFields['"Host.id"'] = 'Host.id'; - $this->virtualFields['"Contact.id"'] = 'Contact.id'; - $this->virtualFields['"Command.id"'] = 'Command.id'; - } - /** * @param HostNotificationConditions $HostNotificationConditions * @param array $paginatorConditions @@ -62,9 +46,12 @@ public function getQuery(HostNotificationConditions $HostNotificationConditions, 'Host.id', 'Host.uuid', 'Host.name', - 'Contact.*' + 'Contact.*', + 'Command.*', ]; + //todo CrateDB bug, check if LEFT join can be refactored with INNER join + //https://github.com/crate/crate/issues/5747 $query = [ 'recursive' => -1, 'fields' => $fields, diff --git a/app/Plugin/CrateModule/Model/NotificationService.php b/app/Plugin/CrateModule/Model/NotificationService.php index 10bcd06468..baff801904 100644 --- a/app/Plugin/CrateModule/Model/NotificationService.php +++ b/app/Plugin/CrateModule/Model/NotificationService.php @@ -31,23 +31,6 @@ class NotificationService extends CrateModuleAppModel { public $tablePrefix = 'statusengine_'; - //See http://nagios.sourceforge.net/docs/ndoutils/NDOUtils_DB_Model.pdf and search for "notifications Table" - public function __construct($id = false, $table = null, $ds = null, $useDynamicAssociations = true){ - parent::__construct($id, $table, $ds, $useDynamicAssociations); - $this->virtualFields['"Host.name"'] = 'Host.name'; - $this->virtualFields['"Service.name"'] = 'Service.name'; - $this->virtualFields['"Contact.name"'] = 'Contact.name'; - $this->virtualFields['"Command.name"'] = 'Command.name'; - - $this->virtualFields['"Service.uuid"'] = 'Service.uuid'; - $this->virtualFields['"Contact.uuid"'] = 'Contact.uuid'; - $this->virtualFields['"Command.uuid"'] = 'Command.uuid'; - - $this->virtualFields['"Service.id"'] = 'Service.id'; - $this->virtualFields['"Contact.id"'] = 'Contact.id'; - $this->virtualFields['"Command.id"'] = 'Command.id'; - } - /** * @param ServiceNotificationConditions $ServiceNotificationConditions * @param array $paginatorConditions @@ -68,9 +51,12 @@ public function getQuery(ServiceNotificationConditions $ServiceNotificationCondi 'Service.uuid', 'Service.name', - 'Contact.*' + 'Contact.*', + 'Command.*' ]; + //todo CrateDB bug, check if LEFT join can be refactored with INNER join + //https://github.com/crate/crate/issues/5747 $query = [ 'recursive' => -1, 'fields' => $fields, diff --git a/app/Plugin/CrateModule/Model/Servicecheck.php b/app/Plugin/CrateModule/Model/Servicecheck.php new file mode 100644 index 0000000000..c4247139d5 --- /dev/null +++ b/app/Plugin/CrateModule/Model/Servicecheck.php @@ -0,0 +1,64 @@ + +// +// This file is dual licensed +// +// 1. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 3 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +// 2. +// If you purchased an openITCOCKPIT Enterprise Edition you can use this file +// under the terms of the openITCOCKPIT Enterprise Edition license agreement. +// License agreement and license key will be shipped with the order +// confirmation. + +use itnovum\openITCOCKPIT\Core\ServicechecksConditions; + +class Servicecheck extends CrateModuleAppModel { + public $useDbConfig = 'Crate'; + public $useTable = 'servicechecks'; + public $tablePrefix = 'statusengine_'; + + public function __construct($id = false, $table = null, $ds = null, $useDynamicAssociations = true){ + parent::__construct($id, $table, $ds, $useDynamicAssociations); + $this->virtualFields['state_type'] = 'Servicecheck.is_hardstate'; + } + + /** + * @param ServicechecksConditions $ServicecheckConditions + * @param array $paginatorConditions + * @return array + */ + public function getQuery(ServicechecksConditions $ServicecheckConditions, $paginatorConditions = []){ + $query = [ + 'conditions' => [ + 'service_description' => $ServicecheckConditions->getServiceUuid(), + 'start_time >' => $ServicecheckConditions->getFrom(), + 'start_time <' => $ServicecheckConditions->getTo() + ], + 'order' => $ServicecheckConditions->getOrder(), + 'limit' => $ServicecheckConditions->getLimit(), + ]; + + if(!empty($ServicecheckConditions->getStates())){ + $query['conditions']['state'] = $ServicecheckConditions->getStates(); + } + + //Merge ListFilter conditions + $query['conditions'] = Hash::merge($paginatorConditions, $query['conditions']); + + return $query; + } + +} diff --git a/app/Plugin/CrateModule/Model/Servicestatus.php b/app/Plugin/CrateModule/Model/Servicestatus.php index cc3f2b9f09..40df15335d 100644 --- a/app/Plugin/CrateModule/Model/Servicestatus.php +++ b/app/Plugin/CrateModule/Model/Servicestatus.php @@ -22,6 +22,8 @@ // License agreement and license key will be shipped with the order // confirmation. +use itnovum\openITCOCKPIT\Core\ServiceConditions; + class Servicestatus extends CrateModuleAppModel { public $useDbConfig = 'Crate'; @@ -58,14 +60,14 @@ private function byUuidMagic($uuid = null, $options = []){ $dbresult = $this->find($findType, $options); - if($findType === 'first'){ + if ($findType === 'first') { return [ 'Servicestatus' => $dbresult['Servicestatus'], ]; } $result = []; - foreach($dbresult as $record){ + foreach ($dbresult as $record) { $result[$record['Servicestatus']['service_description']] = [ 'Servicestatus' => $record['Servicestatus'], ]; @@ -78,10 +80,121 @@ public function byUuid($uuid, $options = []){ } public function byUuids($uuids, $options = []){ - if(!is_array($uuids)){ + if (!is_array($uuids)) { throw new InvalidArgumentException('$uuids need to be an array!'); } return $this->byUuidMagic($uuids, $options); } + public function virtualFieldsForIndexAndServiceList(){ + $this->virtualFields['"Service.servicename"'] = 'Service.name'; + + } + + /** + * @param ServiceConditions $ServiceConditions + * @param array $conditions + * @return array + */ + public function getServiceIndexQuery(ServiceConditions $ServiceConditions, $conditions = []){ + if (isset($conditions['Service.keywords rlike'])) { + $values = []; + foreach (explode('|', $conditions['Service.keywords rlike']) as $value) { + $values[] = sprintf('.*%s.*', $value); + } + unset($conditions['Service.keywords rlike']); + $conditions['Service.tags rlike'] = implode('|', $values); + } + + if(isset($conditions['Servicestatus.problem_has_been_acknowledged'])){ + $acknowledgedCondition = []; + foreach($conditions['Servicestatus.problem_has_been_acknowledged'] as $condition){ + $acknowledgedCondition[] = (bool)$condition; + } + $conditions['Servicestatus.problem_has_been_acknowledged'] = $acknowledgedCondition; + } + + if(isset($conditions['Servicestatus.active_checks_enabled'])){ + $ActiveChecksEnabledCondition = []; + foreach($conditions['Servicestatus.active_checks_enabled'] as $condition){ + $ActiveChecksEnabledCondition[] = (bool)$condition; + } + $conditions['Servicestatus.active_checks_enabled'] = $ActiveChecksEnabledCondition; + } + + if(isset($conditions['Service.servicename LIKE'])){ + $serviceNameCondition = $conditions['Service.servicename LIKE']; + unset($conditions['Service.servicename LIKE']); + $conditions['Service.name LIKE'] = $serviceNameCondition; + } + + //todo CrateDB bug, check if LEFT join can be refactored with INNER join + //https://github.com/crate/crate/issues/5747 + $query = [ + 'fields' => [ + 'Service.id', + 'Service.uuid', + 'Service.name', + 'Service.active_checks_enabled', + 'Service.tags', + + 'Servicestatus.current_state', + 'Servicestatus.last_check', + 'Servicestatus.next_check', + 'Servicestatus.last_hard_state_change', + 'Servicestatus.last_state_change', + 'Servicestatus.output', + 'Servicestatus.scheduled_downtime_depth', + 'Servicestatus.active_checks_enabled', + 'Servicestatus.is_hardstate', + 'Servicestatus.problem_has_been_acknowledged', + 'Servicestatus.acknowledgement_type', + 'Servicestatus.is_flapping', + + + 'Host.name', + 'Host.id', + 'Host.uuid', + 'Host.address', + 'Host.satellite_id', + + 'Hoststatus.current_state', + 'Hoststatus.last_hard_state_change' + + ], + 'joins' => [ + [ + 'table' => 'openitcockpit_hosts', + 'type' => 'LEFT', + 'alias' => 'Host', + 'conditions' => 'Host.uuid = Servicestatus.hostname', + ], + [ + 'table' => 'openitcockpit_services', + 'type' => 'INNER', + 'alias' => 'Service', + 'conditions' => 'Service.uuid = Servicestatus.service_description', + ], + [ + 'table' => 'statusengine_hoststatus', + 'type' => 'INNER', + 'alias' => 'Hoststatus', + 'conditions' => 'Hoststatus.hostname = Host.uuid', + ] + ], + 'conditions' => $conditions, + 'array_difference' => [ + 'Host.container_ids' => + $ServiceConditions->getContainerIds(), + ], + 'order' => $ServiceConditions->getOrder() + ]; + + if($ServiceConditions->getHostId()){ + $query['conditions']['Service.host_id'] = $ServiceConditions->getHostId(); + } + + return $query; + } + } diff --git a/app/Plugin/CrateModule/Model/StatehistoryService.php b/app/Plugin/CrateModule/Model/StatehistoryService.php new file mode 100644 index 0000000000..dbc6e48d47 --- /dev/null +++ b/app/Plugin/CrateModule/Model/StatehistoryService.php @@ -0,0 +1,74 @@ + +// +// This file is dual licensed +// +// 1. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 3 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +// 2. +// If you purchased an openITCOCKPIT Enterprise Edition you can use this file +// under the terms of the openITCOCKPIT Enterprise Edition license agreement. +// License agreement and license key will be shipped with the order +// confirmation. + +use itnovum\openITCOCKPIT\Core\StatehistoryServiceConditions; + +class StatehistoryService extends CrateModuleAppModel { + public $useDbConfig = 'Crate'; + public $useTable = 'service_statehistory'; + public $tablePrefix = 'statusengine_'; + + public function __construct($id = false, $table = null, $ds = null, $useDynamicAssociations = true){ + parent::__construct($id, $table, $ds, $useDynamicAssociations); + $this->virtualFields['state_type'] = 'StatehistoryService.is_hardstate'; + } + + + /** + * @param StatehistoryServiceConditions $StatehistoryServiceConditions + * @param array $paginatorConditions + * @return array + */ + public function getQuery(StatehistoryServiceConditions $StatehistoryServiceConditions, $paginatorConditions = []){ + $query = [ + 'conditions' => [ + 'service_description' => $StatehistoryServiceConditions->getServiceUuid(), + 'state_time >' => $StatehistoryServiceConditions->getFrom(), + 'state_time <' => $StatehistoryServiceConditions->getTo() + ], + 'order' => $StatehistoryServiceConditions->getOrder(), + 'limit' => $StatehistoryServiceConditions->getLimit(), + ]; + + if(!empty($StatehistoryServiceConditions->getStates())){ + $query['conditions']['state'] = $StatehistoryServiceConditions->getStates(); + } + + foreach($StatehistoryServiceConditions->getStateTypes() as $stateType){ + if($stateType === 0){ + $query['conditions']['is_hardstate'] = false; + } + + if($stateType === 1){ + $query['conditions']['is_hardstate'] = true; + } + } + + $query['conditions'] = Hash::merge($paginatorConditions, $query['conditions']); + + return $query; + } + +} diff --git a/app/Plugin/CrateModule/cratedb.sql b/app/Plugin/CrateModule/cratedb.sql index b6996e7cb4..20899ffd7a 100644 --- a/app/Plugin/CrateModule/cratedb.sql +++ b/app/Plugin/CrateModule/cratedb.sql @@ -29,5 +29,9 @@ CREATE TABLE IF NOT EXISTS openitcockpit_services ( servicetemplate_id int, uuid string, name string, - name_from_template boolean + name_from_template boolean, + active_checks_enabled int, + active_checks_enabled_from_template boolean, + tags string, + tags_from_template boolean ) CLUSTERED INTO 4 shards with (number_of_replicas = '1-all'); diff --git a/app/Plugin/NagiosModule/Model/Acknowledged.php b/app/Plugin/NagiosModule/Model/Acknowledged.php index 16ac3fc5ef..f110d0bcd5 100644 --- a/app/Plugin/NagiosModule/Model/Acknowledged.php +++ b/app/Plugin/NagiosModule/Model/Acknowledged.php @@ -23,8 +23,11 @@ // License agreement and license key will be shipped with the order // confirmation. -class Acknowledged extends NagiosModuleAppModel -{ +/** + * Class Acknowledged + * @deprecated Do not you this Model anymore + */ +class Acknowledged extends NagiosModuleAppModel { //public $useDbConfig = 'nagios'; const ACKNOWLEDGE_HOST_PROBLEM = 33; const ACKNOWLEDGE_SVC_PROBLEM = 34; @@ -34,21 +37,20 @@ class Acknowledged extends NagiosModuleAppModel public $tablePrefix = 'nagios_'; public $belongsTo = [ 'Objects' => [ - 'className' => 'NagiosModule.Objects', + 'className' => 'NagiosModule.Objects', 'foreignKey' => 'object_id', ], ]; - public function byUuid($uuid = null) - { + public function byUuid($uuid = null){ $return = []; if ($uuid !== null) { $acknowledged = $this->find('all', [ 'conditions' => [ - 'Objects.name2' => $uuid, + 'Objects.name2' => $uuid, 'Objects.objecttype_id' => 2, ], - 'order' => [ + 'order' => [ 'Acknowledged.entry_time' => 'DESC', ], ]); @@ -60,16 +62,15 @@ public function byUuid($uuid = null) return $return; } - public function byHostUuid($uuid = null) - { + public function byHostUuid($uuid = null){ $return = []; if ($uuid !== null) { $acknowledged = $this->find('first', [ 'conditions' => [ - 'Objects.name1' => $uuid, + 'Objects.name1' => $uuid, 'Objects.objecttype_id' => 1, ], - 'order' => [ + 'order' => [ 'Acknowledged.entry_time' => 'DESC', ], ]); @@ -81,202 +82,4 @@ public function byHostUuid($uuid = null) return $return; } - public function listSettingsService($cakeRequest, $serviceUuid) - { - $requestData = $cakeRequest->data; - - if (isset($cakeRequest->params['named']['Listsettings'])) { - $requestData['Listsettings'] = $cakeRequest->params['named']['Listsettings']; - } - - $requestParams = $cakeRequest->params; - - $service_state_types = [ - 'recovery' => 0, - 'warning' => 1, - 'critical' => 2, - 'unknown' => 3, - ]; - - $return = [ - 'conditions' => [ - 'Objects.name2' => $serviceUuid, - 'Objects.objecttype_id' => 2, - ], - 'paginator' => [ - 'limit' => 30, - 'order' => ['Acknowledged.entry_time' => 'DESC'], - ], - 'Listsettings' => [ - 'limit' => 30, - ], - ]; - - if (isset($requestData['Listsettings']['state_types'])) { - $return['conditions']['Acknowledged.state'] = []; - foreach ($requestData['Listsettings']['state_types'] as $state_type => $value) { - if (isset($service_state_types[$state_type]) && $value == 1) { - $return['conditions']['Acknowledged.state'][] = $service_state_types[$state_type]; - $return['Listsettings']['state_types'][$state_type] = 1; - } - } - } else { - foreach ($service_state_types as $state_type => $state) { - $return['Listsettings']['state_types'][$state_type] = 1; - } - if (isset($return['conditions']['Acknowledged.state'])) { - unset($return['conditions']['Acknowledged.state']); - } - } - - if (isset($requestParams['named']['sort']) && isset($requestParams['named']['direction'])) { - $return['paginator']['order'] = [$requestParams['named']['sort'] => $requestParams['named']['direction']]; - } - - - if (isset($requestData['Listsettings']['limit']) && is_numeric($requestData['Listsettings']['limit'])) { - $return['paginator']['limit'] = $requestData['Listsettings']['limit']; - $return['Listsettings']['limit'] = $return['paginator']['limit']; - } - - if (isset($requestData['Listsettings']['from'])) { - $time = strtotime($requestData['Listsettings']['from']); - if ($time == false || !is_numeric($time)) { - $time = strtotime('3 days ago'); - } - - $return['conditions']['Acknowledged.entry_time >'] = date('Y-m-d H:i:s', $time); - $return['Listsettings']['from'] = date('d.m.Y H:i', $time); - } else { - $return['conditions']['Acknowledged.entry_time >'] = date('Y-m-d H:i:s', strtotime('3 days ago')); - $return['Listsettings']['from'] = date('d.m.Y H:i', strtotime('3 days ago')); - } - - if (isset($requestData['Listsettings']['to'])) { - $time = strtotime($requestData['Listsettings']['to']); - if ($time == false || !is_numeric($time)) { - $time = time() + (60 * 5); //Add 5 minutes to avoid missing entires in result - } - - $return['conditions']['Acknowledged.entry_time <'] = date('Y-m-d H:i:s', $time); - $return['Listsettings']['to'] = date('d.m.Y H:i', $time); - } else { - $return['conditions']['Acknowledged.entry_time <'] = date('Y-m-d H:i:s', time() + (60 * 5)); - $return['Listsettings']['to'] = date('d.m.Y H:i', time() + (60 * 5)); - } - - if (isset($return['conditions']['Acknowledged.state'])) { - if ( - in_array(0, $return['conditions']['Acknowledged.state']) && - in_array(1, $return['conditions']['Acknowledged.state']) && - in_array(2, $return['conditions']['Acknowledged.state']) && - in_array(3, $return['conditions']['Acknowledged.state']) - ) { - //The user want every state, so lets remove this for faster SQL - unset($return['conditions']['Acknowledged.state']); - } - } - - - return $return; - } - - public function listSettingsHost($cakeRequest, $hostUuid) - { - $requestData = $cakeRequest->data; - - if (isset($cakeRequest->params['named']['Listsettings'])) { - $requestData['Listsettings'] = $cakeRequest->params['named']['Listsettings']; - } - - $requestParams = $cakeRequest->params; - - $host_state_types = [ - 'up' => 0, - 'down' => 1, - 'unreachable' => 2, - ]; - - $return = [ - 'conditions' => [ - 'Objects.name1' => $hostUuid, - 'Objects.objecttype_id' => 1, - ], - 'paginator' => [ - 'limit' => 30, - 'order' => ['Acknowledged.entry_time' => 'DESC'], - ], - 'Listsettings' => [ - 'limit' => 30, - ], - ]; - - if (isset($requestData['Listsettings']['state_types'])) { - $return['conditions']['Acknowledged.state'] = []; - foreach ($requestData['Listsettings']['state_types'] as $state_type => $value) { - if (isset($host_state_types[$state_type]) && $value == 1) { - $return['conditions']['Acknowledged.state'][] = $host_state_types[$state_type]; - $return['Listsettings']['state_types'][$state_type] = 1; - } - } - } else { - foreach ($host_state_types as $state_type => $state) { - $return['Listsettings']['state_types'][$state_type] = 1; - } - if (isset($return['conditions']['Acknowledged.state'])) { - unset($return['conditions']['Acknowledged.state']); - } - } - - if (isset($requestParams['named']['sort']) && isset($requestParams['named']['direction'])) { - $return['paginator']['order'] = [$requestParams['named']['sort'] => $requestParams['named']['direction']]; - } - - - if (isset($requestData['Listsettings']['limit']) && is_numeric($requestData['Listsettings']['limit'])) { - $return['paginator']['limit'] = $requestData['Listsettings']['limit']; - $return['Listsettings']['limit'] = $return['paginator']['limit']; - } - - if (isset($requestData['Listsettings']['from'])) { - $time = strtotime($requestData['Listsettings']['from']); - if ($time == false || !is_numeric($time)) { - $time = strtotime('3 days ago'); - } - - $return['conditions']['Acknowledged.entry_time >'] = date('Y-m-d H:i:s', $time); - $return['Listsettings']['from'] = date('d.m.Y H:i', $time); - } else { - $return['conditions']['Acknowledged.entry_time >'] = date('Y-m-d H:i:s', strtotime('3 days ago')); - $return['Listsettings']['from'] = date('d.m.Y H:i', strtotime('3 days ago')); - } - - if (isset($requestData['Listsettings']['to'])) { - $time = strtotime($requestData['Listsettings']['to']); - if ($time == false || !is_numeric($time)) { - $time = time() + (60 * 5); //Add 5 minutes to avoid missing entires in result - } - - $return['conditions']['Acknowledged.entry_time <'] = date('Y-m-d H:i:s', $time); - $return['Listsettings']['to'] = date('d.m.Y H:i', $time); - } else { - $return['conditions']['Acknowledged.entry_time <'] = date('Y-m-d H:i:s', time() + (60 * 5)); - $return['Listsettings']['to'] = date('d.m.Y H:i', time() + (60 * 5)); - } - - if (isset($return['conditions']['Acknowledged.state'])) { - if ( - in_array(0, $return['conditions']['Acknowledged.state']) && - in_array(1, $return['conditions']['Acknowledged.state']) && - in_array(2, $return['conditions']['Acknowledged.state']) && - in_array(3, $return['conditions']['Acknowledged.state']) - ) { - //The user want every state, so lets remove this for faster SQL - unset($return['conditions']['Acknowledged.state']); - } - } - - - return $return; - } } diff --git a/app/Plugin/NagiosModule/Model/AcknowledgedService.php b/app/Plugin/NagiosModule/Model/AcknowledgedService.php new file mode 100644 index 0000000000..95f906d5f8 --- /dev/null +++ b/app/Plugin/NagiosModule/Model/AcknowledgedService.php @@ -0,0 +1,101 @@ + +// +// This file is dual licensed +// +// 1. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 3 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +// 2. +// If you purchased an openITCOCKPIT Enterprise Edition you can use this file +// under the terms of the openITCOCKPIT Enterprise Edition license agreement. +// License agreement and license key will be shipped with the order +// confirmation. + +use itnovum\openITCOCKPIT\Core\AcknowledgedServiceConditions; + + +class AcknowledgedService extends NagiosModuleAppModel +{ + + public $useTable = 'acknowledgements'; + public $primaryKey = 'acknowledgement_id'; + public $tablePrefix = 'nagios_'; + public $belongsTo = [ + 'Objects' => [ + 'className' => 'NagiosModule.Objects', + 'foreignKey' => 'object_id', + ], + ]; + + /** + * @param null $uuid + * @return array|null + */ + public function byServiceUuid($uuid = null){ + return $this->byUuid($uuid); + } + + /** + * @param string $uuid + * @return array|null + */ + public function byUuid($uuid = null) + { + $return = []; + if ($uuid !== null) { + $acknowledged = $this->find('first', [ + 'conditions' => [ + 'Objects.name2' => $uuid, + 'Objects.objecttype_id' => 2, + ], + 'order' => [ + 'AcknowledgedService.entry_time' => 'DESC', + ], + ]); + + return $acknowledged; + + } + + return $return; + } + + + /** + * @param AcknowledgedServiceConditions $AcknowledgedServiceConditions + * @param array $paginatorConditions + * @return array + */ + public function getQuery(AcknowledgedServiceConditions $AcknowledgedServiceConditions, $paginatorConditions = []){ + $query = [ + 'conditions' => [ + 'Objects.name2' => $AcknowledgedServiceConditions->getServiceUuid(), + 'AcknowledgedService.entry_time >' => date('Y-m-d H:i:s', $AcknowledgedServiceConditions->getFrom()), + 'AcknowledgedService.entry_time <' => date('Y-m-d H:i:s', $AcknowledgedServiceConditions->getTo()) + ], + 'order' => $AcknowledgedServiceConditions->getOrder(), + 'limit' => $AcknowledgedServiceConditions->getLimit(), + ]; + + if(!empty($AcknowledgedServiceConditions->getStates())){ + $query['conditions']['AcknowledgedService.state'] = $AcknowledgedServiceConditions->getStates(); + } + + //Merge ListFilter conditions + $query['conditions'] = Hash::merge($paginatorConditions, $query['conditions']); + + return $query; + } +} diff --git a/app/Plugin/NagiosModule/Model/Notification.php b/app/Plugin/NagiosModule/Model/Notification.php index 299e6780a9..af32734495 100644 --- a/app/Plugin/NagiosModule/Model/Notification.php +++ b/app/Plugin/NagiosModule/Model/Notification.php @@ -23,6 +23,10 @@ // License agreement and license key will be shipped with the order // confirmation. +/** + * Class Notification + * @deprecated Do not you this Model anymore + */ class Notification extends NagiosModuleAppModel { //public $useDbConfig = 'default'; @@ -33,366 +37,4 @@ class Notification extends NagiosModuleAppModel //See http://nagios.sourceforge.net/docs/ndoutils/NDOUtils_DB_Model.pdf and search for "notifications Table" public $notification_type = [0, 1]; - - public function listSettings($requestData) - { - - //$host_state_types = [ - // 'recovery' => 0, - // 'down' => 1, - // 'unreachable' => 2 - //]; - // - //$service_state_types = [ - // 'recovery' => 0, - // 'warning' => 1, - // 'critical' => 2, - // 'unknown' => 3, - //]; - - $return = [ - 'conditions' => [], - 'paginator' => [], - 'Listsettings' => [], - ]; - - - if (isset($requestData['Listsettings']['view'])) { - switch ($requestData['Listsettings']['view']) { - case 'hostOnly': - $return['notifiction_type'] = 0; - $return['Listsettings']['view'] = 'hostOnly'; - break; - - case 'serviceOnly': - $return['notifiction_type'] = 1; - $return['Listsettings']['view'] = 'serviceOnly'; - break; - - default: - $return['notifiction_type'] = 0; - $return['Listsettings']['view'] = 'hostOnly'; - break; - } - } - - //if(isset($requestData['Listsettings']['state_types'])){ - // if(isset($requestData['Listsettings']['state_types']['Host'])){ - // foreach($requestData['Listsettings']['state_types']['Host'] as $state_name => $value){ - // if($value == 1 && isset($host_state_types[$state_name])){ - // $return['conditions']['Notification.state'][] = $host_state_types[$state_name]; - // $return['Listsettings']['state_types']['Host'][$state_name] = 1; - // } - // } - // } - // - // if(isset($requestData['Listsettings']['state_types']['Service'])){ - // foreach($requestData['Listsettings']['state_types']['Service'] as $state_name => $value){ - // if($value == 1 && isset($service_state_types[$state_name])){ - // $return['conditions']['Notification.state'][] = $service_state_types[$state_name]; - // $return['Listsettings']['state_types']['Service'][$state_name] = 1; - // } - // } - // } - // - //$return['conditions']['Notification.state'] = array_unique($return['conditions']['Notification.state']); - // - //} - - - if (isset($requestData['Listsettings']['limit']) && is_numeric($requestData['Listsettings']['limit'])) { - $return['paginator']['limit'] = $requestData['Listsettings']['limit']; - $return['Listsettings']['limit'] = $return['paginator']['limit']; - } - - if (isset($requestData['Listsettings']['from'])) { - $time = strtotime($requestData['Listsettings']['from']); - if ($time == false || !is_numeric($time)) { - $time = strtotime('3 days ago'); - } - - $return['conditions']['Contactnotification.start_time >'] = date('Y-m-d H:i:s', $time); - $return['Listsettings']['from'] = date('d.m.Y H:i', $time); - } else { - $return['conditions']['Contactnotification.start_time >'] = date('Y-m-d H:i:s', strtotime('3 days ago')); - $return['Listsettings']['from'] = date('d.m.Y H:i', strtotime('3 days ago')); - } - - if (isset($requestData['Listsettings']['to'])) { - $time = strtotime($requestData['Listsettings']['to']); - if ($time == false || !is_numeric($time)) { - $time = time() + (60 * 5); //Avoid missing entries in result - } - - $return['conditions']['Contactnotification.start_time <'] = date('Y-m-d H:i:s', $time); - $return['Listsettings']['to'] = date('d.m.Y H:i', $time); - } else { - $return['conditions']['Contactnotification.start_time <'] = date('Y-m-d H:i:s', time() + (60 * 5)); - $return['Listsettings']['to'] = date('d.m.Y H:i', time() + (60 * 5)); - } - - //debug($requestData); - //debug($return); - return $return; - - } - - public function serviceListSettings($requestData, $hostUuid, $serviceUuid) - { - - $return = [ - 'conditions' => [ - 'Objects.name1' => $hostUuid, - 'Objects.name2' => $serviceUuid, - 'Objects.objecttype_id' => 2, - ], - 'paginator' => [], - 'Listsettings' => [], - ]; - - - $return['notifiction_type'] = 1; - - - if (isset($requestData['Listsettings']['limit']) && is_numeric($requestData['Listsettings']['limit'])) { - $return['paginator']['limit'] = $requestData['Listsettings']['limit']; - $return['Listsettings']['limit'] = $return['paginator']['limit']; - } - - if (isset($requestData['Listsettings']['from'])) { - $time = strtotime($requestData['Listsettings']['from']); - if ($time == false || !is_numeric($time)) { - $time = strtotime('3 days ago'); - } - - $return['conditions']['Contactnotification.start_time >'] = date('Y-m-d H:i:s', $time); - $return['Listsettings']['from'] = date('d.m.Y H:i', $time); - } else { - $return['conditions']['Contactnotification.start_time >'] = date('Y-m-d H:i:s', strtotime('3 days ago')); - $return['Listsettings']['from'] = date('d.m.Y H:i', strtotime('3 days ago')); - } - - if (isset($requestData['Listsettings']['to'])) { - $time = strtotime($requestData['Listsettings']['to']); - if ($time == false || !is_numeric($time)) { - $time = time() + (60 * 5); //Avoid missing entries in result - } - - $return['conditions']['Contactnotification.start_time <'] = date('Y-m-d H:i:s', $time); - $return['Listsettings']['to'] = date('d.m.Y H:i', $time); - } else { - $return['conditions']['Contactnotification.start_time <'] = date('Y-m-d H:i:s', time() + (60 * 5)); - $return['Listsettings']['to'] = date('d.m.Y H:i', time() + (60 * 5)); - } - - return $return; - - } - - public function hostListSettings($requestData, $hostUuid) - { - - $return = [ - 'conditions' => [ - 'Objects.name1' => $hostUuid, - 'Objects.objecttype_id' => 1, - ], - 'paginator' => [], - 'Listsettings' => [], - ]; - - - $return['notifiction_type'] = 0; - - - if (isset($requestData['Listsettings']['limit']) && is_numeric($requestData['Listsettings']['limit'])) { - $return['paginator']['limit'] = $requestData['Listsettings']['limit']; - $return['Listsettings']['limit'] = $return['paginator']['limit']; - } - - if (isset($requestData['Listsettings']['from'])) { - $time = strtotime($requestData['Listsettings']['from']); - if ($time == false || !is_numeric($time)) { - $time = strtotime('3 days ago'); - } - - $return['conditions']['Contactnotification.start_time >'] = date('Y-m-d H:i:s', $time); - $return['Listsettings']['from'] = date('d.m.Y H:i', $time); - } else { - $return['conditions']['Contactnotification.start_time >'] = date('Y-m-d H:i:s', strtotime('3 days ago')); - $return['Listsettings']['from'] = date('d.m.Y H:i', strtotime('3 days ago')); - } - - if (isset($requestData['Listsettings']['to'])) { - $time = strtotime($requestData['Listsettings']['to']); - if ($time == false || !is_numeric($time)) { - $time = time() + (60 * 5); //Add 5 minutes to avoid missing entries in result - } - - $return['conditions']['Contactnotification.start_time <'] = date('Y-m-d H:i:s', $time); - $return['Listsettings']['to'] = date('d.m.Y H:i', $time); - } else { - $return['conditions']['Contactnotification.start_time <'] = date('Y-m-d H:i:s', time() + (60 * 5)); - $return['Listsettings']['to'] = date('d.m.Y H:i', time() + (60 * 5)); - } - - return $return; - - } - - public function paginatorSettings($notifiction_type = 0, $order, $conditions = [], $join = null, $MY_RIGHTS = []) - { - $_conditions = [ - 'Notification.notification_type' => $notifiction_type, - 'Notification.contacts_notified >' => 0, - 'HostsToContainers.container_id' => $MY_RIGHTS, - ]; - $conditions = Hash::merge($_conditions, $conditions); - - if ($notifiction_type == 0) { - //Host notifications - $fields = [ - 'Notification.object_id', - 'Notification.notification_type', - 'Notification.state', - 'Notification.output', - - 'Host.id', - 'Host.uuid', - 'Host.name', - - 'Contactnotification.notification_id', - 'Contactnotification.contact_object_id', - 'Contactnotification.start_time', - - 'Contact.id', - 'Contact.uuid', - 'Contact.name', - - 'Command.id', - 'Command.uuid', - 'Command.name', - - 'HostsToContainers.container_id', - ]; - - } else { - //Service notifications - $fields = [ - 'Notification.object_id', - 'Notification.notification_type', - 'Notification.state', - 'Notification.output', - - 'Host.id', - 'Host.uuid', - 'Host.name', - - 'Service.id', - 'Service.uuid', - 'Service.name', - 'Service.servicetemplate_id', - - 'Contactnotification.notification_id', - 'Contactnotification.contact_object_id', - 'Contactnotification.start_time', - - 'Contact.id', - 'Contact.uuid', - 'Contact.name', - - 'Command.id', - 'Command.uuid', - 'Command.name', - - 'HostsToContainers.container_id', - ]; - } - - return [ - 'recursive' => -1, - 'fields' => Hash::merge($fields, $join['fields']), - 'joins' => [ - [ - 'table' => 'nagios_objects', - 'type' => 'INNER', - 'alias' => 'Objects', - 'conditions' => 'Objects.object_id = Notification.object_id', - ], - - [ - 'table' => 'hosts', - 'type' => 'INNER', - 'alias' => 'Host', - 'conditions' => 'Objects.name1 = Host.uuid', - ], - - [ - 'table' => 'services', - 'type' => 'LEFT OUTER', - 'alias' => 'Service', - 'conditions' => 'Objects.name2 = Service.uuid', - ], - - [ - 'table' => 'nagios_contactnotifications', - 'type' => 'INNER', - 'alias' => 'Contactnotification', - 'conditions' => 'Notification.notification_id = Contactnotification.notification_id', - ], - - [ - 'table' => 'nagios_objects', - 'type' => 'INNER', - 'alias' => 'ContactObject', - 'conditions' => 'Contactnotification.contact_object_id = ContactObject.object_id', - ], - - [ - 'table' => 'contacts', - 'type' => 'INNER', - 'alias' => 'Contact', - 'conditions' => 'ContactObject.name1 = Contact.uuid', - ], - - [ - 'table' => 'nagios_contactnotificationmethods', - 'type' => 'INNER', - 'alias' => 'Contactnotificationmethod', - 'conditions' => 'Contactnotificationmethod.contactnotification_id = Contactnotification.contactnotification_id', - ], - - [ - 'table' => 'nagios_objects', - 'type' => 'INNER', - 'alias' => 'CommandObject', - 'conditions' => 'Contactnotificationmethod.command_object_id = CommandObject.object_id', - ], - - [ - 'table' => 'commands', - 'type' => 'INNER', - 'alias' => 'Command', - 'conditions' => 'CommandObject.name1 = Command.uuid', - ], - [ - 'table' => 'hosts_to_containers', - 'alias' => 'HostsToContainers', - 'type' => 'LEFT', - 'conditions' => [ - 'HostsToContainers.host_id = Host.id', - ], - ], - - $join['join'], - - ], - 'order' => $order, - //'group' => 'Notification.notification_id', - 'conditions' => $conditions, - 'findType' => 'all', - - ]; - } - -} \ No newline at end of file +} diff --git a/app/Plugin/NagiosModule/Model/Servicecheck.php b/app/Plugin/NagiosModule/Model/Servicecheck.php index d44797a12a..7cdaf41a98 100644 --- a/app/Plugin/NagiosModule/Model/Servicecheck.php +++ b/app/Plugin/NagiosModule/Model/Servicecheck.php @@ -23,6 +23,8 @@ // License agreement and license key will be shipped with the order // confirmation. +use itnovum\openITCOCKPIT\Core\ServicechecksConditions; + class Servicecheck extends NagiosModuleAppModel { //public $useDbConfig = 'nagios'; @@ -36,103 +38,30 @@ class Servicecheck extends NagiosModuleAppModel ], ]; - - public function listSettings($cakeRequest, $serviceUuid) - { - $requestData = $cakeRequest->data; - - if (isset($cakeRequest->params['named']['Listsettings'])) { - $requestData['Listsettings'] = $cakeRequest->params['named']['Listsettings']; - } - - $requestParams = $cakeRequest->params; - - $service_state_types = [ - 'recovery' => 0, - 'warning' => 1, - 'critical' => 2, - 'unknown' => 3, - ]; - - $return = [ - 'conditions' => [ - 'Objects.name2' => $serviceUuid, - ], - 'paginator' => [ - 'limit' => 30, - 'order' => ['Servicecheck.start_time' => 'DESC'], - ], - 'Listsettings' => [ - 'limit' => 30, + /** + * @param ServicechecksConditions $ServicecheckConditions + * @param array $paginatorConditions + * @return array + */ + public function getQuery(ServicechecksConditions $ServicecheckConditions, $paginatorConditions = []){ + $query = [ + 'conditions' => [ + 'Objects.name2' => $ServicecheckConditions->getServiceUuid(), + 'start_time >' => date('Y-m-d H:i:s', $ServicecheckConditions->getFrom()), + 'start_time <' => date('Y-m-d H:i:s', $ServicecheckConditions->getTo()) ], + 'order' => $ServicecheckConditions->getOrder(), + 'limit' => $ServicecheckConditions->getLimit(), ]; - if (isset($requestData['Listsettings']['state_types'])) { - $return['conditions']['Servicecheck.state'] = []; - foreach ($requestData['Listsettings']['state_types'] as $state_type => $value) { - if (isset($service_state_types[$state_type]) && $value == 1) { - $return['conditions']['Servicecheck.state'][] = $service_state_types[$state_type]; - $return['Listsettings']['state_types'][$state_type] = 1; - } - } - } else { - foreach ($service_state_types as $state_type => $state) { - $return['Listsettings']['state_types'][$state_type] = 1; - } - if (isset($return['conditions']['Servicecheck.state'])) { - unset($return['conditions']['Servicecheck.state']); - } - } - - if (isset($requestParams['named']['sort']) && isset($requestParams['named']['direction'])) { - $return['paginator']['order'] = [$requestParams['named']['sort'] => $requestParams['named']['direction']]; - } - - - if (isset($requestData['Listsettings']['limit']) && is_numeric($requestData['Listsettings']['limit'])) { - $return['paginator']['limit'] = $requestData['Listsettings']['limit']; - $return['Listsettings']['limit'] = $return['paginator']['limit']; + if(!empty($ServicecheckConditions->getStates())){ + $query['conditions']['state'] = $ServicecheckConditions->getStates(); } - if (isset($requestData['Listsettings']['from'])) { - $time = strtotime($requestData['Listsettings']['from']); - if ($time == false || !is_numeric($time)) { - $time = strtotime('3 days ago'); - } - - $return['conditions']['Servicecheck.start_time >'] = date('Y-m-d H:i:s', $time); - $return['Listsettings']['from'] = date('d.m.Y H:i', $time); - } else { - $return['conditions']['Servicecheck.start_time >'] = date('Y-m-d H:i:s', strtotime('3 days ago')); - $return['Listsettings']['from'] = date('d.m.Y H:i', strtotime('3 days ago')); - } - - if (isset($requestData['Listsettings']['to'])) { - $time = strtotime($requestData['Listsettings']['to']); - if ($time == false || !is_numeric($time)) { - $time = time() + (60 * 5); //Add 5 minutes to avoid missing entries in result - } - - $return['conditions']['Servicecheck.start_time <'] = date('Y-m-d H:i:s', $time); - $return['Listsettings']['to'] = date('d.m.Y H:i', $time); - } else { - $return['conditions']['Servicecheck.start_time <'] = date('Y-m-d H:i:s', time() + (60 * 5)); - $return['Listsettings']['to'] = date('d.m.Y H:i', time() + (60 * 5)); - } - - if (isset($return['conditions']['Servicecheck.state'])) { - if ( - in_array(0, $return['conditions']['Servicecheck.state']) && - in_array(1, $return['conditions']['Servicecheck.state']) && - in_array(2, $return['conditions']['Servicecheck.state']) && - in_array(3, $return['conditions']['Servicecheck.state']) - ) { - //The user want every state, so lets remove this for faster SQL - unset($return['conditions']['Servicecheck.state']); - } - } + //Merge ListFilter conditions + $query['conditions'] = Hash::merge($paginatorConditions, $query['conditions']); - return $return; + return $query; } -} \ No newline at end of file +} diff --git a/app/Plugin/NagiosModule/Model/Statehistory.php b/app/Plugin/NagiosModule/Model/Statehistory.php index 29f024cee5..e1ffec70b6 100644 --- a/app/Plugin/NagiosModule/Model/Statehistory.php +++ b/app/Plugin/NagiosModule/Model/Statehistory.php @@ -23,6 +23,10 @@ // License agreement and license key will be shipped with the order // confirmation. +/** + * Class Statehistory + * @deprecated Do not you this Model anymore + */ class Statehistory extends NagiosModuleAppModel { public $useTable = 'statehistory'; @@ -35,271 +39,4 @@ class Statehistory extends NagiosModuleAppModel ], ]; - - public function listSettings($cakeRequest, $serviceUuid, $hostUuid) - { - $requestData = $cakeRequest->data; - - if (isset($cakeRequest->params['named']['Listsettings'])) { - $requestData['Listsettings'] = $cakeRequest->params['named']['Listsettings']; - } - $requestParams = $cakeRequest->params; - - $nag_service_state_types = [ - 'soft' => 0, - 'hard' => 1, - ]; - - $service_state_types = [ - 'recovery' => 0, - 'warning' => 1, - 'critical' => 2, - 'unknown' => 3, - ]; - - $return = [ - 'conditions' => [ - 'Objects.name2' => $serviceUuid, - 'Objects.name1' => $hostUuid, - ], - 'paginator' => [ - 'limit' => 30, - 'order' => ['Statehistory.state_time' => 'DESC'], - ], - 'Listsettings' => [ - 'limit' => 30, - ], - ]; - - // Recovery, Warning, Critical, Unknown state - if (isset($requestData['Listsettings']['state_types'])) { - $return['conditions']['Statehistory.state'] = []; - foreach ($requestData['Listsettings']['state_types'] as $state_type => $value) { - if (isset($service_state_types[$state_type]) && $value == 1) { - $return['conditions']['Statehistory.state'][] = $service_state_types[$state_type]; - $return['Listsettings']['state_types'][$state_type] = 1; - } - } - } else { - foreach ($service_state_types as $state_type => $state) { - $return['Listsettings']['state_types'][$state_type] = 1; - } - if (isset($return['conditions']['Statehistory.state'])) { - unset($return['conditions']['Statehistory.state']); - } - } - - //Soft & Hard state - if (isset($requestData['Listsettings']['nag_state_types'])) { - $return['conditions']['Statehistory.state_type'] = []; - foreach ($requestData['Listsettings']['nag_state_types'] as $state_type => $value) { - if (isset($nag_service_state_types[$state_type]) && $value == 1) { - $return['conditions']['Statehistory.state_type'][] = $nag_service_state_types[$state_type]; - $return['Listsettings']['nag_state_types'][$state_type] = 1; - } - } - } else { - foreach ($nag_service_state_types as $state_type => $state) { - $return['Listsettings']['nag_state_types'][$state_type] = 1; - } - if (isset($return['conditions']['Statehistory.state_type'])) { - unset($return['conditions']['Statehistory.state_type']); - } - } - - if (isset($requestParams['named']['sort']) && isset($requestParams['named']['direction'])) { - $return['paginator']['order'] = [$requestParams['named']['sort'] => $requestParams['named']['direction']]; - } - - - if (isset($requestData['Listsettings']['limit']) && is_numeric($requestData['Listsettings']['limit'])) { - $return['paginator']['limit'] = $requestData['Listsettings']['limit']; - $return['Listsettings']['limit'] = $return['paginator']['limit']; - } - - if (isset($requestData['Listsettings']['from'])) { - $time = strtotime($requestData['Listsettings']['from']); - if ($time == false || !is_numeric($time)) { - $time = strtotime('3 days ago'); - } - - $return['conditions']['Statehistory.state_time >'] = date('Y-m-d H:i:s', $time); - $return['Listsettings']['from'] = date('d.m.Y H:i', $time); - } else { - $return['conditions']['Statehistory.state_time >'] = date('Y-m-d H:i:s', strtotime('3 days ago')); - $return['Listsettings']['from'] = date('d.m.Y H:i', strtotime('3 days ago')); - } - - if (isset($requestData['Listsettings']['to'])) { - $time = strtotime($requestData['Listsettings']['to']); - if ($time == false || !is_numeric($time)) { - $time = time() + (60 * 5); //Add 5 minutes to avoid missing entries - } - - $return['conditions']['Statehistory.state_time <'] = date('Y-m-d H:i:s', $time); - $return['Listsettings']['to'] = date('d.m.Y H:i', $time); - } else { - $return['conditions']['Statehistory.state_time <'] = date('Y-m-d H:i:s', time() + (60 * 5)); - $return['Listsettings']['to'] = date('d.m.Y H:i', time() + (60 * 5)); //Add 5 minutes to avoid missing entries - } - - //Make better SQL - if (isset($return['conditions']['Statehistory.state_type'])) { - if ( - in_array(0, $return['conditions']['Statehistory.state_type']) && - in_array(1, $return['conditions']['Statehistory.state_type']) - ) { - unset($return['conditions']['Statehistory.state_type']); - } - } - - if (isset($return['conditions']['Statehistory.state'])) { - if ( - in_array(0, $return['conditions']['Statehistory.state']) && - in_array(1, $return['conditions']['Statehistory.state']) && - in_array(2, $return['conditions']['Statehistory.state']) && - in_array(3, $return['conditions']['Statehistory.state']) - ) { - unset($return['conditions']['Statehistory.state']); - } - } - - return $return; - } - - - //May be refactor me :) - public function listSettingsHost($cakeRequest, $hostUuid) - { - $requestData = $cakeRequest->data; - - if (isset($cakeRequest->params['named']['Listsettings'])) { - $requestData['Listsettings'] = $cakeRequest->params['named']['Listsettings']; - } - $requestParams = $cakeRequest->params; - - $nag_service_state_types = [ - 'soft' => 0, - 'hard' => 1, - ]; - - $service_state_types = [ - 'recovery' => 0, - 'down' => 1, - 'unreachable' => 2, - ]; - - $return = [ - 'conditions' => [ - 'Objects.name1' => $hostUuid, - 'Objects.objecttype_id' => 1, - ], - 'paginator' => [ - 'limit' => 30, - 'order' => ['Statehistory.state_time' => 'DESC'], - ], - 'Listsettings' => [ - 'limit' => 30, - ], - ]; - - // Recovery, Down, Unreachable state - if (isset($requestData['Listsettings']['state_types'])) { - $return['conditions']['Statehistory.state'] = []; - foreach ($requestData['Listsettings']['state_types'] as $state_type => $value) { - if (isset($service_state_types[$state_type]) && $value == 1) { - $return['conditions']['Statehistory.state'][] = $service_state_types[$state_type]; - $return['Listsettings']['state_types'][$state_type] = 1; - } - } - } else { - foreach ($service_state_types as $state_type => $state) { - $return['Listsettings']['state_types'][$state_type] = 1; - } - if (isset($return['conditions']['Statehistory.state'])) { - unset($return['conditions']['Statehistory.state']); - } - } - - //Soft & Hard state - if (isset($requestData['Listsettings']['nag_state_types'])) { - $return['conditions']['Statehistory.state_type'] = []; - foreach ($requestData['Listsettings']['nag_state_types'] as $state_type => $value) { - if (isset($nag_service_state_types[$state_type]) && $value == 1) { - $return['conditions']['Statehistory.state_type'][] = $nag_service_state_types[$state_type]; - $return['Listsettings']['nag_state_types'][$state_type] = 1; - } - } - } else { - foreach ($nag_service_state_types as $state_type => $state) { - $return['Listsettings']['nag_state_types'][$state_type] = 1; - } - if (isset($return['conditions']['Statehistory.state_type'])) { - unset($return['conditions']['Statehistory.state_type']); - } - } - - if (isset($requestParams['named']['sort']) && isset($requestParams['named']['direction'])) { - $return['paginator']['order'] = [$requestParams['named']['sort'] => $requestParams['named']['direction']]; - } - - - if (isset($requestData['Listsettings']['limit']) && is_numeric($requestData['Listsettings']['limit'])) { - $return['paginator']['limit'] = $requestData['Listsettings']['limit']; - $return['Listsettings']['limit'] = $return['paginator']['limit']; - } - - if (isset($requestData['Listsettings']['from'])) { - $time = strtotime($requestData['Listsettings']['from']); - if ($time == false || !is_numeric($time)) { - $time = strtotime('3 days ago'); - } - - $return['conditions']['Statehistory.state_time >'] = date('Y-m-d H:i:s', $time); - $return['Listsettings']['from'] = date('d.m.Y H:i', $time); - } else { - $return['conditions']['Statehistory.state_time >'] = date('Y-m-d H:i:s', strtotime('3 days ago')); - $return['Listsettings']['from'] = date('d.m.Y H:i', strtotime('3 days ago')); - } - - if (isset($requestData['Listsettings']['to'])) { - $time = strtotime($requestData['Listsettings']['to']); - if ($time == false || !is_numeric($time)) { - $time = time() + (60 * 5); - } - - $return['conditions']['Statehistory.state_time <'] = date('Y-m-d H:i:s', $time); - $return['Listsettings']['to'] = date('d.m.Y H:i', $time); - } else { - $return['conditions']['Statehistory.state_time <'] = date('Y-m-d H:i:s', time() + (60 * 5)); - $return['Listsettings']['to'] = date('d.m.Y H:i', time() + (60 * 5)); - } - - if (isset($return['conditions']['Statehistory.state_type'])) { - $return['conditions']['Statehistory.state_type'] = array_unique($return['conditions']['Statehistory.state_type']); - } - - //Make better SQL - if (isset($return['conditions']['Statehistory.state_type'])) { - if ( - in_array(0, $return['conditions']['Statehistory.state_type']) && - in_array(1, $return['conditions']['Statehistory.state_type']) - ) { - unset($return['conditions']['Statehistory.state_type']); - } - } - - if (isset($return['conditions']['Statehistory.state'])) { - if ( - in_array(0, $return['conditions']['Statehistory.state']) && - in_array(1, $return['conditions']['Statehistory.state']) && - in_array(2, $return['conditions']['Statehistory.state']) - ) { - unset($return['conditions']['Statehistory.state']); - } - } - - return $return; - } - } diff --git a/app/Plugin/NagiosModule/Model/StatehistoryService.php b/app/Plugin/NagiosModule/Model/StatehistoryService.php new file mode 100644 index 0000000000..ce5ef729db --- /dev/null +++ b/app/Plugin/NagiosModule/Model/StatehistoryService.php @@ -0,0 +1,73 @@ + +// +// This file is dual licensed +// +// 1. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 3 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +// 2. +// If you purchased an openITCOCKPIT Enterprise Edition you can use this file +// under the terms of the openITCOCKPIT Enterprise Edition license agreement. +// License agreement and license key will be shipped with the order +// confirmation. + +use itnovum\openITCOCKPIT\Core\StatehistoryServiceConditions; + +class StatehistoryService extends NagiosModuleAppModel +{ + public $useTable = 'statehistory'; + public $primaryKey = 'statehistory_id'; + public $tablePrefix = 'nagios_'; + public $belongsTo = [ + 'Objects' => [ + 'className' => 'NagiosModule.Objects', + 'foreignKey' => 'object_id', + 'conditions' => [ + 'Objects.objecttype_id' => 2 + ], + 'type' => 'INNER' + ], + ]; + + + /** + * @param StatehistoryServiceConditions $StatehistoryServiceConditions + * @param array $paginatorConditions + * @return array + */ + public function getQuery(StatehistoryServiceConditions $StatehistoryServiceConditions, $paginatorConditions = []){ + $query = [ + 'conditions' => [ + 'Objects.name2' => $StatehistoryServiceConditions->getServiceUuid(), + 'StatehistoryService.state_time >' => date('Y-m-d H:i:s', $StatehistoryServiceConditions->getFrom()), + 'StatehistoryService.state_time <' => date('Y-m-d H:i:s', $StatehistoryServiceConditions->getTo()) + ], + 'order' => $StatehistoryServiceConditions->getOrder(), + 'limit' => $StatehistoryServiceConditions->getLimit(), + ]; + + if(!empty($StatehistoryServiceConditions->getStates())){ + $query['conditions']['StatehistoryService.state'] = $StatehistoryServiceConditions->getStates(); + } + + if(!empty($StatehistoryServiceConditions->getStateTypes())){ + $query['conditions']['StatehistoryService.state_type'] = $StatehistoryServiceConditions->getStateTypes(); + } + + $query['conditions'] = Hash::merge($paginatorConditions, $query['conditions']); + + return $query; + } +} diff --git a/app/View/Acknowledgements/service.ctp b/app/View/Acknowledgements/service.ctp index a406b9e5d6..6da58cffd5 100644 --- a/app/View/Acknowledgements/service.ctp +++ b/app/View/Acknowledgements/service.ctp @@ -26,6 +26,12 @@ use itnovum\openITCOCKPIT\Core\Views\Service; use itnovum\openITCOCKPIT\Core\Views\Host; use itnovum\openITCOCKPIT\Core\Servicestatus; +use itnovum\openITCOCKPIT\Core\Views\AcknowledgementService; +use itnovum\openITCOCKPIT\Core\Views\ServicestatusIcon; +use itnovum\openITCOCKPIT\Core\Views\ListSettingsRenderer; + +$ListSettingsRenderer = new ListSettingsRenderer($AcknowledgementListsettings); +$ListSettingsRenderer->setPaginator($this->Paginator); $Service = new Service($service); $Host = new Host($service); @@ -69,29 +75,12 @@ $this->Paginator->options(['url' => Hash::merge($this->params['named'], $this->p -
- -
-
-
-
@@ -128,89 +128,19 @@ $this->Paginator->options(['url' => Hash::merge($this->params['named'], $this->p Form->create('acknowledgements', [ 'class' => 'form-horizontal clear', - 'url' => 'service/'.$service['Service']['id'] //reset the URL on submit + 'url' => 'service/' . $Service->getId() //reset the URL on submit ]); + echo $ListSettingsRenderer->getFromInput(); + echo $ListSettingsRenderer->getToInput(); + echo $ListSettingsRenderer->getLimitSelect(); - ?> - - - - - -
- [ - 'submit_target' => '#listoptions_hidden_limit', - 'value' => 30, - 'human' => 30, - 'selector' => '#listoptions_limit', - ], - '50' => [ - 'submit_target' => '#listoptions_hidden_limit', - 'value' => 50, - 'human' => 50, - 'selector' => '#listoptions_limit', - ], - '100' => [ - 'submit_target' => '#listoptions_hidden_limit', - 'value' => 100, - 'human' => 100, - 'selector' => '#listoptions_limit', - ], - '300' => [ - 'submit_target' => '#listoptions_hidden_limit', - 'value' => 300, - 'human' => 300, - 'selector' => '#listoptions_limit', - ], - ]; - - $selected = 30; - if (isset($AcknowledgementListsettings['limit']) && isset($listoptions[$AcknowledgementListsettings['limit']]['human'])) { - $selected = $listoptions[$AcknowledgementListsettings['limit']]['human']; - } - ?> - - - -
- - - __('Recovery'), - 'warning' => __('Warning'), + 'ok' => __('Ok'), + 'warning' => __('Warning'), 'critical' => __('Critical'), - 'unknown' => __('Unknown'), + 'unknown' => __('Unknown'), ]; ?> -
- - getApply(); echo $this->Form->end(); ?>
@@ -251,42 +180,61 @@ $this->Paginator->options(['url' => Hash::merge($this->params['named'], $this->p

- -
- -
- ListFilter->renderFilterbox($filters, ['formActionParams' => ['url' => Router::url(Hash::merge($this->params['named'], $this->params['pass'], ['Listsettings' => $AcknowledgementListsettings])), 'merge' => false]], ' '.__('Filter'), false, false); ?> + ListFilter->renderFilterbox($filters, ['formActionParams' => ['url' => Router::url(Hash::merge($this->params['named'], $this->params['pass'], ['Listsettings' => $AcknowledgementListsettings])), 'merge' => false]], ' ' . __('Filter'), false, false); ?> - Paginator->param('order'); ?> - - - - - + + + + + - + getState()); + ?> - - - - + + + + diff --git a/app/View/Hosts/browser.ctp b/app/View/Hosts/browser.ctp index 8a93ba56a0..356b830ef2 100644 --- a/app/View/Hosts/browser.ctp +++ b/app/View/Hosts/browser.ctp @@ -125,7 +125,7 @@ $Hoststatus = new Hoststatus($hoststatus['Hoststatus']); endif; ?>

- isAacknowledged() && !empty($acknowledged)): ?> + isAcknowledged() && !empty($acknowledged)): ?>

@@ -593,7 +593,7 @@ $Hoststatus = new Hoststatus($hoststatus['Hoststatus']); ?>

- @@ -402,8 +402,8 @@ foreach ($this->params->named as $key => $value) { - - - getApply(); echo $this->Form->end(); ?> +

- -
- -
- ListFilter->renderFilterbox($filters, ['formActionParams' => ['url' => Router::url(Hash::merge($this->params['named'], $this->params['pass'], ['Listsettings' => $ServicecheckListsettings])), 'merge' => false]], ' '.__('Filter'), false, false); ?> + ListFilter->renderFilterbox($filters, ['formActionParams' => ['url' => Router::url(Hash::merge($this->params['named'], $this->params['pass'], ['Listsettings' => $ServicecheckListsettings])), 'merge' => false]], ' ' . __('Filter'), false, false); ?> -
Utils->getDirection($order, 'Acknowledged.state'); - echo $this->Paginator->sort('Acknowledged.state', __('State')); ?>Utils->getDirection($order, 'Acknowledged.entry_time'); - echo $this->Paginator->sort('Acknowledged.entry_time', __('Date')); ?>Utils->getDirection($order, 'Acknowledged.author_name'); - echo $this->Paginator->sort('Acknowledged.author_name', __('Author')); ?>Utils->getDirection($order, 'Acknowledged.comment_data'); - echo $this->Paginator->sort('Acknowledged.comment_data', __('Comment')); ?>Utils->getDirection($order, 'Acknowledged.is_sticky'); - echo $this->Paginator->sort('Acknowledged.is_sticky', __('Sticky')); ?> + Utils->getDirection($order, 'AcknowledgedService.state'); + echo $this->Paginator->sort('AcknowledgedService.state', __('State')); ?> + + Utils->getDirection($order, 'AcknowledgedService.entry_time'); + echo $this->Paginator->sort('AcknowledgedService.entry_time', __('Date')); ?> + + Utils->getDirection($order, 'AcknowledgedService.author_name'); + echo $this->Paginator->sort('AcknowledgedService.author_name', __('Author')); ?> + + Utils->getDirection($order, 'AcknowledgedService.comment_data'); + echo $this->Paginator->sort('AcknowledgedService.comment_data', __('Comment')); ?> + + Utils->getDirection($order, 'AcknowledgedService.is_sticky'); + echo $this->Paginator->sort('AcknowledgedService.is_sticky', __('Sticky')); ?> +
Status->humanServiceStatus($service['Service']['uuid'], 'javascript:void(0)', [$service['Service']['uuid'] => ['Servicestatus' => ['current_state' => $acknowledgement['Acknowledged']['state']]]])['html_icon']; ?>Time->format($acknowledgement['Acknowledged']['entry_time'], $this->Auth->user('dateformat'), false, $this->Auth->user('timezone')); ?> + getHtmlIcon(); ?> + + Time->format( + $AcknowledgementService->getEntryTime(), + $this->Auth->user('dateformat'), + false, + $this->Auth->user('timezone') + ); ?> + getAuthorName()); ?>getCommentData()); ?> isSticky()): echo __('True'); else: echo __('False'); @@ -309,7 +257,7 @@ $this->Paginator->options(['url' => Hash::merge($this->params['named'], $this->p
Paginator->counter(__('Page').' {:page} '.__('of').' {:pages}, '.__('Total').' {:count} '.__('entries')); ?>
+ id="datatable_fixed_column_info">Paginator->counter(__('Page') . ' {:page} ' . __('of') . ' {:pages}, ' . __('Total') . ' {:count} ' . __('entries')); ?>
@@ -321,18 +269,8 @@ $this->Paginator->options(['url' => Hash::merge($this->params['named'], $this->p
- - - - - - - + - - - - \ No newline at end of file diff --git a/app/View/Hostgroups/extended.ctp b/app/View/Hostgroups/extended.ctp index d057162bfe..4943ef72fa 100644 --- a/app/View/Hostgroups/extended.ctp +++ b/app/View/Hostgroups/extended.ctp @@ -45,7 +45,7 @@ use itnovum\openITCOCKPIT\Core\HumanTime; > - + @@ -312,19 +312,19 @@ use itnovum\openITCOCKPIT\Core\HumanTime; getByHostIdEvenIfNotExists($host['Host']['id']); ?> = 0): ?> + ">
currentState() > 0): - if ($hoststatus->isAacknowledged()): ?> + if ($hoststatus->isAcknowledged()): ?> Form->input('type', ['options' => ['hostOnly' => __('Only hosts'), 'hostAndServices' => __('Hosts including services')], 'label' => 'Notifications']); ?>
- - disable notifications.'); ?> - + + disable notifications.'); ?> +
@@ -612,9 +612,9 @@ use itnovum\openITCOCKPIT\Core\HumanTime; ]); ?> Form->input('type', ['options' => ['hostOnly' => __('Only hosts'), 'hostAndServices' => __('Hosts including services')], 'label' => 'Notifications']); ?>
- - enable notifications.'); ?> - + + enable notifications.'); ?> +
diff --git a/app/View/Hostgroups/load_services_by_host_id.ctp b/app/View/Hostgroups/load_services_by_host_id.ctp index 563dd81da2..4760cc15bc 100644 --- a/app/View/Hostgroups/load_services_by_host_id.ctp +++ b/app/View/Hostgroups/load_services_by_host_id.ctp @@ -189,7 +189,7 @@ foreach ($services as $service):
- isAacknowledged() && $servicestatus->currentState() > 0): ?> + isAcknowledged() && $servicestatus->currentState() > 0): ?> - isAacknowledged()): ?> + isAcknowledged()): ?> getAcknowledgementType() == 1): ?> diff --git a/app/View/Hosts/index.ctp b/app/View/Hosts/index.ctp index a8044f2e50..8ec6496fc8 100644 --- a/app/View/Hosts/index.ctp +++ b/app/View/Hosts/index.ctp @@ -228,8 +228,8 @@ foreach ($this->params->named as $key => $value) { Utils->getDirection($order, 'Hoststatus.last_hard_state_change'); - echo $this->Paginator->sort('Hoststatus.last_hard_state_change', __('State since')); + echo $this->Utils->getDirection($order, 'Hoststatus.last_state_change'); + echo $this->Paginator->sort('Hoststatus.last_state_change', __('State since')); ?> @@ -301,7 +301,7 @@ foreach ($this->params->named as $key => $value) { - isAacknowledged()): ?> + isAcknowledged()): ?> getAcknowledgementType() == 1): ?> @@ -372,9 +372,9 @@ foreach ($this->params->named as $key => $value) { getAddress()); ?> - Utils->secondsInHumanShort(time() - strtotime($Hoststatus->getLastHardStateChange()))); ?> + Utils->secondsInHumanShort(time() - $Hoststatus->getLastStateChange())); ?> Time->format($Hoststatus->getLastCheck(), $this->Auth->user('dateformat'), false, $this->Auth->user('timezone'))); ?> getOutput()); ?>
+
Paginator->param('order'); ?> - - - - - - + + + + + + - - + getState()); + ?> - - - - - - + + + + + + @@ -306,7 +262,7 @@ $this->Paginator->options(['url' => Hash::merge($this->params['named'], $this->p
Paginator->counter(__('Page').' {:page} '.__('of').' {:pages}, '.__('Total').' {:count} '.__('entries')); ?>
+ id="datatable_fixed_column_info">Paginator->counter(__('Page') . ' {:page} ' . __('of') . ' {:pages}, ' . __('Total') . ' {:count} ' . __('entries')); ?>
@@ -318,18 +274,7 @@ $this->Paginator->options(['url' => Hash::merge($this->params['named'], $this->p
- - - - - - - - - - - \ No newline at end of file diff --git a/app/View/Services/browser.ctp b/app/View/Services/browser.ctp index bcf794bd37..8206922690 100644 --- a/app/View/Services/browser.ctp +++ b/app/View/Services/browser.ctp @@ -25,13 +25,14 @@ use itnovum\openITCOCKPIT\Core\Hoststatus; use itnovum\openITCOCKPIT\Core\Servicestatus; +use itnovum\openITCOCKPIT\Core\Views\AcknowledgementService; use itnovum\openITCOCKPIT\Core\Views\HoststatusIcon; use itnovum\openITCOCKPIT\Core\Views\ServicestatusIcon; -if(!isset($hoststatus['Hoststatus'])): +if (!isset($hoststatus['Hoststatus'])): $hoststatus['Hoststatus'] = []; endif; -if(!isset($servicestatus['Servicestatus'])): +if (!isset($servicestatus['Servicestatus'])): $servicestatus['Servicestatus'] = []; endif; $Hoststatus = new Hoststatus($hoststatus['Hoststatus']); @@ -145,7 +146,10 @@ $Servicestatus = new Servicestatus($servicestatus['Servicestatus']); endif; ?>

- isAacknowledged() && !empty($acknowledged)): ?> + isAcknowledged() && !empty($acknowledged)): + $AcknowledgementService = new AcknowledgementService($acknowledged['AcknowledgedService']); + ?>

getAcknowledgementType() == 1): ?> @@ -161,10 +165,12 @@ $Servicestatus = new Servicestatus($servicestatus['Servicestatus']); else: echo __('The current status was already acknowledged (STICKY) by'); endif; ?> - ( + + getAuthorName()); ?> + + ( Time->format($acknowledged['Acknowledged']['entry_time'], + echo $this->Time->format($AcknowledgementService->getEntryTime(), $this->Auth->user('dateformat'), false, $this->Auth->user('timezone') @@ -173,15 +179,15 @@ $Servicestatus = new Servicestatus($servicestatus['Servicestatus']); "getCommentData(), $ticketDetails)): echo (isset($ticketDetails[1], $ticketDetails[3], $ticketDetails[2])) ? $this->Html->link( $ticketDetails[1] . ' ' . $ticketDetails[2], $ticketSystem['Systemsetting']['value'] . $ticketDetails[3], ['target' => '_blank']) : - $acknowledged['Acknowledged']['comment_data']; + $AcknowledgementService->getCommentData(); else: - echo h($acknowledged['Acknowledged']['comment_data']); + echo h($AcknowledgementService->getCommentData()); endif; ?>". diff --git a/app/View/Services/index.ctp b/app/View/Services/index.ctp index 43d1e1559e..0d0bba85c1 100755 --- a/app/View/Services/index.ctp +++ b/app/View/Services/index.ctp @@ -22,13 +22,19 @@ // under the terms of the openITCOCKPIT Enterprise Edition license agreement. // License agreement and license key will be shipped with the order // confirmation. -?> -Paginator->options(['url' => $this->params['named']]); $filter = "/"; foreach ($this->params->named as $key => $value) { if (!is_array($value)) { - $filter .= $key.":".$value."/"; + $filter .= $key . ":" . $value . "/"; } } ?> @@ -39,7 +45,7 @@ foreach ($this->params->named as $key => $value) { > - + @@ -71,7 +77,7 @@ foreach ($this->params->named as $key => $value) {

Utils->getDirection($order, 'Servicecheck.state'); - echo $this->Paginator->sort('Servicecheck.state', __('State')); ?>Utils->getDirection($order, 'Servicecheck.start_time'); - echo $this->Paginator->sort('Servicecheck.start_time', __('Date')); ?>Utils->getDirection($order, 'Servicecheck.current_check_attempt'); - echo $this->Paginator->sort('Servicecheck.current_check_attempt', __('Check attempt')); ?>Utils->getDirection($order, 'Servicecheck.state_type'); - echo $this->Paginator->sort('Servicecheck.state_type', __('State type')); ?>Utils->getDirection($order, 'Servicecheck.output'); - echo $this->Paginator->sort('Servicecheck.output', __('Service output')); ?>Utils->getDirection($order, 'Servicecheck.perfdata'); - echo $this->Paginator->sort('Servicecheck.perfdata', __('Performance data')); ?> + Utils->getDirection($order, 'Servicecheck.state'); + echo $this->Paginator->sort('Servicecheck.state', __('State')); ?> + + Utils->getDirection($order, 'Servicecheck.start_time'); + echo $this->Paginator->sort('Servicecheck.start_time', __('Date')); ?> + + Utils->getDirection($order, 'Servicecheck.current_check_attempt'); + echo $this->Paginator->sort('Servicecheck.current_check_attempt', __('Check attempt')); ?> + + Utils->getDirection($order, 'Servicecheck.state_type'); + echo $this->Paginator->sort('Servicecheck.state_type', __('State type')); ?> + + Utils->getDirection($order, 'Servicecheck.output'); + echo $this->Paginator->sort('Servicecheck.output', __('Service output')); ?> + + Utils->getDirection($order, 'Servicecheck.perfdata'); + echo $this->Paginator->sort('Servicecheck.perfdata', __('Performance data')); ?> +
Status->humanServiceStatus($service['Service']['uuid'], 'javascript:void(0)', [$service['Service']['uuid'] => ['Servicestatus' => ['current_state' => $servicecheck['Servicecheck']['state']]]])['html_icon']; ?>Time->format($servicecheck['Servicecheck']['start_time'], $this->Auth->user('dateformat'), false, $this->Auth->user('timezone'))); ?> - /Status->humanServiceStateType($servicecheck['Servicecheck']['state_type'])); ?> + getHtmlIcon(); ?> + + Time->format( + $Servicecheck->getStartTime(), + $this->Auth->user('dateformat'), + false, + $this->Auth->user('timezone') + )); ?> + + getCurrentCheckAttempt()), + h($Servicecheck->getMaxCheckAttempts()) + ); ?> + + Status->humanServiceStateType( + $Servicecheck->isHardstate() + )); ?> + + getOutput()); ?> + + getPerfdata()); ?> +
+
Paginator->param('order'); ?> - - + + + + + + + - - - + - - - - - - - - - Acl->isWritableContainer($hostContainers[$service['Host']['id']])): + if (isset($hostContainers[$Host->getId()])): + if ($this->Acl->isWritableContainer($hostContainers[$Host->getId()])): $allowEdit = true; endif; endif; endif; - if ($tmp_host_name != $service['Host']['name']): - $tmp_host_name = $service['Host']['name']; + if ($tmp_host_name != $Host->getHostname()): + $tmp_host_name = $Host->getHostname(); ?> - - - - - + - +
Utils->getDirection($order, 'Service.servicestatus'); - echo $this->Paginator->sort('Service.servicestatus', 'Servicestatus'); ?> + + Utils->getDirection($order, 'Servicestatus.current_state'); + echo $this->Paginator->sort('Servicestatus.current_state', 'Servicestatus'); ?> + + + + + + + + P + + Utils->getDirection($order, 'Service.servicename'); + echo $this->Paginator->sort('Service.servicename', __('Servicename')); ?> + + Utils->getDirection($order, 'Servicestatus.last_state_change'); + echo $this->Paginator->sort('Servicestatus.last_state_change', __('Last state change')); ?> + + Utils->getDirection($order, 'Servicestatus.last_check'); + echo $this->Paginator->sort('Servicestatus.last_check', __('Last check')); ?> + + Utils->getDirection($order, 'Servicestatus.next_check'); + echo $this->Paginator->sort('Servicestatus.next_check', __('Next check')); ?> P + + Utils->getDirection($order, 'Servicestatus.output'); + echo $this->Paginator->sort('Servicestatus.output', __('Service output')); ?> + + Utils->getDirection($order, 'Service.servicename'); - echo $this->Paginator->sort('Service.servicename', __('Servicename')); ?>Utils->getDirection($order, 'Service.last_hard_state_change'); - echo $this->Paginator->sort('Service.last_hard_state_change', __('Last state change')); ?>Utils->getDirection($order, 'Service.last_check'); - echo $this->Paginator->sort('Service.last_check', __('Last check')); ?>Utils->getDirection($order, 'Service.next_check'); - echo $this->Paginator->sort('Service.next_check', __('Next check')); ?>Utils->getDirection($order, 'Service.output'); - echo $this->Paginator->sort('Service.output', __('Service output')); ?>
Acl->hasPermission('browser', 'hosts')): - $href = '/hosts/browser/'.$service['Host']['id']; + $href = Router::url([ + 'controller' => 'hosts', + 'action' => 'browser', + $Host->getId() + ]); endif; - echo $this->Status->humanHostStatus($service['Host']['uuid'], $href, [$service['Host']['uuid'] => ['Hoststatus' => ['current_state' => $service['Hoststatus']['current_state']]]])['html_icon']; - ?> - Acl->hasPermission('browser', 'hosts')): ?> + $Hoststatus = new Hoststatus($service['Hoststatus']); + $HoststatusIcon = new HoststatusIcon($Hoststatus->currentState(), $href); + + echo $HoststatusIcon->getHtmlIcon(); + if ($this->Acl->hasPermission('browser', 'hosts')): ?> - () + href=""> + getHostname()), + h($Host->getAddress())); ?> + - + getHostname()); ?> Acl->hasPermission('serviceList', 'services')): ?> + href=" 'services', + 'action' => 'serviceList', + $Host->getId() + ]); ?> + "> +
+ servicename="getServicename()); ?>" + value="getId(); ?>" + uuid="getUuid(); ?>" + host-uuid="getUuid(); ?>"> Monitoring->serviceFlappingIconColored($service['Servicestatus']['is_flapping'], '', $service['Servicestatus']['current_state']); + if ($Servicestatus->isFlapping()): + echo $Servicestatus->getServiceFlappingIconColored(); else: $serviceHref = 'javascript:void(0);'; if ($this->Acl->hasPermission('browser')): - $serviceHref = '/services/browser/'.$service['Service']['id']; + $serviceHref = Router::url([ + 'controller' => 'services', + 'action' => 'browser', + $Service->getId() + ]); endif; - echo $this->Status->humanServiceStatus($service['Service']['uuid'], $serviceHref, [$service['Service']['uuid'] => ['Servicestatus' => ['current_state' => $service['Servicestatus']['current_state']]]])['html_icon']; + $ServicestatusIcon = new ServicestatusIcon( + $Servicestatus->currentState(), $serviceHref + ); + echo $ServicestatusIcon->getHtmlIcon(); endif; ?> - Monitoring->checkForAck($service['Servicestatus']['problem_has_been_acknowledged'])): ?> - + isAcknowledged()): ?> + getAcknowledgementType() == 1): ?> @@ -237,65 +275,78 @@ foreach ($this->params->named as $key => $value) { - Monitoring->checkForDowntime($service['Servicestatus']['scheduled_downtime_depth'])): ?> + isInDowntime()): ?> - Monitoring->checkForServiceGraph($service['Host']['uuid'], $service['Service']['uuid'])): ?> + Monitoring->checkForServiceGraph($Host->getUuid(), $Service->getUuid())): ?> Acl->hasPermission('browser')): - $graphHref = '/services/grapherSwitch/'.$service['Service']['id']; + $graphHref = Router::url([ + 'controller' => 'services', + 'action' => 'grapherSwitch', + $Service->getId() + ]); endif; ?> - + + host-uuid="getUuid(); ?>" + service-uuid="getUuid(); ?>"> + - 0): ?> + isActiveChecksEnabled() === false || $Host->isSatelliteHost()): ?> P Acl->hasPermission('browser')): ?> - - + + getServicename()); ?> - + getServicename()); ?> - Utils->secondsInHumanShort(time() - strtotime($service['Servicestatus']['last_hard_state_change']))); ?> + + Utils->secondsInHumanShort(time() - $Servicestatus->getLastStateChange())); ?> Time->format($service['Servicestatus']['last_check'], $this->Auth->user('dateformat'), false, $this->Auth->user('timezone'))); ?>Time->format($Servicestatus->getLastCheck(), $this->Auth->user('dateformat'), false, $this->Auth->user('timezone'))); ?> Time->format($service['Servicestatus']['last_check'], $this->Auth->user('dateformat'), false, $this->Auth->user('timezone'))); - else: - echo __('n/a'); - endif; + if ($Service->isActiveChecksEnabled() && $Host->isSatelliteHost() === false): + echo h($this->Time->format($Servicestatus->getNextCheck(), $this->Auth->user('dateformat'), false, $this->Auth->user('timezone'))); else: echo __('n/a'); + endif; ?> getOutput()); ?>
Acl->hasPermission('edit') && $allowEdit): ?> -    + +    + -    + &n +   params->named as $key => $value) { @@ -422,7 +484,7 @@ foreach ($this->params->named as $key => $value) {
Paginator->counter(__('Page').' {:page} '.__('of').' {:pages}, '.__('Total').' {:count} '.__('entries')); ?>
+ id="datatable_fixed_column_info">Paginator->counter(__('Page') . ' {:page} ' . __('of') . ' {:pages}, ' . __('Total') . ' {:count} ' . __('entries')); ?>
@@ -497,7 +559,7 @@ foreach ($this->params->named as $key => $value) { echo $this->Form->create('CommitServiceDowntime', [ 'class' => 'form-horizontal clear', ]); ?> - Form->input('comment', ['value' => __('In progress'), 'label' => __('Comment').':']); ?> + Form->input('comment', ['value' => __('In progress'), 'label' => __('Comment') . ':']); ?>
@@ -562,7 +624,7 @@ foreach ($this->params->named as $key => $value) { echo $this->Form->create('CommitServiceAck', [ 'class' => 'form-horizontal clear', ]); ?> - Form->input('comment', ['value' => __('In progress'), 'label' => __('Comment').':']); ?> + Form->input('comment', ['value' => __('In progress'), 'label' => __('Comment') . ':']); ?> Form->input('sticky', ['type' => 'checkbox', 'label' => __('Sticky'), 'wrapInput' => 'col-md-offset-2 col-md-10']); ?> Form->input('author', ['type' => 'hidden', 'value' => $username]) ?>
@@ -599,9 +661,9 @@ foreach ($this->params->named as $key => $value) { 'class' => 'form-horizontal clear', ]); ?>
- - disable notifications.'); ?> - + + disable notifications.'); ?> +
@@ -641,9 +703,9 @@ foreach ($this->params->named as $key => $value) { 'class' => 'form-horizontal clear', ]); ?>
- - enable notifications.'); ?> - + + enable notifications.'); ?> +
diff --git a/app/View/Services/service_list.ctp b/app/View/Services/service_list.ctp index 75e31705cf..e647091092 100644 --- a/app/View/Services/service_list.ctp +++ b/app/View/Services/service_list.ctp @@ -22,9 +22,15 @@ // under the terms of the openITCOCKPIT Enterprise Edition license agreement. // License agreement and license key will be shipped with the order // confirmation. -?> -Paginator->url($this->params['url']); ?> -Paginator->options(array('url' => $this->params['named'])); ?> + +use itnovum\openITCOCKPIT\Core\Servicestatus; +use itnovum\openITCOCKPIT\Core\Views\Host; +use itnovum\openITCOCKPIT\Core\Views\Service; +use itnovum\openITCOCKPIT\Core\Views\ServicestatusIcon; + +$Host = new Host($host); + +$this->Paginator->url($this->params['url']); ?>

@@ -32,7 +38,7 @@ > - +

@@ -58,20 +64,24 @@
Form->input('host_id', [ - 'options' => $hosts, - 'selected' => $host_id, + 'options' => $hosts, + 'selected' => $Host->getId(), 'data-placeholder' => __('Please select...'), - 'class' => 'chosen', - 'label' => false, - 'wrapInput' => 'col col-xs-12', - 'style' => 'width: 100%', + 'class' => 'chosen', + 'label' => false, + 'wrapInput' => 'col col-xs-12', + 'style' => 'width: 100%', ]); ?>
Acl->hasPermission('edit', 'hosts') && $allowEdit): ?> - +       @@ -82,38 +92,63 @@ @@ -126,28 +161,45 @@ -

+

getHostname()); ?>

@@ -158,71 +210,97 @@
- Paginator->param('order'); ?> - + - + + - - - + + + - - - - - - - currentState(), + Router::url([ + 'controller' => 'services', + 'action' => 'browser', + $Service->getId() + ]) + ); ?> - + - - + @@ -338,22 +446,24 @@ - + - - + + - - - + + +
Utils->getDirection($order, 'Service.servicestatus'); - echo $this->Paginator->sort('Service.servicestatus', 'Service'); ?> + Utils->getDirection($order, 'Servicestatus.current_state'); + echo $this->Paginator->sort('Servicestatus.current_state', 'Servicestatus'); ?> + + + + + + + + + + P + + + Utils->getDirection($order, 'Service.servicename'); + echo $this->Paginator->sort('Service.servicename', __('Servicename')); ?> P + + Utils->getDirection($order, 'Servicestatus.last_state_change'); + echo $this->Paginator->sort('Servicestatus.last_state_change', __('Status since')); ?> + + Utils->getDirection($order, 'Servicestatus.last_check'); + echo $this->Paginator->sort('Servicestatus.last_check', __('Last check')); ?> + + Utils->getDirection($order, 'Servicestatus.next_check'); + echo $this->Paginator->sort('Servicestatus.next_check', __('Next check')); ?> + + Utils->getDirection($order, 'Servicestatus.output'); + echo $this->Paginator->sort('Servicestatus.output', __('Service output')); ?> Utils->getDirection($order, 'Service.servicename'); - echo $this->Paginator->sort('Service.servicename', __('Servicename')); ?>Utils->getDirection($order, 'Service.last_hard_state_change'); - echo $this->Paginator->sort('Service.last_hard_state_change', __('Status since')); ?>Utils->getDirection($order, 'Service.last_check'); - echo $this->Paginator->sort('Service.last_check', __('Last check')); ?>Utils->getDirection($order, 'Service.next_check'); - echo $this->Paginator->sort('Service.next_check', __('Next check')); ?>Utils->getDirection($order, 'Service.output'); - echo $this->Paginator->sort('Service.output', __('Service output')); ?>
+ servicename="getServicename()); ?>" + value="getId(); ?>" + uuid="getUuid(); ?>"> Monitoring->serviceFlappingIconColored($service['Servicestatus']['is_flapping'], '', $service['Servicestatus']['current_state']); + if ($Servicestatus->isFlapping()): + echo $Servicestatus->getServiceFlappingIconColored(); else: - echo $this->Status->humanServiceStatus($service['Service']['uuid'], '/services/browser/'.$service['Service']['id'], [$service['Service']['uuid'] => ['Servicestatus' => ['current_state' => $service['Servicestatus']['current_state']]]])['html_icon']; + echo $ServicestatusIcon->getHtmlIcon(); endif; ?>
Acl->hasPermission('edit', 'services') && $allowEdit): ?> -    +      Acl->hasPermission('edit', 'services') && $allowEdit): ?>
  • - + +
  • Acl->hasPermission('deactivate', 'services') && $allowEdit): ?>
  • - + +
  • Acl->hasPermission('delete', 'services') && $allowEdit): ?>
  • - Form->postLink(' '.__('Delete'), ['controller' => 'services', 'action' => 'delete', $service['Service']['id']], ['class' => 'txt-color-red', 'escape' => false]); ?> + Form->postLink(' ' . __('Delete'), ['controller' => 'services', 'action' => 'delete', $Service->getId()], ['class' => 'txt-color-red', 'escape' => false]); ?>
  • - Monitoring->checkForAck($service['Servicestatus']['problem_has_been_acknowledged'])): ?> - + isAcknowledged()): ?> + getAcknowledgementType() == 1): ?> @@ -267,47 +353,69 @@ - Monitoring->checkForDowntime($service['Servicestatus']['scheduled_downtime_depth'])): ?> + isInDowntime()): ?> - Monitoring->checkForServiceGraph($service['Host']['uuid'], $service['Service']['uuid'])): ?> + Monitoring->checkForServiceGraph($Host->getUuid(), $Service->getUuid())): ?> + href=" 'services', + 'action' => 'grapherSwitch', + $Service->getId() + + ]); ?>"> + + - 0): ?> + isActiveChecksEnabled() || $Host->isSatelliteHost()): ?> P - - + + getServicename()); ?> - Utils->secondsInHumanShort(time() - strtotime($service['Servicestatus']['last_hard_state_change']))); ?> + Utils->secondsInHumanShort( + time() - $Servicestatus->getLastStateChange()) + ); ?> + + Time->format( + $Servicestatus->getLastCheck(), + $this->Auth->user('dateformat'), + false, + $this->Auth->user('timezone')) + ); ?> Time->format($service['Servicestatus']['last_check'], $this->Auth->user('dateformat'), false, $this->Auth->user('timezone'))); ?> Time->format($service['Servicestatus']['last_check'], $this->Auth->user('dateformat'), false, $this->Auth->user('timezone'))); - else: - echo __('n/a'); - endif; + if ($Service->isActiveChecksEnabled() === true && $Host->isSatelliteHost() === false): + echo h($this->Time->format( + $Servicestatus->getNextCheck(), + $this->Auth->user('dateformat'), + false, + $this->Auth->user('timezone')) + ); else: echo __('n/a'); endif; ?> + getOutput()); ?> +
    - + getServicename()); ?> getUuid()); ?>
    Acl->hasPermission('edit', 'services') && $allowEdit): ?> -    + +    Acl->hasPermission('edit', 'services') && $allowEdit): ?>
  • - + +
  • Acl->hasPermission('enable', 'services') && $allowEdit): ?>
  • - + +
  • Acl->hasPermission('delete', 'services') && $allowEdit): ?>
  • - Form->postLink(' '.__('Delete'), ['controller' => 'services', 'action' => 'delete', $disabledService['Service']['id']], ['class' => 'txt-color-red', 'escape' => false]); ?> + Form->postLink(' ' . __('Delete'), ['controller' => 'services', 'action' => 'delete', $Service->getId()], ['class' => 'txt-color-red', 'escape' => false]); ?>
  • @@ -411,9 +529,16 @@
    Time->format($deletedService['DeletedService']['created'], $this->Auth->user('dateformat'), false, $this->Auth->user('timezone')); ?> + Time->format( + $deletedService['DeletedService']['created'], + $this->Auth->user('dateformat'), + false, + $this->Auth->user('timezone') + ); ?> + @@ -433,7 +558,7 @@
    Paginator->counter(__('Page').' {:page} '.__('of').' {:pages}, '.__('Total').' {:count} '.__('entries')); ?>
    + id="datatable_fixed_column_info">Paginator->counter(__('Page') . ' {:page} ' . __('of') . ' {:pages}, ' . __('Total') . ' {:count} ' . __('entries')); ?>
    @@ -509,7 +634,7 @@ echo $this->Form->create('CommitServiceDowntime', [ 'class' => 'form-horizontal clear', ]); ?> - Form->input('comment', ['value' => __('In progress'), 'label' => __('Comment').':']); ?> + Form->input('comment', ['value' => __('In progress'), 'label' => __('Comment') . ':']); ?>
    @@ -574,7 +699,7 @@ echo $this->Form->create('CommitServiceAck', [ 'class' => 'form-horizontal clear', ]); ?> - Form->input('comment', ['value' => __('In progress'), 'label' => __('Comment').':']); ?> + Form->input('comment', ['value' => __('In progress'), 'label' => __('Comment') . ':']); ?> Form->input('sticky', ['type' => 'checkbox', 'label' => __('Sticky'), 'wrapInput' => 'col-md-offset-2 col-md-10']); ?> Form->input('author', ['type' => 'hidden', 'value' => $username]) ?>
    @@ -611,9 +736,9 @@ 'class' => 'form-horizontal clear', ]); ?>
    - - disable notifications.'); ?> - + + disable notifications.'); ?> +
    @@ -653,9 +778,9 @@ 'class' => 'form-horizontal clear', ]); ?>
    - - enable notifications.'); ?> - + + enable notifications.'); ?> +
    diff --git a/app/View/Statehistories/host.ctp b/app/View/Statehistories/host.ctp index 489dfa9b78..d3d41038bb 100644 --- a/app/View/Statehistories/host.ctp +++ b/app/View/Statehistories/host.ctp @@ -235,8 +235,10 @@ $this->Paginator->options(['url' => Hash::merge($this->params['named'], $this->p )); ?>
    - getCurrentCheckAttempt()); ?> - /getMaxCheckAttempts()); ?> + getCurrentCheckAttempt()), + h($StatehistoryHost->getMaxCheckAttempts()) + ); ?> Status->humanServiceStateType( diff --git a/app/View/Statehistories/service.ctp b/app/View/Statehistories/service.ctp index 440075d8b9..a79b5a8789 100644 --- a/app/View/Statehistories/service.ctp +++ b/app/View/Statehistories/service.ctp @@ -26,6 +26,13 @@ use itnovum\openITCOCKPIT\Core\Views\Service; use itnovum\openITCOCKPIT\Core\Views\Host; use itnovum\openITCOCKPIT\Core\Servicestatus; +use itnovum\openITCOCKPIT\Core\Views\ServicestatusIcon; +use itnovum\openITCOCKPIT\Core\Views\StatehistoryService; +use itnovum\openITCOCKPIT\Core\Views\ListSettingsRenderer; + +$ListSettingsRenderer = new ListSettingsRenderer($StatehistoryListsettings); +$ListSettingsRenderer->setPaginator($this->Paginator); + $Service = new Service($service); $Host = new Host($service); @@ -60,8 +67,13 @@ $this->Paginator->options(['url' => Hash::merge($this->params['named'], $this->p
    @@ -69,29 +81,10 @@ $this->Paginator->options(['url' => Hash::merge($this->params['named'], $this->p
    -
    - -
    - -
    -
    -
    @@ -128,86 +137,23 @@ $this->Paginator->options(['url' => Hash::merge($this->params['named'], $this->p Form->create('statehistories', [ 'class' => 'form-horizontal clear', - 'url' => 'service/'.$service['Service']['id'] //reset the URL on submit + 'url' => 'service/' . $Service->getId() //reset the URL on submit ]); + echo $ListSettingsRenderer->getFromInput(); + echo $ListSettingsRenderer->getToInput(); + echo $ListSettingsRenderer->getLimitSelect(); - ?> - - - - - -
    - [ - 'submit_target' => '#listoptions_hidden_limit', - 'value' => 30, - 'human' => 30, - 'selector' => '#listoptions_limit', - ], - '50' => [ - 'submit_target' => '#listoptions_hidden_limit', - 'value' => 50, - 'human' => 50, - 'selector' => '#listoptions_limit', - ], - '100' => [ - 'submit_target' => '#listoptions_hidden_limit', - 'value' => 100, - 'human' => 100, - 'selector' => '#listoptions_limit', - ], - '300' => [ - 'submit_target' => '#listoptions_hidden_limit', - 'value' => 300, - 'human' => 300, - 'selector' => '#listoptions_limit', - ], - ]; - - $selected = 30; - if (isset($StatehistoryListsettings['limit']) && isset($listoptions[$StatehistoryListsettings['limit']]['human'])) { - $selected = $listoptions[$StatehistoryListsettings['limit']]['human']; - } - ?> - - - -
    - - - __('Recovery'), - 'warning' => __('Warning'), + 'ok' => __('Ok'), + 'warning' => __('Warning'), 'critical' => __('Critical'), - 'unknown' => __('Unknown'), + 'unknown' => __('Unknown'), + ]; + $nag_service_state_types = [ + 'soft' => __('Soft'), + 'hard' => __('Hard'), ]; + ?>
    @@ -225,21 +171,17 @@ $this->Paginator->options(['url' => Hash::merge($this->params['named'], $this->p
  • +
  • />  
  • -
  • __('Soft'), - 'hard' => __('Hard'), - ]; foreach ($nag_service_state_types as $state_type => $name): $checked = ''; @@ -250,25 +192,27 @@ $this->Paginator->options(['url' => Hash::merge($this->params['named'], $this->p
  • +
  • />  
  • -
    - getApply(); echo $this->Form->end(); ?>
    + + @@ -276,40 +220,70 @@ $this->Paginator->options(['url' => Hash::merge($this->params['named'], $this->p -
    -
    - ListFilter->renderFilterbox($filters, ['formActionParams' => ['url' => Router::url(Hash::merge($this->params['named'], $this->params['pass'], ['Listsettings' => $StatehistoryListsettings])), 'merge' => false]], ' '.__('Filter'), false, false); ?> + ListFilter->renderFilterbox($filters, ['formActionParams' => ['url' => Router::url(Hash::merge($this->params['named'], $this->params['pass'], ['Listsettings' => $StatehistoryListsettings])), 'merge' => false]], ' ' . __('Filter'), false, false); ?> - Paginator->param('order'); ?> - - - - - + + + + + - - + getState()); + ?> - - - - - + + + + + @@ -326,7 +300,7 @@ $this->Paginator->options(['url' => Hash::merge($this->params['named'], $this->p
    Paginator->counter(__('Page').' {:page} '.__('of').' {:pages}, '.__('Total').' {:count} '.__('entries')); ?>
    + id="datatable_fixed_column_info">Paginator->counter(__('Page') . ' {:page} ' . __('of') . ' {:pages}, ' . __('Total') . ' {:count} ' . __('entries')); ?>
    @@ -338,18 +312,7 @@ $this->Paginator->options(['url' => Hash::merge($this->params['named'], $this->p
    - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/itnovum/openITCOCKPIT/Core/AcknowledgedServiceConditions.php b/app/src/itnovum/openITCOCKPIT/Core/AcknowledgedServiceConditions.php new file mode 100644 index 0000000000..e5f309f0fc --- /dev/null +++ b/app/src/itnovum/openITCOCKPIT/Core/AcknowledgedServiceConditions.php @@ -0,0 +1,75 @@ + +// +// This file is dual licensed +// +// 1. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 3 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// 2. +// If you purchased an openITCOCKPIT Enterprise Edition you can use this file +// under the terms of the openITCOCKPIT Enterprise Edition license agreement. +// License agreement and license key will be shipped with the order +// confirmation. + +namespace itnovum\openITCOCKPIT\Core; + + +use itnovum\openITCOCKPIT\Core\ValueObjects\ServiceStates; + +class AcknowledgedServiceConditions extends ListSettingsConditions { + + /** + * @var array + */ + protected $order = [ + 'AcknowledgedService.entry_time' => 'DESC' + ]; + + protected $states = [ + 0, 1, 2, 3 + ]; + + /** + * @var string + */ + protected $serviceUuid; + + /** + * @param $serviceUuid + */ + public function setServiceUuid($serviceUuid){ + $this->serviceUuid = $serviceUuid; + } + + /** + * @return string + */ + public function getServiceUuid(){ + return $this->serviceUuid; + } + + /** + * @param ServiceStates $ServiceStates + */ + public function setStates(ServiceStates $ServiceStates){ + if(sizeof($ServiceStates->asIntegerArray()) == 4){ + $this->states = []; + return; + } + + $this->states = $ServiceStates->asIntegerArray(); + } + +} + diff --git a/app/src/itnovum/openITCOCKPIT/Core/AcknowledgedServiceControllerRequest.php b/app/src/itnovum/openITCOCKPIT/Core/AcknowledgedServiceControllerRequest.php new file mode 100644 index 0000000000..af46d6dc1f --- /dev/null +++ b/app/src/itnovum/openITCOCKPIT/Core/AcknowledgedServiceControllerRequest.php @@ -0,0 +1,95 @@ + +// +// This file is dual licensed +// +// 1. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 3 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// 2. +// If you purchased an openITCOCKPIT Enterprise Edition you can use this file +// under the terms of the openITCOCKPIT Enterprise Edition license agreement. +// License agreement and license key will be shipped with the order +// confirmation. + +namespace itnovum\openITCOCKPIT\Core; + + +use itnovum\openITCOCKPIT\Core\ValueObjects\ListSettingsDefaults; +use itnovum\openITCOCKPIT\Core\ValueObjects\ServiceStates; + +class AcknowledgedServiceControllerRequest extends ControllerListSettingsRequest { + + /** + * @var ServiceStates + */ + protected $ServiceStates; + + public function __construct(\CakeRequest $request, ServiceStates $ServiceStates, $userLimit = 25){ + $this->ListSettingsDefaults = new ListSettingsDefaults($userLimit); + + $this->ServiceStates = $ServiceStates; + $this->request = $request; + + if ($this->request->is('post')) { + $this->requestParameters = $this->request->data; + } + + //Parameters from URL (GET) + if (isset($this->request->params['named']['Listsettings'])) { + $this->requestParameters['Listsettings'] = $this->request->params['named']['Listsettings']; + } + } + + /** + * @return ServiceStates + */ + public function getServiceStates(){ + $availableStates = $this->ServiceStates->getAvailableStateIds(); + + if (isset($this->requestParameters['Listsettings']['state_types'])) { + foreach ($this->requestParameters['Listsettings']['state_types'] as $stateName => $value) { + if (isset($availableStates[$stateName]) && $value == 1) { + $this->ServiceStates->setState($availableStates[$stateName], true); + } + } + } + return $this->ServiceStates; + } + + /** + * @return array + */ + public function getRequestSettingsForListSettings(){ + $states = $this->ServiceStates->asArray(); + if( + !$this->ServiceStates->hasOk() && + !$this->ServiceStates->hasWarning() && + !$this->ServiceStates->hasCritical() && + !$this->ServiceStates->hasUnknown() + ){ + //User disabled all check boxes or first page load + //Enable all to avoid empty list + foreach($states as $key => $value){ + $states[$key] = true; + } + } + + return [ + 'limit' => $this->getLimit(), + 'state_types' => $states, + 'from' => date('d.m.Y H:i', $this->getFrom()), + 'to' => date('d.m.Y H:i', $this->getTo()) + ]; + } +} diff --git a/app/src/itnovum/openITCOCKPIT/Core/Hoststatus.php b/app/src/itnovum/openITCOCKPIT/Core/Hoststatus.php index babcd43841..d631160916 100644 --- a/app/src/itnovum/openITCOCKPIT/Core/Hoststatus.php +++ b/app/src/itnovum/openITCOCKPIT/Core/Hoststatus.php @@ -255,7 +255,7 @@ public function currentState(){ return $this->currentState; } - public function isAacknowledged(){ + public function isAcknowledged(){ return (bool)$this->problemHasBeenAcknowledged; } @@ -278,18 +278,30 @@ public function isHardState(){ } public function getLastHardStateChange(){ + if(!is_numeric($this->lastHardStateChange)){ + return strtotime($this->lastHardStateChange); + } return $this->lastHardStateChange; } public function getLastStateChange(){ + if(!is_numeric($this->last_state_change)){ + return strtotime($this->last_state_change); + } return $this->last_state_change; } public function getLastCheck(){ + if(!is_numeric($this->lastCheck)){ + return strtotime($this->lastCheck); + } return $this->lastCheck; } public function getNextCheck(){ + if(!is_numeric($this->nextCheck)){ + return strtotime($this->nextCheck); + } return $this->nextCheck; } diff --git a/app/src/itnovum/openITCOCKPIT/Core/ServiceConditions.php b/app/src/itnovum/openITCOCKPIT/Core/ServiceConditions.php new file mode 100644 index 0000000000..839f41158c --- /dev/null +++ b/app/src/itnovum/openITCOCKPIT/Core/ServiceConditions.php @@ -0,0 +1,128 @@ + +// +// This file is dual licensed +// +// 1. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 3 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// 2. +// If you purchased an openITCOCKPIT Enterprise Edition you can use this file +// under the terms of the openITCOCKPIT Enterprise Edition license agreement. +// License agreement and license key will be shipped with the order +// confirmation. + +namespace itnovum\openITCOCKPIT\Core; + + +class ServiceConditions { + + /** + * @var array + */ + private $conditions = []; + + /** + * @var bool + */ + private $includeDisabled = false; + + /** + * @var array + */ + private $containerIds = []; + + /** + * @var array + */ + private $order = []; + + /** + * @var int + */ + private $hostId; + + /** + * HostConditions constructor. + * @param array $conditions + */ + public function __construct($conditions = []){ + $this->conditions = $conditions; + } + + /** + * @return array + */ + public function getConditions(){ + return $this->conditions; + } + + + /** + * @return boolean + */ + public function includeDisabled(){ + return $this->includeDisabled; + } + + /** + * @param boolean $includeDisabled + */ + public function setIncludeDisabled($includeDisabled){ + $this->includeDisabled = $includeDisabled; + } + + /** + * @return array + */ + public function getContainerIds(){ + return $this->containerIds; + } + + /** + * @param array $containerIds + */ + public function setContainerIds($containerIds){ + $this->containerIds = $containerIds; + } + + /** + * @param array $order + */ + public function setOrder($order = []){ + $this->order = $order; + } + + /** + * @return array + */ + public function getOrder(){ + return $this->order; + } + + /** + * @return int + */ + public function getHostId(){ + return $this->hostId; + } + + /** + * @param int $hostId + */ + public function setHostId($hostId){ + $this->hostId = $hostId; + } + + +} diff --git a/app/src/itnovum/openITCOCKPIT/Core/ServiceControllerRequest.php b/app/src/itnovum/openITCOCKPIT/Core/ServiceControllerRequest.php new file mode 100644 index 0000000000..ef1c81590c --- /dev/null +++ b/app/src/itnovum/openITCOCKPIT/Core/ServiceControllerRequest.php @@ -0,0 +1,73 @@ + +// +// This file is dual licensed +// +// 1. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 3 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// 2. +// If you purchased an openITCOCKPIT Enterprise Edition you can use this file +// under the terms of the openITCOCKPIT Enterprise Edition license agreement. +// License agreement and license key will be shipped with the order +// confirmation. + +namespace itnovum\openITCOCKPIT\Core; + + +class ServiceControllerRequest { + + /** + * @var \CakeRequest + */ + private $request; + + + public function __construct(\CakeRequest $request){ + $this->request = $request; + } + + /** + * @return bool + */ + public function isRequestFromBrowser(){ + return isset($this->request->params['named']['BrowserContainerId']); + } + + /** + * @return array + */ + public function getBrowserContainerIdsByRequest(){ + $containerIds = $this->request->params['named']['BrowserContainerId']; + if (!is_array($containerIds)) { + $containerIds = [$containerIds]; + } + return $containerIds; + } + + /** + * @param array $defaultOrder + * @return array + */ + public function getOrder($defaultOrder = []){ + if (isset($this->request['named']['sort']) && isset($this->request['named']['direction'])) { + return [ + $this->request['named']['sort'] => $this->request['named']['direction'] + ]; + } + + return $defaultOrder; + + } + +} \ No newline at end of file diff --git a/app/src/itnovum/openITCOCKPIT/Core/ServicechecksConditions.php b/app/src/itnovum/openITCOCKPIT/Core/ServicechecksConditions.php new file mode 100644 index 0000000000..ee80a75683 --- /dev/null +++ b/app/src/itnovum/openITCOCKPIT/Core/ServicechecksConditions.php @@ -0,0 +1,74 @@ + +// +// This file is dual licensed +// +// 1. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 3 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// 2. +// If you purchased an openITCOCKPIT Enterprise Edition you can use this file +// under the terms of the openITCOCKPIT Enterprise Edition license agreement. +// License agreement and license key will be shipped with the order +// confirmation. + +namespace itnovum\openITCOCKPIT\Core; + +use itnovum\openITCOCKPIT\Core\ValueObjects\ServiceStates; + +class ServicechecksConditions extends ListSettingsConditions { + + protected $states = [ + 0, 1, 2, 3 + ]; + + /** + * @var array + */ + protected $order = [ + 'Servicecheck.start_time' => 'DESC' + ]; + + /** + * @var string + */ + protected $serviceUuid; + + /** + * @param $uuid + */ + public function setServiceUuid($uuid){ + $this->serviceUuid = $uuid; + } + + /** + * @return string + */ + public function getServiceUuid(){ + return $this->serviceUuid; + } + + /** + * @param ServiceStates $ServiceStates + */ + public function setStates(ServiceStates $ServiceStates){ + if (sizeof($ServiceStates->asIntegerArray()) == 4) { + $this->states = []; + return; + } + + $this->states = $ServiceStates->asIntegerArray(); + } + +} + diff --git a/app/src/itnovum/openITCOCKPIT/Core/ServicechecksControllerRequest.php b/app/src/itnovum/openITCOCKPIT/Core/ServicechecksControllerRequest.php new file mode 100644 index 0000000000..99cc5932c6 --- /dev/null +++ b/app/src/itnovum/openITCOCKPIT/Core/ServicechecksControllerRequest.php @@ -0,0 +1,92 @@ + +// +// This file is dual licensed +// +// 1. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 3 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// 2. +// If you purchased an openITCOCKPIT Enterprise Edition you can use this file +// under the terms of the openITCOCKPIT Enterprise Edition license agreement. +// License agreement and license key will be shipped with the order +// confirmation. + +namespace itnovum\openITCOCKPIT\Core; + + +use itnovum\openITCOCKPIT\Core\ValueObjects\ListSettingsDefaults; +use itnovum\openITCOCKPIT\Core\ValueObjects\ServiceStates; + +class ServicechecksControllerRequest extends ControllerListSettingsRequest { + + protected $ServiceStates; + + public function __construct(\CakeRequest $request, ServiceStates $ServiceStates, $userLimit){ + $this->ListSettingsDefaults = new ListSettingsDefaults($userLimit); + + $this->ServiceStates = $ServiceStates; + $this->request = $request; + + if ($this->request->is('post')) { + $this->requestParameters = $this->request->data; + } + + //Parameters from URL (GET) + if (isset($this->request->params['named']['Listsettings'])) { + $this->requestParameters['Listsettings'] = $this->request->params['named']['Listsettings']; + } + } + + /** + * @return ServiceStates + */ + public function getServiceStates(){ + $availableStates = $this->ServiceStates->getAvailableStateIds(); + + if (isset($this->requestParameters['Listsettings']['state_types'])) { + foreach ($this->requestParameters['Listsettings']['state_types'] as $stateName => $value) { + if (isset($availableStates[$stateName]) && $value == 1) { + $this->ServiceStates->setState($availableStates[$stateName], true); + } + } + } + return $this->ServiceStates; + } + + /** + * @return array + */ + public function getRequestSettingsForListSettings(){ + $states = $this->ServiceStates->asArray(); + if( + !$this->ServiceStates->hasOk() && + !$this->ServiceStates->hasWarning() && + !$this->ServiceStates->hasCritical() && + !$this->ServiceStates->hasUnknown() + ){ + //User disabled all check boxes or first page load + //Enable all to avoid empty list + foreach($states as $key => $value){ + $states[$key] = true; + } + } + + return [ + 'limit' => $this->getLimit(), + 'state_types' => $states, + 'from' => date('d.m.Y H:i', $this->getFrom()), + 'to' => date('d.m.Y H:i', $this->getTo()) + ]; + } +} diff --git a/app/src/itnovum/openITCOCKPIT/Core/Servicestatus.php b/app/src/itnovum/openITCOCKPIT/Core/Servicestatus.php index 2fb8531e00..7b62f9d15e 100644 --- a/app/src/itnovum/openITCOCKPIT/Core/Servicestatus.php +++ b/app/src/itnovum/openITCOCKPIT/Core/Servicestatus.php @@ -276,7 +276,7 @@ public function currentState(){ return $this->currentState; } - public function isAacknowledged(){ + public function isAcknowledged(){ return (bool)$this->problemHasBeenAcknowledged; } @@ -289,18 +289,30 @@ public function isInDowntime(){ } public function getLastHardStateChange(){ + if(!is_numeric($this->lastHardStateChange)){ + return strtotime($this->lastHardStateChange); + } return $this->lastHardStateChange; } public function getLastStateChange(){ + if(!is_numeric($this->last_state_change)){ + return strtotime($this->last_state_change); + } return $this->last_state_change; } public function getLastCheck(){ + if(!is_numeric($this->lastCheck)){ + return strtotime($this->lastCheck); + } return $this->lastCheck; } public function getNextCheck(){ + if(!is_numeric($this->nextCheck)){ + return strtotime($this->nextCheck); + } return $this->nextCheck; } diff --git a/app/src/itnovum/openITCOCKPIT/Core/StatehistoryServiceConditions.php b/app/src/itnovum/openITCOCKPIT/Core/StatehistoryServiceConditions.php new file mode 100644 index 0000000000..2485d9090e --- /dev/null +++ b/app/src/itnovum/openITCOCKPIT/Core/StatehistoryServiceConditions.php @@ -0,0 +1,74 @@ + +// +// This file is dual licensed +// +// 1. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 3 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// 2. +// If you purchased an openITCOCKPIT Enterprise Edition you can use this file +// under the terms of the openITCOCKPIT Enterprise Edition license agreement. +// License agreement and license key will be shipped with the order +// confirmation. + +namespace itnovum\openITCOCKPIT\Core; + +use itnovum\openITCOCKPIT\Core\ValueObjects\ServiceStates; + +class StatehistoryServiceConditions extends ListSettingsConditions { + + protected $states = [ + 0, 1, 2, 3 + ]; + + /** + * @var array + */ + protected $order = [ + 'StatehistoryService.state_time' => 'DESC' + ]; + + /** + * @var string + */ + protected $serviceUuid; + + /** + * @param $uuid + */ + public function setServiceUuid($uuid){ + $this->serviceUuid = $uuid; + } + + /** + * @return string + */ + public function getServiceUuid(){ + return $this->serviceUuid; + } + + /** + * @param ServiceStates $ServiceStates + */ + public function setStates(ServiceStates $ServiceStates){ + if (sizeof($ServiceStates->asIntegerArray()) == 4) { + $this->states = []; + return; + } + + $this->states = $ServiceStates->asIntegerArray(); + } + +} + diff --git a/app/src/itnovum/openITCOCKPIT/Core/StatehistoryServiceControllerRequest.php b/app/src/itnovum/openITCOCKPIT/Core/StatehistoryServiceControllerRequest.php new file mode 100644 index 0000000000..14ad8f73de --- /dev/null +++ b/app/src/itnovum/openITCOCKPIT/Core/StatehistoryServiceControllerRequest.php @@ -0,0 +1,126 @@ + +// +// This file is dual licensed +// +// 1. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 3 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// 2. +// If you purchased an openITCOCKPIT Enterprise Edition you can use this file +// under the terms of the openITCOCKPIT Enterprise Edition license agreement. +// License agreement and license key will be shipped with the order +// confirmation. + +namespace itnovum\openITCOCKPIT\Core; + +use itnovum\openITCOCKPIT\Core\ValueObjects\ListSettingsDefaults; +use itnovum\openITCOCKPIT\Core\ValueObjects\ServiceStates; +use itnovum\openITCOCKPIT\Core\ValueObjects\StateTypes; + +class StatehistoryServiceControllerRequest extends ControllerListSettingsRequest { + + /** + * @var ServiceStates + */ + protected $ServiceStates; + + /** + * @var StateTypes + */ + protected $StateTypes; + + public function __construct(\CakeRequest $request, ServiceStates $ServiceStates, StateTypes $StateTypes, $userLimit = 25){ + $this->StateTypes = $StateTypes; + $this->ListSettingsDefaults = new ListSettingsDefaults($userLimit); + + $this->ServiceStates = $ServiceStates; + $this->request = $request; + + if ($this->request->is('post')) { + $this->requestParameters = $this->request->data; + } + + //Parameters from URL (GET) + if (isset($this->request->params['named']['Listsettings'])) { + $this->requestParameters['Listsettings'] = $this->request->params['named']['Listsettings']; + } + } + + /** + * @return ServiceStates + */ + public function getServiceStates(){ + $availableStates = $this->ServiceStates->getAvailableStateIds(); + + if (isset($this->requestParameters['Listsettings']['state_types'])) { + foreach ($this->requestParameters['Listsettings']['state_types'] as $stateName => $value) { + if (isset($availableStates[$stateName]) && $value == 1) { + $this->ServiceStates->setState($availableStates[$stateName], true); + } + } + } + return $this->ServiceStates; + } + + /** + * @return StateTypes + */ + public function getStateTypes(){ + $availableStateTypes = $this->StateTypes->getAvailableStateTypeIds(); + if (isset($this->requestParameters['Listsettings']['nag_state_types'])) { + foreach ($this->requestParameters['Listsettings']['nag_state_types'] as $stateTypeName => $value) { + if (isset($availableStateTypes[$stateTypeName]) && $value == 1) { + $this->StateTypes->setStateType($availableStateTypes[$stateTypeName], true); + } + } + } + return $this->StateTypes; + } + + /** + * @return array + */ + public function getRequestSettingsForListSettings(){ + $states = $this->ServiceStates->asArray(); + if( + !$this->ServiceStates->hasOk() && + !$this->ServiceStates->hasWarning() && + !$this->ServiceStates->hasCritical() && + !$this->ServiceStates->hasUnknown() + ){ + //User disabled all check boxes or first page load + //Enable all to avoid empty list + foreach($states as $key => $value){ + $states[$key] = true; + } + } + + $stateTypes = $this->StateTypes->asArray(); + if(!$this->StateTypes->hasSoft() && !$this->StateTypes->hasHard()){ + //User disabled all check boxes or first page load + //Enable all to avoid empty list + foreach($stateTypes as $key => $value){ + $stateTypes[$key] = true; + } + } + + return [ + 'limit' => $this->getLimit(), + 'state_types' => $states, + 'nag_state_types' => $stateTypes, + 'from' => date('d.m.Y H:i', $this->getFrom()), + 'to' => date('d.m.Y H:i', $this->getTo()) + ]; + } +} diff --git a/app/src/itnovum/openITCOCKPIT/Core/ValueObjects/ServiceStates.php b/app/src/itnovum/openITCOCKPIT/Core/ValueObjects/ServiceStates.php new file mode 100644 index 0000000000..a51d1e4d51 --- /dev/null +++ b/app/src/itnovum/openITCOCKPIT/Core/ValueObjects/ServiceStates.php @@ -0,0 +1,148 @@ + +// +// This file is dual licensed +// +// 1. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 3 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// 2. +// If you purchased an openITCOCKPIT Enterprise Edition you can use this file +// under the terms of the openITCOCKPIT Enterprise Edition license agreement. +// License agreement and license key will be shipped with the order +// confirmation. + +namespace itnovum\openITCOCKPIT\Core\ValueObjects; + + +use itnovum\openITCOCKPIT\Exceptions\UnknownStateException; + +class ServiceStates { + + /** + * @var array + */ + private $stateNames = [ + 0 => 'ok', + 1 => 'warning', + 2 => 'critical', + 3 => 'unknown' + ]; + + /** + * @var array + */ + private $stateIds = [ + 'ok' => 0, + 'warning' => 1, + 'critical' => 2, + 'unknown' => 3 + ]; + + /** + * @var array + */ + private $states = [ + 'ok' => false, + 'warning' => false, + 'critical' => false, + 'unknown' => false + ]; + + /** + * @param int $state + * @param bool $value + */ + public function setState($state, $value){ + $key = $this->getStateNameByState($state); + $this->states[$key] = $value; + } + + /** + * @return bool + */ + public function hasOk(){ + return $this->states['ok']; + } + + /** + * @return bool + */ + public function hasWarning(){ + return $this->states['warning']; + } + + /** + * @return bool + */ + public function hasCritical(){ + return $this->states['critical']; + } + + /** + * @return bool + */ + public function hasUnknown(){ + return $this->states['unknown']; + } + + + /** + * @return array + */ + public function asArray(){ + return $this->states; + } + + + /** + * @return array + */ + public function asIntegerArray(){ + $states = []; + if ($this->hasOk()) { + $states[] = 0; + } + if ($this->hasWarning()) { + $states[] = 1; + } + if ($this->hasCritical()) { + $states[] = 2; + } + if ($this->hasUnknown()) { + $states[] = 3; + } + return $states; + } + + /** + * @return array + */ + public function getAvailableStateIds(){ + return $this->stateIds; + } + + /** + * @param int $state + * @return string + * @throws UnknownStateException + */ + public function getStateNameByState($state){ + if (isset($this->stateNames[$state])) { + return $this->stateNames[$state]; + } + + throw new UnknownStateException(sprintf('State "%s" is not a valid state id', $state)); + } + +} \ No newline at end of file diff --git a/app/src/itnovum/openITCOCKPIT/Core/Views/Acknowledgement.php b/app/src/itnovum/openITCOCKPIT/Core/Views/Acknowledgement.php new file mode 100644 index 0000000000..f4ccd79401 --- /dev/null +++ b/app/src/itnovum/openITCOCKPIT/Core/Views/Acknowledgement.php @@ -0,0 +1,168 @@ + +// +// This file is dual licensed +// +// 1. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 3 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// 2. +// If you purchased an openITCOCKPIT Enterprise Edition you can use this file +// under the terms of the openITCOCKPIT Enterprise Edition license agreement. +// License agreement and license key will be shipped with the order +// confirmation. + +namespace itnovum\openITCOCKPIT\Core\Views; + + +abstract class Acknowledgement { + + + /** + * @var int + */ + private $acknowledgement_type; + + /** + * @var string + */ + private $author_name; + + /** + * @var string + */ + private $comment_data; + + /** + * @var int|string + */ + private $entry_time; + + + /** + * @var bool + */ + private $is_sticky; + + /** + * @var bool + */ + private $notify_contacts; + + /** + * @var bool + */ + private $persistent_comment; + + /** + * @var int + */ + private $state; + + + /** + * StatehistoryHost constructor. + * @param array $data + */ + public function __construct($data){ + if (isset($data['acknowledgement_type'])) { + $this->acknowledgement_type = (int)$data['acknowledgement_type']; + } + + if (isset($data['author_name'])) { + $this->author_name = $data['author_name']; + } + + if (isset($data['comment_data'])) { + $this->comment_data = $data['comment_data']; + } + + if (isset($data['entry_time'])) { + $this->entry_time = $data['entry_time']; + } + + if (isset($data['is_sticky'])) { + $this->is_sticky = (bool)$data['is_sticky']; + } + + if (isset($data['notify_contacts'])) { + $this->notify_contacts = (bool)$data['notify_contacts']; + } + + if (isset($data['persistent_comment'])) { + $this->persistent_comment = (bool)$data['persistent_comment']; + } + + if (isset($data['state'])) { + $this->state = (int)$data['state']; + } + + } + + /** + * @return int + */ + public function getAcknowledgementType(){ + return $this->acknowledgement_type; + } + + /** + * @return string + */ + public function getAuthorName(){ + return $this->author_name; + } + + /** + * @return string + */ + public function getCommentData(){ + return $this->comment_data; + } + + /** + * @return int|string + */ + public function getEntryTime(){ + return $this->entry_time; + } + + /** + * @return boolean + */ + public function isSticky(){ + return $this->is_sticky; + } + + /** + * @return boolean + */ + public function hasNotifyContacts(){ + return $this->notify_contacts; + } + + /** + * @return boolean + */ + public function isPersistentComment(){ + return $this->persistent_comment; + } + + /** + * @return int + */ + public function getState(){ + return $this->state; + } + +} \ No newline at end of file diff --git a/app/src/itnovum/openITCOCKPIT/Core/Views/AcknowledgementHost.php b/app/src/itnovum/openITCOCKPIT/Core/Views/AcknowledgementHost.php index 9f2950ea0b..665ce705ef 100644 --- a/app/src/itnovum/openITCOCKPIT/Core/Views/AcknowledgementHost.php +++ b/app/src/itnovum/openITCOCKPIT/Core/Views/AcknowledgementHost.php @@ -25,144 +25,7 @@ namespace itnovum\openITCOCKPIT\Core\Views; -class AcknowledgementHost { +class AcknowledgementHost extends Acknowledgement { - /** - * @var int - */ - private $acknowledgement_type; - - /** - * @var string - */ - private $author_name; - - /** - * @var string - */ - private $comment_data; - - /** - * @var int|string - */ - private $entry_time; - - - /** - * @var bool - */ - private $is_sticky; - - /** - * @var bool - */ - private $notify_contacts; - - /** - * @var bool - */ - private $persistent_comment; - - /** - * @var int - */ - private $state; - - - /** - * StatehistoryHost constructor. - * @param array $data - */ - public function __construct($data){ - if (isset($data['acknowledgement_type'])) { - $this->acknowledgement_type = (int)$data['acknowledgement_type']; - } - - if (isset($data['author_name'])) { - $this->author_name = $data['author_name']; - } - - if (isset($data['comment_data'])) { - $this->comment_data = $data['comment_data']; - } - - if (isset($data['entry_time'])) { - $this->entry_time = $data['entry_time']; - } - - if (isset($data['is_sticky'])) { - $this->is_sticky = (bool)$data['is_sticky']; - } - - if (isset($data['notify_contacts'])) { - $this->notify_contacts = (bool)$data['notify_contacts']; - } - - if (isset($data['persistent_comment'])) { - $this->persistent_comment = (bool)$data['persistent_comment']; - } - - if (isset($data['state'])) { - $this->state = (int)$data['state']; - } - - } - - /** - * @return int - */ - public function getAcknowledgementType(){ - return $this->acknowledgement_type; - } - - /** - * @return string - */ - public function getAuthorName(){ - return $this->author_name; - } - - /** - * @return string - */ - public function getCommentData(){ - return $this->comment_data; - } - - /** - * @return int|string - */ - public function getEntryTime(){ - return $this->entry_time; - } - - /** - * @return boolean - */ - public function isSticky(){ - return $this->is_sticky; - } - - /** - * @return boolean - */ - public function hasNotifyContacts(){ - return $this->notify_contacts; - } - - /** - * @return boolean - */ - public function isPersistentComment(){ - return $this->persistent_comment; - } - - /** - * @return int - */ - public function getState(){ - return $this->state; - } - -} \ No newline at end of file +} diff --git a/app/src/itnovum/openITCOCKPIT/Core/Views/AcknowledgementService.php b/app/src/itnovum/openITCOCKPIT/Core/Views/AcknowledgementService.php new file mode 100644 index 0000000000..ff410fb86a --- /dev/null +++ b/app/src/itnovum/openITCOCKPIT/Core/Views/AcknowledgementService.php @@ -0,0 +1,30 @@ + +// +// This file is dual licensed +// +// 1. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 3 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// 2. +// If you purchased an openITCOCKPIT Enterprise Edition you can use this file +// under the terms of the openITCOCKPIT Enterprise Edition license agreement. +// License agreement and license key will be shipped with the order +// confirmation. + +namespace itnovum\openITCOCKPIT\Core\Views; + + +class AcknowledgementService extends Acknowledgement { + +} diff --git a/app/src/itnovum/openITCOCKPIT/Core/Views/Host.php b/app/src/itnovum/openITCOCKPIT/Core/Views/Host.php index 39131350a4..6ab25a09d4 100644 --- a/app/src/itnovum/openITCOCKPIT/Core/Views/Host.php +++ b/app/src/itnovum/openITCOCKPIT/Core/Views/Host.php @@ -176,6 +176,16 @@ public function getSatelliteId(){ return $this->satelliteId; } + /** + * @return bool + */ + public function isSatelliteHost(){ + if($this->satelliteId === null){ + return false; + } + return ($this->satelliteId !== 0); + } + /** * @return int */ diff --git a/app/src/itnovum/openITCOCKPIT/Core/Views/Service.php b/app/src/itnovum/openITCOCKPIT/Core/Views/Service.php index 2e1982631d..2ab7d981d5 100644 --- a/app/src/itnovum/openITCOCKPIT/Core/Views/Service.php +++ b/app/src/itnovum/openITCOCKPIT/Core/Views/Service.php @@ -38,9 +38,9 @@ class Service { private $uuid; /** - * @var string + * @var string|null */ - private $servicename; + private $servicename = null; /** * @var string @@ -48,9 +48,9 @@ class Service { private $description; /** - * @var int|bool + * @var int|bool|null */ - private $active_checks_enabled; + private $active_checks_enabled = null; /** * @var string @@ -94,10 +94,14 @@ public function __construct($service, $servicename = null){ $this->description = $service['Service']['description']; } - if (isset($service['Service']['active_checks_enabled'])) { + if (isset($service['Service']['active_checks_enabled']) && $service['Service']['active_checks_enabled'] !== '') { $this->active_checks_enabled = (bool)$service['Service']['active_checks_enabled']; } + if($this->active_checks_enabled === null && isset($service['Servicetemplate']['active_checks_enabled'])){ + $this->active_checks_enabled = (bool)$service['Servicetemplate']['active_checks_enabled']; + } + if (isset($service['Service']['tags'])) { $this->tags = $service['Service']['tags']; } diff --git a/app/src/itnovum/openITCOCKPIT/Core/Views/Servicecheck.php b/app/src/itnovum/openITCOCKPIT/Core/Views/Servicecheck.php new file mode 100644 index 0000000000..314cca4d63 --- /dev/null +++ b/app/src/itnovum/openITCOCKPIT/Core/Views/Servicecheck.php @@ -0,0 +1,266 @@ + +// +// This file is dual licensed +// +// 1. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 3 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// 2. +// If you purchased an openITCOCKPIT Enterprise Edition you can use this file +// under the terms of the openITCOCKPIT Enterprise Edition license agreement. +// License agreement and license key will be shipped with the order +// confirmation. + +namespace itnovum\openITCOCKPIT\Core\Views; + + +class Servicecheck { + + /** + * @var string + */ + private $command; + + /** + * @var int + */ + private $current_check_attempt; + + /** + * @var bool + */ + private $early_timeout; + + /** + * @var int|string + */ + private $end_time; + + /** + * @var float + */ + private $execution_time; + + /** + * @var bool + */ + private $is_hardstate; + + /** + * @var float + */ + private $latency; + + /** + * @var string + */ + private $long_output; + + /** + * @var int + */ + private $max_check_attempts; + + /** + * @var string + */ + private $output; + + /** + * @var string + */ + private $perfdata; + + /** + * @var int|string + */ + private $start_time; + + /** + * @var int + */ + private $state; + + /** + * @var int + */ + private $timeout; + + + + /** + * StatehistoryHost constructor. + * @param array $data + */ + public function __construct($data){ + if (isset($data['command'])) { + $this->command = $data['command']; + } + + if (isset($data['early_timeout'])) { + $this->early_timeout = (bool)$data['early_timeout']; + } + + if (isset($data['execution_time'])) { + $this->execution_time = (float)$data['execution_time']; + } + + if (isset($data['long_output'])) { + $this->long_output = $data['long_output']; + } + + if (isset($data['current_check_attempt'])) { + $this->current_check_attempt = (int)$data['current_check_attempt']; + } + + if (isset($data['max_check_attempts'])) { + $this->max_check_attempts = (int)$data['max_check_attempts']; + } + + if (isset($data['output'])) { + $this->output = $data['output']; + } + + if (isset($data['state'])) { + $this->state = (int)$data['state']; + } + + if (isset($data['end_time'])) { + $this->end_time = $data['end_time']; + } + + if (isset($data['start_time'])) { + $this->start_time = $data['start_time']; + } + + if (isset($data['state_type'])) { + $this->is_hardstate = (bool)$data['state_type']; + } + + if (isset($data['is_hardstate'])) { + $this->is_hardstate = (bool)$data['is_hardstate']; + } + + if (isset($data['latency'])) { + $this->latency = (float)$data['latency']; + } + + if (isset($data['perfdata'])) { + $this->perfdata = $data['perfdata']; + } + + if (isset($data['timeout'])) { + $this->timeout = (int)$data['timeout']; + } + + } + + /** + * @return boolean + */ + public function isHardstate(){ + return $this->is_hardstate; + } + + /** + * @return string + */ + public function getCommand(){ + return $this->command; + } + + /** + * @return int + */ + public function getCurrentCheckAttempt(){ + return $this->current_check_attempt; + } + + /** + * @return boolean + */ + public function isEarlyTimeout(){ + return $this->early_timeout; + } + + /** + * @return int|string + */ + public function getEndTime(){ + return $this->end_time; + } + + /** + * @return float + */ + public function getExecutionTime(){ + return $this->execution_time; + } + + /** + * @return float + */ + public function getLatency(){ + return $this->latency; + } + + /** + * @return string + */ + public function getLongOutput(){ + return $this->long_output; + } + + /** + * @return int + */ + public function getMaxCheckAttempts(){ + return $this->max_check_attempts; + } + + /** + * @return string + */ + public function getOutput(){ + return $this->output; + } + + /** + * @return string + */ + public function getPerfdata(){ + return $this->perfdata; + } + + /** + * @return int|string + */ + public function getStartTime(){ + return $this->start_time; + } + + /** + * @return int + */ + public function getState(){ + return $this->state; + } + + /** + * @return int + */ + public function getTimeout(){ + return $this->timeout; + } +} diff --git a/app/src/itnovum/openITCOCKPIT/Core/Views/Statehistory.php b/app/src/itnovum/openITCOCKPIT/Core/Views/Statehistory.php new file mode 100644 index 0000000000..8c9404537a --- /dev/null +++ b/app/src/itnovum/openITCOCKPIT/Core/Views/Statehistory.php @@ -0,0 +1,191 @@ + +// +// This file is dual licensed +// +// 1. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 3 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// 2. +// If you purchased an openITCOCKPIT Enterprise Edition you can use this file +// under the terms of the openITCOCKPIT Enterprise Edition license agreement. +// License agreement and license key will be shipped with the order +// confirmation. + +namespace itnovum\openITCOCKPIT\Core\Views; + + +abstract class Statehistory { + + + /** + * @var int + */ + private $current_check_attempt; + + private $last_hard_state; + + /** + * @var int + */ + private $last_state; + + /** + * @var string + */ + private $long_output; + + /** + * @var int + */ + private $max_check_attempts; + + /** + * @var string + */ + private $output; + + /** + * @var int + */ + private $state; + + private $state_change; + + private $state_time; + + /** + * @var bool + */ + private $is_hardstate; + + /** + * StatehistoryHost constructor. + * @param array $data + */ + public function __construct($data){ + if (isset($data['current_check_attempt'])) { + $this->current_check_attempt = (int)$data['current_check_attempt']; + } + + if (isset($data['last_hard_state'])) { + $this->last_hard_state = $data['last_hard_state']; + } + + if (isset($data['last_state'])) { + $this->last_state = (int)$data['last_state']; + } + + if (isset($data['long_output'])) { + $this->long_output = $data['long_output']; + } + + if (isset($data['max_check_attempts'])) { + $this->max_check_attempts = (int)$data['max_check_attempts']; + } + + if (isset($data['output'])) { + $this->output = $data['output']; + } + + if (isset($data['state'])) { + $this->state = (int)$data['state']; + } + + if (isset($data['state_change'])) { + $this->state_change = $data['state_change']; + } + + if (isset($data['state_time'])) { + $this->state_time = $data['state_time']; + } + + if (isset($data['state_type'])) { + $this->is_hardstate = (bool)$data['state_type']; + } + + } + + /** + * @return int + */ + public function getCurrentCheckAttempt(){ + return $this->current_check_attempt; + } + + /** + * @return mixed + */ + public function getLastHardState(){ + return $this->last_hard_state; + } + + /** + * @return int + */ + public function getLastState(){ + return $this->last_state; + } + + /** + * @return string + */ + public function getLongOutput(){ + return $this->long_output; + } + + /** + * @return int + */ + public function getMaxCheckAttempts(){ + return $this->max_check_attempts; + } + + /** + * @return string + */ + public function getOutput(){ + return $this->output; + } + + /** + * @return int + */ + public function getState(){ + return $this->state; + } + + /** + * @return mixed + */ + public function getStateChange(){ + return $this->state_change; + } + + /** + * @return mixed + */ + public function getStateTime(){ + return $this->state_time; + } + + /** + * @return boolean + */ + public function isHardstate(){ + return $this->is_hardstate; + } + + + +} \ No newline at end of file diff --git a/app/src/itnovum/openITCOCKPIT/Core/Views/StatehistoryHost.php b/app/src/itnovum/openITCOCKPIT/Core/Views/StatehistoryHost.php index 7e12ab26df..01f275dbac 100644 --- a/app/src/itnovum/openITCOCKPIT/Core/Views/StatehistoryHost.php +++ b/app/src/itnovum/openITCOCKPIT/Core/Views/StatehistoryHost.php @@ -25,167 +25,6 @@ namespace itnovum\openITCOCKPIT\Core\Views; -class StatehistoryHost { +class StatehistoryHost extends Statehistory { - - /** - * @var int - */ - private $current_check_attempt; - - private $last_hard_state; - - /** - * @var int - */ - private $last_state; - - /** - * @var string - */ - private $long_output; - - /** - * @var int - */ - private $max_check_attempts; - - /** - * @var string - */ - private $output; - - /** - * @var int - */ - private $state; - - private $state_change; - - private $state_time; - - /** - * @var bool - */ - private $is_hardstate; - - /** - * StatehistoryHost constructor. - * @param array $data - */ - public function __construct($data){ - if (isset($data['current_check_attempt'])) { - $this->current_check_attempt = (int)$data['current_check_attempt']; - } - - if (isset($data['last_hard_state'])) { - $this->last_hard_state = $data['last_hard_state']; - } - - if (isset($data['last_state'])) { - $this->last_state = (int)$data['last_state']; - } - - if (isset($data['long_output'])) { - $this->long_output = $data['long_output']; - } - - if (isset($data['max_check_attempts'])) { - $this->max_check_attempts = (int)$data['max_check_attempts']; - } - - if (isset($data['output'])) { - $this->output = $data['output']; - } - - if (isset($data['state'])) { - $this->state = (int)$data['state']; - } - - if (isset($data['state_change'])) { - $this->state_change = $data['state_change']; - } - - if (isset($data['state_time'])) { - $this->state_time = $data['state_time']; - } - - if (isset($data['state_type'])) { - $this->is_hardstate = (bool)$data['state_type']; - } - - } - - /** - * @return int - */ - public function getCurrentCheckAttempt(){ - return $this->current_check_attempt; - } - - /** - * @return mixed - */ - public function getLastHardState(){ - return $this->last_hard_state; - } - - /** - * @return int - */ - public function getLastState(){ - return $this->last_state; - } - - /** - * @return string - */ - public function getLongOutput(){ - return $this->long_output; - } - - /** - * @return int - */ - public function getMaxCheckAttempts(){ - return $this->max_check_attempts; - } - - /** - * @return string - */ - public function getOutput(){ - return $this->output; - } - - /** - * @return int - */ - public function getState(){ - return $this->state; - } - - /** - * @return mixed - */ - public function getStateChange(){ - return $this->state_change; - } - - /** - * @return mixed - */ - public function getStateTime(){ - return $this->state_time; - } - - /** - * @return boolean - */ - public function isHardstate(){ - return $this->is_hardstate; - } - - - -} \ No newline at end of file +} diff --git a/app/src/itnovum/openITCOCKPIT/Core/Views/StatehistoryService.php b/app/src/itnovum/openITCOCKPIT/Core/Views/StatehistoryService.php new file mode 100644 index 0000000000..491731c8ec --- /dev/null +++ b/app/src/itnovum/openITCOCKPIT/Core/Views/StatehistoryService.php @@ -0,0 +1,30 @@ + +// +// This file is dual licensed +// +// 1. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 3 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// 2. +// If you purchased an openITCOCKPIT Enterprise Edition you can use this file +// under the terms of the openITCOCKPIT Enterprise Edition license agreement. +// License agreement and license key will be shipped with the order +// confirmation. + +namespace itnovum\openITCOCKPIT\Core\Views; + + +class StatehistoryService extends Statehistory { + +}
    Utils->getDirection($order, 'Statehistory.state'); - echo $this->Paginator->sort('Statehistory.state', __('State')); ?>Utils->getDirection($order, 'Statehistory.state_time'); - echo $this->Paginator->sort('Statehistory.state_time', __('Date')); ?>Utils->getDirection($order, 'Statehistory.current_check_attempt'); - echo $this->Paginator->sort('Statehistory.current_check_attempt', __('Check attempt')); ?>Utils->getDirection($order, 'Statehistory.state_type'); - echo $this->Paginator->sort('Statehistory.state_type', __('State type')); ?>Utils->getDirection($order, 'Statehistory.output'); - echo $this->Paginator->sort('Statehistory.output', __('Service output')); ?> + Utils->getDirection($order, 'StatehistoryService.state'); + echo $this->Paginator->sort('StatehistoryService.state', __('State')); ?> + + Utils->getDirection($order, 'StatehistoryService.state_time'); + echo $this->Paginator->sort('StatehistoryService.state_time', __('Date')); ?> + + Utils->getDirection($order, 'StatehistoryService.current_check_attempt'); + echo $this->Paginator->sort('StatehistoryService.current_check_attempt', __('Check attempt')); ?> + + Utils->getDirection($order, 'StatehistoryService.state_type'); + echo $this->Paginator->sort('StatehistoryService.state_type', __('State type')); ?> + + Utils->getDirection($order, 'StatehistoryService.output'); + echo $this->Paginator->sort('StatehistoryService.output', __('Service output')); ?> +
    Status->humanServiceStatus($service['Service']['uuid'], 'javascript:void(0)', [$service['Service']['uuid'] => ['Servicestatus' => ['current_state' => $statehistory['Statehistory']['state']]]])['html_icon']; ?>Time->format($statehistory['Statehistory']['state_time'], $this->Auth->user('dateformat'), false, $this->Auth->user('timezone'))); ?> - /Status->humanServiceStateType($statehistory['Statehistory']['state_type'])); ?> + getHtmlIcon(); ?> + + Time->format( + $StatehistoryService->getStateTime(), + $this->Auth->user('dateformat'), + false, + $this->Auth->user('timezone') + )); ?> + + getCurrentCheckAttempt()), + h($StatehistoryService->getMaxCheckAttempts()) + ); ?> + + Status->humanServiceStateType( + $StatehistoryService->isHardstate() + )); ?> + + getOutput()); ?> +