Jannis Moßhammer d6bbed3a54 Extract the transport functions from the CommandPipe
- The CommandPipe class now delegates submission of commands to
  the Transport classes (LocalPipe or SecureShell)
- Added SSH options for non-interactive mode
- Refactored tests

refs #4441
2013-08-06 09:27:37 +02:00

32 lines
958 B
PHP

<?php
namespace Icinga\Protocol\Commandpipe\Transport;
use Icinga\Application\Logger;
class LocalPipe implements Transport
{
private $path;
private $openMode = "w";
public function setEndpoint(\Zend_Config $config)
{
$this->path = isset($config->path) ? $config->path : '/usr/local/icinga/var/rw/icinga.cmd';
}
public function send($message)
{
Logger::debug('Attempting to send external icinga command %s to local command file ', $message, $this->path);
$file = @fopen($this->path, $this->openMode);
if (!$file) {
throw new \RuntimeException('Could not open icinga pipe at $file : ' . print_r(error_get_last(), true));
}
fwrite($file, '[' . time() . '] ' . $message . PHP_EOL);
Logger::debug('Writing [' . time() . '] ' . $message . PHP_EOL);
fclose($file);
}
public function setOpenMode($mode)
{
$this->openMode = $mode;
}
}