/usr/share/icingaweb2/modules/monitoring/library/Monitoring/Web/Controller/MonitoredObjectController.php is in icingaweb2-module-monitoring 2.1.0-1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 | <?php
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
namespace Icinga\Module\Monitoring\Web\Controller;
use Icinga\Module\Monitoring\Controller;
use Icinga\Module\Monitoring\Forms\Command\Object\CheckNowCommandForm;
use Icinga\Module\Monitoring\Forms\Command\Object\DeleteCommentCommandForm;
use Icinga\Module\Monitoring\Forms\Command\Object\DeleteDowntimeCommandForm;
use Icinga\Module\Monitoring\Forms\Command\Object\ObjectsCommandForm;
use Icinga\Module\Monitoring\Forms\Command\Object\RemoveAcknowledgementCommandForm;
use Icinga\Module\Monitoring\Forms\Command\Object\ToggleObjectFeaturesCommandForm;
use Icinga\Web\Hook;
use Icinga\Web\Url;
use Icinga\Web\Widget\Tabextension\DashboardAction;
use Icinga\Web\Widget\Tabextension\MenuAction;
/**
* Base class for the host and service controller
*/
abstract class MonitoredObjectController extends Controller
{
/**
* The requested host or service
*
* @var \Icinga\Module\Monitoring\Object\Host|\Icinga\Module\Monitoring\Object\Host
*/
protected $object;
/**
* URL to redirect to after a command was handled
*
* @var string
*/
protected $commandRedirectUrl;
/**
* (non-PHPDoc)
* @see \Icinga\Web\Controller\ActionController For the method documentation.
*/
public function prepareInit()
{
parent::prepareInit();
if (Hook::has('ticket')) {
$this->view->tickets = Hook::first('ticket');
}
if (Hook::has('grapher')) {
$this->view->grapher = Hook::first('grapher');
}
}
/**
* Show a host or service
*/
public function showAction()
{
$this->setAutorefreshInterval(10);
$auth = $this->Auth();
if ($auth->hasPermission('monitoring/command/schedule-check')) {
$checkNowForm = new CheckNowCommandForm();
$checkNowForm
->setObjects($this->object)
->handleRequest();
$this->view->checkNowForm = $checkNowForm;
}
if (! in_array((int) $this->object->state, array(0, 99))) {
if ((bool) $this->object->acknowledged) {
if ($auth->hasPermission('monitoring/command/remove-acknowledgement')) {
$removeAckForm = new RemoveAcknowledgementCommandForm();
$removeAckForm
->setObjects($this->object)
->handleRequest();
$this->view->removeAckForm = $removeAckForm;
}
}
}
$this->object->populate();
$toggleFeaturesForm = new ToggleObjectFeaturesCommandForm();
$toggleFeaturesForm
->setBackend($this->backend)
->load($this->object)
->setObjects($this->object)
->handleRequest();
$this->view->toggleFeaturesForm = $toggleFeaturesForm;
if (! empty($this->object->comments) && $auth->hasPermission('monitoring/command/comment/delete')) {
$delCommentForm = new DeleteCommentCommandForm();
$delCommentForm->handleRequest();
$this->view->delCommentForm = $delCommentForm;
}
if (! empty($this->object->downtimes) && $auth->hasPermission('monitoring/command/downtime/delete')) {
$delDowntimeForm = new DeleteDowntimeCommandForm();
$delDowntimeForm->handleRequest();
$this->view->delDowntimeForm = $delDowntimeForm;
}
$this->view->showInstance = $this->backend->select()->from('instance')->count() > 1;
$this->view->object = $this->object;
}
/**
* Show the history for a host or service
*/
public function historyAction()
{
$this->getTabs()->activate('history');
$this->view->history = $this->object->fetchEventHistory()->eventhistory;
$this->applyRestriction('monitoring/filter/objects', $this->view->history);
$this->setupLimitControl(50);
$this->setupPaginationControl($this->view->history, 50);
$this->view->object = $this->object;
$this->render('object/detail-history', null, true);
}
/**
* Handle a command form
*
* @param ObjectsCommandForm $form
*
* @return ObjectsCommandForm
*/
protected function handleCommandForm(ObjectsCommandForm $form)
{
$form
->setObjects($this->object)
->setRedirectUrl(Url::fromPath($this->commandRedirectUrl)->setParams($this->params))
->handleRequest();
$this->view->form = $form;
$this->view->object = $this->object;
$this->view->tabs->remove('dashboard');
$this->_helper->viewRenderer('partials/command/object-command-form', null, true);
return $form;
}
/**
* Acknowledge a problem
*/
abstract public function acknowledgeProblemAction();
/**
* Add a comment
*/
abstract public function addCommentAction();
/**
* Reschedule a check
*/
abstract public function rescheduleCheckAction();
/**
* Schedule a downtime
*/
abstract public function scheduleDowntimeAction();
/**
* Create tabs
*/
protected function createTabs()
{
$tabs = $this->getTabs();
$object = $this->object;
if ($object->getType() === $object::TYPE_HOST) {
$isService = false;
$params = array(
'host' => $object->getName()
);
if ($this->params->has('service')) {
$params['service'] = $this->params->get('service');
}
} else {
$isService = true;
$params = array(
'host' => $object->getHost()->getName(),
'service' => $object->getName()
);
}
$tabs->add(
'host',
array(
'title' => sprintf(
$this->translate('Show detailed information for host %s'),
$isService ? $object->getHost()->getName() : $object->getName()
),
'label' => $this->translate('Host'),
'url' => 'monitoring/host/show',
'urlParams' => $params
)
);
if ($isService || $this->params->has('service')) {
$tabs->add(
'service',
array(
'title' => sprintf(
$this->translate('Show detailed information for service %s on host %s'),
$isService ? $object->getName() : $this->params->get('service'),
$isService ? $object->getHost()->getName() : $object->getName()
),
'label' => $this->translate('Service'),
'url' => 'monitoring/service/show',
'urlParams' => $params
)
);
}
$tabs->add(
'services',
array(
'title' => sprintf(
$this->translate('List all services on host %s'),
$isService ? $object->getHost()->getName() : $object->getName()
),
'label' => $this->translate('Services'),
'url' => 'monitoring/host/services',
'urlParams' => $params
)
);
if ($this->backend->hasQuery('eventhistory')) {
$tabs->add(
'history',
array(
'title' => $isService
? sprintf(
$this->translate('Show all event records of service %s on host %s'),
$object->getName(),
$object->getHost()->getName()
)
: sprintf($this->translate('Show all event records of host %s'), $object->getName())
,
'label' => $this->translate('History'),
'url' => $isService ? 'monitoring/service/history' : 'monitoring/host/history',
'urlParams' => $params
)
);
}
$tabs->extend(new DashboardAction())->extend(new MenuAction());
}
}
|