/**
  * 
  * @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;
     }
 }
Beispiel #2
0
 /**
  * @param \CentreonConfiguration\Events\BrokerProcess $event
  * @throws \Centreon\Internal\Exception
  */
 public static function execute(BrokerProcessEvent $event)
 {
     $action = $event->getAction();
     if (!in_array($action, array('reload', 'restart', 'forcereload'))) {
         throw new Exception(sprintf('Invalid action for Broker: %s', $action));
     }
     $command = "sudo /etc/init.d/cbd {$action} 2>&1";
     $status = 0;
     $output = array();
     exec($command, $output, $status);
     foreach ($output as $line) {
         $event->setOutput($line);
     }
     $event->setStatus($status ? false : true);
 }