2014-11-30 04:59:27 -05:00
|
|
|
<?php
|
|
|
|
|
|
2014-11-30 09:56:58 -05:00
|
|
|
namespace Icinga\Module\Businessprocess\Storage;
|
2014-11-30 04:59:27 -05:00
|
|
|
|
2016-11-23 04:44:24 -05:00
|
|
|
use DirectoryIterator;
|
|
|
|
|
use Icinga\Application\Benchmark;
|
2014-11-30 04:59:27 -05:00
|
|
|
use Icinga\Application\Icinga;
|
2015-02-12 19:57:12 -05:00
|
|
|
use Icinga\Exception\ConfigurationError;
|
2014-11-30 09:56:58 -05:00
|
|
|
use Icinga\Module\Businessprocess\BpNode;
|
2016-11-23 04:44:24 -05:00
|
|
|
use Icinga\Module\Businessprocess\BusinessProcess;
|
2014-11-30 04:59:27 -05:00
|
|
|
use Icinga\Exception\SystemPermissionException;
|
2016-12-09 03:58:00 -05:00
|
|
|
use Icinga\Module\Businessprocess\Metadata;
|
2014-11-30 04:59:27 -05:00
|
|
|
|
|
|
|
|
class LegacyStorage extends Storage
|
|
|
|
|
{
|
2016-11-23 04:44:24 -05:00
|
|
|
/** @var string */
|
2014-11-30 04:59:27 -05:00
|
|
|
protected $configDir;
|
|
|
|
|
|
2016-11-23 04:44:24 -05:00
|
|
|
/** @var int */
|
2014-11-30 06:26:28 -05:00
|
|
|
protected $parsing_line_number;
|
|
|
|
|
|
2016-11-23 04:44:24 -05:00
|
|
|
/** @var string */
|
2015-02-12 19:57:12 -05:00
|
|
|
protected $currentFilename;
|
|
|
|
|
|
2014-11-30 04:59:27 -05:00
|
|
|
public function getConfigDir()
|
|
|
|
|
{
|
|
|
|
|
if ($this->configDir === null) {
|
2016-11-23 04:44:24 -05:00
|
|
|
$this->prepareDefaultConfigDir();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this->configDir;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function prepareDefaultConfigDir()
|
|
|
|
|
{
|
|
|
|
|
$dir = Icinga::app()
|
|
|
|
|
->getModuleManager()
|
|
|
|
|
->getModule('businessprocess')
|
|
|
|
|
->getConfigDir();
|
|
|
|
|
|
|
|
|
|
// TODO: This is silly. We need Config::requireDirectory().
|
|
|
|
|
if (! is_dir($dir)) {
|
|
|
|
|
if (! is_dir(dirname($dir))) {
|
|
|
|
|
if (! @mkdir(dirname($dir))) {
|
|
|
|
|
throw new SystemPermissionException('Could not create config directory "%s"', dirname($dir));
|
2014-11-30 04:59:27 -05:00
|
|
|
}
|
|
|
|
|
}
|
2016-11-23 04:44:24 -05:00
|
|
|
if (! mkdir($dir)) {
|
|
|
|
|
throw new SystemPermissionException('Could not create config directory "%s"', $dir);
|
2014-11-30 04:59:27 -05:00
|
|
|
}
|
|
|
|
|
}
|
2016-11-23 04:44:24 -05:00
|
|
|
$dir = $dir . '/processes';
|
|
|
|
|
if (! is_dir($dir)) {
|
|
|
|
|
if (! mkdir($dir)) {
|
|
|
|
|
throw new SystemPermissionException('Could not create config directory "%s"', $dir);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->configDir = $dir;
|
2014-11-30 04:59:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function listProcesses()
|
|
|
|
|
{
|
|
|
|
|
$files = array();
|
2015-11-20 06:35:09 -05:00
|
|
|
|
2016-12-09 03:58:00 -05:00
|
|
|
foreach ($this->listAllProcessNames() as $name) {
|
|
|
|
|
$meta = $this->loadMetadata($name);
|
2016-12-09 08:03:49 -05:00
|
|
|
if (! $meta->canRead()) {
|
2016-11-23 05:13:29 -05:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-09 03:58:00 -05:00
|
|
|
$files[$name] = $name;
|
2014-11-30 04:59:27 -05:00
|
|
|
}
|
2015-11-02 11:25:51 -05:00
|
|
|
|
|
|
|
|
natsort($files);
|
2014-11-30 04:59:27 -05:00
|
|
|
return $files;
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-09 03:58:00 -05:00
|
|
|
public function listAllProcessNames()
|
2015-11-20 06:35:09 -05:00
|
|
|
{
|
2016-12-09 03:58:00 -05:00
|
|
|
$files = array();
|
2015-11-20 06:35:09 -05:00
|
|
|
|
2016-12-09 03:58:00 -05:00
|
|
|
foreach (new DirectoryIterator($this->getConfigDir()) as $file) {
|
|
|
|
|
if ($file->isDot()) {
|
|
|
|
|
continue;
|
2015-11-20 06:35:09 -05:00
|
|
|
}
|
|
|
|
|
|
2016-12-09 03:58:00 -05:00
|
|
|
$filename = $file->getFilename();
|
|
|
|
|
if (substr($filename, -5) === '.conf') {
|
|
|
|
|
$files[] = substr($filename, 0, -5);
|
2015-11-20 06:35:09 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-09 03:58:00 -05:00
|
|
|
natsort($files);
|
|
|
|
|
return $files;
|
2015-11-20 06:35:09 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function splitCommaSeparated($string)
|
|
|
|
|
{
|
|
|
|
|
return preg_split('/\s*,\s*/', $string, -1, PREG_SPLIT_NO_EMPTY);
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-09 08:03:49 -05:00
|
|
|
protected function readHeader($file, Metadata $metadata)
|
2014-12-01 07:57:57 -05:00
|
|
|
{
|
|
|
|
|
$fh = fopen($file, 'r');
|
|
|
|
|
$cnt = 0;
|
2016-11-23 07:53:47 -05:00
|
|
|
while ($cnt < 15 && false !== ($line = fgets($fh))) {
|
|
|
|
|
$cnt++;
|
2016-12-09 08:03:49 -05:00
|
|
|
$this->parseHeaderLine($line, $metadata);
|
2016-11-23 07:53:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fclose($fh);
|
2016-12-09 08:03:49 -05:00
|
|
|
return $metadata;
|
2016-11-23 07:53:47 -05:00
|
|
|
}
|
|
|
|
|
|
2016-12-09 08:03:49 -05:00
|
|
|
protected function readHeaderString($string, Metadata $metadata)
|
2016-11-23 07:53:47 -05:00
|
|
|
{
|
|
|
|
|
foreach (preg_split('/\n/', $string) as $line) {
|
2016-12-09 08:03:49 -05:00
|
|
|
$this->parseHeaderLine($line, $metadata);
|
2016-11-23 07:53:47 -05:00
|
|
|
}
|
|
|
|
|
|
2016-12-09 08:03:49 -05:00
|
|
|
return $metadata;
|
2016-11-23 07:53:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function emptyHeader()
|
|
|
|
|
{
|
|
|
|
|
return array(
|
2016-12-09 03:58:00 -05:00
|
|
|
'Title' => null,
|
|
|
|
|
'Description' => null,
|
|
|
|
|
'Owner' => null,
|
|
|
|
|
'AllowedUsers' => null,
|
|
|
|
|
'AllowedGroups' => null,
|
|
|
|
|
'AllowedRoles' => null,
|
|
|
|
|
'Backend' => null,
|
|
|
|
|
'Statetype' => 'soft',
|
|
|
|
|
'SLAHosts' => null
|
2014-12-01 07:57:57 -05:00
|
|
|
);
|
2016-11-23 07:53:47 -05:00
|
|
|
}
|
|
|
|
|
|
2016-12-09 08:03:49 -05:00
|
|
|
protected function parseHeaderLine($line, Metadata $metadata)
|
2016-11-23 07:53:47 -05:00
|
|
|
{
|
|
|
|
|
if (preg_match('/^\s*#\s+(.+?)\s*:\s*(.+)$/', $line, $m)) {
|
2016-12-09 08:03:49 -05:00
|
|
|
if ($metadata->hasKey($m[1])) {
|
|
|
|
|
$metadata->set($m[1], $m[2]);
|
2014-12-01 07:57:57 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-30 04:59:27 -05:00
|
|
|
/**
|
2016-11-23 07:53:47 -05:00
|
|
|
* @param BusinessProcess $process
|
2016-11-26 15:18:18 -05:00
|
|
|
*
|
|
|
|
|
* @return void
|
2014-11-30 04:59:27 -05:00
|
|
|
*/
|
2015-03-02 12:23:19 -05:00
|
|
|
public function storeProcess(BusinessProcess $process)
|
2014-11-30 04:59:27 -05:00
|
|
|
{
|
2015-03-02 12:23:19 -05:00
|
|
|
file_put_contents(
|
2016-12-09 03:58:00 -05:00
|
|
|
$this->getFilename($process->getName()),
|
|
|
|
|
$this->render($process)
|
2015-03-02 12:23:19 -05:00
|
|
|
);
|
2014-11-30 04:59:27 -05:00
|
|
|
}
|
|
|
|
|
|
2016-12-09 03:58:00 -05:00
|
|
|
public function render(BusinessProcess $process)
|
|
|
|
|
{
|
|
|
|
|
return $this->renderHeader($process)
|
|
|
|
|
. $this->renderNodes($process);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function renderHeader(BusinessProcess $process)
|
|
|
|
|
{
|
|
|
|
|
$conf = "### Business Process Config File ###\n#\n";
|
|
|
|
|
|
|
|
|
|
$meta = $process->getMetadata();
|
|
|
|
|
foreach ($meta->getProperties() as $key => $value) {
|
|
|
|
|
if ($value === null) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$conf .= sprintf("# %-11s : %s\n", $key, $value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$conf .= "#\n###################################\n\n";
|
|
|
|
|
|
|
|
|
|
return $conf;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function renderNodes(BusinessProcess $bp)
|
|
|
|
|
{
|
|
|
|
|
$rendered = array();
|
|
|
|
|
$conf = '';
|
|
|
|
|
|
2016-12-09 08:11:56 -05:00
|
|
|
foreach ($bp->getRootNodes() as $child) {
|
2016-12-09 03:58:00 -05:00
|
|
|
$conf .= $child->toLegacyConfigString($rendered);
|
|
|
|
|
$rendered[$child->getName()] = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ($bp->getUnboundNodes() as $name => $node) {
|
|
|
|
|
$conf .= $node->toLegacyConfigString($rendered);
|
|
|
|
|
$rendered[$name] = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $conf . "\n";
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-16 04:08:00 -04:00
|
|
|
public function getSource($name)
|
|
|
|
|
{
|
|
|
|
|
return file_get_contents($this->getFilename($name));
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-12 19:57:12 -05:00
|
|
|
public function getFilename($name)
|
|
|
|
|
{
|
|
|
|
|
return $this->getConfigDir() . '/' . $name . '.conf';
|
|
|
|
|
}
|
2014-11-30 04:59:27 -05:00
|
|
|
|
2015-03-03 05:44:19 -05:00
|
|
|
public function loadFromString($name, $string)
|
|
|
|
|
{
|
|
|
|
|
$bp = new BusinessProcess();
|
|
|
|
|
$bp->setName($name);
|
|
|
|
|
$this->parseString($string, $bp);
|
2016-12-09 08:03:49 -05:00
|
|
|
$this->readHeaderString($string, $bp->getMetadata());
|
2015-03-03 05:44:19 -05:00
|
|
|
return $bp;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-23 04:44:24 -05:00
|
|
|
/**
|
|
|
|
|
* @inheritdoc
|
|
|
|
|
*/
|
2015-03-16 04:08:00 -04:00
|
|
|
public function deleteProcess($name)
|
|
|
|
|
{
|
2016-11-23 04:44:24 -05:00
|
|
|
return @unlink($this->getFilename($name));
|
2015-03-16 04:08:00 -04:00
|
|
|
}
|
|
|
|
|
|
2015-03-03 05:44:19 -05:00
|
|
|
/**
|
|
|
|
|
* @return BusinessProcess
|
|
|
|
|
*/
|
|
|
|
|
public function loadProcess($name)
|
2014-11-30 04:59:27 -05:00
|
|
|
{
|
2015-03-16 04:08:00 -04:00
|
|
|
Benchmark::measure('Loading business process ' . $name);
|
2014-11-30 04:59:27 -05:00
|
|
|
$bp = new BusinessProcess();
|
2014-12-02 05:35:50 -05:00
|
|
|
$bp->setName($name);
|
2015-03-03 05:44:19 -05:00
|
|
|
$this->parseFile($name, $bp);
|
|
|
|
|
$this->loadHeader($name, $bp);
|
2015-03-16 04:08:00 -04:00
|
|
|
Benchmark::measure('Business process ' . $name . ' loaded');
|
2015-03-03 05:44:19 -05:00
|
|
|
return $bp;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-23 07:53:47 -05:00
|
|
|
/**
|
|
|
|
|
* @param $name
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
2015-11-22 18:43:17 -05:00
|
|
|
public function hasProcess($name)
|
|
|
|
|
{
|
|
|
|
|
$file = $this->getFilename($name);
|
|
|
|
|
if (! is_file($file)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-09 08:03:49 -05:00
|
|
|
return $this->loadMetadata($name)->canRead();
|
2016-12-09 03:58:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function loadMetadata($name)
|
|
|
|
|
{
|
2016-12-09 08:03:49 -05:00
|
|
|
$metadata = new Metadata($name);
|
|
|
|
|
return $this->readHeader($this->getFilename($name), $metadata);
|
2015-11-22 18:43:17 -05:00
|
|
|
}
|
|
|
|
|
|
2016-11-23 07:53:47 -05:00
|
|
|
/**
|
|
|
|
|
* @param string $name
|
|
|
|
|
* @param BusinessProcess $bp
|
|
|
|
|
*/
|
2015-03-03 05:44:19 -05:00
|
|
|
protected function loadHeader($name, $bp)
|
|
|
|
|
{
|
|
|
|
|
// TODO: do not open twice, this is quick and dirty based on existing code
|
|
|
|
|
$file = $this->currentFilename = $this->getFilename($name);
|
2016-12-09 08:03:49 -05:00
|
|
|
$this->readHeader($file, $bp->getMetadata());
|
2015-03-03 05:44:19 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function parseFile($name, $bp)
|
|
|
|
|
{
|
|
|
|
|
$file = $this->currentFilename = $this->getFilename($name);
|
2014-11-30 04:59:27 -05:00
|
|
|
$fh = @fopen($file, 'r');
|
|
|
|
|
if (! $fh) {
|
2015-10-01 16:38:43 -04:00
|
|
|
throw new SystemPermissionException('Could not open "%s"', $file);
|
2014-11-30 04:59:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->parsing_line_number = 0;
|
|
|
|
|
while ($line = fgets($fh)) {
|
2015-03-03 05:44:19 -05:00
|
|
|
$this->parseLine($line, $bp);
|
|
|
|
|
}
|
2014-11-30 04:59:27 -05:00
|
|
|
|
2015-03-03 05:44:19 -05:00
|
|
|
fclose($fh);
|
|
|
|
|
unset($this->parsing_line_number);
|
|
|
|
|
unset($this->currentFilename);
|
|
|
|
|
}
|
2014-11-30 04:59:27 -05:00
|
|
|
|
2016-12-09 03:58:00 -05:00
|
|
|
protected function parseString($string, BusinessProcess $bp)
|
2015-03-03 05:44:19 -05:00
|
|
|
{
|
|
|
|
|
foreach (preg_split('/\n/', $string) as $line) {
|
|
|
|
|
$this->parseLine($line, $bp);
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-11-30 04:59:27 -05:00
|
|
|
|
2016-12-09 03:58:00 -05:00
|
|
|
/**
|
|
|
|
|
* @param $line
|
|
|
|
|
* @param BusinessProcess $bp
|
|
|
|
|
*/
|
|
|
|
|
protected function parseDisplay(& $line, BusinessProcess $bp)
|
2015-03-03 05:44:19 -05:00
|
|
|
{
|
2016-12-09 03:58:00 -05:00
|
|
|
list($display, $name, $desc) = preg_split('~\s*;\s*~', substr($line, 8), 3);
|
|
|
|
|
$bp->getNode($name)->setAlias($desc)->setDisplay($display);
|
|
|
|
|
if ($display > 0) {
|
|
|
|
|
$bp->addRootNode($name);
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-11-30 04:59:27 -05:00
|
|
|
|
2016-12-09 03:58:00 -05:00
|
|
|
protected function parseExternalInfo(& $line, BusinessProcess $bp)
|
|
|
|
|
{
|
|
|
|
|
list($name, $script) = preg_split('~\s*;\s*~', substr($line, 14), 2);
|
|
|
|
|
$bp->getNode($name)->setInfoCommand($script);
|
|
|
|
|
}
|
2014-11-30 04:59:27 -05:00
|
|
|
|
2016-12-09 03:58:00 -05:00
|
|
|
protected function parseExtraInfo(& $line, BusinessProcess $bp)
|
|
|
|
|
{
|
|
|
|
|
// TODO: Not yet
|
|
|
|
|
// list($name, $script) = preg_split('~\s*;\s*~', substr($line, 14), 2);
|
|
|
|
|
// $this->getNode($name)->setExtraInfo($script);
|
|
|
|
|
}
|
2014-11-30 04:59:27 -05:00
|
|
|
|
2016-12-09 03:58:00 -05:00
|
|
|
protected function parseInfoUrl(& $line, BusinessProcess $bp)
|
|
|
|
|
{
|
|
|
|
|
list($name, $url) = preg_split('~\s*;\s*~', substr($line, 9), 2);
|
|
|
|
|
$bp->getNode($name)->setInfoUrl($url);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function parseExtraLine(& $line, $typeLength, BusinessProcess $bp)
|
|
|
|
|
{
|
|
|
|
|
$type = substr($line, 0, $typeLength);
|
|
|
|
|
if (substr($type, 0, 7) === 'display') {
|
|
|
|
|
$this->parseDisplay($line, $bp);
|
|
|
|
|
return true;
|
2015-03-03 05:44:19 -05:00
|
|
|
}
|
2014-11-30 04:59:27 -05:00
|
|
|
|
2016-12-09 03:58:00 -05:00
|
|
|
switch ($type) {
|
|
|
|
|
case 'external_info':
|
|
|
|
|
$this->parseExternalInfo($line, $bp);
|
|
|
|
|
break;
|
|
|
|
|
case 'extra_info':
|
|
|
|
|
$this->parseExtraInfo($line, $bp);
|
|
|
|
|
break;
|
|
|
|
|
case 'info_url':
|
|
|
|
|
$this->parseInfoUrl($line, $bp);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return false;
|
2015-03-03 05:44:19 -05:00
|
|
|
}
|
2014-11-30 04:59:27 -05:00
|
|
|
|
2016-12-09 03:58:00 -05:00
|
|
|
return true;
|
|
|
|
|
}
|
2014-11-30 04:59:27 -05:00
|
|
|
|
2016-12-09 03:58:00 -05:00
|
|
|
/**
|
|
|
|
|
* Parses a single line
|
|
|
|
|
*
|
|
|
|
|
* Adds eventual new knowledge to the given Business Process config
|
|
|
|
|
*
|
|
|
|
|
* @param $line
|
|
|
|
|
* @param $bp
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
protected function parseLine(& $line, BusinessProcess $bp)
|
|
|
|
|
{
|
|
|
|
|
$line = trim($line);
|
|
|
|
|
|
|
|
|
|
$this->parsing_line_number++;
|
|
|
|
|
|
|
|
|
|
// Skip empty or comment-only lines
|
|
|
|
|
if (empty($line) || $line[0] === '#') {
|
2015-03-03 05:44:19 -05:00
|
|
|
return;
|
|
|
|
|
}
|
2015-09-11 08:05:08 -04:00
|
|
|
|
2016-12-09 03:58:00 -05:00
|
|
|
// Semicolon found in the first 14 cols? Might be a line with extra information
|
|
|
|
|
$pos = strpos($line, ';');
|
|
|
|
|
if ($pos !== false && $pos < 14) {
|
|
|
|
|
if ($this->parseExtraLine($line, $pos, $bp)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-03 05:44:19 -05:00
|
|
|
list($name, $value) = preg_split('~\s*=\s*~', $line, 2);
|
2014-11-30 04:59:27 -05:00
|
|
|
|
2015-03-03 05:44:19 -05:00
|
|
|
if (strpos($name, ';') !== false) {
|
|
|
|
|
$this->parseError('No semicolon allowed in varname');
|
|
|
|
|
}
|
2015-01-28 13:59:10 -05:00
|
|
|
|
2015-03-03 05:44:19 -05:00
|
|
|
$op = '&';
|
2015-10-05 10:42:04 -04:00
|
|
|
if (preg_match_all('~([\|\+&\!])~', $value, $m)) {
|
2015-03-03 05:44:19 -05:00
|
|
|
$op = implode('', $m[1]);
|
|
|
|
|
for ($i = 1; $i < strlen($op); $i++) {
|
|
|
|
|
if ($op[$i] !== $op[$i - 1]) {
|
|
|
|
|
$this->parseError('Mixing operators is not allowed');
|
2015-02-12 19:57:12 -05:00
|
|
|
}
|
2014-11-30 04:59:27 -05:00
|
|
|
}
|
2015-03-03 05:44:19 -05:00
|
|
|
}
|
|
|
|
|
$op = $op[0];
|
|
|
|
|
$op_name = $op;
|
2015-01-28 13:59:10 -05:00
|
|
|
|
2015-03-03 05:44:19 -05:00
|
|
|
if ($op === '+') {
|
2016-11-23 05:13:29 -05:00
|
|
|
if (! preg_match('~^(\d+)(?::(\d+))?\s*of:\s*(.+?)$~', $value, $m)) {
|
2015-03-03 05:44:19 -05:00
|
|
|
$this->parseError('syntax: <var> = <num> of: <var1> + <var2> [+ <varn>]*');
|
|
|
|
|
}
|
|
|
|
|
$op_name = $m[1];
|
2016-11-23 05:13:29 -05:00
|
|
|
// New feature: $minWarn = $m[2];
|
|
|
|
|
$value = $m[3];
|
2014-11-30 04:59:27 -05:00
|
|
|
}
|
2015-10-05 10:37:10 -04:00
|
|
|
$cmps = preg_split('~\s*\\' . $op . '\s*~', $value, -1, PREG_SPLIT_NO_EMPTY);
|
2015-11-22 18:46:18 -05:00
|
|
|
$childNames = array();
|
2014-11-30 04:59:27 -05:00
|
|
|
|
2015-11-22 18:46:18 -05:00
|
|
|
foreach ($cmps as $val) {
|
2015-03-03 05:44:19 -05:00
|
|
|
if (strpos($val, ';') !== false) {
|
2016-11-23 05:13:29 -05:00
|
|
|
if ($bp->hasNode($val)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2015-02-06 18:22:52 -05:00
|
|
|
|
2015-03-03 05:44:19 -05:00
|
|
|
list($host, $service) = preg_split('~;~', $val, 2);
|
|
|
|
|
if ($service === 'Hoststatus') {
|
|
|
|
|
$bp->createHost($host);
|
|
|
|
|
} else {
|
|
|
|
|
$bp->createService($host, $service);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ($val[0] === '@' && strpos($val, ':') !== false) {
|
|
|
|
|
list($config, $nodeName) = preg_split('~:\s*~', substr($val, 1), 2);
|
|
|
|
|
$bp->createImportedNode($config, $nodeName);
|
|
|
|
|
$val = $nodeName;
|
|
|
|
|
}
|
2015-11-22 18:46:18 -05:00
|
|
|
|
|
|
|
|
$childNames[] = $val;
|
2015-02-06 18:49:32 -05:00
|
|
|
}
|
2015-02-06 18:22:52 -05:00
|
|
|
|
2015-03-03 05:44:19 -05:00
|
|
|
$node = new BpNode($bp, (object) array(
|
|
|
|
|
'name' => $name,
|
|
|
|
|
'operator' => $op_name,
|
2015-11-22 18:46:18 -05:00
|
|
|
'child_names' => $childNames
|
2015-03-03 05:44:19 -05:00
|
|
|
));
|
2015-11-22 18:46:18 -05:00
|
|
|
|
2015-03-03 05:44:19 -05:00
|
|
|
$bp->addNode($name, $node);
|
2014-11-30 04:59:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function parseError($msg)
|
|
|
|
|
{
|
2015-02-12 19:57:12 -05:00
|
|
|
throw new ConfigurationError(
|
2014-11-30 04:59:27 -05:00
|
|
|
sprintf(
|
|
|
|
|
'Parse error on %s:%s: %s',
|
2015-02-12 19:57:12 -05:00
|
|
|
$this->currentFilename,
|
2014-11-30 04:59:27 -05:00
|
|
|
$this->parsing_line_number,
|
|
|
|
|
$msg
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|