summaryrefslogtreecommitdiffstats
path: root/library/Icingadb/Model/ServicestateSummary.php
blob: daf3bec16900109fd62735f60e6f8a3e57a3e86d (plain)
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php

/* Icinga DB Web | (c) 2020 Icinga GmbH | GPLv2 */

namespace Icinga\Module\Icingadb\Model;

use ipl\Sql\Connection;
use ipl\Sql\Expression;

/**
 * @property int $services_acknowledged
 * @property int $services_active_checks_enabled
 * @property int $services_passive_checks_enabled
 * @property int $services_critical_handled
 * @property int $services_critical_unhandled
 * @property int $services_event_handler_enabled
 * @property int $services_flapping_enabled
 * @property int $services_notifications_enabled
 * @property int $services_ok
 * @property int $services_pending
 * @property int $services_problems_unacknowledged
 * @property int $services_total
 * @property int $services_unknown_handled
 * @property int $services_unknown_unhandled
 * @property int $services_warning_handled
 * @property int $services_warning_unhandled
 */
class ServicestateSummary extends Service
{
    public function getSummaryColumns()
    {
        return [
            'services_acknowledged' => new Expression(
                'SUM(CASE WHEN service_state.is_acknowledged = \'y\' THEN 1 ELSE 0 END)'
            ),
            'services_active_checks_enabled' => new Expression(
                'SUM(CASE WHEN service.active_checks_enabled = \'y\' THEN 1 ELSE 0 END)'
            ),
            'services_passive_checks_enabled' => new Expression(
                'SUM(CASE WHEN service.passive_checks_enabled = \'y\' THEN 1 ELSE 0 END)'
            ),
            'services_critical_handled' => new Expression(
                'SUM(CASE WHEN service_state.soft_state = 2'
                . ' AND (service_state.is_handled = \'y\' OR service_state.is_reachable = \'n\') THEN 1 ELSE 0 END)'
            ),
            'services_critical_unhandled' => new Expression(
                'SUM(CASE WHEN service_state.soft_state = 2'
                . ' AND service_state.is_handled = \'n\' AND service_state.is_reachable = \'y\' THEN 1 ELSE 0 END)'
            ),
            'services_event_handler_enabled' => new Expression(
                'SUM(CASE WHEN service.event_handler_enabled = \'y\' THEN 1 ELSE 0 END)'
            ),
            'services_flapping_enabled' => new Expression(
                'SUM(CASE WHEN service.flapping_enabled = \'y\' THEN 1 ELSE 0 END)'
            ),
            'services_notifications_enabled' => new Expression(
                'SUM(CASE WHEN service.notifications_enabled = \'y\' THEN 1 ELSE 0 END)'
            ),
            'services_ok' => new Expression(
                'SUM(CASE WHEN service_state.soft_state = 0 THEN 1 ELSE 0 END)'
            ),
            'services_pending' => new Expression(
                'SUM(CASE WHEN service_state.soft_state = 99 THEN 1 ELSE 0 END)'
            ),
            'services_problems_unacknowledged' => new Expression(
                'SUM(CASE WHEN service_state.is_problem = \'y\''
                . ' AND service_state.is_acknowledged = \'n\' THEN 1 ELSE 0 END)'
            ),
            'services_total' => new Expression(
                'SUM(CASE WHEN service.id IS NOT NULL THEN 1 ELSE 0 END)'
            ),
            'services_unknown_handled' => new Expression(
                'SUM(CASE WHEN service_state.soft_state = 3'
                . ' AND (service_state.is_handled = \'y\' OR service_state.is_reachable = \'n\') THEN 1 ELSE 0 END)'
            ),
            'services_unknown_unhandled' => new Expression(
                'SUM(CASE WHEN service_state.soft_state = 3'
                . ' AND service_state.is_handled = \'n\' AND service_state.is_reachable = \'y\' THEN 1 ELSE 0 END)'
            ),
            'services_warning_handled' => new Expression(
                'SUM(CASE WHEN service_state.soft_state = 1'
                . ' AND (service_state.is_handled = \'y\' OR service_state.is_reachable = \'n\') THEN 1 ELSE 0 END)'
            ),
            'services_warning_unhandled' => new Expression(
                'SUM(CASE WHEN service_state.soft_state = 1'
                . ' AND service_state.is_handled = \'n\' AND service_state.is_reachable = \'y\' THEN 1 ELSE 0 END)'
            )
        ];
    }

    public static function on(Connection $db)
    {
        $q = parent::on($db);
        $q->utilize('state');

        /** @var static $m */
        $m = $q->getModel();
        $q->columns($m->getSummaryColumns());

        return $q;
    }

    public function getColumns()
    {
        return array_merge(parent::getColumns(), $this->getSummaryColumns());
    }

    public function getDefaultSort()
    {
        return null;
    }

    public function getSearchColumns()
    {
        return ['name_ci', 'host.name_ci'];
    }
}