mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-27 07:44:04 +02:00
parent
b3bc1b6f81
commit
f53eb48e38
@ -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()
|
||||||
{
|
{
|
||||||
|
if ($this->count === null) {
|
||||||
try {
|
try {
|
||||||
if ($this->isCurrentlyRunning()) {
|
$count = 0;
|
||||||
return 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 $_) {
|
} catch (Exception $_) {
|
||||||
// pass
|
$this->count = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user