summaryrefslogtreecommitdiffstats
path: root/modules/monitoring/library/Monitoring/Backend/Ido/Query/EmptyservicegroupQuery.php
blob: 88ee4c35bc60c36e4e6e544e56ccaebca68b6733 (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
<?php
/* Icinga Web 2 | (c) 2019 Icinga GmbH | GPLv2+ */

namespace Icinga\Module\Monitoring\Backend\Ido\Query;

class EmptyservicegroupQuery extends ServicegroupQuery
{
    protected $subQueryTargets = [];

    protected $columnMap = [
        'servicegroups' => [
            'servicegroup'          => 'sgo.name1 COLLATE latin1_general_ci',
            'servicegroup_alias'    => 'sg.alias COLLATE latin1_general_ci',
            'servicegroup_name'     => 'sgo.name1',
            'host_name'             => '(NULL)',
            'hostgroup_name'        => '(NULL)',
            'service_description'   => '(NULL)',
            'host_contact'          => '(NULL)',
            'host_contactgroup'     => '(NULL)',
            'service_contact'       => '(NULL)',
            'service_contactgroup'  => '(NULL)'
        ],
        'instances' => [
            'instance_name'         => 'i.instance_name'
        ]
    ];

    protected function joinBaseTables()
    {
        parent::joinBaseTables();

        $this->select->joinLeft(
            ['esgm' => $this->prefix . 'servicegroup_members'],
            'esgm.servicegroup_id = sg.servicegroup_id',
            []
        );
        $this->select->group(['sgo.object_id', 'sg.servicegroup_id']);
        $this->select->having('COUNT(esgm.servicegroup_member_id) = ?', 0);
    }

    protected function joinHosts()
    {
        parent::joinHosts();

        $this->select->joinLeft(
            ['h' => 'icinga_hosts'],
            'h.host_object_id = s.host_object_id',
            []
        );
    }
}