diff options
Diffstat (limited to 'application/controllers')
-rw-r--r-- | application/controllers/CommentsController.php | 17 | ||||
-rw-r--r-- | application/controllers/ConfigController.php | 45 | ||||
-rw-r--r-- | application/controllers/EventController.php | 216 | ||||
-rw-r--r-- | application/controllers/EventsController.php | 186 | ||||
-rw-r--r-- | application/controllers/IndexController.php | 14 |
5 files changed, 478 insertions, 0 deletions
diff --git a/application/controllers/CommentsController.php b/application/controllers/CommentsController.php new file mode 100644 index 0000000..a371c7b --- /dev/null +++ b/application/controllers/CommentsController.php @@ -0,0 +1,17 @@ +<?php +/* Icinga Web 2 | (c) 2016 Icinga Development Team | GPLv2+ */ + +namespace Icinga\Module\Eventdb\Controllers; + +use Icinga\Module\Eventdb\EventdbController; + +class CommentsController extends EventdbController +{ + /** + * @deprecated Moved to eventdb/events/details + */ + public function newAction() + { + $this->redirectNow($this->getRequest()->getUrl()->setPath('eventdb/events/details')); + } +} diff --git a/application/controllers/ConfigController.php b/application/controllers/ConfigController.php new file mode 100644 index 0000000..d812918 --- /dev/null +++ b/application/controllers/ConfigController.php @@ -0,0 +1,45 @@ +<?php +/* Icinga Web 2 | (c) 2016 Icinga Development Team | GPLv2+ */ + +namespace Icinga\Module\Eventdb\Controllers; + +use Icinga\Module\Eventdb\Forms\Config\BackendConfigForm; +use Icinga\Module\Eventdb\Forms\Config\GlobalConfigForm; +use Icinga\Module\Eventdb\Forms\Config\MonitoringConfigForm; +use Icinga\Web\Controller; + +class ConfigController extends Controller +{ + public function init() + { + $this->assertPermission('config/modules'); + parent::init(); + } + + public function indexAction() + { + $backendConfig = new BackendConfigForm(); + $backendConfig + ->setIniConfig($this->Config()) + ->handleRequest(); + $this->view->backendConfig = $backendConfig; + + $globalConfig = new GlobalConfigForm(); + $globalConfig + ->setIniConfig($this->Config()) + ->handleRequest(); + $this->view->globalConfig = $globalConfig; + + $this->view->tabs = $this->Module()->getConfigTabs()->activate('config'); + } + + public function monitoringAction() + { + $monitoringConfig = new MonitoringConfigForm(); + $monitoringConfig + ->setIniConfig($this->Config()) + ->handleRequest(); + $this->view->form = $monitoringConfig; + $this->view->tabs = $this->Module()->getConfigTabs()->activate('monitoring'); + } +} diff --git a/application/controllers/EventController.php b/application/controllers/EventController.php new file mode 100644 index 0000000..f6a323c --- /dev/null +++ b/application/controllers/EventController.php @@ -0,0 +1,216 @@ +<?php +/* Icinga Web 2 | (c) 2016 Icinga Development Team | GPLv2+ */ + +namespace Icinga\Module\Eventdb\Controllers; + +use Icinga\Data\Filter\Filter; +use Icinga\Exception\NotFoundError; +use Icinga\Module\Eventdb\Event; +use Icinga\Module\Eventdb\EventdbController; +use Icinga\Module\Eventdb\Forms\Event\EventCommentForm; +use Icinga\Module\Eventdb\Hook\DetailviewExtensionHook; +use Icinga\Module\Eventdb\Web\EventdbOutputFormat; +use Icinga\Web\Hook; +use Icinga\Web\Url; + +class EventController extends EventdbController +{ + public function indexAction() + { + $eventId = $this->params->getRequired('id'); + + $url = Url::fromRequest(); + + $this->getTabs()->add('event', array( + 'active' => ! $this->isFormatRequest(), + 'title' => $this->translate('Event'), + 'url' => $url->without(array('format')) + ))->extend(new EventdbOutputFormat(array(), array(EventdbOutputFormat::TYPE_TEXT))); + + $columnConfig = $this->Config('columns'); + if (! $columnConfig->isEmpty()) { + $additionalColumns = $columnConfig->keys(); + } else { + $additionalColumns = array(); + } + + $event = $this->getDb() + ->select() + ->from('event'); + + $columns = array_merge($event->getColumns(), $additionalColumns); + + $event->from('event', $columns); + $event->where('id', $eventId); + + $event->applyFilter(Filter::matchAny(array_map( + '\Icinga\Data\Filter\Filter::fromQueryString', + $this->getRestrictions('eventdb/events/filter', 'eventdb/events') + ))); + + $eventData = $event->fetchRow(); + if (! $eventData) { + throw new NotFoundError('Could not find event with id %d', $eventId); + } + + $eventObj = Event::fromData($eventData); + + $groupedEvents = null; + if ($this->getDb()->hasCorrelatorExtensions()) { + $group_leader = (int) $eventObj->group_leader; + if ($group_leader > 0) { + // redirect to group leader + $this->redirectNow(Url::fromPath('eventdb/event', array('id' => $group_leader))); + } + + if ($group_leader === -1) { + // load grouped events, if any + $groupedEvents = $this->getDb() + ->select() + ->from('event') + ->where('group_leader', $eventObj->id) + ->order('ack', 'ASC') + ->order('created', 'DESC'); + } + } + + $comments = null; + $commentForm = null; + if ($this->hasPermission('eventdb/comments')) { + $comments = $this->getDb() + ->select() + ->from('comment', array( + 'id', + 'type', + 'message', + 'created', + 'modified', + 'user' + )) + ->where('event_id', $eventId) + ->order('created', 'DESC'); + + if ($this->hasPermission('eventdb/interact')) { + $commentForm = new EventCommentForm(); + $commentForm + ->setDb($this->getDb()) + ->setFilter(Filter::expression('id', '=', $eventId)); + } + } + + $format = $this->params->get('format'); + if ($format === 'sql') { + $this->sendSqlSummary(array($event, $comments, $groupedEvents)); + } elseif ($this->isApiRequest()) { + $data = new \stdClass; + $data->event = $eventData; + if ($comments !== null) { + $data->comments = $comments; + } + if ($groupedEvents !== null) { + $data->groupedEvents = $groupedEvents; + } + $this->sendJson($data); + } elseif ($this->isTextRequest()) { + $this->view->event = $eventObj; + $this->view->columnConfig = $columnConfig; + $this->view->additionalColumns = $additionalColumns; + $this->view->groupedEvents = $groupedEvents; + $this->view->comments = $comments; + + $this->sendText(null, 'event/index-plain'); + } else { + if ($commentForm !== null) { + $commentForm->handleRequest(); + } + + $this->view->event = $eventObj; + $this->view->columnConfig = $columnConfig; + $this->view->additionalColumns = $additionalColumns; + $this->view->groupedEvents = $groupedEvents; + $this->view->comments = $comments; + $this->view->commentForm = $commentForm; + + $this->view->extensionsHtml = array(); + foreach (Hook::all('Eventdb\DetailviewExtension') as $hook) { + /** @var DetailviewExtensionHook $hook */ + $module = $this->view->escape($hook->getModule()->getName()); + $this->view->extensionsHtml[] = + '<div class="icinga-module module-' . $module . '" data-icinga-module="' . $module . '">' + . $hook->setView($this->view)->getHtmlForEvent($eventObj) + . '</div>'; + } + } + } + + /** + * @deprecated redirects to index view now + */ + public function commentsAction() + { + $this->redirectNow( + Url::fromPath( + 'eventdb/event', + array('id' => $this->params->getRequired('id')) + ) + ); + } + + /** + * Action allowing you to be forwarded to host in Icinga monitoring + * + * **But** case insensitive! + */ + public function hostAction() + { + $host = $this->params->getRequired('host'); + + $backend = $this->monitoringBackend(); + + $query = $backend->select() + ->from('hoststatus', array('host_name')) + ->where('host', $host); + + $realHostname = $query->fetchOne(); + + if ($realHostname !== null && $realHostname !== false) { + $this->redirectNow(Url::fromPath('monitoring/host/services', array('host' => $realHostname))); + } else { + throw new NotFoundError('Could not find a hostname matching: %s', $host); + } + } + + /** + * Action allowing you to be forwarded to host in Icinga monitoring + * + * **But** case insensitive! + */ + public function serviceAction() + { + $host = $this->params->getRequired('host'); + $service = $this->params->getRequired('service'); + + $backend = $this->monitoringBackend(); + + $query = $backend->select() + ->from('servicestatus', array('host_name', 'service')) + ->where('host', $host) + ->where('service', $service); + + $realService = $query->fetchRow(); + + if ($realService !== null && $realService !== false) { + $this->redirectNow( + Url::fromPath( + 'monitoring/service/show', + array( + 'host' => $realService->host_name, + 'service' => $realService->service + ) + ) + ); + } else { + throw new NotFoundError('Could not find a service "%s" for host "%s"', $service, $host); + } + } +} diff --git a/application/controllers/EventsController.php b/application/controllers/EventsController.php new file mode 100644 index 0000000..09e5a8d --- /dev/null +++ b/application/controllers/EventsController.php @@ -0,0 +1,186 @@ +<?php +/* Icinga Web 2 | (c) 2016 Icinga Development Team | GPLv2+ */ + +namespace Icinga\Module\Eventdb\Controllers; + +use Icinga\Data\Filter\Filter; +use Icinga\Module\Eventdb\EventdbController; +use Icinga\Module\Eventdb\Forms\Event\EventCommentForm; +use Icinga\Module\Eventdb\Forms\Events\AckFilterForm; +use Icinga\Module\Eventdb\Forms\Events\SeverityFilterForm; +use Icinga\Module\Eventdb\Hook\DetailviewExtensionHook; +use Icinga\Module\Eventdb\Web\EventdbOutputFormat; +use Icinga\Util\StringHelper; +use Icinga\Web\Hook; +use Icinga\Web\Url; + +class EventsController extends EventdbController +{ + public function init() + { + parent::init(); + $this->view->title = 'EventDB: ' . $this->translate('Events'); + } + + public function indexAction() + { + $this->assertPermission('eventdb/events'); + + $this->getTabs()->add('events', array( + 'active' => ! $this->isFormatRequest(), + 'title' => $this->translate('Events'), + 'url' => Url::fromRequest()->without(array('format')) + ))->extend(new EventdbOutputFormat(array(), array(EventdbOutputFormat::TYPE_TEXT))); + + $columnConfig = $this->Config('columns'); + if ($this->params->has('columns')) { + $additionalColumns = StringHelper::trimSplit($this->params->get('columns')); + } elseif (! $columnConfig->isEmpty()) { + $additionalColumns = $columnConfig->keys(); + } else { + $additionalColumns = array(); + } + + $events = $this->getDb()->select() + ->from('event'); + + $columns = array_merge($events->getColumns(), $additionalColumns); + $events->columns($columns); + + $events->applyFilter(Filter::matchAny(array_map( + '\Icinga\Data\Filter\Filter::fromQueryString', + $this->getRestrictions('eventdb/events/filter', 'eventdb/events') + ))); + + $this->getDb()->filterGroups($events); + + $this->setupPaginationControl($events); + + $this->setupFilterControl( + $events, + array( + 'host_name' => $this->translate('Host'), + 'host_address' => $this->translate('Host Address'), + 'type' => $this->translate('Type'), + 'program' => $this->translate('Program'), + 'facility' => $this->translate('Facility'), + 'priority' => $this->translate('Priority'), + 'message' => $this->translate('Message'), + 'ack' => $this->translate('Acknowledged'), + 'created' => $this->translate('Created') + ), + array('host_name'), + array('columns', 'format') + ); + + $this->setupLimitControl(); + + $this->setupSortControl( + array( + 'host_name' => $this->translate('Host'), + 'host_address' => $this->translate('Host Address'), + 'type' => $this->translate('Type'), + 'program' => $this->translate('Program'), + 'facility' => $this->translate('Facility'), + 'priority' => $this->translate('Priority'), + 'message' => $this->translate('Message'), + 'ack' => $this->translate('Acknowledged'), + 'created' => $this->translate('Created') + ), + $events, + array('created' => 'desc') + ); + + if ($this->view->compact) { + $events->peekAhead(); + } + + if ($this->params->get('format') === 'sql') { + $this->sendSqlSummary($events); + } elseif ($this->isApiRequest()) { + $data = new \stdClass; + $data->events = $events->fetchAll(); + $this->sendJson($data); + exit; + } elseif ($this->isTextRequest()) { + $this->view->columnConfig = $this->Config('columns'); + $this->view->additionalColumns = $additionalColumns; + $this->view->events = $events; + + $this->sendText(null, 'events/index-plain'); + } else { + $this->setAutorefreshInterval(15); + + $severityFilterForm = new SeverityFilterForm(); + $severityFilterForm->handleRequest(); + + $ackFilterForm = new AckFilterForm(); + $ackFilterForm->handleRequest(); + + $this->view->ackFilterForm = $ackFilterForm; + $this->view->columnConfig = $this->Config('columns'); + $this->view->additionalColumns = $additionalColumns; + $this->view->events = $events; + $this->view->severityFilterForm = $severityFilterForm; + } + } + + public function detailsAction() + { + $this->assertPermission('eventdb/events'); + + $url = Url::fromRequest()->without(array('format')); + + $this->getTabs()->add('events', array( + 'active' => ! $this->isFormatRequest(), + 'title' => $this->translate('Events'), + 'url' => $url + ))->extend(new EventdbOutputFormat(array(), array(EventdbOutputFormat::TYPE_TEXT))); + + $events = $this->getDb() + ->select() + ->from('event'); + + $this->getDb()->filterGroups($events); + + $filter = Filter::fromQueryString($url->getQueryString()); + $events->applyFilter($filter); + + $events->applyFilter(Filter::matchAny(array_map( + '\Icinga\Data\Filter\Filter::fromQueryString', + $this->getRestrictions('eventdb/events/filter', 'eventdb/events') + ))); + + if ($this->isApiRequest()) { + $this->sendJson($events->fetchAll()); + } elseif ($this->isTextRequest()) { + $this->view->events = $events->fetchAll(); + $this->view->columnConfig = $this->Config('columns'); + + $this->sendText(null, 'events/details-plain'); + } else { + $commentForm = null; + if ($this->hasPermission('eventdb/interact')) { + $commentForm = new EventCommentForm(); + $commentForm + ->setDb($this->getDb()) + ->setFilter($filter) + ->handleRequest(); + $this->view->commentForm = $commentForm; + } + + $this->view->events = $events->fetchAll(); + $this->view->columnConfig = $this->Config('columns'); + + $this->view->extensionsHtml = array(); + foreach (Hook::all('Eventdb\DetailviewExtension') as $hook) { + /** @var DetailviewExtensionHook $hook */ + $module = $this->view->escape($hook->getModule()->getName()); + $this->view->extensionsHtml[] = + '<div class="icinga-module module-' . $module . '" data-icinga-module="' . $module . '">' + . $hook->setView($this->view)->getHtmlForEvents($this->view->events) + . '</div>'; + } + } + } +} diff --git a/application/controllers/IndexController.php b/application/controllers/IndexController.php new file mode 100644 index 0000000..5322936 --- /dev/null +++ b/application/controllers/IndexController.php @@ -0,0 +1,14 @@ +<?php +/* Icinga Web 2 | (c) 2018 Icinga Development Team | GPLv2+ */ + +namespace Icinga\Module\Eventdb\Controllers; + +use Icinga\Web\Controller; + +class IndexController extends Controller +{ + public function indexAction() + { + $this->redirectNow('eventdb/events'); + } +} |