2015-04-30 10:13:10 -04:00
|
|
|
<?php
|
|
|
|
|
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
|
|
|
|
|
|
|
|
|
namespace Icinga\Module\Monitoring\Web\Menu;
|
|
|
|
|
|
2015-07-21 10:47:17 -04:00
|
|
|
use Icinga\Web\Menu;
|
2015-08-20 11:38:55 -04:00
|
|
|
use Icinga\Web\Menu\BadgeMenuItemRenderer;
|
2015-07-21 10:47:17 -04:00
|
|
|
use Icinga\Module\Monitoring\Backend\MonitoringBackend;
|
2015-04-30 10:13:10 -04:00
|
|
|
|
2015-08-20 11:38:55 -04:00
|
|
|
class BackendAvailabilityMenuItemRenderer extends BadgeMenuItemRenderer
|
2015-04-30 10:13:10 -04:00
|
|
|
{
|
|
|
|
|
/**
|
2015-07-21 10:47:17 -04:00
|
|
|
* Get whether or not the monitoring backend is currently running
|
2015-04-30 10:13:10 -04:00
|
|
|
*
|
2015-07-21 10:47:17 -04:00
|
|
|
* @return bool
|
2015-04-30 10:13:10 -04:00
|
|
|
*/
|
|
|
|
|
protected function isCurrentlyRunning()
|
|
|
|
|
{
|
2015-07-21 10:47:17 -04:00
|
|
|
$programStatus = MonitoringBackend::instance()
|
|
|
|
|
->select()
|
|
|
|
|
->from(
|
|
|
|
|
'programstatus',
|
|
|
|
|
array('is_currently_running')
|
2015-04-30 10:13:10 -04:00
|
|
|
)
|
2015-08-18 07:09:34 -04:00
|
|
|
->fetchOne();
|
2015-07-21 10:47:17 -04:00
|
|
|
return $programStatus !== false ? (bool) $programStatus : false;
|
2015-04-30 10:13:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2015-08-20 11:38:55 -04:00
|
|
|
* The css class of the badge
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
2015-04-30 10:13:10 -04:00
|
|
|
*/
|
2015-08-20 11:38:55 -04:00
|
|
|
public function getState()
|
2015-04-30 10:13:10 -04:00
|
|
|
{
|
2015-08-20 11:38:55 -04:00
|
|
|
return self::STATE_CRITICAL;
|
2015-04-30 10:13:10 -04:00
|
|
|
}
|
|
|
|
|
|
2015-07-21 10:47:17 -04:00
|
|
|
/**
|
2015-08-20 11:38:55 -04:00
|
|
|
* The amount of items to display in the badge
|
2015-07-21 10:47:17 -04:00
|
|
|
*
|
2015-08-20 11:38:55 -04:00
|
|
|
* @return int
|
2015-07-21 10:47:17 -04:00
|
|
|
*/
|
2015-08-20 11:38:55 -04:00
|
|
|
public function getCount()
|
2015-04-30 10:13:10 -04:00
|
|
|
{
|
2015-07-21 10:47:17 -04:00
|
|
|
if (! $this->isCurrentlyRunning()) {
|
2015-08-20 11:38:55 -04:00
|
|
|
return 1;
|
2015-04-30 10:13:10 -04:00
|
|
|
}
|
2015-08-20 11:38:55 -04:00
|
|
|
return 0;
|
2015-04-30 10:13:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2015-08-20 11:38:55 -04:00
|
|
|
* The tooltip title
|
2015-04-30 10:13:10 -04:00
|
|
|
*
|
2015-08-20 11:38:55 -04:00
|
|
|
* @return string
|
|
|
|
|
* @throws \Icinga\Exception\ConfigurationError
|
2015-04-30 10:13:10 -04:00
|
|
|
*/
|
2015-08-20 11:38:55 -04:00
|
|
|
public function getTitle()
|
2015-04-30 10:13:10 -04:00
|
|
|
{
|
2015-08-20 11:38:55 -04:00
|
|
|
return sprintf(
|
|
|
|
|
mt('monitoring', 'Monitoring backend %s is not running'),
|
|
|
|
|
MonitoringBackend::instance()->getName()
|
|
|
|
|
);
|
2015-04-30 10:13:10 -04:00
|
|
|
}
|
|
|
|
|
}
|