-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
69bd61d
commit 535a5a4
Showing
26 changed files
with
1,424 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
|
||
namespace Icinga\Module\Lshw\Clicommands; | ||
|
||
use Icinga\Cli\Command; | ||
use Icinga\Module\Lshw\DirectorConfig; | ||
|
||
|
||
class CreateCommand extends Command | ||
{ | ||
/** | ||
* USAGE: | ||
* | ||
* icingacli selenium create command | ||
*/ | ||
public function commandAction() | ||
{ | ||
$config = new DirectorConfig(); | ||
$config->sync(); | ||
if($config->commandExists($config->createWindowsCommand()) && $config->commandExists($config->createLinuxCommand()) && $config->commandExists($config->createLinuxCommandUnprivileged())){ | ||
echo "Commands in sync\n"; | ||
exit(0); | ||
}else{ | ||
echo "Commands not sync\n"; | ||
exit(1); | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
<?php | ||
|
||
namespace Icinga\Module\Lshw\Controllers; | ||
|
||
use Exception; | ||
use Icinga\Exception\ConfigurationError; | ||
use Icinga\Module\Director\Objects\IcingaCommand; | ||
use Icinga\Module\Lshw\DirectorConfig; | ||
use Icinga\Web\Notification; | ||
use Icinga\Web\Widget\Tab; | ||
use Icinga\Web\Widget\Tabs; | ||
use ipl\Html\Html; | ||
use ipl\Web\Compat\CompatController; | ||
use ipl\Web\Url; | ||
use ipl\Web\Widget\ActionLink; | ||
use ipl\Web\Widget\Link; | ||
|
||
class DirectorController extends CompatController | ||
{ | ||
/** | ||
* @throws \Icinga\Security\SecurityException | ||
*/ | ||
public function init() | ||
{ | ||
$this->assertPermission('config/modules'); | ||
} | ||
|
||
|
||
protected function runFailSafe($callable) | ||
{ | ||
try { | ||
if (is_array($callable)) { | ||
return call_user_func($callable); | ||
} elseif (is_string($callable)) { | ||
return call_user_func([$this, $callable]); | ||
} else { | ||
return $callable(); | ||
} | ||
} catch (Exception $e) { | ||
$this->addContent( | ||
Html::tag('p', ['class' => 'state-hint error'], sprintf( | ||
$this->translate('ERROR: %s'), | ||
$e->getMessage() | ||
)) | ||
); | ||
// $this->addContent(Html::tag('pre', null, $e->getTraceAsString())); | ||
|
||
return false; | ||
} | ||
} | ||
|
||
|
||
|
||
public function indexAction() | ||
{ | ||
$this->assertPermission('director/admin'); | ||
$this->mergeTabs($this->Module()->getConfigTabs()->activate('config/director')); | ||
|
||
if ($this->params->get('action') === 'sync') { | ||
$this->runFailSafe('sync'); | ||
return; | ||
} | ||
$this->addControl(new ActionLink( | ||
'Sync to Director', | ||
Url::fromPath('lshw/director', ['action' => 'sync']), | ||
'sync' | ||
)); | ||
$this->runFailSafe(function () { | ||
try { | ||
$config = new DirectorConfig(); | ||
$this->addCommand($config->createLinuxCommand(), $config); | ||
$this->addCommand($config->createLinuxCommandUnprivileged(), $config); | ||
$this->addCommand($config->createWindowsCommand(), $config); | ||
} catch (ConfigurationError $e) { | ||
$this->addContent( | ||
Html::tag('h1', ['class' => 'state-hint error'], $this->translate( | ||
'Icinga Director has not been configured on this system: %s', | ||
$e->getMessage() | ||
)) | ||
); | ||
} | ||
}); | ||
} | ||
|
||
protected function sync() | ||
{ | ||
$config = new DirectorConfig(); | ||
if ($config->sync()) { | ||
Notification::success('Commands have been updated in Icinga Director'); | ||
} else { | ||
Notification::success('Nothing changed, commands are fine'); | ||
} | ||
$this->redirectNow($this->getRequest()->getUrl()->without('action')); | ||
} | ||
|
||
/** | ||
* @param IcingaCommand $command | ||
* @param DirectorConfig $config | ||
*/ | ||
protected function addCommand(IcingaCommand $command, DirectorConfig $config) | ||
{ | ||
$name = $command->getObjectName(); | ||
$this->addContent(Html::tag('h1', null, $name)); | ||
if ($config->commandExists($command)) { | ||
$link = new Link( | ||
$name, | ||
Url::fromPath('director/command', ['name' => $name]), | ||
['data-base-target' => '_next'] | ||
); | ||
|
||
if ($config->commandDiffers($command)) { | ||
$this->addContent($this->createHint( | ||
Html::sprintf( | ||
'The CheckCommand %s exists but differs in your Icinga Director', | ||
$link | ||
), | ||
'warning' | ||
)); | ||
} else { | ||
$this->addContent($this->createHint( | ||
Html::sprintf( | ||
'The CheckCommand definition for %s is fine', | ||
$link | ||
), | ||
'ok' | ||
)); | ||
} | ||
} else { | ||
$this->addContent($this->createHint( | ||
'Command does not exist in your Icinga Director', | ||
'warning' | ||
)); | ||
} | ||
$this->addContent(Html::tag('pre', null, (string) $command)); | ||
} | ||
|
||
protected function createHint($msg, $state) | ||
{ | ||
return Html::tag('p', ['class' => ['state-hint', $state]], $msg); | ||
} | ||
|
||
/** | ||
* Merge tabs with other tabs contained in this tab panel | ||
* | ||
* @param Tabs $tabs | ||
* | ||
* @return void | ||
*/ | ||
protected function mergeTabs(Tabs $tabs): void | ||
{ | ||
/** @var Tab $tab */ | ||
foreach ($tabs->getTabs() as $tab) { | ||
$this->tabs->add($tab->getName(), $tab); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
$this->providePermission('config/lshw', $this->translate('allow access to lshw configuration')); | ||
|
||
$this->provideConfigTab('config/director', array( | ||
'title' => $this->translate('Director Configuration'), | ||
'label' => $this->translate('Director Configuration'), | ||
'url' => 'director' | ||
)); | ||
|
||
?> |
Oops, something went wrong.