Add CopyToClipboard button to copy executed command in Source tab (#758)

This commit is contained in:
raviks789 2023-06-20 12:04:08 +02:00 committed by GitHub
parent c193b51b7f
commit d462a4fae7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 1 deletions

View file

@ -21,6 +21,7 @@ use ipl\Html\HtmlElement;
use ipl\Html\Table;
use ipl\Html\Text;
use ipl\Orm\Model;
use ipl\Web\Widget\CopyToClipboard;
abstract class ObjectInspectionDetail extends BaseHtmlElement
{
@ -88,9 +89,17 @@ abstract class ObjectInspectionDetail extends BaseHtmlElement
'active'
];
$execCommand = new HtmlElement(
'pre',
null,
Text::create($command)
);
CopyToClipboard::attachTo($execCommand);
return [
new HtmlElement('h2', null, Text::create(t('Executed Command'))),
new HtmlElement('pre', null, Text::create($command)),
$execCommand,
new HtmlElement('h2', null, Text::create(t('Execution Details'))),
$this->createNameValueTable(
array_diff_key($this->attrs['last_check_result'], array_flip($denylist)),
@ -313,6 +322,10 @@ abstract class ObjectInspectionDetail extends BaseHtmlElement
$value = call_user_func($formatters[$name], $value);
} else {
$value = $this->formatJson($value);
if ($value instanceof BaseHtmlElement) {
CopyToClipboard::attachTo($value);
}
}
} catch (Exception $e) {
$value = new EmptyState(IcingaException::describe($e));

View file

@ -26,6 +26,7 @@ use Icinga\Module\Icingadb\Model\NotificationHistory;
use Icinga\Module\Icingadb\Model\StateHistory;
use Icinga\Module\Icingadb\Util\PluginOutput;
use Icinga\Module\Icingadb\Widget\EmptyState;
use ipl\Web\Widget\CopyToClipboard;
use ipl\Web\Widget\HorizontalKeyValue;
use Icinga\Module\Icingadb\Widget\ItemTable\UserTable;
use Icinga\Module\Icingadb\Widget\PluginOutputContainer;
@ -79,6 +80,8 @@ class EventDetail extends BaseHtmlElement
? $this->event->host->checkcommand_name
: $this->event->service->checkcommand_name)
);
CopyToClipboard::attachTo($notificationText);
}
$pluginOutput = [
@ -189,6 +192,8 @@ class EventDetail extends BaseHtmlElement
(new PluginOutput($stateChange->output . "\n" . $stateChange->long_output))
->setCommandName($commandName)
);
CopyToClipboard::attachTo($commandOutput);
}
$pluginOutput = [

View file

@ -33,6 +33,7 @@ use Icinga\Module\Icingadb\Util\PluginOutput;
use Icinga\Module\Icingadb\Widget\ItemList\DowntimeList;
use Icinga\Module\Icingadb\Widget\EmptyState;
use Icinga\Module\Icingadb\Widget\StateChange;
use ipl\Web\Widget\CopyToClipboard;
use ipl\Web\Widget\HorizontalKeyValue;
use Icinga\Module\Icingadb\Widget\ItemList\CommentList;
use Icinga\Module\Icingadb\Widget\PluginOutputContainer;
@ -418,6 +419,7 @@ class ObjectDetail extends BaseHtmlElement
$pluginOutput = new EmptyState(t('Output unavailable.'));
} else {
$pluginOutput = new PluginOutputContainer(PluginOutput::fromObject($this->object));
CopyToClipboard::attachTo($pluginOutput);
}
return [