/** * * @param \CentreonConfiguration\Events\RunTest $event */ public static function execute(RunTestEvent $event) { $di = Di::getDefault(); $dbconn = $di->get('db_centreon'); $tmpdir = $di->get('config')->get('global', 'centreon_generate_tmp_dir'); $pollerId = $event->getPollerId(); $enginePath = '/usr/sbin/centengine'; $path = "{$tmpdir}/engine/generate/{$pollerId}/centengine-testing.cfg"; $command = "sudo {$enginePath} -v {$path} 2>&1"; exec($command, $output, $status); if ($status == 0) { // We are only selecting warning/errors here // Colors/formatting is performed either in Command (centreonConsole) or JS (web => API thru JSON) foreach ($output as $out) { if (preg_match("/warning|error/i", $out)) { $out = preg_replace("/\\[\\d+\\] /", "", $out); $event->setOutput($out); } } } else { $event->setOutput('Error while executing test command'); foreach ($output as $out) { $event->setOutput($out); } } }
/** * Check configuration * * @param int $poller_id * @return array */ public function checkConfig() { try { $result = ""; $event = $this->di->get('events'); $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; } }