-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: Introduce
DependencyNodeSummary
Model
This summary is required to create `ObjectsStatistics`
- Loading branch information
1 parent
d140512
commit ab39f4f
Showing
1 changed file
with
119 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
<?php | ||
|
||
/* Icinga DB Web | (c) 2020 Icinga GmbH | GPLv2 */ | ||
|
||
namespace Icinga\Module\Icingadb\Model; | ||
|
||
use ipl\Orm\Query; | ||
use ipl\Sql\Connection; | ||
use ipl\Sql\Expression; | ||
|
||
/** | ||
* @property int $objects_down_handled | ||
* @property int $objects_down_unhandled | ||
* @property int $objects_event_handler_enabled | ||
* @property int $objects_flapping_enabled | ||
* @property int $objects_notifications_enabled | ||
* @property int $objects_pending | ||
* @property int $objects_problems_unacknowledged | ||
* @property int $objects_total | ||
* @property int $objects_up | ||
*/ | ||
class DependencyNodeSummary extends DependencyNode | ||
{ | ||
public function getSummaryColumns() | ||
{ | ||
return [ | ||
'objects_ok' => new Expression( | ||
'SUM(CASE WHEN (dependency_node.service_id IS NOT NULL AND dependency_node_service_state.soft_state = 0)' | ||
. 'OR (dependency_node.host_id IS NOT NULL AND dependency_node_host_state.soft_state = 0)' | ||
. 'OR (dependency_node.redundancy_group_id IS NOT NULL AND dependency_node_redundancy_group_state.failed = \'n\')' | ||
. ' THEN 1 ELSE 0 END)' | ||
), | ||
'objects_problem_handled' => new Expression( | ||
'SUM(CASE WHEN' | ||
. ' (dependency_node.service_id IS NOT NULL AND dependency_node_service_state.soft_state = 2' | ||
. ' AND (dependency_node_service_state.is_handled = \'y\' OR dependency_node_service_state.is_reachable = \'n\'))' | ||
. ' OR' | ||
. ' (dependency_node.host_id IS NOT NULL AND dependency_node_host_state.soft_state = 1' | ||
. ' AND (dependency_node_host_state.is_handled = \'y\' OR dependency_node_host_state.is_reachable = \'n\'))' | ||
// . ' OR' | ||
// .' (dependency_node.redundancy_group_id IS NOT NULL AND dependency_node_redundancy_group_state.failed = \'y\')' | ||
. ' THEN 1 ELSE 0 END)' | ||
), | ||
'objects_problem_unhandled' => new Expression( | ||
'SUM(CASE WHEN' | ||
. ' (dependency_node.service_id IS NOT NULL AND dependency_node_service_state.soft_state = 2' | ||
. ' AND (dependency_node_service_state.is_handled = \'n\' OR dependency_node_service_state.is_reachable = \'y\'))' | ||
. ' OR' | ||
. ' (dependency_node.host_id IS NOT NULL AND dependency_node_host_state.soft_state = 1' | ||
. ' AND (dependency_node_host_state.is_handled = \'n\' OR dependency_node_host_state.is_reachable = \'y\'))' | ||
. ' OR' | ||
. ' (dependency_node.redundancy_group_id IS NOT NULL AND dependency_node_redundancy_group_state.failed = \'y\')' | ||
. ' THEN 1 ELSE 0 END)' | ||
), | ||
'objects_warning_handled' => new Expression( | ||
'SUM(CASE WHEN(' | ||
. 'dependency_node.service_id IS NOT NULL AND dependency_node_service_state.soft_state = 1' | ||
. ' AND (dependency_node_service_state.is_handled = \'y\' OR dependency_node_service_state.is_reachable = \'n\')' | ||
. ') THEN 1 ELSE 0 END)' | ||
), | ||
'objects_warning_unhandled' => new Expression( | ||
'SUM(CASE WHEN(' | ||
. 'dependency_node.service_id IS NOT NULL AND dependency_node_service_state.soft_state = 1' | ||
. ' AND (dependency_node_service_state.is_handled = \'n\' OR dependency_node_service_state.is_reachable = \'y\')' | ||
. ') THEN 1 ELSE 0 END)' | ||
), | ||
'objects_unknown_handled' => new Expression( | ||
'SUM(CASE WHEN(' | ||
. 'dependency_node.service_id IS NOT NULL AND dependency_node_service_state.soft_state = 3' | ||
. ' AND (dependency_node_service_state.is_handled = \'y\' OR dependency_node_service_state.is_reachable = \'n\')' | ||
. ') THEN 1 ELSE 0 END)' | ||
), | ||
'objects_unknown_unhandled' => new Expression( | ||
'SUM(CASE WHEN(' | ||
. 'dependency_node.service_id IS NOT NULL AND dependency_node_service_state.soft_state = 3' | ||
. ' AND (dependency_node_service_state.is_handled = \'n\' OR dependency_node_service_state.is_reachable = \'y\')' | ||
. ') THEN 1 ELSE 0 END)' | ||
), | ||
'objects_pending' => new Expression( | ||
'SUM(CASE WHEN (dependency_node.service_id IS NOT NULL AND dependency_node_service_state.soft_state = 99)' | ||
. 'OR (dependency_node.host_id IS NOT NULL AND dependency_node_host_state.soft_state = 99)' | ||
//. 'OR (dependency_node.redundancy_group_id IS NOT NULL AND dependency_node_redundancy_group_state.failed = \'n\')' | ||
. ' THEN 1 ELSE 0 END)' | ||
), | ||
'objects_total' => new Expression( | ||
'SUM(CASE WHEN dependency_node.id IS NOT NULL THEN 1 ELSE 0 END)' | ||
), | ||
]; | ||
} | ||
|
||
public static function on(Connection $db): Query | ||
{ | ||
$q = parent::on($db) | ||
->with([ | ||
'host', | ||
'host.state', | ||
'service', | ||
'service.state', | ||
'service.host', | ||
'service.host.state', | ||
'redundancy_group', | ||
'redundancy_group.state' | ||
]); | ||
|
||
$q->getSelectBase() | ||
->groupBy('dependency_node.id'); | ||
|
||
/** @var static $m */ | ||
$m = $q->getModel(); | ||
$q->columns($m->getSummaryColumns()); | ||
|
||
return $q; | ||
} | ||
|
||
public function getColumns(): array | ||
{ | ||
return array_merge(parent::getColumns(), $this->getSummaryColumns()); | ||
} | ||
} |