summaryrefslogtreecommitdiffstats
path: root/modules/monitoring/application/controllers/HostController.php
blob: 94f1a60b8c27b1ee2c2f56726807a18dde8ac2c7 (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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<?php
/* Icinga Web 2 | (c) 2014 Icinga Development Team | GPLv2+ */

namespace Icinga\Module\Monitoring\Controllers;

use Icinga\Module\Monitoring\Forms\Command\Object\AcknowledgeProblemCommandForm;
use Icinga\Module\Monitoring\Forms\Command\Object\AddCommentCommandForm;
use Icinga\Module\Monitoring\Forms\Command\Object\ProcessCheckResultCommandForm;
use Icinga\Module\Monitoring\Forms\Command\Object\ScheduleHostCheckCommandForm;
use Icinga\Module\Monitoring\Forms\Command\Object\ScheduleHostDowntimeCommandForm;
use Icinga\Module\Monitoring\Forms\Command\Object\SendCustomNotificationCommandForm;
use Icinga\Module\Monitoring\Object\Host;
use Icinga\Module\Monitoring\Web\Controller\MonitoredObjectController;
use Icinga\Web\Hook;
use Icinga\Web\Navigation\Navigation;

class HostController extends MonitoredObjectController
{

    /**
     * {@inheritdoc}
     */
    protected $commandRedirectUrl = 'monitoring/host/show';

    /**
     * Fetch the requested host from the monitoring backend
     */
    public function init()
    {
        $host = new Host($this->backend, $this->params->getRequired('host'));
        $this->applyRestriction('monitoring/filter/objects', $host);
        if ($host->fetch() === false) {
            $this->httpNotFound($this->translate('Host not found'));
        }
        $this->object = $host;
        $this->createTabs();
        $this->getTabs()->activate('host');
        $this->view->title = $host->host_display_name;
        $this->view->defaultTitle = $this->translate('Hosts') . ' :: ' . $this->view->defaultTitle;
    }

    /**
     * Get host actions from hook
     *
     * @return  Navigation
     */
    protected function getHostActions()
    {
        $navigation = new Navigation();
        foreach (Hook::all('Monitoring\\HostActions') as $hook) {
            $navigation->merge($hook->getNavigation($this->object));
        }

        return $navigation;
    }

    /**
     * Show a host
     */
    public function showAction()
    {
        $this->view->actions = $this->getHostActions();
        parent::showAction();
    }

    /**
     * List a host's services
     */
    public function servicesAction()
    {
        $this->setAutorefreshInterval(10);
        $this->getTabs()->activate('services');
        $query = $this->backend->select()->from('servicestatus', array(
            'host_name',
            'host_display_name',
            'host_state',
            'host_state_type',
            'host_last_state_change',
            'host_address',
            'host_address6',
            'host_handled',
            'service_description',
            'service_display_name',
            'service_state',
            'service_in_downtime',
            'service_acknowledged',
            'service_handled',
            'service_output',
            'service_perfdata',
            'service_attempt',
            'service_last_state_change',
            'service_icon_image',
            'service_icon_image_alt',
            'service_is_flapping',
            'service_state_type',
            'service_handled',
            'service_severity',
            'service_last_check',
            'service_notifications_enabled',
            'service_action_url',
            'service_notes_url',
            'service_active_checks_enabled',
            'service_passive_checks_enabled',
            'current_check_attempt' => 'service_current_check_attempt',
            'max_check_attempts'    => 'service_max_check_attempts',
            'service_check_command',
            'service_next_update'
        ));
        $this->applyRestriction('monitoring/filter/objects', $query);
        $this->view->services = $query->where('host_name', $this->object->getName());
        $this->view->object = $this->object;
    }

    /**
     * Acknowledge a host problem
     */
    public function acknowledgeProblemAction()
    {
        $this->assertPermission('monitoring/command/acknowledge-problem');

        $form = new AcknowledgeProblemCommandForm();
        $form->setTitle($this->translate('Acknowledge Host Problem'));
        $this->handleCommandForm($form);
    }

    /**
     * Add a host comment
     */
    public function addCommentAction()
    {
        $this->assertPermission('monitoring/command/comment/add');

        $form = new AddCommentCommandForm();
        $form->setTitle($this->translate('Add Host Comment'));
        $this->handleCommandForm($form);
    }

    /**
     * Reschedule a host check
     */
    public function rescheduleCheckAction()
    {
        $this->assertPermission('monitoring/command/schedule-check');

        $form = new ScheduleHostCheckCommandForm();
        $form->setTitle($this->translate('Reschedule Host Check'));
        $this->handleCommandForm($form);
    }

    /**
     * Schedule a host downtime
     */
    public function scheduleDowntimeAction()
    {
        $this->assertPermission('monitoring/command/downtime/schedule');

        $form = new ScheduleHostDowntimeCommandForm();
        $form->setTitle($this->translate('Schedule Host Downtime'));
        $this->handleCommandForm($form);
    }

    /**
     * Submit a passive host check result
     */
    public function processCheckResultAction()
    {
        $this->assertPermission('monitoring/command/process-check-result');

        $form = new ProcessCheckResultCommandForm();
        $form->setTitle($this->translate('Submit Passive Host Check Result'));
        $this->handleCommandForm($form);
    }

    /**
     * Send a custom notification for host
     */
    public function sendCustomNotificationAction()
    {
        $this->assertPermission('monitoring/command/send-custom-notification');

        $form = new SendCustomNotificationCommandForm();
        $form->setTitle($this->translate('Send Custom Host Notification'));
        $this->handleCommandForm($form);
    }
}