Ejemplo n.º 1
0
 /**
  * Action for Testing configuration files
  *
  * @method GET
  * @route /testcfg/[i:id]
  */
 public function testAction()
 {
     $di = Di::getDefault();
     $router = $di->get('router');
     $param = $router->request()->paramsNamed();
     $obj = new ConfigTestRepository($param["id"]);
     $obj->checkConfig();
     $router->response()->json(array("status" => $obj->getStatus(), "output" => $obj->getOutput()));
 }
Ejemplo n.º 2
0
 /**
  * @cmdObject string poller the poller slug
  */
 public function testAction($object)
 {
     $exit = 1;
     $id = PollerRepository::getIdBySlugName($object['poller']);
     if (!is_null($id)) {
         $obj = new ConfigTestRepository($id);
         $obj->checkConfig();
         // Only CentEngine is tested at the moment
         // We are formatting the output to have a colored, readable ouput on terminal
         $totalWarningsStr = Colorize::colorizeMessage('Total Warnings', 'warning');
         $warningStr = Colorize::colorizeMessage('Warning', 'warning');
         $totalErrorsStr = Colorize::colorizeMessage('Total Errors', 'danger');
         $errorStr = Colorize::colorizeMessage('Error', 'danger');
         $finalStr = $obj->getOutput();
         $finalStr = str_replace("\nTotal Warnings", "\n" . $totalWarningsStr, $finalStr);
         $finalStr = str_replace("\nWarning", "\n" . $warningStr, $finalStr);
         $finalStr = str_replace("\nTotal Errors", "\n" . $totalErrorsStr, $finalStr);
         $finalStr = str_replace("\nError", "\n" . $errorStr, $finalStr);
         if ($obj->getStatus() === 1) {
             $exit = 0;
         } else {
             $exit = 1;
         }
         echo $finalStr;
     } else {
         \Centreon\Internal\Utils\CommandLine\InputOutput::display("Error : Poller not in Database", true, 'red');
         $exit = 1;
     }
     exit($exit);
 }