2014-09-17 18:30:15 +02:00
|
|
|
<?php
|
2015-02-04 10:46:36 +01:00
|
|
|
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
2014-09-17 18:30:15 +02:00
|
|
|
|
2014-11-14 11:17:22 +01:00
|
|
|
namespace Icinga\Module\Monitoring\Forms;
|
2014-09-17 18:30:15 +02:00
|
|
|
|
|
|
|
use Icinga\Web\Form;
|
|
|
|
use Icinga\Data\Filter\Filter;
|
|
|
|
|
|
|
|
/**
|
2014-11-13 18:38:42 +01:00
|
|
|
* Configure the filter for the event grid
|
2014-09-17 18:30:15 +02:00
|
|
|
*/
|
|
|
|
class StatehistoryForm extends Form
|
|
|
|
{
|
2014-11-13 18:40:13 +01:00
|
|
|
/**
|
2015-07-28 13:36:51 +02:00
|
|
|
* {@inheritdoc}
|
2014-11-13 18:40:13 +01:00
|
|
|
*/
|
|
|
|
public function init()
|
|
|
|
{
|
|
|
|
$this->setName('form_event_overview');
|
2015-01-19 13:47:01 +01:00
|
|
|
$this->setSubmitLabel($this->translate('Apply'));
|
2014-11-13 18:40:13 +01:00
|
|
|
}
|
|
|
|
|
2014-09-17 18:30:15 +02:00
|
|
|
/**
|
|
|
|
* Return the corresponding filter-object
|
|
|
|
*
|
|
|
|
* @returns Filter
|
|
|
|
*/
|
|
|
|
public function getFilter()
|
|
|
|
{
|
|
|
|
$baseFilter = Filter::matchAny(
|
|
|
|
Filter::expression('type', '=', 'hard_state')
|
|
|
|
);
|
|
|
|
|
|
|
|
if ($this->getValue('objecttype', 'hosts') === 'hosts') {
|
|
|
|
$objectTypeFilter = Filter::expression('object_type', '=', 'host');
|
|
|
|
} else {
|
|
|
|
$objectTypeFilter = Filter::expression('object_type', '=', 'service');
|
|
|
|
}
|
|
|
|
|
|
|
|
$states = array(
|
|
|
|
'cnt_down_hard' => Filter::expression('state', '=', '1'),
|
|
|
|
'cnt_unreachable_hard' => Filter::expression('state', '=', '2'),
|
|
|
|
'cnt_up' => Filter::expression('state', '=', '0'),
|
|
|
|
'cnt_critical_hard' => Filter::expression('state', '=', '2'),
|
|
|
|
'cnt_warning_hard' => Filter::expression('state', '=', '1'),
|
|
|
|
'cnt_unknown_hard' => Filter::expression('state', '=', '3'),
|
|
|
|
'cnt_ok' => Filter::expression('state', '=', '0')
|
|
|
|
);
|
2014-09-18 09:24:50 +02:00
|
|
|
$state = $this->getValue('state', 'cnt_critical_hard');
|
|
|
|
$stateFilter = $states[$state];
|
|
|
|
if (in_array($state, array('cnt_ok', 'cnt_up'))) {
|
|
|
|
return Filter::matchAll($objectTypeFilter, $stateFilter);
|
|
|
|
}
|
2014-09-17 18:30:15 +02:00
|
|
|
return Filter::matchAll($baseFilter, $objectTypeFilter, $stateFilter);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-07-28 13:36:51 +02:00
|
|
|
* {@inheritdoc}
|
2014-09-17 18:30:15 +02:00
|
|
|
*/
|
2014-09-30 11:34:04 +02:00
|
|
|
public function createElements(array $formData)
|
2014-09-17 18:30:15 +02:00
|
|
|
{
|
|
|
|
$this->addElement(
|
|
|
|
'select',
|
|
|
|
'from',
|
|
|
|
array(
|
2015-01-19 13:47:01 +01:00
|
|
|
'label' => $this->translate('From'),
|
2014-09-17 18:30:15 +02:00
|
|
|
'value' => $this->getRequest()->getParam('from', strtotime('3 months ago')),
|
|
|
|
'multiOptions' => array(
|
2015-01-19 13:47:01 +01:00
|
|
|
strtotime('midnight 3 months ago') => $this->translate('3 Months'),
|
|
|
|
strtotime('midnight 4 months ago') => $this->translate('4 Months'),
|
|
|
|
strtotime('midnight 8 months ago') => $this->translate('8 Months'),
|
|
|
|
strtotime('midnight 12 months ago') => $this->translate('1 Year'),
|
|
|
|
strtotime('midnight 24 months ago') => $this->translate('2 Years')
|
2014-09-17 18:30:15 +02:00
|
|
|
),
|
|
|
|
'class' => 'autosubmit'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->addElement(
|
|
|
|
'select',
|
|
|
|
'to',
|
|
|
|
array(
|
2015-01-19 13:47:01 +01:00
|
|
|
'label' => $this->translate('To'),
|
2014-09-17 18:30:15 +02:00
|
|
|
'value' => $this->getRequest()->getParam('to', time()),
|
|
|
|
'multiOptions' => array(
|
2015-01-19 13:47:01 +01:00
|
|
|
time() => $this->translate('Today')
|
2014-09-17 18:30:15 +02:00
|
|
|
),
|
|
|
|
'class' => 'autosubmit'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$objectType = $this->getRequest()->getParam('objecttype', 'services');
|
|
|
|
$this->addElement(
|
|
|
|
'select',
|
|
|
|
'objecttype',
|
|
|
|
array(
|
2015-01-19 13:47:01 +01:00
|
|
|
'label' => $this->translate('Object type'),
|
2014-09-17 18:30:15 +02:00
|
|
|
'value' => $objectType,
|
|
|
|
'multiOptions' => array(
|
2015-01-19 13:47:01 +01:00
|
|
|
'services' => $this->translate('Services'),
|
|
|
|
'hosts' => $this->translate('Hosts')
|
2014-09-17 18:30:15 +02:00
|
|
|
),
|
|
|
|
'class' => 'autosubmit'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
if ($objectType === 'services') {
|
|
|
|
$serviceState = $this->getRequest()->getParam('state', 'cnt_critical_hard');
|
2014-09-18 09:24:50 +02:00
|
|
|
if (in_array($serviceState, array('cnt_down_hard', 'cnt_unreachable_hard', 'cnt_up'))) {
|
2014-09-17 18:30:15 +02:00
|
|
|
$serviceState = 'cnt_critical_hard';
|
|
|
|
}
|
|
|
|
$this->addElement(
|
|
|
|
'select',
|
|
|
|
'state',
|
|
|
|
array(
|
2015-01-19 13:47:01 +01:00
|
|
|
'label' => $this->translate('State'),
|
2014-09-17 18:30:15 +02:00
|
|
|
'value' => $serviceState,
|
|
|
|
'multiOptions' => array(
|
2015-01-19 13:47:01 +01:00
|
|
|
'cnt_critical_hard' => $this->translate('Critical'),
|
|
|
|
'cnt_warning_hard' => $this->translate('Warning'),
|
|
|
|
'cnt_unknown_hard' => $this->translate('Unknown'),
|
|
|
|
'cnt_ok' => $this->translate('Ok')
|
2014-09-17 18:30:15 +02:00
|
|
|
),
|
|
|
|
'class' => 'autosubmit'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$hostState = $this->getRequest()->getParam('state', 'cnt_down_hard');
|
|
|
|
if (in_array($hostState, array('cnt_ok', 'cnt_critical_hard', 'cnt_warning', 'cnt_unknown'))) {
|
|
|
|
$hostState = 'cnt_down_hard';
|
|
|
|
}
|
|
|
|
$this->addElement(
|
|
|
|
'select',
|
|
|
|
'state',
|
|
|
|
array(
|
2015-01-19 13:47:01 +01:00
|
|
|
'label' => $this->translate('State'),
|
2014-09-17 18:30:15 +02:00
|
|
|
'value' => $hostState,
|
|
|
|
'multiOptions' => array(
|
2015-01-19 13:47:01 +01:00
|
|
|
'cnt_up' => $this->translate('Up'),
|
|
|
|
'cnt_down_hard' => $this->translate('Down'),
|
|
|
|
'cnt_unreachable_hard' => $this->translate('Unreachable')
|
2014-09-17 18:30:15 +02:00
|
|
|
),
|
|
|
|
'class' => 'autosubmit'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|