Event history: show also flapping events

refs #12766
This commit is contained in:
Alexander A. Klimov 2016-12-06 14:15:44 +01:00
parent f1051f0ea5
commit efed4a34a1
8 changed files with 627 additions and 1 deletions

View File

@ -34,6 +34,7 @@ $history->limit($limit * $page);
<?php <?php
$dateFormat = $this->translate('%A, %B %e, %Y', 'date.verbose'); $dateFormat = $this->translate('%A, %B %e, %Y', 'date.verbose');
$lastDate = null; $lastDate = null;
$flappingMsg = $this->translate('Flapping with a %.2f%% state change rate');
?> ?>
<table class="state-table" data-base-target="_next"<?php if (isset($tableCssClass)): ?> class="<?=$tableCssClass ?>"<?php endif ?>> <table class="state-table" data-base-target="_next"<?php if (isset($tableCssClass)): ?> class="<?=$tableCssClass ?>"<?php endif ?>>
<tbody> <tbody>
@ -92,12 +93,14 @@ $lastDate = null;
$icon = 'flapping'; $icon = 'flapping';
$iconTitle = $this->translate('Flapping started', 'tooltip'); $iconTitle = $this->translate('Flapping started', 'tooltip');
$label = $this->translate('FLAPPING'); $label = $this->translate('FLAPPING');
$msg = sprintf($flappingMsg, $msg);
break; break;
case 'flapping_deleted': case 'flapping_deleted':
$icon = 'flapping'; $icon = 'flapping';
$iconCssClass = 'icon-strikethrough'; $iconCssClass = 'icon-strikethrough';
$iconTitle = $this->translate('Flapping stopped', 'tooltip'); $iconTitle = $this->translate('Flapping stopped', 'tooltip');
$label = $this->translate('FLAPPING STOPPED'); $label = $this->translate('FLAPPING STOPPED');
$msg = sprintf($flappingMsg, $msg);
break; break;
case 'hard_state': case 'hard_state':
if ((int) $event->state === 0) { if ((int) $event->state === 0) {

View File

@ -67,7 +67,9 @@ class EventhistoryQuery extends IdoQuery
$this->createSubQuery('Downtimeendhistory', $columns), $this->createSubQuery('Downtimeendhistory', $columns),
$this->createSubQuery('Commenthistory', $columns), $this->createSubQuery('Commenthistory', $columns),
$this->createSubQuery('Commentdeletionhistory', $columns), $this->createSubQuery('Commentdeletionhistory', $columns),
$this->createSubQuery('Notificationhistory', $columns) $this->createSubQuery('Notificationhistory', $columns),
$this->createSubQuery('Flappingstarthistory', $columns),
$this->createSubQuery('Flappingendhistory', $columns)
); );
$sub = $this->db->select()->union($this->subQueries, Zend_Db_Select::SQL_UNION_ALL); $sub = $this->db->select()->union($this->subQueries, Zend_Db_Select::SQL_UNION_ALL);
$this->select->from(array('eh' => $sub), array()); $this->select->from(array('eh' => $sub), array());

View File

@ -0,0 +1,49 @@
<?php
/* Icinga Web 2 | (c) 2016 Icinga Development Team | GPLv2+ */
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
use Zend_Db_Expr;
use Zend_Db_Select;
use Icinga\Data\Filter\Filter;
/**
* Query for host and service flapping end history records
*/
class FlappingendhistoryQuery extends FlappingstarthistoryQuery
{
/**
* Join hosts
*/
protected function joinHosts()
{
$columns = array_keys(
$this->columnMap['flappinghistory'] + $this->columnMap['hosts']
);
foreach ($this->columnMap['services'] as $column => $_) {
$columns[$column] = new Zend_Db_Expr('NULL');
}
if ($this->fetchHistoryColumns) {
$columns = array_merge($columns, array_keys($this->columnMap['history']));
}
$hosts = $this->createSubQuery('Hostflappingendhistory', $columns);
$this->subQueries[] = $hosts;
$this->flappingStartHistoryQuery->union(array($hosts), Zend_Db_Select::SQL_UNION_ALL);
}
/**
* Join services
*/
protected function joinServices()
{
$columns = array_keys(
$this->columnMap['flappinghistory'] + $this->columnMap['hosts'] + $this->columnMap['services']
);
if ($this->fetchHistoryColumns) {
$columns = array_merge($columns, array_keys($this->columnMap['history']));
}
$services = $this->createSubQuery('Serviceflappingendhistory', $columns);
$this->subQueries[] = $services;
$this->flappingStartHistoryQuery->union(array($services), Zend_Db_Select::SQL_UNION_ALL);
}
}

