Skip to content

Commit

Permalink
better cli
Browse files Browse the repository at this point in the history
code reformat
CredentialType class introduced
  • Loading branch information
Vitexus committed Dec 13, 2024
1 parent 4182fea commit bcf1c3c
Show file tree
Hide file tree
Showing 10 changed files with 121 additions and 26 deletions.
14 changes: 13 additions & 1 deletion db/migrations/20241212075548_artifact_note.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
<?php

declare(strict_types=1);

/**
* This file is part of the MultiFlexi package
*
* https://multiflexi.eu/
*
* (c) Vítězslav Dvořák <http://vitexsoftware.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

use Phinx\Migration\AbstractMigration;

final class ArtifactNote extends AbstractMigration
Expand All @@ -20,6 +32,6 @@ public function change(): void
{
$table = $this->table('artifacts');
$table->addColumn('note', 'string', ['limit' => 255, 'null' => true])
->update();
->update();
}
}
32 changes: 29 additions & 3 deletions lib/cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
Shared::init(['DB_CONNECTION', 'DB_HOST', 'DB_PORT', 'DB_DATABASE', 'DB_USERNAME', 'DB_PASSWORD'], '../.env');
$loggers = ['syslog', '\MultiFlexi\LogToSQL', 'console'];

if (\Ease\Shared::cfg('ZABBIX_SERVER') && \Ease\Shared::cfg('ZABBIX_HOST') && class_exists('\MultiFlexi\LogToZabbix')) {
if (Shared::cfg('ZABBIX_SERVER') && Shared::cfg('ZABBIX_HOST') && class_exists('\MultiFlexi\LogToZabbix')) {
$loggers[] = '\MultiFlexi\LogToZabbix';
}

if (\Ease\Shared::cfg('APP_DEBUG') === 'true') {
if (Shared::cfg('APP_DEBUG') === 'true') {
$loggers[] = 'console';
}

Expand Down Expand Up @@ -66,7 +66,7 @@

switch ($command) {
case 'version':
echo \Ease\Shared::appName().' '.\Ease\Shared::appVersion()."\n";
echo Shared::appName().' '.Shared::appVersion().\PHP_EOL;

break;
case 'remove':
Expand All @@ -86,6 +86,10 @@
case 'runtemplate':
$engine = new \MultiFlexi\RunTemplate((int) $identifier);

break;
case 'job':
$engine = new \MultiFlexi\Job((int) $identifier);

break;

default:
Expand Down Expand Up @@ -132,6 +136,28 @@
$checkData = ['code' => (string) $identifier];
$engine = new \MultiFlexi\Company(['code' => (string) $identifier, 'name' => $property ? $property : $identifier], ['autoload' => false]);

break;
case 'credential_type':
if (empty($identifier)) {
echo $argv[0].' add credential_type <name>';

exit;
}

$checkData = ['name' => (string) $identifier];
$engine = new \MultiFlexi\CredentialType($checkData, ['autoload' => false]);

break;
case 'credential':
if (empty($identifier)) {
echo $argv[0].' add credential <name> <type id> <company id> [--CONFIG_FIELD=VALUE ..]';

exit;
}

$checkData = ['name' => (string) $identifier, 'type_id' => $property, 'company_id' => $option];
$engine = new \MultiFlexi\Credential($checkData, ['autoload' => false]);

break;
case 'runtemplate':
if (empty($identifier)) {
Expand Down
2 changes: 1 addition & 1 deletion src/MultiFlexi/Action/Zabbix.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function perform(\MultiFlexi\Job $job): void

if ($dataForZabbix) {
$artifactor = new \MultiFlexi\Artifact();
$artifactor->createArtifact($job->getMyKey(), $dataForZabbix, $metricsfile, file_exists($metricsfile) ? mime_content_type($metricsfile) : 'application/json', sprintf(_('Reported to Zabbix: from %s sent to %s as %s '), $me, $server , $zabbixKey) );
$artifactor->createArtifact($job->getMyKey(), $dataForZabbix, $metricsfile, file_exists($metricsfile) ? mime_content_type($metricsfile) : 'application/json', sprintf(_('Reported to Zabbix: from %s sent to %s as %s '), $me, $server, $zabbixKey));

if (\Ease\Shared::cfg('USE_ZABBIX_SENDER') && file_exists('/usr/bin/zabbix_sender')) {
$cmd = sprintf("zabbix_sender -v -z %s -s %s -k %s -o '%s'", $server, $me, $zabbixKey, $dataForZabbix);
Expand Down
5 changes: 3 additions & 2 deletions src/MultiFlexi/Artifact.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ public function __construct($identifier = null, $options = [])
/**
* Create a new artifact record.
*
* @param int $jobId Number of producing job
* @param int $jobId Number of producing job
* @param mixed $filename
* @param mixed $contentType
* @param mixed $note
*
* @return int Atrifacts Record ID
*/
Expand All @@ -53,7 +54,7 @@ public function createArtifact(int $jobId, string $artifact, $filename = '', $co
'content_type' => $contentType,
'artifact' => $artifact,
'created_at' => date('Y-m-d H:i:s'),
'note' => $note
'note' => $note,
]);
}

