IcingaService: support and test speciall object...
...name variants with apply for
This commit is contained in:
parent
4c9de0fa34
commit
9ba6116091
|
@ -258,6 +258,11 @@ class IcingaConfigHelper
|
|||
return $seconds . 's';
|
||||
}
|
||||
|
||||
public static function stringHasMacro($string)
|
||||
{
|
||||
return preg_match('/(?<!\$)\$[\w\.]+\$(?!\$)/', $string);
|
||||
}
|
||||
|
||||
public static function renderStringWithVariables($string)
|
||||
{
|
||||
$string = preg_replace(
|
||||
|
|
|
@ -173,7 +173,12 @@ class IcingaService extends IcingaObject
|
|||
&& $this->get('apply_for') !== null) {
|
||||
|
||||
$name = $this->getObjectName();
|
||||
if ($name !== '') {
|
||||
$extraName = '';
|
||||
|
||||
if (c::stringHasMacro($name)) {
|
||||
$extraName = c::renderKeyValue('name', c::renderStringWithVariables($name));
|
||||
$name = '';
|
||||
} elseif ($name !== '') {
|
||||
$name = ' ' . c::renderString($name);
|
||||
}
|
||||
|
||||
|
@ -183,7 +188,7 @@ class IcingaService extends IcingaObject
|
|||
$this->getType(),
|
||||
$name,
|
||||
$this->get('apply_for')
|
||||
);
|
||||
) . $extraName;
|
||||
}
|
||||
return parent::renderObjectHeader();
|
||||
}
|
||||
|
|
|
@ -279,7 +279,7 @@ class IcingaServiceTest extends BaseTestCase
|
|||
);
|
||||
}
|
||||
|
||||
public function testApplyFor()
|
||||
public function testApplyForRendersInVariousModes()
|
||||
{
|
||||
if ($this->skipForMissingDb()) {
|
||||
return;
|
||||
|
@ -297,6 +297,18 @@ class IcingaServiceTest extends BaseTestCase
|
|||
$this->loadRendered('service5'),
|
||||
(string) $service
|
||||
);
|
||||
|
||||
$service->object_name = '___TEST$config$___service $host.var.bla$';
|
||||
$this->assertEquals(
|
||||
$this->loadRendered('service6'),
|
||||
(string) $service
|
||||
);
|
||||
|
||||
$service->object_name = '';
|
||||
$this->assertEquals(
|
||||
$this->loadRendered('service7'),
|
||||
(string) $service
|
||||
);
|
||||
}
|
||||
|
||||
protected function host()
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
apply Service for (config in host.vars.test1) {
|
||||
name = "___TEST" + config + "___service " + host.var.bla
|
||||
display_name = "Whatever service"
|
||||
vars.test1 = "string"
|
||||
vars.test2 = 17
|
||||
vars.test3 = false
|
||||
vars.test4 = {
|
||||
a = [ "dict", "ionary" ]
|
||||
@this = "is"
|
||||
}
|
||||
|
||||
assign where host.vars.env == "test"
|
||||
|
||||
import DirectorOverrideTemplate
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
apply Service for (config in host.vars.test1) {
|
||||
display_name = "Whatever service"
|
||||
vars.test1 = "string"
|
||||
vars.test2 = 17
|
||||
vars.test3 = false
|
||||
vars.test4 = {
|
||||
a = [ "dict", "ionary" ]
|
||||
@this = "is"
|
||||
}
|
||||
|
||||
assign where host.vars.env == "test"
|
||||
|
||||
import DirectorOverrideTemplate
|
||||
}
|
||||
|
Loading…
Reference in New Issue