View File

@ -0,0 +1,167 @@
<?php
/* Icinga Web 2 | (c) 2016 Icinga Development Team | GPLv2+ */
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
use Zend_Db_Expr;
use Zend_Db_Select;
use Icinga\Data\Filter\Filter;
/**
* Query for host and service flapping start history records
*/
class FlappingstarthistoryQuery extends IdoQuery
{
/**
* {@inheritdoc}
*/
protected $columnMap = array(
'flappinghistory' => array(
'object_type' => 'fsh.object_type'
),
'history' => array(
'type' => 'fsh.type',
'timestamp' => 'fsh.timestamp',
'object_id' => 'fsh.object_id',
'state' => 'fsh.state',
'output' => 'fsh.output'
),
'hosts' => array(
'host_display_name' => 'fsh.host_display_name',
'host_name' => 'fsh.host_name'
),
'services' => array(
'service_description' => 'fsh.service_description',
'service_display_name' => 'fsh.service_display_name',
'service_host_name' => 'fsh.service_host_name'
)
);
/**
* The union
*
* @var Zend_Db_Select
*/
protected $flappingStartHistoryQuery;
/**
* Subqueries used for the flapping start history query
*
* @var IdoQuery[]
*/
protected $subQueries = array();
/**
* Whether to additionally select all history columns
*
* @var bool
*/
protected $fetchHistoryColumns = false;
/**
* {@inheritdoc}
*/
public function allowsCustomVars()
{
foreach ($this->subQueries as $query) {
if (! $query->allowsCustomVars()) {
return false;
}
}
return true;
}
/**
* {@inheritdoc}
*/
protected function joinBaseTables()
{
$this->flappingStartHistoryQuery = $this->db->select();
$this->select->from(
array('fsh' => $this->flappingStartHistoryQuery),
array()
);
$this->joinedVirtualTables['flappinghistory'] = true;
}
/**
* Join history related columns and tables
*/
protected function joinHistory()
{
// TODO: Ensure that one is selecting the history columns first...
$this->fetchHistoryColumns = true;
$this->requireVirtualTable('hosts');
$this->requireVirtualTable('services');
}
/**
* Join hosts
*/
protected function joinHosts()
{
$columns = array_keys(
$this->columnMap['flappinghistory'] + $this->columnMap['hosts']
);
foreach ($this->columnMap['services'] as $column => $_) {
$columns[$column] = new Zend_Db_Expr('NULL');
}
if ($this->fetchHistoryColumns) {
$columns = array_merge($columns, array_keys($this->columnMap['history']));
}
$hosts = $this->createSubQuery('Hostflappingstarthistory', $columns);
$this->subQueries[] = $hosts;
$this->flappingStartHistoryQuery->union(array($hosts), Zend_Db_Select::SQL_UNION_ALL);
}
/**
* Join services
*/
protected function joinServices()
{
$columns = array_keys(
$this->columnMap['flappinghistory'] + $this->columnMap['hosts'] + $this->columnMap['services']
);
if ($this->fetchHistoryColumns) {
$columns = array_merge($columns, array_keys($this->columnMap['history']));
}
$services = $this->createSubQuery('Serviceflappingstarthistory', $columns);
$this->subQueries[] = $services;
$this->flappingStartHistoryQuery->union(array($services), Zend_Db_Select::SQL_UNION_ALL);
}
/**
* {@inheritdoc}
*/
public function order($columnOrAlias, $dir = null)
{
foreach ($this->subQueries as $sub) {
$sub->requireColumn($columnOrAlias);
}
return parent::order($columnOrAlias, $dir);
}
/**
* {@inheritdoc}
*/
public function where($condition, $value = null)
{
$this->requireColumn($condition);
foreach ($this->subQueries as $sub) {
$sub->where($condition, $value);
}
return $this;
}
/**
* {@inheritdoc}
*/
public function addFilter(Filter $filter)
{
foreach ($this->subQueries as $sub) {
$sub->applyFilter(clone $filter);
}
return $this;
}
}

