From ca192ac3a2901347de1e794480141b8725eea0b6 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 3 Mar 2022 09:16:16 +0100 Subject: [PATCH] host|service: Add missing details to pdf exports --- application/controllers/HostController.php | 1 + application/controllers/ServiceController.php | 5 +++ library/Icingadb/Widget/Detail/HostDetail.php | 4 ++ .../Icingadb/Widget/Detail/ObjectDetail.php | 37 +++++++++++++++++++ .../Icingadb/Widget/Detail/ServiceDetail.php | 4 ++ 5 files changed, 51 insertions(+) diff --git a/application/controllers/HostController.php b/application/controllers/HostController.php index 0cc4f5cd..04f501cf 100644 --- a/application/controllers/HostController.php +++ b/application/controllers/HostController.php @@ -57,6 +57,7 @@ class HostController extends Controller $this->loadTabsForObject($host); $this->setTitleTab($this->getRequest()->getActionName()); + $this->view->title = $host->display_name; } public function indexAction() diff --git a/application/controllers/ServiceController.php b/application/controllers/ServiceController.php index a9516aea..ec617ea5 100644 --- a/application/controllers/ServiceController.php +++ b/application/controllers/ServiceController.php @@ -61,6 +61,11 @@ class ServiceController extends Controller $this->loadTabsForObject($service); $this->setTitleTab($this->getRequest()->getActionName()); + $this->view->title = sprintf( + t('%s on %s', ' on '), + $service->display_name, + $service->host->display_name + ); } public function indexAction() diff --git a/library/Icingadb/Widget/Detail/HostDetail.php b/library/Icingadb/Widget/Detail/HostDetail.php index 7ef7f054..87574367 100644 --- a/library/Icingadb/Widget/Detail/HostDetail.php +++ b/library/Icingadb/Widget/Detail/HostDetail.php @@ -36,6 +36,10 @@ class HostDetail extends ObjectDetail protected function assemble() { + if (getenv('ICINGAWEB_EXPORT_FORMAT') === 'pdf') { + $this->add($this->createPrintHeader()); + } + $this->add(ObjectDetailExtensionHook::injectExtensions([ 0 => $this->createPluginOutput(), 190 => $this->createServiceStatistics(), diff --git a/library/Icingadb/Widget/Detail/ObjectDetail.php b/library/Icingadb/Widget/Detail/ObjectDetail.php index d47c3f05..2aeb6475 100644 --- a/library/Icingadb/Widget/Detail/ObjectDetail.php +++ b/library/Icingadb/Widget/Detail/ObjectDetail.php @@ -9,6 +9,7 @@ use Icinga\Application\ClassLoader; use Icinga\Application\Hook\GrapherHook; use Icinga\Application\Icinga; use Icinga\Application\Logger; +use Icinga\Date\DateFormatter; use Icinga\Exception\IcingaException; use Icinga\Module\Icingadb\Common\Auth; use Icinga\Module\Icingadb\Common\Database; @@ -30,6 +31,7 @@ use Icinga\Module\Icingadb\Model\Usergroup; use Icinga\Module\Icingadb\Util\PluginOutput; use Icinga\Module\Icingadb\Widget\ItemList\DowntimeList; use Icinga\Module\Icingadb\Widget\EmptyState; +use Icinga\Module\Icingadb\Widget\StateChange; use ipl\Web\Widget\HorizontalKeyValue; use Icinga\Module\Icingadb\Widget\ItemList\CommentList; use Icinga\Module\Icingadb\Widget\Detail\PerfDataTable; @@ -48,6 +50,7 @@ use ipl\Html\Text; use ipl\Orm\ResultSet; use ipl\Stdlib\Filter; use ipl\Web\Widget\Icon; +use ipl\Web\Widget\StateBall; class ObjectDetail extends BaseHtmlElement { @@ -76,6 +79,40 @@ class ObjectDetail extends BaseHtmlElement $this->objectType = $object instanceof Host ? 'host' : 'service'; } + protected function createPrintHeader() + { + $info = [new HorizontalKeyValue(t('Name'), $this->object->name)]; + + if ($this->objectType === 'host') { + $info[] = new HorizontalKeyValue( + t('IPv4 Address'), + $this->object->address ?: new EmptyState(t('None', 'address')) + ); + $info[] = new HorizontalKeyValue( + t('IPv6 Address'), + $this->object->address6 ?: new EmptyState(t('None', 'address')) + ); + } + + $info[] = new HorizontalKeyValue(t('State'), [ + $this->object->state->getStateTextTranslated(), + ' ', + new StateBall($this->object->state->getStateText()) + ]); + + $info[] = new HorizontalKeyValue( + t('Last State Change'), + DateFormatter::formatDateTime($this->object->state->last_state_change) + ); + + return [ + new HtmlElement('h2', null, Text::create( + $this->objectType === 'host' ? t('Host') : t('Service') + )), + $info + ]; + } + protected function createActions() { $this->fetchCustomVars(); diff --git a/library/Icingadb/Widget/Detail/ServiceDetail.php b/library/Icingadb/Widget/Detail/ServiceDetail.php index e977e9e0..8421e314 100644 --- a/library/Icingadb/Widget/Detail/ServiceDetail.php +++ b/library/Icingadb/Widget/Detail/ServiceDetail.php @@ -16,6 +16,10 @@ class ServiceDetail extends ObjectDetail protected function assemble() { + if (getenv('ICINGAWEB_EXPORT_FORMAT') === 'pdf') { + $this->add($this->createPrintHeader()); + } + $this->add(ObjectDetailExtensionHook::injectExtensions([ 0 => $this->createPluginOutput(), 300 => $this->createActions(),