/** * * @param string $method * @return array */ public function action($method) { try { $event = $this->di->get('events'); /* Engine */ $this->output[] = sprintf(_("Performing %s action on Engine..."), $method); $engineEvent = new EngineProcess($this->pollerId, $method); $event->emit("centreon-configuration.engine.process", array($engineEvent)); $this->output = array_merge($this->output, $engineEvent->getOutput()); // Check Engine action is OK before going on with Broker if ($engineEvent->getStatus()) { /* Broker */ $this->output[] = sprintf(_("Performing %s action on Broker..."), $method); $brokerEvent = new BrokerProcess($this->pollerId, $method); $event->emit("centreon-configuration.broker.process", array($brokerEvent)); $this->output = array_merge($this->output, $brokerEvent->getOutput()); if (!$brokerEvent->getStatus()) { $this->status = false; } } else { $this->status = false; } } catch (Exception $e) { $this->output[] = $e->getMessage(); $this->status = false; } }
/** * @param \CentreonConfiguration\Events\EngineProcess $event * @throws \Centreon\Internal\Exception * @todo send command to centreon.d */ public static function execute(EngineProcessEvent $event) { /*$action = $event->getAction(); if (!in_array($action, array('reload', 'restart', 'forcereload'))) { throw new Exception(sprintf('Invalid action for Engine: %s', $action)); } $engineParams = Engine::get($event->getPollerId(), 'init_script'); if (!isset($engineParams['init_script'])) { throw new Exception(sprintf("Could not find init script for poller %s", $event->getPollerId())); } $initScript = $engineParams['init_script']; $command = "sudo {$initScript} {$action} 2>&1"; $status = 0; $output = array(); exec($command, $output, $status); foreach ($output as $line) { $event->setOutput($line); } $event->setStatus( $status ? false : true );*/ $action = $event->getAction(); if ($action == "restart") { $cmd = "[%u] RESTART_PROGRAM\n"; } else { if ($action == "reload") { $cmd = "[%u] RELOAD_PROGRAM\n"; } else { throw new \Exception("Bad type of command."); } } $extCommand = new ExternalCommand($event->getPollerId(), sprintf($cmd, time()), 'engine'); Di::getDefault()->get('events')->emit('centreon-realtime.command.send', array($extCommand)); }