View File

@ -0,0 +1,31 @@
<?php
/* Icinga Web 2 | (c) 2016 Icinga Development Team | GPLv2+ */
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
/**
* Query for host flapping end history records
*/
class HostflappingendhistoryQuery extends HostflappingstarthistoryQuery
{
/**
* {@inheritdoc}
*/
protected function joinBaseTables()
{
$this->select->from(
array('hfh' => $this->prefix . 'flappinghistory'),
array()
)->join(
array('ho' => $this->prefix . 'objects'),
'ho.object_id = hfh.object_id AND ho.is_active = 1 AND ho.objecttype_id = 1',
array()
);
$this->select->where('hfh.event_type = 1001');
$this->joinedVirtualTables['flappinghistory'] = true;
$this->columnMap['flappinghistory']['type'] = '(\'flapping_deleted\')';
}
}

View File

@ -0,0 +1,172 @@
<?php
/* Icinga Web 2 | (c) 2016 Icinga Development Team | GPLv2+ */
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
/**
* Query for host flapping start history records
*/
class HostflappingstarthistoryQuery extends IdoQuery
{
/**
* {@inheritdoc}
*/
protected $allowCustomVars = true;
/**
* {@inheritdoc}
*/
protected $groupBase = array('flappinghistory' => array('hfh.flappinghistory_id', 'ho.object_id'));
/**
* {@inheritdoc}
*/
protected $groupOrigin = array('hostgroups', 'services');
/**
* {@inheritdoc}
*/
protected $columnMap = array(
'flappinghistory' => array(
'host_name' => 'ho.name1',
'object_id' => 'hfh.object_id',
'object_type' => '(\'host\')',
'output' => '(hfh.percent_state_change || \'\')',
'state' => '(-1)',
'timestamp' => 'UNIX_TIMESTAMP(hfh.event_time)',
'type' => '(\'flapping\')'
),
'hostgroups' => array(
'hostgroup_alias' => 'hg.alias COLLATE latin1_general_ci',
'hostgroup_name' => 'hgo.name1'
),
'hosts' => array(
'host_alias' => 'h.alias',
'host_display_name' => 'h.display_name COLLATE latin1_general_ci'
),
'instances' => array(
'instance_name' => 'i.instance_name'
),
'servicegroups' => array(
'servicegroup_name' => 'sgo.name1',
'servicegroup_alias' => 'sg.alias COLLATE latin1_general_ci'
),
'services' => array(
'service_description' => 'so.name2',
'service_display_name' => 's.display_name COLLATE latin1_general_ci',
'service_host_name' => 'so.name1'
)
);
/**
* {@inheritdoc}
*/
public function whereToSql($col, $sign, $expression)
{
if ($col === 'UNIX_TIMESTAMP(hfh.event_time)') {
return 'hfh.event_time ' . $sign . ' ' . $this->timestampForSql($this->valueToTimestamp($expression));
} else {
return parent::whereToSql($col, $sign, $expression);
}
}
/**
* {@inheritdoc}
*/
protected function joinBaseTables()
{
$this->select->from(
array('hfh' => $this->prefix . 'flappinghistory'),
array()
)->join(
array('ho' => $this->prefix . 'objects'),
'ho.object_id = hfh.object_id AND ho.is_active = 1 AND ho.objecttype_id = 1',
array()
);
$this->select->where('hfh.event_type = 1000');
$this->joinedVirtualTables['flappinghistory'] = true;
}
/**
* Join host groups
*/
protected function joinHostgroups()
{
$this->select->joinLeft(
array('hgm' => $this->prefix . 'hostgroup_members'),
'hgm.host_object_id = ho.object_id',
array()
)->joinLeft(
array('hg' => $this->prefix . 'hostgroups'),
'hg.hostgroup_id = hgm.hostgroup_id',
array()
)->joinLeft(
array('hgo' => $this->prefix . 'objects'),
'hgo.object_id = hg.hostgroup_object_id AND hgo.is_active = 1 AND hgo.objecttype_id = 3',
array()
);
}
/**
* Join hosts
*/
protected function joinHosts()
{
$this->select->join(
array('h' => $this->prefix . 'hosts'),
'h.host_object_id = ho.object_id',
array()
);
}
/**
* Join instances
*/
protected function joinInstances()
{
$this->select->join(
array('i' => $this->prefix . 'instances'),
'i.instance_id = hfh.instance_id',
array()
);
}
/**
* Join service groups
*/
protected function joinServicegroups()
{
$this->requireVirtualTable('services');
$this->select->joinLeft(
array('sgm' => $this->prefix . 'servicegroup_members'),
'sgm.service_object_id = s.service_object_id',
array()
)->joinLeft(
array('sg' => $this->prefix . 'servicegroups'),
'sg.' . $this->servicegroup_id . ' = sgm.servicegroup_id',
array()
)->joinLeft(
array('sgo' => $this->prefix . 'objects'),
'sgo.object_id = sg.servicegroup_object_id AND sgo.is_active = 1 AND sgo.objecttype_id = 4',
array()
);
}
/**
* Join services
*/
protected function joinServices()
{
$this->select->joinLeft(
array('s' => $this->prefix . 'services'),
's.host_object_id = ho.object_id',
array()
)->joinLeft(
array('so' => $this->prefix . 'objects'),
'so.object_id = s.service_object_id AND so.is_active = 1 AND so.objecttype_id = 2',
array()
);
}
}

