/usr/share/icingaweb2/modules/monitoring/library/Monitoring/Backend/Ido/Query/EventhistoryQuery.php is in icingaweb2-module-monitoring 2.1.0-1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | <?php
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
use Zend_Db_Select;
use Icinga\Data\Filter\Filter;
/**
* Query for event history records
*/
class EventhistoryQuery extends IdoQuery
{
/**
* {@inheritdoc}
*/
protected $useSubqueryCount = true;
/**
* Subqueries used for the event history query
*
* @type IdoQuery[]
*/
protected $subQueries = array();
/**
* {@inheritdoc}
*/
protected $columnMap = array(
'eventhistory' => array(
'cnt_notification' => "SUM(CASE eh.type WHEN 'notify' THEN 1 ELSE 0 END)",
'cnt_hard_state' => "SUM(CASE eh.type WHEN 'hard_state' THEN 1 ELSE 0 END)",
'cnt_soft_state' => "SUM(CASE eh.type WHEN 'hard_state' THEN 1 ELSE 0 END)",
'cnt_downtime_start' => "SUM(CASE eh.type WHEN 'dt_start' THEN 1 ELSE 0 END)",
'cnt_downtime_end' => "SUM(CASE eh.type WHEN 'dt_end' THEN 1 ELSE 0 END)",
'host_name' => 'eh.host_name',
'service_description' => 'eh.service_description',
'object_type' => 'eh.object_type',
'timestamp' => 'eh.timestamp',
'state' => 'eh.state',
'output' => 'eh.output',
'type' => 'eh.type',
'host_display_name' => 'eh.host_display_name',
'service_display_name' => 'eh.service_display_name'
)
);
/**
* {@inheritdoc}
*/
protected function joinBaseTables()
{
$columns = array(
'timestamp',
'output',
'type',
'state',
'object_type',
'object_id',
'host_name',
'service_description',
'host_display_name',
'service_display_name'
);
$this->subQueries = array(
$this->createSubQuery('Statehistory', $columns),
$this->createSubQuery('Downtimestarthistory', $columns),
$this->createSubQuery('Downtimeendhistory', $columns),
$this->createSubQuery('Commenthistory', $columns),
$this->createSubQuery('Commentdeletionhistory', $columns),
$this->createSubQuery('Notification', $columns)
);
$sub = $this->db->select()->union($this->subQueries, Zend_Db_Select::SQL_UNION_ALL);
$this->select->from(array('eh' => $sub), array());
$this->joinedVirtualTables['eventhistory'] = true;
}
/**
* {@inheritdoc}
*/
public function allowsCustomVars()
{
foreach ($this->subQueries as $query) {
if (! $query->allowsCustomVars()) {
return false;
}
}
return true;
}
/**
* {@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;
}
}
|