Skip to content

Commit

Permalink
prepare for zabbix status
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitexus committed Jan 18, 2025
1 parent 37dfb61 commit 9aa5d05
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 21 deletions.
29 changes: 14 additions & 15 deletions lib/cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,31 +34,31 @@
\define('APP_NAME', 'MultiFlexi cli');
Shared::user(new Anonym());

$command = \array_key_exists(1, $argv) ? $argv[1] : 'help';
$argument = \array_key_exists(2, $argv) ? $argv[2] : null;
$identifier = \array_key_exists(3, $argv) ? $argv[3] : null;
$property = \array_key_exists(4, $argv) ? $argv[4] : null;
$option = \array_key_exists(5, $argv) ? $argv[5] : null;

// Collect properties starting with --
$properties = [];

$probBegin = 0;

// Parse command line arguments
$command = $argv[1] ?? null;
$argument = $argv[2] ?? null;
$identifier = $argv[3] ?? null;
$property = $argv[4] ?? null;
$format = 'plain'; // Default format

// Parse options
for ($i = 1; $i < \count($argv); ++$i) {
if (strpos($argv[$i], '--') === 0) {
$probBegin = $i;

break;
}
}

if ($probBegin) {
if (isset($probBegin)) {
for ($i = $probBegin; $i < \count($argv); ++$i) {
if (strpos($argv[$i], '--') === 0) {
$key = substr($argv[$i], 2);
$value = \array_key_exists($i + 1, $argv) ? $argv[$i + 1] : null;
$properties[$key] = $value;
if ($key === 'format') {
$format = $value ?? 'plain';
} else {
$properties[$key] = $value;
}
++$i; // Skip the next argument as it is the value
}
}
Expand Down Expand Up @@ -90,7 +90,6 @@
break;

case 'status':
$format = $argument ?? 'plaintext';
$engine = new \MultiFlexi\Engine();
$pdo = $engine->getPdo();
$database = $pdo->getAttribute(\PDO::ATTR_DRIVER_NAME).' '.
Expand Down
31 changes: 26 additions & 5 deletions src/MultiFlexi/Ui/CredentialTypeForm.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use MultiFlexi\CredentialType;

<?php

declare(strict_types=1);

namespace MultiFlexi\Ui\Form;
namespace MultiFlexi\Ui;


/**
Expand All @@ -14,5 +12,28 @@
*/
class CredentialTypeForm extends \Ease\TWB4\Form
{

}
#[\Override]
public function __construct(\MultiFlexi\CredentialType $credtype, $formProperties = []) {
$formContents[] = new \Ease\Html\InputHiddenTag('id', $credtype->getMyKey());
$formContents[] = new \Ease\TWB4\FormGroup(_('Credential Name'), new \Ease\Html\InputTextTag('name', $credtype->getRecordName()));


$submitRow = new \Ease\TWB4\Row();
$submitRow->addColumn(10, new \Ease\TWB4\SubmitButton('🍏 '._('Apply'), 'primary btn-lg btn-block'));

if (null === $credtype->getMyKey()) {
$submitRow->addColumn(2, new \Ease\TWB4\SubmitButton('⚰️ '._('Remove').' !', 'disabled btn-lg btn-block', ['disabled' => 'true']));
} else {
if (WebPage::getRequestValue('remove') === 'true') {
$submitRow->addColumn(2, new \Ease\TWB4\LinkButton('credentialtype.php?delete='.$credtype->getMyKey(), '⚰️ '._('Remove').' !', 'danger btn-lg btn-block'));
} else {
$submitRow->addColumn(2, new \Ease\TWB4\LinkButton('credentialtype.php?id='.$credtype->getMyKey().'&remove=true', '⚰️ '._('Remove').' ?', 'warning btn-lg btn-block'));
}
}

$formContents[] = $submitRow;

parent::__construct(['action' => 'credentialtype.php'], ['method' => 'POST'], $formContents);

}
}
36 changes: 35 additions & 1 deletion src/credentialtype.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,43 @@

WebPage::singleton()->onlyForLogged();

$credTypeId = WebPage::getRequestValue('id', 'int');

$crtype = new \MultiFlexi\CredentialType($credTypeId);

$delete = WebPage::getRequestValue('delete', 'int');

if (null !== $delete) {
$crtype->loadFromSQL($delete);
$cnf = new \MultiFlexi\Configuration();
$crtype->addStatusMessage(sprintf(_('%d used configurations removed'), $cnf->deleteFromSQL(['app_id' => $appId, 'name' => $crtype->getDataValue('keyname')])));

if ($crtype->deleteFromSQL($delete)) {
$crtype->addStatusMessage(_('Credential removed'));
}

WebPage::singleton()->redirect('credentialtypes.php');
}

if (WebPage::singleton()->isPosted()) {
if ($crtype->takeData($_POST) && null !== $crtype->dbsync()) {
$crtype->addStatusMessage(_('Credential field Saved'), 'success');
} else {
$crtype->addStatusMessage(_('Error saving Credential field'), 'error');
}
} else {
if ((null === WebPage::getRequestValue('company_id')) === false) {
$crtype->setDataValue('company_id', WebPage::getRequestValue('company_id'));
}

if ((null === WebPage::getRequestValue('formType')) === false) {
$crtype->setDataValue('formType', WebPage::getRequestValue('formType'));
}
}


WebPage::singleton()->addItem(new PageTop(_('Crednetial Type')));

$crtype = new \MultiFlexi\CredentialType();

WebPage::singleton()->container->addItem(new CredentialTypeForm($crtype));

Expand Down
2 changes: 2 additions & 0 deletions zabbix/multiflexi.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ UserParameter=multiflexi.company.lld,multiflexi-zabbix-lld-company
UserParameter=multiflexi.job.lld,multiflexi-zabbix-lld-tasks
UserParameter=multiflexi.runtemplate.lld[*],multiflexi-zabbix-lld $1
UserParameter=multiflexi.action.lld,multiflexi-zabbix-lld-actions
UserParameter=multiflexi.status,multiflexi-cli status --format=json
UserParameter=multiflexi.jobs.lld,multiflexi-cli jobstatus --format=json

0 comments on commit 9aa5d05

Please sign in to comment.