host|service: Add missing details to pdf exports

This commit is contained in:
Johannes Meyer 2022-03-03 09:16:16 +01:00
parent 1e17c58909
commit ca192ac3a2
5 changed files with 51 additions and 0 deletions

View file

@ -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()

View file

@ -61,6 +61,11 @@ class ServiceController extends Controller
$this->loadTabsForObject($service);
$this->setTitleTab($this->getRequest()->getActionName());
$this->view->title = sprintf(
t('%s on %s', '<service> on <host>'),
$service->display_name,
$service->host->display_name
);
}
public function indexAction()

View file

@ -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(),

View file

@ -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();

View file

@ -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(),