2016-11-29 09:06:38 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Icinga\Module\Businessprocess\Modification;
|
|
|
|
|
|
2017-01-11 08:04:45 -05:00
|
|
|
use Icinga\Module\Businessprocess\BpConfig;
|
2016-11-29 09:06:38 -05:00
|
|
|
|
|
|
|
|
class NodeAddChildrenAction extends NodeAction
|
|
|
|
|
{
|
|
|
|
|
protected $children = array();
|
|
|
|
|
|
|
|
|
|
protected $preserveProperties = array('children');
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @inheritdoc
|
|
|
|
|
*/
|
2017-01-11 11:36:32 -05:00
|
|
|
public function appliesTo(BpConfig $config)
|
2016-11-29 09:06:38 -05:00
|
|
|
{
|
|
|
|
|
$name = $this->getNodeName();
|
|
|
|
|
|
2019-01-14 08:57:16 -05:00
|
|
|
if (! $config->hasBpNode($name)) {
|
|
|
|
|
$this->error('Process "%s" not found', $name);
|
2016-11-29 09:06:38 -05:00
|
|
|
}
|
|
|
|
|
|
2019-01-14 08:57:16 -05:00
|
|
|
return true;
|
2016-11-29 09:06:38 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @inheritdoc
|
|
|
|
|
*/
|
2017-01-11 11:36:32 -05:00
|
|
|
public function applyTo(BpConfig $config)
|
2016-11-29 09:06:38 -05:00
|
|
|
{
|
2017-01-11 11:38:19 -05:00
|
|
|
$node = $config->getBpNode($this->getNodeName());
|
|
|
|
|
|
2016-11-29 09:06:38 -05:00
|
|
|
foreach ($this->children as $name) {
|
2019-02-22 08:30:06 -05:00
|
|
|
if (! $config->hasNode($name) || $config->getNode($name)->getBpConfig()->getName() !== $config->getName()) {
|
2017-01-11 11:38:19 -05:00
|
|
|
if (strpos($name, ';') !== false) {
|
2019-05-20 06:08:06 -04:00
|
|
|
if (strpos($name, ':') !== false) {
|
|
|
|
|
list($host, $service, $statesOverride) = preg_split('~[;:]~', $name, 3);
|
|
|
|
|
$config->createService($host, $service, $statesOverride);
|
2017-01-11 11:38:19 -05:00
|
|
|
} else {
|
2019-05-20 06:08:06 -04:00
|
|
|
list($host, $service) = preg_split('/;/', $name, 2);
|
|
|
|
|
|
|
|
|
|
if ($service === 'Hoststatus') {
|
|
|
|
|
$config->createHost($host);
|
|
|
|
|
} else {
|
|
|
|
|
$config->createService($host, $service);
|
|
|
|
|
}
|
2017-01-11 11:38:19 -05:00
|
|
|
}
|
2019-01-16 04:25:11 -05:00
|
|
|
} elseif ($name[0] === '@' && strpos($name, ':') !== false) {
|
|
|
|
|
list($configName, $nodeName) = preg_split('~:\s*~', substr($name, 1), 2);
|
|
|
|
|
$config->createImportedNode($configName, $nodeName);
|
2017-01-11 11:38:19 -05:00
|
|
|
}
|
2016-11-29 09:06:38 -05:00
|
|
|
}
|
2017-01-11 11:38:19 -05:00
|
|
|
$node->addChild($config->getNode($name));
|
2016-11-29 09:06:38 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param array|string $children
|
|
|
|
|
* @return $this
|
|
|
|
|
*/
|
|
|
|
|
public function setChildren($children)
|
|
|
|
|
{
|
|
|
|
|
if (is_string($children)) {
|
|
|
|
|
$children = array($children);
|
|
|
|
|
}
|
|
|
|
|
$this->children = $children;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function getChildren()
|
|
|
|
|
{
|
|
|
|
|
return $this->children;
|
|
|
|
|
}
|
|
|
|
|
}
|