Private GIT

Skip to content
Snippets Groups Projects
Commit 2690fedc authored by Sylvestre Ho's avatar Sylvestre Ho
Browse files

refs #5106; call run.test

parent e1f50f19
No related branches found
No related tags found
No related merge requests found
......@@ -35,45 +35,22 @@
namespace CentreonConfiguration\Events;
class EngineProcess
class EngineProcess extends PollerEvent
{
/**
* Refers to the poller id
* @var int
*/
private $pollerId;
/**
* Refers to the action to perform: restart, reload, forcereload
* @var string
*/
private $action;
/**
* Array of output - should be the output of the process after
* performing the action
* @var array
*/
private $output;
/**
* @param int $pollerId
* @param string $action
*/
public function __construct($pollerId, $action)
{
$this->pollerId = $pollerId;
parent::__construct($pollerId);
$this->action = $action;
$this->output = array();
$this->status = 0;
}
/**
* @return int
*/
public function getPollerId()
{
return $this->pollerId;
}
/**
......@@ -81,35 +58,6 @@ class EngineProcess
*/
public function getAction()
{
return $this->action();
}
/**
* @return array
*/
public function getOutput()
{
return $this->output;
}
/**
* @return int
*/
public function getStatus()
{
return $this->status;
}
/**
* @param array $output
*/
public function setOutput(array $output)
{
$this->output = $output;
}
public function setStatus(int $status)
{
$this->status = $status;
return $this->action;
}
}
......@@ -98,7 +98,7 @@ class PollerEvent
$this->output[] = $output;
}
public function setStatus(int $status)
public function setStatus($status)
{
$this->status = $status;
}
......
......@@ -70,8 +70,8 @@ class ConfigApplyRepository extends ConfigRepositoryAbstract
$event = $this->di->get('events');
$engineEvent = new EngineProcess($this->pollerId, $method);
$brokerEvent = new BrokerProcess($this->pollerId, $method);
$event->emit("centreon-configuration.$method.engine", array($engineEvent));
$event->emit("centreon-configuration.$method.broker", array($brokerEvent));
$event->emit("centreon-configuration.engine.process", array($engineEvent));
$event->emit("centreon-configuration.broker.process", array($brokerEvent));
} catch (Exception $e) {
$this->output[] = $e->getMessage();
$this->status = false;
......
......@@ -67,8 +67,9 @@ class ConfigMoveRepository extends ConfigRepositoryAbstract
try {
/* Get Path */
$event = $this->di->get('events');
$event->emit('centreon-configuration.copy.files', array(new CopyFiles($this->pollerId)));
$this->output[] = _('Successfully copied files.');
$eventObj = new CopyFiles($this->pollerId);
$event->emit('centreon-configuration.copy.files', array($eventObj));
$this->output = array_merge($this->output, $eventObj->getOutput());
} catch (Exception $e) {
$this->output[] = $e->getMessage();
$this->status = false;
......
......@@ -71,8 +71,9 @@ class ConfigTestRepository extends ConfigRepositoryAbstract
try {
$result = "";
$event = $this->di->get('events');
$event->emit('centreon-configuration.run.test', array(new RunTest($this->pollerId)));
$this->output[] = $result;
$eventObj = new RunTest($this->pollerId);
$event->emit('centreon-configuration.run.test', array($eventObj));
$this->output = array_merge($this->output, $eventObj->getOutput());
} catch (Exception $e) {
$this->output[] = $e->getMessage();
$this->status = false;
......
......@@ -52,5 +52,6 @@ class CopyFiles
$tmpdir = $config->get('global', 'centreon_generate_tmp_dir');
system("cp -Rf $tmpdir/{$event->getPollerId()}/* /etc/centreon-engine/");
$event->setOutput(_('Successfully copied files.'));
}
}
......@@ -47,10 +47,9 @@ class EngineProcess
public static function execute(EngineProcessEvent $event)
{
$action = $event->getAction();
if (in_array($action, array('reload', 'restart', 'forcereload'))) {
if (!in_array($action, array('reload', 'restart', 'forcereload'))) {
throw new Exception(sprintf('Unknown action %s', $action));
}
echo "Hello Dude";
$command = "sudo /etc/init.d/centengine {$action}";
$status = 0;
$output = array();
......
......@@ -51,9 +51,10 @@ class RunTest
$tmpdir = $di->get('config')->get('global', 'centreon_generate_tmp_dir');
$pollerId = $event->getPollerId();
$enginePath = '/usr/sbin/centengine/';
$enginePath = '/usr/sbin/centengine';
$path = "{$tmpdir}/{$pollerId}/centengine-testing.cfg";
$command = "sudo {$enginePath} -v $path 2>&1";
$output = shell_exec($command);
$event->setOutput($output);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment