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
|
<?php
/* Icinga Web 2 | (c) 2014 Icinga Development Team | GPLv2+ */
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
abstract class EventgridQuery extends StatehistoryQuery
{
/**
* The columns additionally provided by this query
*
* @var array
*/
protected $additionalColumns = array(
'day' => 'DATE(FROM_UNIXTIME(sth.timestamp))',
'cnt_up' => "SUM(CASE WHEN sth.state = 0 THEN 1 ELSE 0 END)",
'cnt_down_hard' => "SUM(CASE WHEN sth.state = 1 AND sth.type = 'hard_state' THEN 1 ELSE 0 END)",
'cnt_down' => "SUM(CASE WHEN sth.state = 1 THEN 1 ELSE 0 END)",
'cnt_unreachable_hard' => "SUM(CASE WHEN sth.state = 2 AND sth.type = 'hard_state' THEN 1 ELSE 0 END)",
'cnt_unreachable' => "SUM(CASE WHEN sth.state = 2 THEN 1 ELSE 0 END)",
'cnt_unknown' => "SUM(CASE WHEN sth.state = 3 THEN 1 ELSE 0 END)",
'cnt_unknown_hard' => "SUM(CASE WHEN sth.state = 3 AND sth.type = 'hard_state' THEN 1 ELSE 0 END)",
'cnt_critical' => "SUM(CASE WHEN sth.state = 2 THEN 1 ELSE 0 END)",
'cnt_critical_hard' => "SUM(CASE WHEN sth.state = 2 AND sth.type = 'hard_state' THEN 1 ELSE 0 END)",
'cnt_warning' => "SUM(CASE WHEN sth.state = 1 THEN 1 ELSE 0 END)",
'cnt_warning_hard' => "SUM(CASE WHEN sth.state = 1 AND sth.type = 'hard_state' THEN 1 ELSE 0 END)",
'cnt_ok' => "SUM(CASE WHEN sth.state = 0 THEN 1 ELSE 0 END)"
);
/**
* {@inheritdoc}
*/
protected function joinBaseTables()
{
parent::joinBaseTables();
$this->requireVirtualTable('history');
$this->columnMap['statehistory'] += $this->additionalColumns;
$this->select->group(array('DATE(FROM_UNIXTIME(sth.timestamp))'));
}
/**
* {@inheritdoc}
*/
public function order($columnOrAlias, $dir = null)
{
if (array_key_exists($columnOrAlias, $this->additionalColumns)) {
$subQueries = $this->subQueries;
$this->subQueries = array();
parent::order($columnOrAlias, $dir);
$this->subQueries = $subQueries;
} else {
parent::order($columnOrAlias, $dir);
}
return $this;
}
}
|