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
|
<?php
/* Icinga Web 2 | (c) 2013 Icinga Development Team | GPLv2+ */
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
use Zend_Db_Select;
/**
* Query check summaries out of database
*/
class RuntimesummaryQuery extends IdoQuery
{
protected $columnMap = array(
'runtimesummary' => array(
'check_type' => 'check_type',
'active_checks_enabled' => 'active_checks_enabled',
'passive_checks_enabled' => 'passive_checks_enabled',
'execution_time' => 'execution_time',
'latency' => 'latency',
'object_count' => 'object_count',
'object_type' => 'object_type'
)
);
protected function joinBaseTables()
{
$hosts = $this->db->select()->from(
array('ho' => $this->prefix . 'objects'),
array()
)->join(
array('hs' => $this->prefix . 'hoststatus'),
'ho.object_id = hs.host_object_id AND ho.is_active = 1 AND ho.objecttype_id = 1',
array()
)->columns(
array(
'check_type' => 'CASE '
. 'WHEN hs.active_checks_enabled = 0 AND hs.passive_checks_enabled = 1 THEN \'passive\' '
. 'WHEN hs.active_checks_enabled = 1 THEN \'active\' '
. 'END',
'active_checks_enabled' => 'hs.active_checks_enabled',
'passive_checks_enabled' => 'hs.passive_checks_enabled',
'execution_time' => 'SUM(hs.execution_time)',
'latency' => 'SUM(hs.latency)',
'object_count' => 'COUNT(*)',
'object_type' => "('host')"
)
)->group('check_type')->group('active_checks_enabled')->group('passive_checks_enabled');
$services = $this->db->select()->from(
array('so' => $this->prefix . 'objects'),
array()
)->join(
array('ss' => $this->prefix . 'servicestatus'),
'so.object_id = ss.service_object_id AND so.is_active = 1 AND so.objecttype_id = 2',
array()
)->columns(
array(
'check_type' => 'CASE '
. 'WHEN ss.active_checks_enabled = 0 AND ss.passive_checks_enabled = 1 THEN \'passive\' '
. 'WHEN ss.active_checks_enabled = 1 THEN \'active\' '
. 'END',
'active_checks_enabled' => 'ss.active_checks_enabled',
'passive_checks_enabled' => 'ss.passive_checks_enabled',
'execution_time' => 'SUM(ss.execution_time)',
'latency' => 'SUM(ss.latency)',
'object_count' => 'COUNT(*)',
'object_type' => "('service')"
)
)->group('check_type')->group('active_checks_enabled')->group('passive_checks_enabled');
$union = $this->db->select()->union(
array('s' => $services, 'h' => $hosts),
Zend_Db_Select::SQL_UNION_ALL
);
$this->select->from(array('hs' => $union));
$this->joinedVirtualTables = array('runtimesummary' => true);
}
}
|