Add a backend problem menu item renderer to system menu

refs #4139
This commit is contained in:
Alexander Fuhr 2015-04-30 16:13:10 +02:00
parent 880b1eb21a
commit 8484a27b56
1 changed files with 62 additions and 0 deletions

View File

@ -0,0 +1,62 @@
<?php
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
namespace Icinga\Module\Monitoring\Web\Menu;
use Icinga\Web\Menu as Menu;
use Icinga\Module\Monitoring\Backend\MonitoringBackend;
use Icinga\Web\Menu\MenuItemRenderer;
class BackendAvailabilityMenuItemRenderer extends MenuItemRenderer
{
/**
* Checks whether the monitoring backend is running or not
*
* @return mixed
*/
protected function isCurrentlyRunning()
{
return MonitoringBackend::instance()->select()->from(
'programstatus',
array(
'is_currently_running'
)
)->getQuery()->fetchRow()->is_currently_running;
}
/**
* @see MenuItemRenderer::render()
*/
public function render(Menu $menu)
{
return $this->getBadge() . $this->createLink($menu);
}
protected function getBadge()
{
if (! (bool)$this->isCurrentlyRunning()) {
return sprintf(
'<div title="%s" class="badge-container"><span class="badge badge-critical">%s</span></div>',
mt('monitoring', 'monitoring backend is not running'),
1
);
}
return '';
}
/**
* Get the problem data for the summary
*
* @return array|null
*/
public function getSummary()
{
if (! (bool)$this->isCurrentlyRunning()) {
return array(
'problems' => 1,
'title' => mt('monitoring', 'monitoring backend is not running')
);
}
return null;
}
}