Exemple #1
0
 /**
  * Write a message to the log
  *
  * @param string $message
  */
 protected function write($message)
 {
     $file = new File($this->file, 'a');
     $file->fwrite($message);
     $file->fflush();
 }
 /**
  * Write the command to the local Icinga command file
  *
  * @param   IcingaCommand   $command
  * @param   int|null        $now
  *
  * @throws  ConfigurationError
  * @throws  CommandTransportException
  */
 public function send(IcingaCommand $command, $now = null)
 {
     if (!isset($this->path)) {
         throw new ConfigurationError('Can\'t send external Icinga Command. Path to the local command file is missing');
     }
     $commandString = $this->renderer->render($command, $now);
     Logger::debug('Sending external Icinga command "%s" to the local command file "%s"', $commandString, $this->path);
     try {
         $file = new File($this->path, $this->openMode);
         $file->fwrite($commandString . "\n");
         $file->fflush();
     } catch (Exception $e) {
         $message = $e->getMessage();
         if ($e instanceof RuntimeException && ($pos = strrpos($message, ':')) !== false) {
             // Assume RuntimeException thrown by SplFileObject in the format: __METHOD__ . "({$filename}): Message"
             $message = substr($message, $pos + 1);
         }
         throw new CommandTransportException('Can\'t send external Icinga command to the local command file "%s": %s', $this->path, $message);
     }
 }