View File

@ -0,0 +1,31 @@
<?php
/* Icinga Web 2 | (c) 2016 Icinga Development Team | GPLv2+ */
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
/**
* Query for service flapping end history records
*/
class ServiceflappingendhistoryQuery extends ServiceflappingstarthistoryQuery
{
/**
* {@inheritdoc}
*/
protected function joinBaseTables()
{
$this->select->from(
array('sfh' => $this->prefix . 'flappinghistory'),
array()
)->join(
array('so' => $this->prefix . 'objects'),
'so.object_id = sfh.object_id AND so.is_active = 1 AND so.objecttype_id = 2',
array()
);
$this->select->where('sfh.event_type = 1001');
$this->joinedVirtualTables['flappinghistory'] = true;
$this->columnMap['flappinghistory']['type'] = '(\'flapping_deleted\')';
}
}

View File

@ -0,0 +1,171 @@
<?php
/* Icinga Web 2 | (c) 2016 Icinga Development Team | GPLv2+ */
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
/**
* Query for service flapping start history records
*/
class ServiceflappingstarthistoryQuery extends IdoQuery
{
/**
* {@inheritdoc}
*/
protected $allowCustomVars = true;
/**
* {@inheritdoc}
*/
protected $groupBase = array('flappinghistory' => array('sfh.flappinghistory_id', 'so.object_id'));
/**
* {@inheritdoc}
*/
protected $groupOrigin = array('hostgroups', 'servicegroups');
/**
* {@inheritdoc}
*/
protected $columnMap = array(
'flappinghistory' => array(
'host_name' => 'so.name1',
'object_id' => 'sfh.object_id',
'object_type' => '(\'service\')',
'output' => '(sfh.percent_state_change || \'\')',
'service_description' => 'so.name2',
'service_host_name' => 'so.name1',
'state' => '(-1)',
'timestamp' => 'UNIX_TIMESTAMP(sfh.event_time)',
'type' => "('flapping')"
),
'hostgroups' => array(
'hostgroup_alias' => 'hg.alias COLLATE latin1_general_ci',
'hostgroup_name' => 'hgo.name1'
),
'hosts' => array(
'host_alias' => 'h.alias',
'host_display_name' => 'h.display_name COLLATE latin1_general_ci'
),
'instances' => array(
'instance_name' => 'i.instance_name'
),
'servicegroups' => array(
'servicegroup_name' => 'sgo.name1',
'servicegroup_alias' => 'sg.alias COLLATE latin1_general_ci'
),
'services' => array(
'service_display_name' => 's.display_name COLLATE latin1_general_ci'
)
);
/**
* {@inheritdoc}
*/
public function whereToSql($col, $sign, $expression)
{
if ($col === 'UNIX_TIMESTAMP(sfh.event_time)') {
return 'sfh.event_time ' . $sign . ' ' . $this->timestampForSql(
$this->valueToTimestamp($expression)
);
} else {
return parent::whereToSql($col, $sign, $expression);
}
}
/**
* {@inheritdoc}
*/
protected function joinBaseTables()
{
$this->select->from(
array('sfh' => $this->prefix . 'flappinghistory'),
array()
)->join(
array('so' => $this->prefix . 'objects'),
'so.object_id = sfh.object_id AND so.is_active = 1 AND so.objecttype_id = 2',
array()
);
$this->select->where('sfh.event_type = 1000');
$this->joinedVirtualTables['flappinghistory'] = true;
}
/**
* Join host groups
*/
protected function joinHostgroups()
{
$this->requireVirtualTable('services');
$this->select->joinLeft(
array('hgm' => $this->prefix . 'hostgroup_members'),
'hgm.host_object_id = s.host_object_id',
array()
)->joinLeft(
array('hg' => $this->prefix . 'hostgroups'),
'hg.hostgroup_id = hgm.hostgroup_id',
array()
)->joinLeft(
array('hgo' => $this->prefix . 'objects'),
'hgo.object_id = hg.hostgroup_object_id AND hgo.is_active = 1 AND hgo.objecttype_id = 3',
array()
);
}
/**
* Join hosts
*/
protected function joinHosts()
{
$this->requireVirtualTable('services');
$this->select->join(
array('h' => $this->prefix . 'hosts'),
'h.host_object_id = s.host_object_id',
array()
);
}
/**
* Join instances
*/
protected function joinInstances()
{
$this->select->join(
array('i' => $this->prefix . 'instances'),
'i.instance_id = sfh.instance_id',
array()
);
}
/**
* Join service groups
*/
protected function joinServicegroups()
{
$this->select->joinLeft(
array('sgm' => $this->prefix . 'servicegroup_members'),
'sgm.service_object_id = so.object_id',
array()
)->joinLeft(
array('sg' => $this->prefix . 'servicegroups'),
'sg.' . $this->servicegroup_id . ' = sgm.servicegroup_id',
array()
)->joinLeft(
array('sgo' => $this->prefix . 'objects'),
'sgo.object_id = sg.servicegroup_object_id AND sgo.is_active = 1 AND sgo.objecttype_id = 4',
array()
);
}
/**
* Join services
*/
protected function joinServices()
{
$this->select->join(
array('s' => $this->prefix . 'services'),
's.service_object_id = so.object_id',
array()
);
}
}