Expand Down
31 changes: 31 additions & 0 deletions src/MultiFlexi/CredentialType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

/**
* This file is part of the MultiFlexi package
*
* https://multiflexi.eu/
*
* (c) Vítězslav Dvořák <http://vitexsoftware.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace MultiFlexi;

/**
* Description of CredentialType.
*
* @author Vitex <info@vitexsoftware.cz>
*/
class CredentialType extends DBEngine
{
#[\Override]
public function __construct($init = null, $filter = [])
{
$this->myTable = 'credential_types';
parent::__construct($init, $filter);
}
}
4 changes: 2 additions & 2 deletions src/MultiFlexi/DBEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class DBEngine extends \Ease\SQL\Engine
* Data Processing Engine.
*
* @param int $init
* @param int $filter Initial conditons
* @param int $filter Initial conditions
*/
public function __construct($init = null, $filter = [])
{
Expand Down Expand Up @@ -117,7 +117,7 @@ public function takemyTable($myTable)
}

/**
* Set page where to work wiht one row detail.
* Set page where to work with one row detail.
*
* @param string $detailPage
*/
Expand Down
30 changes: 29 additions & 1 deletion src/MultiFlexi/RunTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
/**
* @author vitex
*/
class RunTemplate extends \MultiFlexi\Engine
class RunTemplate extends \MultiFlexi\DBEngine
{
public static array $intervalCode = [
'y' => 'yearly',
Expand Down Expand Up @@ -452,4 +452,32 @@ public function credentialsEnvironment()

return $credentials;
}

public function columns($columns = [])
{
return parent::columns([
['name' => 'id', 'type' => 'text', 'label' => _('ID')],
['name' => 'interv', 'type' => 'text', 'label' => _('Interval')],
['name' => 'delay', 'type' => 'text', 'label' => _('Delay')],
['name' => 'executor', 'type' => 'text', 'label' => _('Executor')],
// ['name' => 'created', 'type' => 'datetime', 'label' => _('Created')],
// ['name' => 'resolved', 'type' => 'datetime', 'label' => _('Resolved')],
['name' => 'app_id', 'type' => 'selectize', 'label' => _('Application'),
'listingPage' => 'apps.php',
'detailPage' => 'app.php',
'idColumn' => 'apps',
'valueColumn' => 'apps.name',
'engine' => '\MultiFlexi\Application',
'filterby' => 'name',
],
['name' => 'company_id', 'type' => 'selectize', 'label' => _('Company'),
'listingPage' => 'companies.php',
'detailPage' => 'company.php',
'idColumn' => 'company',
'valueColumn' => 'company.name',
'engine' => '\MultiFlexi\Company',
'filterby' => 'name',
],
]);
}
}
13 changes: 5 additions & 8 deletions src/MultiFlexi/Ui/CompaniesBar.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,15 @@ public function __construct(array $properties = [])
$companyAppCard->addTagClass('text-center');

