Show hint if notifications are disabled globally

resolves #11792
This commit is contained in:
Eric Lippmann 2016-12-06 14:47:37 +01:00
parent b3bc1b6f81
commit f53eb48e38

View File

@ -4,15 +4,22 @@
namespace Icinga\Module\Monitoring\Web\Navigation\Renderer; namespace Icinga\Module\Monitoring\Web\Navigation\Renderer;
use Exception; use Exception;
use Icinga\Web\Navigation\Renderer\BadgeNavigationItemRenderer;
use Icinga\Module\Monitoring\Backend\MonitoringBackend; use Icinga\Module\Monitoring\Backend\MonitoringBackend;
use Icinga\Web\Navigation\Renderer\BadgeNavigationItemRenderer;
class BackendAvailabilityNavigationItemRenderer extends BadgeNavigationItemRenderer class BackendAvailabilityNavigationItemRenderer extends BadgeNavigationItemRenderer
{ {
/**
* Cached count
*
* @var int
*/
protected $count;
/** /**
* Get whether or not the monitoring backend is currently running * Get whether or not the monitoring backend is currently running
* *
* @return bool * @return object
*/ */
protected function isCurrentlyRunning() protected function isCurrentlyRunning()
{ {
@ -20,51 +27,50 @@ class BackendAvailabilityNavigationItemRenderer extends BadgeNavigationItemRende
->select() ->select()
->from( ->from(
'programstatus', 'programstatus',
array('is_currently_running') array('is_currently_running', 'notifications_enabled')
) )
->fetchOne(); ->fetchRow();
return $programStatus !== false ? (bool) $programStatus : false; return $programStatus;
} }
/** /**
* The css class of the badge * {@inheritdoc}
*
* @return string
*/
public function getState()
{
return self::STATE_CRITICAL;
}
/**
* The amount of items to display in the badge
*
* @return int
*/ */
public function getCount() public function getCount()
{ {
try { if ($this->count === null) {
if ($this->isCurrentlyRunning()) { try {
return 0; $count = 0;
$programStatus = $this->isCurrentlyRunning();
$titles = array();
if (! (bool) $programStatus->notifications_enabled) {
$count = 1;
$this->state = static::STATE_WARNING;
$titles[] = mt('monitoring', 'Notifications are disabled');
}
if (! (bool) $programStatus->is_currently_running) {
$count = 1;
$this->state = static::STATE_CRITICAL;
array_unshift($titles, sprintf(
mt('monitoring', 'Monitoring backend %s is not running'),
MonitoringBackend::instance()->getName()
));
}
$this->count = $count;
$this->title = implode('. ', $titles);
} catch (Exception $_) {
$this->count = 1;
} }
} catch (Exception $_) {
// pass
} }
return 1; return $this->count;
} }
/** /**
* The tooltip title * {@inheritdoc}
*
* @return string
* @throws \Icinga\Exception\ConfigurationError
*/ */
public function getTitle() public function getState()
{ {
return sprintf( return $this->state;
mt('monitoring', 'Monitoring backend %s is not running'),
MonitoringBackend::instance()->getName()
);
} }
} }