Skip to content

Commit

Permalink
RunTemplate can be triggered using multiflexi-cli runtemplate trigger…
Browse files Browse the repository at this point in the history
… RtplID
  • Loading branch information
Vitexus committed Jan 19, 2025
1 parent 4cc927b commit 3e207f6
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/MultiFlexi/Command/AppStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class AppStatus extends Command
protected function configure(): void
{
$this
->setName('appstatus')
->setName('status')
->setDescription('Prints App Status')
->addOption('--format', '-f', InputOption::VALUE_OPTIONAL, 'The output format: text or json. Defaults to text.', 'text')
->setHelp('This command prints overall MultiFlexi status');
Expand Down
46 changes: 39 additions & 7 deletions src/MultiFlexi/Command/RunTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,56 @@
*/

namespace MultiFlexi\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Output\OutputInterface;

/**
* Description of RunTemplate
*
* @author Vitex <[email protected]>
*/
class RunTemplate extends Command {
protected function configure(): void
{
class RunTemplate extends Command {

protected function configure(): void {
$this
->setName('runtemplate')
->setDescription('Runtemplate operations')
->addOption('--format', '-f', InputOption::VALUE_OPTIONAL, 'The output format: text or json. Defaults to text.', 'text')
->setHelp('This command manage Runtemplates');
->setName('runtemplate')
->setDescription('Runtemplate operations')
->addOption('--format', '-f', InputOption::VALUE_OPTIONAL, 'The output format: text or json. Defaults to text.', 'text')
->addArgument('operation', InputArgument::REQUIRED, 'what to do with RunTemplate')
->addArgument('id', InputArgument::OPTIONAL, 'which RunTemplate ?')
->setHelp(<<<EOT
The <info>runtemplate</info> command mangafe runtemplate
<info>multilflexi-cli runtemplate trigger 220</info>
<info>multilflexi-cli runtemplate list -f json</info>
EOT);
}

protected function execute(InputInterface $input, OutputInterface $output): int {

$runTemplate = new \MultiFlexi\RunTemplate(is_numeric($input->getArgument('id')) ? (int) $input->getArgument('id') : $input->getArgument('id'));

switch ($input->getArgument('operation')) {
case 'trigger':
$jobber = new \MultiFlexi\Job();
$when = new \DateTime();
$executor = 'Native';
$customEnv = [];
$prepared = $jobber->prepareJob($runTemplate->getMyKey(), $customEnv, $when, $executor, 'adhoc');
$jobber->scheduleJobRun($when);

break;

default:
break;
}


return Command::SUCCESS;
}
}
2 changes: 2 additions & 0 deletions src/MultiFlexi/Job.php
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,8 @@ public function reportToZabbix(array $messageData): bool
$itemKey = 'job-['.$this->company->getDataValue('code').'-'.$this->application->getDataValue('code').'-'.$this->runTemplate->getMyKey().']';
$packet->addMetric((new ZabbixMetric($itemKey, json_encode($this->zabbixMessageData)))->withHostname($hostname));

file_put_contents('/tmp/zabbix-' . $this->getMyKey().'-'. time().'.json' , json_encode($this->zabbixMessageData));

try {
$result = $this->zabbixSender->send($packet);

Expand Down

0 comments on commit 3e207f6

Please sign in to comment.