From 6625e8d391f12bf9052a7062f33527e02d901363 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Tue, 23 Sep 2014 22:16:33 -0700 Subject: [PATCH] monitoring: Add tabs to the host and service controller --- .../controllers/HostController.php | 10 +++ .../controllers/ServiceController.php | 10 +++ .../Controller/MonitoredObjectController.php | 79 ++++++++++++++++++- 3 files changed, 98 insertions(+), 1 deletion(-) diff --git a/modules/monitoring/application/controllers/HostController.php b/modules/monitoring/application/controllers/HostController.php index 7799cb4ec..f77d11deb 100644 --- a/modules/monitoring/application/controllers/HostController.php +++ b/modules/monitoring/application/controllers/HostController.php @@ -29,6 +29,16 @@ class Monitoring_HostController extends MonitoredObjectController throw new Zend_Controller_Action_Exception($this->translate('Host not found')); } $this->object = $host; + $this->createTabs(); + } + + /** + * Show a host + */ + public function showAction() + { + $this->getTabs()->activate('host'); + parent::showAction(); } /** diff --git a/modules/monitoring/application/controllers/ServiceController.php b/modules/monitoring/application/controllers/ServiceController.php index 24bb23024..ea29aa54a 100644 --- a/modules/monitoring/application/controllers/ServiceController.php +++ b/modules/monitoring/application/controllers/ServiceController.php @@ -29,6 +29,16 @@ class Monitoring_ServiceController extends MonitoredObjectController throw new Zend_Controller_Action_Exception($this->translate('Service not found')); } $this->object = $service; + $this->createTabs(); + } + + /** + * Show a service + */ + public function showAction() + { + $this->getTabs()->activate('service'); + parent::showAction(); } /** diff --git a/modules/monitoring/library/Monitoring/Web/Controller/MonitoredObjectController.php b/modules/monitoring/library/Monitoring/Web/Controller/MonitoredObjectController.php index ae257e9f1..856496ca8 100644 --- a/modules/monitoring/library/Monitoring/Web/Controller/MonitoredObjectController.php +++ b/modules/monitoring/library/Monitoring/Web/Controller/MonitoredObjectController.php @@ -12,7 +12,10 @@ use Icinga\Module\Monitoring\Form\Command\Object\DeleteDowntimeCommandForm; use Icinga\Module\Monitoring\Form\Command\Object\ObjectsCommandForm; use Icinga\Module\Monitoring\Form\Command\Object\RemoveAcknowledgementCommandForm; use Icinga\Module\Monitoring\Form\Command\Object\ToggleObjectFeaturesCommandForm; +use Icinga\Web\Hook; use Icinga\Web\Url; +use Icinga\Web\Widget\Tabextension\DashboardAction; +use Icinga\Web\Widget\Tabextension\OutputFormat; /** * Base class for the host and service controller @@ -33,6 +36,21 @@ abstract class MonitoredObjectController extends Controller */ 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 */ @@ -120,7 +138,6 @@ abstract class MonitoredObjectController extends Controller */ abstract public function scheduleDowntimeAction(); - /** * Remove a comment */ @@ -148,4 +165,64 @@ abstract class MonitoredObjectController extends Controller */ $this->handleCommandForm(new DeleteDowntimeCommandForm()); } + + /** + * Create tabs + */ + protected function createTabs() + { + $tabs = $this->getTabs(); + $object = $this->object; + if ($object->getType() === $object::TYPE_HOST) { + $params = array( + 'host' => $object->getName() + ); + } else { + $params = array( + 'host' => $object->getHost()->getName(), + 'service' => $object->getName() + ); + } + $tabs->add( + 'host', + array( + 'title' => 'Host', + 'icon' => 'img/icons/host.png', + 'url' => 'monitoring/host/show', + 'urlParams' => $params + ) + ); + if (isset($params['service'])) { + $tabs->add( + 'service', + array( + 'title' => 'Service', + 'icon' => 'img/icons/service.png', + 'url' => 'monitoring/service/show', + 'urlParams' => $params + ) + ); + } + $tabs->add( + 'services', + array( + 'title' => 'Services', + 'icon' => 'img/icons/service.png', + 'url' => 'monitoring/show/services', + 'urlParams' => $params + ) + ); + $tabs->add( + 'history', + array( + 'title' => 'History', + 'icon' => 'img/icons/history.png', + 'url' => 'monitoring/show/history', + 'urlParams' => $params + ) + ); + $tabs + ->extend(new OutputFormat()) + ->extend(new DashboardAction()); + } }