diff --git a/modules/monitoring/application/controllers/ListController.php b/modules/monitoring/application/controllers/ListController.php index 821b6df79..50eff1ea6 100644 --- a/modules/monitoring/application/controllers/ListController.php +++ b/modules/monitoring/application/controllers/ListController.php @@ -537,6 +537,24 @@ class Monitoring_ListController extends Controller } $this->addTitleTab('eventhistory', $this->translate('Event Overview')); + $form = new EventOverviewForm(); + $form->handleRequest($this->getRequest()); + $this->view->form = $form; + + if ($this->getRequest()->isPost()) { + // update filter string + $filters = $form->getFilter(); + $url = $this->_request->getUrl(); + $url->setQueryString($filters->toQueryString()); + if ($this->getParam('sort') !== null) { + $url->setParam('sort', $this->getParam('sort')); + } + if ($this->getParam('dir') !== null) { + $url->setParam('dir', $this->getParam('dir')); + } + return $this->redirectNow($url); + } + $query = $this->backend->select()->from('eventHistory', array( 'host_name', 'service_description', @@ -550,6 +568,9 @@ class Monitoring_ListController extends Controller 'host', 'service' )); + if ($this->getParam('state')) { + $query->applyFilter(Filter::expression('state', '=', $this->getParam('state'))); + } $this->setupSortControl(array( 'timestamp' => 'Occurence' diff --git a/modules/monitoring/application/forms/EventOverviewForm.php b/modules/monitoring/application/forms/EventOverviewForm.php new file mode 100644 index 000000000..25d268f76 --- /dev/null +++ b/modules/monitoring/application/forms/EventOverviewForm.php @@ -0,0 +1,160 @@ +setName('form_event_overview'); + $this->setDecorators(array( + 'FormElements', + array('HtmlTag', array('tag' => 'div', 'class' => 'hbox')), + 'Form' + )); + } + + /** + * @see Form::createElements() + */ + public function createElements(array $formData) + { + $decorators = array( + array('Label', array('class' => 'optional')), + 'ViewHelper', + array('HtmlTag', array('tag' => 'div', 'class' => 'hbox-item optionbox')), + ); + + $url = Url::fromRequest()->getAbsoluteUrl(); + $this->addElement( + 'checkbox', + 'statechange', + array( + 'label' => t('State Changes'), + 'class' => 'autosubmit', + 'decorators' => $decorators, + 'value' => strpos($url, $this->stateChangeFilter()->toQueryString()) === false ? 0 : 1 + ) + ); + $this->addElement( + 'checkbox', + 'downtime', + array( + 'label' => t('Downtimes'), + 'class' => 'autosubmit', + 'decorators' => $decorators, + 'value' => strpos($url, $this->downtimeFilter()->toQueryString()) === false ? 0 : 1 + ) + ); + $this->addElement( + 'checkbox', + 'comment', + array( + 'label' => t('Comments'), + 'class' => 'autosubmit', + 'decorators' => $decorators, + 'value' => strpos($url, $this->commentFilter()->toQueryString()) === false ? 0 : 1 + ) + ); + $this->addElement( + 'checkbox', + 'notification', + array( + 'label' => t('Notifications'), + 'class' => 'autosubmit', + 'decorators' => $decorators, + 'value' => strpos($url, $this->notificationFilter()->toQueryString()) === false ? 0 : 1 + ) + ); + $this->addElement( + 'checkbox', + 'flapping', + array( + 'label' => t('Flapping'), + 'class' => 'autosubmit', + 'decorators' => $decorators, + 'value' => strpos($url, $this->flappingFilter()->toQueryString()) === false ? 0 : 1 + ) + ); + } + + /** + * Return the corresponding filter-object + * + * @returns Filter + */ + public function getFilter() + { + $filters = array(); + if ($this->getValue('statechange', 1)) { + $filters[] = $this->stateChangeFilter(); + } + if ($this->getValue('comment', 1)) { + $filters[] = $this->commentFilter(); + } + if ($this->getValue('notification', 1)) { + $filters[] = $this->notificationFilter(); + } + if ($this->getValue('downtime', 1)) { + $filters[] = $this->downtimeFilter(); + } + if ($this->getValue('flapping', 1)) { + $filters[] = $this->flappingFilter(); + } + return Filter::matchAny($filters); + } + + public function stateChangeFilter() + { + return Filter::matchAny( + Filter::expression('type', '=', 'hard_state'), + Filter::expression('type', '=', 'soft_state') + ); + } + + public function commentFilter() + { + return Filter::matchAny( + Filter::expression('type', '=', 'comment'), + Filter::expression('type', '=', 'comment_deleted'), + Filter::expression('type', '=', 'dt_comment'), + Filter::expression('type', '=', 'dt_comment_deleted'), + Filter::expression('type', '=', 'ack') + ); + } + + public function notificationFilter() + { + return Filter::expression('type', '=', 'notify'); + } + + public function downtimeFilter() + { + return Filter::matchAny( + Filter::expression('type', '=', 'downtime_start'), + Filter::expression('type', '=', 'downtime_end') + ); + } + + public function flappingFilter() + { + return Filter::matchAny( + Filter::expression('type', '=', 'flapping'), + Filter::expression('type', '=', 'flapping_deleted') + ); + } +} diff --git a/modules/monitoring/application/views/scripts/list/eventhistory.phtml b/modules/monitoring/application/views/scripts/list/eventhistory.phtml index 97eda5354..62b635763 100644 --- a/modules/monitoring/application/views/scripts/list/eventhistory.phtml +++ b/modules/monitoring/application/views/scripts/list/eventhistory.phtml @@ -4,6 +4,9 @@
translate('Sort by'); ?> sortControl->render($this); ?>
+ + +
widget('limiter', array('url' => $this->url, 'max' => $this->history->count())); ?> paginationControl($history, null, null, array('preserve' => $this->preserve)); ?> diff --git a/public/css/icinga/forms.less b/public/css/icinga/forms.less index 2acb3d4d2..33a7fdd01 100644 --- a/public/css/icinga/forms.less +++ b/public/css/icinga/forms.less @@ -195,3 +195,19 @@ textarea { input, select, textarea { display: inline; } + +.optionbox { + margin-left: 0em; + margin-right: 3em; +} + +.optionbox label { + max-width: 6.5em; + text-align: left; + vertical-align: middle; + margin-right: 0em; +} + +.optionbox input { + vertical-align: middle; +}