Consider is_active column when fetching host and service statistics

fixes #6157
This commit is contained in:
Johannes Meyer 2014-07-09 11:49:22 +02:00
parent 0fc2604af3
commit 0d92efc1b0
1 changed files with 43 additions and 37 deletions

View File

@ -29,7 +29,7 @@
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
use \Zend_Db_Select;
use Zend_Db_Select;
/**
* Query check summaries out of database
@ -50,43 +50,49 @@ class RuntimesummaryQuery extends IdoQuery
protected function joinBaseTables()
{
$p = $this->prefix;
$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');
$hostColumns = array(
'check_type' => 'CASE '
. 'WHEN ' . $p
. 'hoststatus.active_checks_enabled = 0 AND '
. $p . 'hoststatus.passive_checks_enabled = 1 '
. 'THEN \'passive\' '
. 'WHEN ' . $p . 'hoststatus.active_checks_enabled = 1 THEN \'active\' END',
'active_checks_enabled' => 'active_checks_enabled',
'passive_checks_enabled' => 'passive_checks_enabled',
'execution_time' => 'SUM(execution_time)',
'latency' => 'SUM(latency)',
'object_count' => 'COUNT(*)',
'object_type' => "('host')"
);
$serviceColumns = array(
'check_type' => 'CASE '
. 'WHEN ' . $p
. 'servicestatus.active_checks_enabled = 0 AND ' . $p
. 'servicestatus.passive_checks_enabled = 1 '
. 'THEN \'passive\' '
. 'WHEN ' . $p . 'servicestatus.active_checks_enabled = 1 THEN \'active\' END',
'active_checks_enabled' => 'active_checks_enabled',
'passive_checks_enabled' => 'passive_checks_enabled',
'execution_time' => 'SUM(execution_time)',
'latency' => 'SUM(latency)',
'object_count' => 'COUNT(*)',
'object_type' => "('service')"
);
$hosts = $this->db->select()->from($this->prefix . 'hoststatus', $hostColumns)
->group('check_type')->group('active_checks_enabled')->group('passive_checks_enabled');
$services = $this->db->select()->from($this->prefix . 'servicestatus', $serviceColumns)
->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),