Skip to content

Commit

Permalink
WIP: Introduce DependencyNodeSummary Model
Browse files Browse the repository at this point in the history
This summary is required to create `ObjectsStatistics`
  • Loading branch information
sukhwinder33445 committed Oct 1, 2024
1 parent d140512 commit ab39f4f
Showing 1 changed file with 119 additions and 0 deletions.
119 changes: 119 additions & 0 deletions library/Icingadb/Model/DependencyNodeSummary.php
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());
}
}

0 comments on commit ab39f4f

Please sign in to comment.