Huge change, getting rid of legacy assignment...

...code. All objects should work with the new code base right now
This commit is contained in:
Thomas Gelf 2016-10-24 03:41:37 +00:00
parent 3ff6fd5211
commit 0d86c24cd8
16 changed files with 178 additions and 618 deletions

View File

@ -2,6 +2,7 @@
namespace Icinga\Module\Director\Forms;
use Icinga\Module\Director\Objects\IcingaHost;
use Icinga\Module\Director\Web\Form\DirectorObjectForm;
class IcingaHostGroupForm extends DirectorObjectForm
@ -23,12 +24,14 @@ class IcingaHostGroupForm extends DirectorObjectForm
protected function addAssignmentElements()
{
$sub = new AssignListSubForm();
$sub->setObject($this->object());
$sub->setup();
$sub->setOrder(30);
$this->addSubForm($sub, 'assignlist');
$this->addAssignFilter(array(
'columns' => IcingaHost::enumProperties($this->db, 'host.'),
'required' => true,
'description' => $this->translate(
'This allows you to configure an assignment filter. Please feel'
. ' free to combine as many nested operators as you want'
)
));
return $this;
}

View File

@ -2,6 +2,8 @@
namespace Icinga\Module\Director\Forms;
use Icinga\Module\Director\Objects\IcingaHost;
use Icinga\Module\Director\Objects\IcingaService;
use Icinga\Module\Director\Web\Form\DirectorObjectForm;
class IcingaNotificationForm extends DirectorObjectForm
@ -41,31 +43,40 @@ class IcingaNotificationForm extends DirectorObjectForm
return $this;
}
$this->addElement(
'select',
'apply_to',
array(
'label' => $this->translate('Apply to'),
'description' => $this->translate(
'Whether this notification should affect hosts or services'
),
'required' => true,
'multiOptions' => $this->optionalEnum(
array(
'host' => $this->translate('Hosts'),
'service' => $this->translate('Services'),
)
$this->addElement('select', 'apply_to', array(
'label' => $this->translate('Apply to'),
'description' => $this->translate(
'Whether this notification should affect hosts or services'
),
'required' => true,
'class' => 'autosubmit',
'multiOptions' => $this->optionalEnum(
array(
'host' => $this->translate('Hosts'),
'service' => $this->translate('Services'),
)
)
);
));
$sub = new AssignListSubForm();
$sub->setObject($this->getObject());
$sub->setup();
$sub->setOrder(30);
$applyTo = $this->getSentOrObjectValue('apply_to');
$this->addSubForm($sub, 'assignlist');
if ($applyTo === 'host') {
$columns = IcingaHost::enumProperties($this->db, 'host.');
} elseif ($applyTo === 'service') {
// TODO: Also add host properties
$columns = IcingaService::enumProperties($this->db, 'service.');
} else {
return $this;
}
$this->addAssignFilter(array(
'columns' => $columns,
'required' => true,
'description' => $this->translate(
'This allows you to configure an assignment filter. Please feel'
. ' free to combine as many nested operators as you want'
)
));
return $this;
}

View File

@ -157,37 +157,14 @@ class IcingaServiceForm extends DirectorObjectForm
protected function addAssignmentElements()
{
if (!$this->object || !$this->object->isApplyRule()) {
return $this;
}
$this->addElement('dataFilter', 'assign_filter', array(
'columns' => IcingaHost::enumProperties($this->db),
$this->addAssignFilter(array(
'columns' => IcingaHost::enumProperties($this->db, 'host.'),
'required' => true,
'description' => $this->translate(
'This allows you to configure an assignment filter. Please feel'
. ' free to combine as many nested operators as you want'
)
));
$el = $this->getElement('assign_filter');
$el->clearDecorators()
->addDecorator('ViewHelper')
->addDecorator('Errors')
->addDecorator('Description', array('tag' => 'p', 'class' => 'description'))
->addDecorator('HtmlTag', array(
'tag' => 'dd',
'class' => 'full-width required',
));
$this->addDisplayGroup(array($el), 'assign', array(
'decorators' => array(
'FormElements',
array('HtmlTag', array('tag' => 'dl')),
'Fieldset',
),
'order' => 30,
'legend' => $this->translate('Assign where')
));
return $this;
}

View File

@ -47,7 +47,7 @@ class IcingaNotificationTable extends IcingaObjectTable
$htm .= ' ' . $v->qlink(
'Create apply-rule',
'director/notification/add',
array('apply' => $row->notification),
array('apply' => $row->notification, 'type' => 'apply'),
array('class' => 'icon-plus')
);
@ -72,23 +72,12 @@ class IcingaNotificationTable extends IcingaObjectTable
protected function appliedOnes($id)
{
if ($this->connection()->isPgsql()) {
$nameCol = "s.object_name || COALESCE(': ' || ARRAY_TO_STRING(ARRAY_AGG("
. "a.assign_type || ' where ' || a.filter_string"
. " ORDER BY a.assign_type, a.filter_string), ', '), '')";
} else {
$nameCol = "s.object_name || COALESCE(': ' || GROUP_CONCAT("
. "a.assign_type || ' where ' || a.filter_string"
. " ORDER BY a.assign_type, a.filter_string SEPARATOR ', '"
. "), '')";
}
$db = $this->connection()->getConnection();
$query = $db->select()->from(
array('s' => 'icinga_notification'),
array(
'id' => 's.id',
'objectname' => $nameCol,
'objectname' => 's.object_name',
)
)->join(
array('i' => 'icinga_notification_inheritance'),
@ -97,11 +86,6 @@ class IcingaNotificationTable extends IcingaObjectTable
)->where('i.parent_notification_id = ?', $id)
->where('s.object_type = ?', 'apply');
$query->joinLeft(
array('a' => 'icinga_notification_assignment'),
'a.notification_id = s.id',
array()
)->group('s.id');
return $db->fetchPairs($query);
}

View File

@ -25,6 +25,7 @@ class IcingaNotification extends IcingaObject
'notification_interval' => null,
'period_id' => null,
'zone_id' => null,
'assign_filter' => null,
);
protected $supportsCustomVars = true;

View File

@ -386,6 +386,33 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
return $this->supportsSets;
}
/**
* @codingStandardsIgnoreStart
*/
public function setAssign_filter($filter)
{
if (! $this->supportsAssignments()) {
if ($this->hasProperty('object_type')) {
$type = $this->object_type;
} else {
$type = get_class($this);
}
throw new ProgrammingError(
'I can only assign for applied objects or objects with native'
. ' support for assigments, got %s',
$type
);
}
// @codingStandardsIgnoreEnd
if ($filter instanceof Filter) {
$filter = $filter->toQueryString();
}
return $this->reallySet('assign_filter', $filter);
}
/**
* It sometimes makes sense to defer lookups for related properties. This
* kind of lazy-loading allows us to for example set host = 'localhost' and
@ -441,10 +468,6 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
return true;
}
if ($this->supportsAssignments() && $this->assignments !== null && $this->assignments()->hasBeenModified()) {
return true;
}
foreach ($this->loadedRelatedSets as $set) {
if ($set->hasBeenModified()) {
return true;
@ -627,21 +650,6 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
return $this->arguments()->toPlainObject();
}
protected function setAssignments($value)
{
$this->assignments()->setValues($value);
return $this;
}
public function assignments()
{
if ($this->assignments === null) {
$this->assignments = new IcingaObjectAssignments($this);
}
return $this->assignments;
}
protected function getRanges()
{
return $this->ranges()->getValues();
@ -1214,11 +1222,6 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
return $fields;
}
protected function getAssignments()
{
return $this->assignments()->getValues();
}
public function hasProperty($key)
{
if ($this->propertyIsRelatedSet($key)) {
@ -1265,8 +1268,7 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
->storeImports()
->storeRanges()
->storeRelatedSets()
->storeArguments()
->storeAssignments();
->storeArguments();
}
protected function beforeStore()
@ -1331,15 +1333,6 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
return $this;
}
protected function storeAssignments()
{
if ($this->supportsAssignments()) {
$this->assignments !== null && $this->assignments()->store();
}
return $this;
}
protected function storeRelatedSets()
{
foreach ($this->loadedRelatedSets as $set) {
@ -1896,15 +1889,6 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
);
}
protected function renderAssignments()
{
if ($this->supportsAssignments()) {
return $this->assignments()->toConfigString();
} else {
return '';
}
}
protected function renderLegacyObjectHeader()
{
$type = strtolower($this->getType());
@ -1958,7 +1942,6 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
//$this->renderMultiRelations(),
//$this->renderCustomExtensions(),
//$this->renderCustomVars(),
//$this->renderAssignments(),
$this->renderLegacySuffix()
));
@ -2005,7 +1988,6 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
$this->renderMultiRelations(),
$this->renderCustomExtensions(),
$this->renderCustomVars(),
$this->renderAssignments(),
$this->renderSuffix()
));
@ -2247,10 +2229,6 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
);
}
if ($this->supportsAssignments()) {
$props['assignments'] = $this->assignments()->getPlain();
}
if ($this->supportsCustomVars()) {
if ($resolved) {
$props['vars'] = $this->getResolvedVars();
@ -2426,10 +2404,6 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
}
}
if ($this->supportsAssignments()) {
$props['assignments'] = $this->assignments()->getUnmodifiedPlain();
}
foreach ($this->relatedSets() as $property => $set) {
if ($set->isEmpty()) {
continue;
@ -2477,7 +2451,6 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
unset($this->ranges);
unset($this->arguments);
parent::__destruct();
}
}

View File

@ -1,343 +0,0 @@
<?php
namespace Icinga\Module\Director\Objects;
use Icinga\Data\Filter\Filter;
use Icinga\Exception\IcingaException;
use Icinga\Exception\ProgrammingError;
use Icinga\Module\Director\IcingaConfig\AssignRenderer;
use Icinga\Module\Director\IcingaConfig\IcingaConfigHelper as c;
class IcingaObjectAssignments
{
protected $object;
protected $stored;
protected $current;
public function __construct(IcingaObject $object)
{
if (! $object->supportsAssignments()) {
if ($object->hasProperty('object_type')) {
$type = $object->object_type;
} else {
$type = get_class($object);
}
throw new ProgrammingError(
'I can only assign for applied objects, got %s',
$type
);
}
$this->object = $object;
}
public function store()
{
if ($this->hasBeenModified()) {
$this->reallyStore();
return true;
}
return false;
}
public function setValues($values)
{
if (is_string($values)) {
return $this->setValues(array($values));
}
if (is_object($values)) {
$values = (array) $values;
}
$this->current = array();
ksort($values);
foreach ($values as $type => $value) {
if (is_numeric($type)) {
$this->addRule($value);
} else {
if (is_string($value)) {
$this->addRule($value, $type);
continue;
}
foreach ($value as $key => $strings) {
$this->addRule($strings, $type);
}
}
}
return $this;
}
public function getFormValues()
{
$result = array();
foreach ($this->getCurrent() as $rule) {
$f = array(
'assign_type' => $rule['assign_type']
);
$filter = Filter::fromQueryString($rule['filter_string']);
if (!$filter->isExpression()) {
throw new IcingaException(
'We currently support only flat filters in our forms, got %',
(string) $filter
);
}
$f['property'] = $filter->getColumn();
$f['operator'] = $filter->getSign();
$f['expression'] = trim(stripcslashes($filter->getExpression()), '"');
$result[] = $f;
}
return $result;
}
public function setFormValues($values)
{
$rows = array();
foreach ($values as $key => $val) {
if (! is_numeric($key)) {
// Skip buttons or similar
continue;
}
if (!array_key_exists($val['assign_type'], $rows)) {
$rows[$val['assign_type']] = array();
}
if (array_key_exists('filter_string', $val)) {
$filter = $val['filter_string'];
if (! $filter->isEmpty()) {
$rows[$val['assign_type']][] = $filter;
}
continue;
}
if (empty($val['property'])) {
continue;
}
if (is_numeric($val['expression'])) {
$expression = $val['expression'];
} else {
$expression = '"' . addcslashes($val['expression'], '"') . '"';
}
$rows[$val['assign_type']][] = $this->rerenderFilter(
implode('', array(
$val['property'],
$val['operator'],
$expression,
))
);
}
return $this->setValues($rows);
}
protected function addRule($string, $type = 'assign')
{
if (is_array($string) && array_key_exists('assign_type', $string)) {
$type = $string['assign_type'];
$string = $string['filter_string'];
}
// TODO: validate
//echo "ADD RULE\n";
//var_dump($string);
//echo "ADD RULE END\n";
$this->current[] = array(
'assign_type' => $type,
'filter_string' => $string instanceof Filter ? $this->renderFilter($string) : $string
);
return $this;
}
public function getValues()
{
return $this->getCurrent();
}
public function getUnmodifiedValues()
{
return $this->getStored();
}
public function toConfigString()
{
return $this->renderRules($this->getCurrent());
}
public function toUnmodifiedConfigString()
{
return $this->renderRules($this->getStored());
}
protected function renderRules($rules)
{
if (empty($rules)) {
return '';
}
$filters = array();
foreach ($rules as $rule) {
$filters[] = AssignRenderer::forFilter(
Filter::fromQueryString($rule['filter_string'])
)->render($rule['assign_type']);
}
return "\n " . implode("\n ", $filters) . "\n";
}
public function getPlain()
{
if ($this->current === null) {
if (! $this->object->hasBeenLoadedFromDb()) {
return array();
}
$this->current = $this->getStored();
}
return $this->createPlain($this->current);
}
public function getUnmodifiedPlain()
{
if (! $this->object->hasBeenLoadedFromDb()) {
return array();
}
return $this->createPlain($this->getStored());
}
public function hasBeenModified()
{
if ($this->current === null) {
return false;
}
return json_encode($this->getCurrent()) !== json_encode($this->getStored());
}
protected function getCurrent()
{
if ($this->current === null) {
$this->current = $this->getStored();
}
return $this->current;
}
protected function getStored()
{
if ($this->stored === null) {
$this->stored = $this->loadFromDb();
}
return $this->stored;
}
protected function renderFilter(Filter $filter)
{
return rawurldecode($filter->toQueryString());
}
protected function rerenderFilter($string)
{
return $this->renderFilterFilter::fromQueryString($string);
}
protected function createPlain($dbRows)
{
$result = array();
foreach ($dbRows as $row) {
if (! array_key_exists($row['assign_type'], $result)) {
$result[$row['assign_type']] = array();
}
$result[$row['assign_type']][] = $row['filter_string'];
}
return $result;
}
protected function getDb()
{
return $this->object->getDb();
}
protected function loadFromDb()
{
$db = $this->getDb();
$object = $this->object;
$query = $db->select()->from(
$this->getTableName(),
array('assign_type', 'filter_string')
)->where($this->createWhere())->order('assign_type', 'filter_string');
$this->stored = array();
foreach ($db->fetchAll($query) as $row) {
$this->stored[] = (array) $row;
}
return $this->stored;
}
protected function createWhere()
{
return $this->getRelationColumn()
. ' = '
. $this->getObjectId();
}
protected function getObjectId()
{
return (int) $this->object->id;
}
protected function getRelationColumn()
{
return $this->object->getShortTableName() . '_id';
}
protected function getTableName()
{
return $this->object->getTableName() . '_assignment';
}
protected function reallyStore()
{
$db = $this->getDb();
$table = $this->getTableName();
$objectId = $this->object->id;
$relationCol = $this->getRelationColumn();
$db->delete($table, $this->createWhere());
foreach ($this->getCurrent() as $row) {
$data = (array) $row;
$data[$relationCol] = $objectId;
$db->insert($table, $data);
}
$this->stored = $this->current;
return $this;
}
}

View File

@ -9,11 +9,12 @@ abstract class IcingaObjectGroup extends IcingaObject
protected $supportsImports = true;
protected $defaultProperties = array(
'id' => null,
'object_name' => null,
'object_type' => null,
'disabled' => 'n',
'display_name' => null,
'id' => null,
'object_name' => null,
'object_type' => null,
'disabled' => 'n',
'display_name' => null,
'assign_filter' => null,
);
public function getRenderingZone(IcingaConfig $config = null)

View File

@ -118,19 +118,6 @@ class IcingaService extends IcingaObject
return $this->use_var_overrides === 'y';
}
/**
* @codingStandardsIgnoreStart
*/
public function setAssign_filter($filter)
{
// @codingStandardsIgnoreEnd
if ($filter instanceof Filter) {
$filter = $filter->toQueryString();
}
return $this->reallySet('assign_filter', $filter);
}
protected function setKey($key)
{
if (is_int($key)) {
@ -208,21 +195,6 @@ class IcingaService extends IcingaObject
return parent::renderObjectHeader();
}
protected function renderAssignments()
{
if (! $this->hasBeenAssignedToHostTemplate()) {
return parent::renderAssignments();
}
// TODO: use assignment renderer?
$filter = sprintf(
'assign where %s in host.templates',
c::renderString($this->host)
);
return "\n " . $filter . "\n";
}
protected function hasBeenAssignedToHostTemplate()
{
return $this->host_id && $this->getRelatedObject(
@ -253,18 +225,30 @@ class IcingaService extends IcingaObject
protected function renderCustomExtensions()
{
// A hand-crafted command endpoint overrides use_agent
$output = '';
if ($this->hasBeenAssignedToHostTemplate()) {
// TODO: use assignment renderer?
$filter = sprintf(
'assign where %s in host.templates',
c::renderString($this->host)
);
$output .= "\n " . $filter . "\n";
}
// A hand-crafted command endpoint overrides use_agent
if ($this->command_endpoint_id !== null) {
return '';
return $output;
}
// In case use_agent isn't defined, do nothing
// TODO: what if we inherit use_agent and override it with 'n'?
if ($this->use_agent !== 'y') {
return '';
return $output;
}
return c::renderKeyValue('command_endpoint', 'host_name');
return $output . c::renderKeyValue('command_endpoint', 'host_name');
}
/**

View File

@ -551,9 +551,6 @@ abstract class DirectorObjectForm extends QuickForm
$post = $this->getRequest()->getPost();
// ?? $this->populate($post);
if (array_key_exists('assignlist', $post)) {
$object->assignments()->setFormValues($post['assignlist']);
}
foreach ($post as $key => $value) {
$el = $this->getElement($key);
@ -564,10 +561,6 @@ abstract class DirectorObjectForm extends QuickForm
}
if ($object instanceof IcingaObject) {
if ($object->supportsAssignments()) {
$this->setElementValue('assignlist', $object->assignments()->getFormValues());
}
$this->handleProperties($object, $values);
$this->handleCustomVars($object, $post);
$this->handleRanges($object, $values);
@ -1136,6 +1129,71 @@ abstract class DirectorObjectForm extends QuickForm
return $this;
}
/**
* Add an assign_filter form element
*
* Forms should use this helper method for objects using the typical
* assign_filter column
*
* @param array $properties Form element properties
*
* @return self
*/
protected function addAssignFilter($properties)
{
if (!$this->object || !$this->object->supportsAssignments()) {
return $this;
}
$this->addFilterElement('assign_filter', $properties);
$el = $this->getElement('assign_filter');
$this->addDisplayGroup(array($el), 'assign', array(
'decorators' => array(
'FormElements',
array('HtmlTag', array('tag' => 'dl')),
'Fieldset',
),
'order' => 30,
'legend' => $this->translate('Assign where')
));
return $this;
}
/**
* Add a dataFilter element with fitting decorators
*
* TODO: Evaluate whether parts or all of this could be moved to the element
* class.
*
* @param string $name Element name
* @param array $properties Form element properties
*
* @return self
*/
protected function addFilterElement($name, $properties)
{
$this->addElement('dataFilter', $name, $properties);
$el = $this->getElement($name);
$ddClass = 'full-width';
if (array_key_exists('required', $properties) && $properties['required']) {
$ddClass .= ' required';
}
$el->clearDecorators()
->addDecorator('ViewHelper')
->addDecorator('Errors')
->addDecorator('Description', array('tag' => 'p', 'class' => 'description'))
->addDecorator('HtmlTag', array(
'tag' => 'dd',
'class' => $ddClass,
));
return $this;
}
protected function addEventFilterElements()
{
$this->addElement('extensibleSet', 'states', array(

View File

@ -47,9 +47,7 @@ class IcingaServiceTest extends BaseTestCase
{
$service = $this->service();
$service->object_type = 'apply';
$service->assignments = array(
'host.address="127.*"'
);
$service->assign_filter = 'host.address="127.*"';
}
/**
@ -58,9 +56,7 @@ class IcingaServiceTest extends BaseTestCase
public function testRefusesAssignRulesWhenNotBeingAnApply()
{
$service = $this->service();
$service->assignments = array(
'host.address=127.*'
);
$service->assign_filter = 'host.address=127.*';
}
public function testAcceptsAndRendersFlatAssignRules()
@ -76,10 +72,7 @@ class IcingaServiceTest extends BaseTestCase
// Service apply rule rendering requires access to settings:
$service->setConnection($db);
$service->object_type = 'apply';
$service->assignments = array(
'host.address="127.*"',
'host.vars.env="test"'
);
$service->assign_filter = 'host.address="127.*"|host.vars.env="test"';
$this->assertEquals(
$this->loadRendered('service1'),
@ -87,8 +80,8 @@ class IcingaServiceTest extends BaseTestCase
);
$this->assertEquals(
'host.address="127.*"',
$service->toPlainObject()->assignments['assign'][0]
'host.address="127.*"|host.vars.env="test"',
$service->assign_filter
);
}
@ -104,10 +97,7 @@ class IcingaServiceTest extends BaseTestCase
// Service apply rule rendering requires access to settings:
$service->setConnection($db);
$service->object_type = 'apply';
$service->assignments = array(
'host.address="127.*"',
'host.vars.env="test"'
);
$service->assign_filter = 'host.address="127.*"|host.vars.env="test"';
$this->assertEquals(
$this->loadRendered('service1'),
@ -115,8 +105,8 @@ class IcingaServiceTest extends BaseTestCase
);
$this->assertEquals(
'host.address="127.*"',
$service->toPlainObject()->assignments['assign'][0]
'host.address="127.*"|host.vars.env="test"',
$service->assign_filter = 'host.address="127.*"|host.vars.env="test"'
);
}
@ -130,10 +120,7 @@ class IcingaServiceTest extends BaseTestCase
$service = $this->service();
$service->object_type = 'apply';
$service->assignments = array(
'host.address="127.*"',
'host.vars.env="test"'
);
$service->assign_filter = 'host.address="127.*"|host.vars.env="test"';
$service->store($db);
@ -144,74 +131,8 @@ class IcingaServiceTest extends BaseTestCase
);
$this->assertEquals(
'host.address="127.*"',
$service->toPlainObject()->assignments['assign'][0]
);
$service->delete();
}
public function testStaysUnmodifiedWhenSameFiltersAreSetInDifferentWays()
{
if ($this->skipForMissingDb()) {
return;
}
$db = $this->getDb();
$service = $this->service();
$service->object_type = 'apply';
$service->assignments = 'host.address="127.*"';
$service->store($db);
$this->assertFalse($service->hasBeenModified());
$service->assignments = array(
'host.address="127.*"',
);
$this->assertFalse($service->hasBeenModified());
$service->assignments = 'host.address="128.*"';
$this->assertTrue($service->hasBeenModified());
$service->store();
$this->assertFalse($service->hasBeenModified());
$service->assignments = array('assign' => 'host.address="128.*"');
$this->assertFalse($service->hasBeenModified());
$service->assignments = array(
'assign' => array(
'host.address="128.*"'
)
);
$this->assertFalse($service->hasBeenModified());
$service->assignments = array(
'assign' => array(
'host.address="128.*"'
),
'ignore' => 'host.name="localhost"'
);
$this->assertTrue($service->hasBeenModified());
$service->store();
$service = IcingaService::loadWithAutoIncId($service->id, $db);
$this->assertEquals(
'host.address="128.*"',
$service->toPlainObject()->assignments['assign'][0]
);
$this->assertEquals(
'host.name="localhost"',
$service->toPlainObject()->assignments['ignore'][0]
);
$this->assertEquals(
$this->loadRendered('service2'),
(string) $service
'host.address="127.*"|host.vars.env="test"',
$service->assign_filter
);
$service->delete();
@ -247,9 +168,7 @@ class IcingaServiceTest extends BaseTestCase
$service->setConnection($db);
$service->object_type = 'apply';
$service->display_name = 'Service: $host.vars.replaced$';
$service->assignments = array(
'host.address="127.*"',
);
$service->assign_filter = 'host.address="127.*"';
$service->{'vars.custom_var'} = '$host.vars.replaced$';
$this->assertEquals(
@ -290,9 +209,7 @@ class IcingaServiceTest extends BaseTestCase
$service = $this->service()->setConnection($db);
$service->object_type = 'apply';
$service->apply_for = 'host.vars.test1';
$service->assignments = array(
'host.vars.env="test"'
);
$service->assign_filter = 'host.vars.env="test"';
$this->assertEquals(
$this->loadRendered('service5'),
(string) $service

View File

@ -1,5 +1,6 @@
apply Service "___TEST___service" {
display_name = "Whatever service"
assign where match("127.*", host.address) || host.vars.env == "test"
vars.test1 = "string"
vars.test2 = 17
vars.test3 = false
@ -8,9 +9,6 @@ apply Service "___TEST___service" {
@this = "is"
}
assign where match("127.*", host.address)
assign where host.vars.env == "test"
import DirectorOverrideTemplate
}

View File

@ -1,5 +1,6 @@
apply Service "___TEST___service_$not_replaced$" {
display_name = "Service: " + host.vars.replaced
assign where match("127.*", host.address)
vars.custom_var = host.vars.replaced
vars.test1 = "string"
vars.test2 = 17
@ -9,8 +10,6 @@ apply Service "___TEST___service_$not_replaced$" {
@this = "is"
}
assign where match("127.*", host.address)
import DirectorOverrideTemplate
}

View File

@ -1,5 +1,6 @@
apply Service "___TEST___service" for (config in host.vars.test1) {
display_name = "Whatever service"
assign where host.vars.env == "test"
vars.test1 = "string"
vars.test2 = 17
vars.test3 = false
@ -8,8 +9,6 @@ apply Service "___TEST___service" for (config in host.vars.test1) {
@this = "is"
}
assign where host.vars.env == "test"
import DirectorOverrideTemplate
}

View File

@ -1,6 +1,7 @@
apply Service for (config in host.vars.test1) {
name = "___TEST" + config + "___service " + host.var.bla
display_name = "Whatever service"
assign where host.vars.env == "test"
vars.test1 = "string"
vars.test2 = 17
vars.test3 = false
@ -9,8 +10,6 @@ apply Service for (config in host.vars.test1) {
@this = "is"
}
assign where host.vars.env == "test"
import DirectorOverrideTemplate
}

View File

@ -1,5 +1,6 @@
apply Service for (config in host.vars.test1) {
display_name = "Whatever service"
assign where host.vars.env == "test"
vars.test1 = "string"
vars.test2 = 17
vars.test3 = false
@ -8,8 +9,6 @@ apply Service for (config in host.vars.test1) {
@this = "is"
}
assign where host.vars.env == "test"
import DirectorOverrideTemplate
}