mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-30 01:04:12 +02:00
menu: show health summary
This commit is contained in:
parent
46fae7d60c
commit
0af71a82f0
@ -24,7 +24,12 @@ $this->provideConfigTab('config', array(
|
|||||||
|
|
||||||
$section = $this->menuSection(
|
$section = $this->menuSection(
|
||||||
$this->translate('Icinga Director')
|
$this->translate('Icinga Director')
|
||||||
)->setIcon('cubes');
|
)->setIcon(
|
||||||
|
'cubes'
|
||||||
|
)->setRenderer(array(
|
||||||
|
'SummaryNavigationItemRenderer',
|
||||||
|
'state' => 'critical'
|
||||||
|
));
|
||||||
|
|
||||||
$section->add($this->translate('Overview'))->setUrl('director')->setPriority(20);
|
$section->add($this->translate('Overview'))->setUrl('director')->setPriority(20);
|
||||||
$section->add($this->translate('Hosts'))->setUrl('director/hosts')->setPriority(30);
|
$section->add($this->translate('Hosts'))->setUrl('director/hosts')->setPriority(30);
|
||||||
@ -36,5 +41,6 @@ $section->add($this->translate('Import / Sync'))
|
|||||||
->setPriority(901);
|
->setPriority(901);
|
||||||
$section->add($this->translate('Config'))
|
$section->add($this->translate('Config'))
|
||||||
->setUrl('director/list/deploymentlog')
|
->setUrl('director/list/deploymentlog')
|
||||||
->setPriority(902);
|
->setPriority(902)
|
||||||
|
->setRenderer('ConfigHealthItemRenderer');
|
||||||
|
|
||||||
|
@ -0,0 +1,101 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Icinga\Module\Director\Web\Navigation\Renderer;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
use Icinga\Application\Config;
|
||||||
|
use Icinga\Module\Director\ConfigHealthChecker;
|
||||||
|
use Icinga\Module\Director\Db;
|
||||||
|
use Icinga\Module\Director\KickstartHelper;
|
||||||
|
use Icinga\Web\Navigation\Renderer\BadgeNavigationItemRenderer;
|
||||||
|
|
||||||
|
class ConfigHealthItemRenderer extends BadgeNavigationItemRenderer
|
||||||
|
{
|
||||||
|
private $db;
|
||||||
|
|
||||||
|
private $directorState = self::STATE_OK;
|
||||||
|
|
||||||
|
private $message;
|
||||||
|
|
||||||
|
private $count = 0;
|
||||||
|
|
||||||
|
protected function hasProblems()
|
||||||
|
{
|
||||||
|
$this->checkHealth();
|
||||||
|
return $this->count > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getState()
|
||||||
|
{
|
||||||
|
return $this->directorState;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCount()
|
||||||
|
{
|
||||||
|
if ($this->hasProblems()) {
|
||||||
|
return $this->count;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTitle()
|
||||||
|
{
|
||||||
|
return $this->message;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function checkHealth()
|
||||||
|
{
|
||||||
|
$db = $this->db();
|
||||||
|
if (! $db) {
|
||||||
|
$this->directorState = self::STATE_PENDING;
|
||||||
|
$this->count = 1;
|
||||||
|
$this->message = $this->translate(
|
||||||
|
'No database has been configured for Icinga Director'
|
||||||
|
);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$kickstart = new KickstartHelper($db);
|
||||||
|
if ($kickstart->isRequired()) {
|
||||||
|
$this->directorState = self::STATE_PENDING;
|
||||||
|
$this->count = 1;
|
||||||
|
$this->message = $this->translate(
|
||||||
|
'No API user configured, you might run the kickstart helper'
|
||||||
|
);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$pendingChanges = $db->countActivitiesSinceLastDeployedConfig();
|
||||||
|
|
||||||
|
if ($pendingChanges > 0) {
|
||||||
|
$this->directorState = self::STATE_WARNING;
|
||||||
|
$this->count = $pendingChanges;
|
||||||
|
$this->message = sprintf(
|
||||||
|
$this->translate(
|
||||||
|
'%s config changes happend since the last deployed configuration'
|
||||||
|
),
|
||||||
|
$pendingChanges
|
||||||
|
);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function translate($message)
|
||||||
|
{
|
||||||
|
return mt('director', $message);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function db()
|
||||||
|
{
|
||||||
|
$resourceName = Config::module('director')->get('db', 'resource');
|
||||||
|
if ($resourceName) {
|
||||||
|
return Db::fromResourceName($resourceName);
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user