$companyAppCard->addItem(new \Ease\Html\DivTag(new \Ease\Html\H5Tag($companyData['name'], ['class' => 'card-title']), ['class' => 'card-body']));





$companyAppStatus = new \Ease\Html\DivTag();

$companyApps = (new CompanyApp($companer))->getAssigned()->leftJoin('apps ON apps.id = companyapp.app_id')->select(['apps.name', 'apps.description', 'apps.id', 'apps.uuid'], true)->fetchAll();
foreach ($companyApps as $companyApp){
$companyAppStatus->addItem(new \Ease\Html\ATag('companyapp.php?company_id='.$companer->getMyKey().'&app_id='.$companyApp['id'], new \Ease\Html\ImgTag('appimage.php?uuid='.$companyApp['uuid'], _($companyApp['name']), ['title' => _($companyApp['description']), 'style' => 'padding: 5px; margin: 5px;max-height: 50px;max-width: 50px;'])));

foreach ($companyApps as $companyApp) {
$companyAppStatus->addItem(new \Ease\Html\ATag('companyapp.php?company_id='.$companer->getMyKey().'&app_id='.$companyApp['id'], new \Ease\Html\ImgTag('appimage.php?uuid='.$companyApp['uuid'], _($companyApp['name']), ['title' => _($companyApp['description']), 'style' => 'padding: 5px; margin: 5px;max-height: 50px;max-width: 50px;'])));
}

$companyAppCard->addItem(new \Ease\Html\DivTag($companyAppStatus, ['class' => 'card-footer bg-transparent']));

$cardGroup->addItem($companyAppCard);
Expand Down
14 changes: 7 additions & 7 deletions src/MultiFlexi/Ui/IntervalChooser.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ class IntervalChooser extends \Ease\Html\SelectTag
public function __construct(string $name, string $defaultValue = '', array $properties = [])
{
parent::__construct($name, [
'n' => RunTemplate::getIntervalEmoji('n') .' '. _('Disabled'),
'i' => RunTemplate::getIntervalEmoji('i') .' '._('Minutly'),
'h' => RunTemplate::getIntervalEmoji('h') .' '._('Hourly'),
'd' => RunTemplate::getIntervalEmoji('d') .' '._('Daily'),
'w' => RunTemplate::getIntervalEmoji('w') .' '. _('Weekly'),
'm' => RunTemplate::getIntervalEmoji('m') .' '. _('Monthly'),
'y' => RunTemplate::getIntervalEmoji('y') .' '. _('Yearly'),
'n' => RunTemplate::getIntervalEmoji('n').' '._('Disabled'),
'i' => RunTemplate::getIntervalEmoji('i').' '._('Minutly'),
'h' => RunTemplate::getIntervalEmoji('h').' '._('Hourly'),
'd' => RunTemplate::getIntervalEmoji('d').' '._('Daily'),
'w' => RunTemplate::getIntervalEmoji('w').' '._('Weekly'),
'm' => RunTemplate::getIntervalEmoji('m').' '._('Monthly'),
'y' => RunTemplate::getIntervalEmoji('y').' '._('Yearly'),
], $defaultValue, $properties);
}
}
2 changes: 1 addition & 1 deletion src/job.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
$artifactsDiv = new \Ease\Html\DivTag();

foreach ($artifacts->fetchAll() as $artifactData) {
$artifactsDiv->addItem( new \Ease\TWB4\Panel($artifactData['filename'],'inverse', new \Ease\Html\DivTag(nl2br($artifactData['artifact']), ['style' => 'font-family: monospace; color: black']), $artifactData['note'] ) );
$artifactsDiv->addItem(new \Ease\TWB4\Panel($artifactData['filename'], 'inverse', new \Ease\Html\DivTag(nl2br($artifactData['artifact']), ['style' => 'font-family: monospace; color: black']), $artifactData['note']));
}

$outputTabs->addTab(_('Artifacts'), $artifactsDiv);
Expand Down

0 comments on commit bcf1c3c

Please sign in to comment.