summaryrefslogtreecommitdiffstats
path: root/modules/monitoring/application/controllers/ServiceController.php
blob: d3eeb1c813aab8d915ddc8ccfdfcd2e78317123b (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
<?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\ScheduleServiceCheckCommandForm;
use Icinga\Module\Monitoring\Forms\Command\Object\ScheduleServiceDowntimeCommandForm;
use Icinga\Module\Monitoring\Forms\Command\Object\SendCustomNotificationCommandForm;
use Icinga\Module\Monitoring\Object\Service;
use Icinga\Module\Monitoring\Web\Controller\MonitoredObjectController;
use Icinga\Web\Hook;
use Icinga\Web\Navigation\Navigation;

class ServiceController extends MonitoredObjectController
{
    /**
     * {@inheritdoc}
     */
    protected $commandRedirectUrl = 'monitoring/service/show';

    /**
     * Fetch the requested service from the monitoring backend
     */
    public function init()
    {
        $service = new Service(
            $this->backend,
            $this->params->getRequired('host'),
            $this->params->getRequired('service')
        );

        $this->applyRestriction('monitoring/filter/objects', $service);

        if ($service->fetch() === false) {
            $this->httpNotFound($this->translate('Service not found'));
        }
        $this->object = $service;
        $this->createTabs();
        $this->getTabs()->activate('service');
        $this->view->title = $service->service_display_name;
        $this->view->defaultTitle = join(' :: ', [
            $service->host_display_name,
            $this->translate('Services'),
            $this->view->defaultTitle
        ]);
    }

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

        return $navigation;
    }

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


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

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

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

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

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

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

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

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

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

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

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

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