SelfService: more improvements

refs #2147
This commit is contained in:
Thomas Gelf 2020-11-30 22:03:41 +01:00
parent 62c4c6f44b
commit f85a767028
1 changed files with 60 additions and 60 deletions

View File

@ -45,7 +45,7 @@ class SelfService
if ($host->isTemplate()) {
$this->showSelfServiceTemplateInstructions($controller);
} elseif ($key = $host->getProperty('api_key')) {
$this->showRegisteredAgentInstructions($controller);
$this->showRegisteredAgentInstructions($key, $controller);
} elseif ($key = $host->getSingleResolvedProperty('api_key')) {
$this->showNewAgentInstructions($controller);
} else {
@ -54,9 +54,10 @@ class SelfService
}
/**
* @param string $key
* @param ControlsAndContent $c
*/
protected function showRegisteredAgentInstructions(ControlsAndContent $c)
protected function showRegisteredAgentInstructions($key, ControlsAndContent $c)
{
$c->addTitle($this->translate('Registered Agent'));
$c->content()->add([
@ -66,6 +67,7 @@ class SelfService
. ' secret key, you might want to dismiss the current key. This'
. ' would allow you to register the same host again.'
)),
Html::tag('p', null, [$this->translate('Api Key:'), ' ', Html::tag('strong', null, $key)]),
Hint::warning($this->translate(
'It is not a good idea to do so as long as your Agent still has'
. ' a valid Self Service API key!'
@ -101,44 +103,14 @@ class SelfService
]
));
$actions->add(Documentation::link(
$this->translate('Documentation'),
'director',
'74-Self-Service-API',
$this->translate('Self Service API')
));
$actions->add($this->getDocumentationLink());
if ($hasKey) {
$wizard = new AgentWizard($host);
$c->add([
Html::tag('p', null, [$this->translate('Api Key:'), ' ', Html::tag('strong', null, $key)]),
Html::tag('h2', $this->translate('Icinga for Windows')),
Html::tag('p', Html::sprintf(
$this->translate('In case you\'re using %s, please run this Script:'),
Html::tag('a', [
'href' => 'https://icinga.com/docs/windows/latest/',
'target' => '_blank',
], $this->translate('Icinga for Windows'))
)),
Html::tag(
'pre',
['class' => 'logfile'],
$wizard->renderIcinga4WindowsWizardCommand($key)
),
Html::tag('h3', $this->translate('Icinga 2 Powershell Module')),
Html::tag('p', Html::sprintf(
$this->translate('In case you\'re using the legacy %s, please run:'),
Html::tag('a', [
'href' => 'https://github.com/Icinga/icinga2-powershell-module',
'target' => '_blank',
], $this->translate('Icinga 2 Powershell Module'))
)),
Html::tag(
'pre',
['class' => 'logfile'],
$wizard->renderPowershellModuleInstaller($key)
),
Html::tag('p', [
$this->translate('Api Key:'), ' ', Html::tag('strong', null, $key)
]),
$this->getWindowsInstructions($host, $key),
Html::tag('h2', null, $this->translate('Generate a new key')),
Hint::warning($this->translate(
'This will invalidate the former key'
@ -165,36 +137,64 @@ class SelfService
}
}
protected function getWindowsInstructions($host, $key)
{
$wizard = new AgentWizard($host);
return [
Html::tag('h2', $this->translate('Icinga for Windows')),
Html::tag('p', Html::sprintf(
$this->translate('In case you\'re using %s, please run this Script:'),
Html::tag('a', [
'href' => 'https://icinga.com/docs/windows/latest/',
'target' => '_blank',
], $this->translate('Icinga for Windows'))
)),
Html::tag(
'pre',
['class' => 'logfile'],
$wizard->renderIcinga4WindowsWizardCommand($key)
),
Html::tag('h3', $this->translate('Icinga 2 Powershell Module')),
Html::tag('p', Html::sprintf(
$this->translate('In case you\'re using the legacy %s, please run:'),
Html::tag('a', [
'href' => 'https://github.com/Icinga/icinga2-powershell-module',
'target' => '_blank',
], $this->translate('Icinga 2 Powershell Module'))
)),
Html::tag(
'pre',
['class' => 'logfile'],
$wizard->renderPowershellModuleInstaller($key)
),
];
}
protected function getDocumentationLink()
{
return Documentation::link(
$this->translate('Documentation'),
'director',
'74-Self-Service-API',
$this->translate('Self Service API')
);
}
/**
* @param ControlsAndContent $cc
*/
protected function showNewAgentInstructions(ControlsAndContent $cc)
{
$c = $cc->content();
$content = $cc->content();
$host = $this->host;
$key = $host->getSingleResolvedProperty('api_key');
$cc->addTitle($this->translate('Configure this Agent via Self Service API'));
if ($this->hasDocsModuleLoaded()) {
$actions = $cc->actions();
$actions->add(Link::create(
$this->translate('Documentation'),
'doc/module/director/chapter/Self-Service-API',
null,
['class' => 'icon-book']
));
}
$wizard = new AgentWizard($host);
$c->add([
Html::tag('h2', null, 'Microsoft Windows'),
Html::tag(
'pre',
['class' => 'logfile'],
$wizard->renderIcinga4WindowsWizardCommand($key)
)
]);
$cc->addTitle($this->translate('Configure this Agent via Self Service API'));
$cc->actions()->add($this->getDocumentationLink());
$content->add(Html::tag('p', [
$this->translate('Inherited Template Api Key:'), ' ', Html::tag('strong', null, $key)
]));
$content->add($this->getWindowsInstructions($host, $key));
}
/**