Skip to content

Commit

Permalink
Do not log to stdout (EASE_LOGGER value) when Zabbix action is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
Vítězslav Dvořák committed Apr 10, 2024
1 parent 3380577 commit 37cba1f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/MultiFlexi/Env/Logger.php
Expand Up @@ -34,7 +34,15 @@ public static function allKeysHandled()
*/
public function getEnvironment(): array
{
return $this->addMetaData($this->addSelfAsSource(['EASE_LOGGER' => ['value' => 'syslog|console']]));
// If Zabbix action is enabled log only to syslog
$actions = $this->engine->runTemplate->getPostActions();
$methods[] = 'syslog';
if(array_key_exists('Zabbix', $actions)){
if(!($actions['Zabbix']['success'] || $actions['Zabbix']['fail'])){
$methods[] = 'console';
}
}
return $this->addMetaData($this->addSelfAsSource(['EASE_LOGGER' => ['value' => implode('|', $methods)]]));
}

/**
Expand Down
5 changes: 5 additions & 0 deletions src/MultiFlexi/Job.php
Expand Up @@ -119,6 +119,7 @@ class Job extends Engine
*/
public function __construct($identifier = null, $options = [])
{
$this->runTemplate = new RunTemplate();
parent::__construct($identifier, $options);
if (\Ease\Shared::cfg('ZABBIX_SERVER')) {
$this->zabbixSender = new ZabbixSender(\Ease\Shared::cfg('ZABBIX_SERVER'));
Expand Down Expand Up @@ -528,6 +529,10 @@ public function takeData($data)
if (is_null($this->getDataValue('app_id')) === false) {
$this->application = new Application(intval($this->getDataValue('app_id')));
}

if($this->application->getMyKey() && $this->company->getMyKey()){
$this->runTemplate->loadFromSQL($this->runTemplate->runTemplateID($this->application->getMyKey(), $this->company->getMyKey()));
}

if ($this->getDataValue('executor')) {
$executorClass = '\\MultiFlexi\\Executor\\' . $this->getDataValue('executor');
Expand Down
21 changes: 21 additions & 0 deletions src/MultiFlexi/RunTemplate.php
Expand Up @@ -256,4 +256,25 @@ public static function stripToValues(array $envData)
}
return $env;
}


/**
* Actions Availble with flag when performed in case of success of failure
*
* @return array<array>
*/
public function getPostActions()
{
$actions = [];
$s = $this->getDataValue('success') ? unserialize($this->getDataValue('success')): [];
$f = $this->getDataValue('fail') ? unserialize($this->getDataValue('fail')): [];
foreach ($s as $action => $enabled){
$actions[$action]['success'] = $enabled;
}
foreach ($s as $action => $enabled){
$actions[$action]['fail'] = $enabled;
}
return $actions;
}

}

0 comments on commit 37cba1f

Please sign in to comment.