Exemple #1
0
 /**
  *
  * @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);
         }
     }
 }