/usr/share/icingaweb2/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostgroupsummaryQuery.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 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | <?php
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
use Icinga\Data\Filter\Filter;
use Zend_Db_Expr;
use Zend_Db_Select;
/**
* Query for host group summary
*/
class HostgroupsummaryQuery extends IdoQuery
{
/**
* {@inheritdoc}
*/
protected $columnMap = array(
'hoststatussummary' => array(
'hostgroup' => 'hostgroup COLLATE latin1_general_ci',
'hostgroup_alias' => 'hostgroup_alias COLLATE latin1_general_ci',
'hostgroup_name' => 'hostgroup_name',
'hosts_down' => 'SUM(CASE WHEN object_type = \'host\' AND state = 1 THEN 1 ELSE 0 END)',
'hosts_down_handled' => 'SUM(CASE WHEN object_type = \'host\' AND state = 1 AND handled != 0 THEN 1 ELSE 0 END)',
'hosts_down_handled_last_state_change' => 'MAX(CASE WHEN object_type = \'host\' AND state = 1 AND handled != 0 THEN state_change ELSE 0 END)',
'hosts_down_unhandled' => 'SUM(CASE WHEN object_type = \'host\' AND state = 1 AND handled = 0 THEN 1 ELSE 0 END)',
'hosts_down_unhandled_last_state_change' => 'MAX(CASE WHEN object_type = \'host\' AND state = 1 AND handled = 0 THEN state_change ELSE 0 END)',
'hosts_pending' => 'SUM(CASE WHEN object_type = \'host\' AND state = 99 THEN 1 ELSE 0 END)',
'hosts_pending_last_state_change' => 'MAX(CASE WHEN object_type = \'host\' AND state = 99 THEN state_change ELSE 0 END)',
'hosts_severity' => 'MAX(CASE WHEN object_type = \'host\' THEN severity ELSE 0 END)',
'hosts_total' => 'SUM(CASE WHEN object_type = \'host\' THEN 1 ELSE 0 END)',
'hosts_unreachable' => 'SUM(CASE WHEN object_type = \'host\' AND state = 2 THEN 1 ELSE 0 END)',
'hosts_unreachable_handled' => 'SUM(CASE WHEN object_type = \'host\' AND state = 2 AND handled != 0 THEN 1 ELSE 0 END)',
'hosts_unreachable_handled_last_state_change' => 'MAX(CASE WHEN object_type = \'host\' AND state = 2 AND handled != 0 THEN state_change ELSE 0 END)',
'hosts_unreachable_unhandled' => 'SUM(CASE WHEN object_type = \'host\' AND state = 2 AND handled = 0 THEN 1 ELSE 0 END)',
'hosts_unreachable_unhandled_last_state_change' => 'MAX(CASE WHEN object_type = \'host\' AND state = 2 AND handled = 0 THEN state_change ELSE 0 END)',
'hosts_up' => 'SUM(CASE WHEN object_type = \'host\' AND state = 0 THEN 1 ELSE 0 END)',
'hosts_up_last_state_change' => 'MAX(CASE WHEN object_type = \'host\' AND state = 0 THEN state_change ELSE 0 END)',
'services_critical' => 'SUM(CASE WHEN object_type = \'service\' AND state = 2 THEN 1 ELSE 0 END)',
'services_critical_handled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 2 AND handled + host_state > 0 THEN 1 ELSE 0 END)',
'services_critical_unhandled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 2 AND handled + host_state = 0 THEN 1 ELSE 0 END)',
'services_ok' => 'SUM(CASE WHEN object_type = \'service\' AND state = 0 THEN 1 ELSE 0 END)',
'services_pending' => 'SUM(CASE WHEN object_type = \'service\' AND state = 99 THEN 1 ELSE 0 END)',
'services_severity' => 'MAX(CASE WHEN object_type = \'service\' THEN severity ELSE 0 END)',
'services_total' => 'SUM(CASE WHEN object_type = \'service\' THEN 1 ELSE 0 END)',
'services_unknown' => 'SUM(CASE WHEN object_type = \'service\' AND state = 3 THEN 1 ELSE 0 END)',
'services_unknown_handled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 3 AND handled + host_state > 0 THEN 1 ELSE 0 END)',
'services_unknown_unhandled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 3 AND handled + host_state = 0 THEN 1 ELSE 0 END)',
'services_warning' => 'SUM(CASE WHEN object_type = \'service\' AND state = 1 THEN 1 ELSE 0 END)',
'services_warning_handled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 1 AND handled + host_state > 0 THEN 1 ELSE 0 END)',
'services_warning_unhandled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 1 AND handled + host_state = 0 THEN 1 ELSE 0 END)',
)
);
/**
* The union
*
* @var Zend_Db_Select
*/
protected $summaryQuery;
/**
* Subqueries used for the summary query
*
* @var IdoQuery[]
*/
protected $subQueries = array();
/**
* {@inheritdoc}
*/
public function allowsCustomVars()
{
foreach ($this->subQueries as $query) {
if (! $query->allowsCustomVars()) {
return false;
}
}
return true;
}
/**
* {@inheritdoc}
*/
public function addFilter(Filter $filter)
{
foreach ($this->subQueries as $sub) {
$sub->applyFilter(clone $filter);
}
return $this;
}
/**
* {@inheritdoc}
*/
protected function joinBaseTables()
{
// TODO(el): Allow to switch between hard and soft states
$hosts = $this->createSubQuery(
'Hoststatus',
array(
'handled' => 'host_handled',
'host_state' => new Zend_Db_Expr('NULL'),
'hostgroup_alias',
'hostgroup_name',
'object_type',
'severity' => 'host_severity',
'state' => 'host_state',
'state_change' => 'host_last_state_change'
)
);
$hosts->select()->where('hgo.name1 IS NOT NULL'); // TODO(9458): Should be possible using our filters!
$this->subQueries[] = $hosts;
$services = $this->createSubQuery(
'Servicestatus',
array(
'handled' => 'service_handled',
'host_state' => 'host_hard_state',
'hostgroup_alias',
'hostgroup_name',
'object_type',
'severity' => new Zend_Db_Expr('NULL'),
'state' => 'service_state',
'state_change' => 'service_last_state_change'
)
);
$services->select()->where('hgo.name1 IS NOT NULL'); // TODO(9458): Should be possible using our filters!
$this->subQueries[] = $services;
$this->summaryQuery = $this->db->select()->union(array($hosts, $services), Zend_Db_Select::SQL_UNION_ALL);
$this->select->from(array('statussummary' => $this->summaryQuery), array());
$this->group(array('statussummary.hostgroup_name', 'statussummary.hostgroup_alias'));
$this->joinedVirtualTables['hoststatussummary'] = true;
}
/**
* {@inheritdoc}
*/
public function order($columnOrAlias, $dir = null)
{
if (! $this->hasAliasName($columnOrAlias)) {
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;
}
}
|