mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-09-25 10:57:41 +02:00
parent
5842e40fb6
commit
bff76dad8e
@ -103,15 +103,7 @@ class HostApplyMatches
|
|||||||
protected static function fixFilterColumns(Filter $filter)
|
protected static function fixFilterColumns(Filter $filter)
|
||||||
{
|
{
|
||||||
if ($filter->isExpression()) {
|
if ($filter->isExpression()) {
|
||||||
/** @var FilterExpression $filter */
|
static::fixFilterExpressionColumn($filter);
|
||||||
$col = $filter->getColumn();
|
|
||||||
if (substr($col, 0, 5) === 'host.') {
|
|
||||||
$filter->setColumn($col = substr($col, 5));
|
|
||||||
}
|
|
||||||
if (array_key_exists($col, self::$columnMap)) {
|
|
||||||
$filter->setColumn(self::$columnMap[$col]);
|
|
||||||
}
|
|
||||||
$filter->setExpression(json_decode($filter->getExpression()));
|
|
||||||
} else {
|
} else {
|
||||||
foreach ($filter->filters() as $sub) {
|
foreach ($filter->filters() as $sub) {
|
||||||
static::fixFilterColumns($sub);
|
static::fixFilterColumns($sub);
|
||||||
@ -119,6 +111,32 @@ class HostApplyMatches
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected static function fixFilterExpressionColumn(FilterExpression $filter)
|
||||||
|
{
|
||||||
|
if (static::columnIsJson($filter)) {
|
||||||
|
$column = $filter->getExpression();
|
||||||
|
$filter->setExpression($filter->getColumn());
|
||||||
|
$filter->setColumn($column);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var FilterExpression $filter */
|
||||||
|
$col = $filter->getColumn();
|
||||||
|
if (substr($col, 0, 5) === 'host.') {
|
||||||
|
$filter->setColumn($col = substr($col, 5));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (array_key_exists($col, self::$columnMap)) {
|
||||||
|
$filter->setColumn(self::$columnMap[$col]);
|
||||||
|
}
|
||||||
|
$filter->setExpression(json_decode($filter->getExpression()));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static function columnIsJson(FilterExpression $filter)
|
||||||
|
{
|
||||||
|
$col = $filter->getColumn();
|
||||||
|
return strlen($col) && $col[0] === '"';
|
||||||
|
}
|
||||||
|
|
||||||
protected static function flattenVars(& $object, $key = 'vars')
|
protected static function flattenVars(& $object, $key = 'vars')
|
||||||
{
|
{
|
||||||
if (property_exists($object, 'vars')) {
|
if (property_exists($object, 'vars')) {
|
||||||
|
@ -64,6 +64,21 @@ class HostApplyMatchesTest extends BaseTestCase
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testArrayVariableMatches()
|
||||||
|
{
|
||||||
|
$matcher = HostApplyMatches::prepare($this->sampleHost());
|
||||||
|
$this->assertTrue(
|
||||||
|
$matcher->matchesFilter(
|
||||||
|
Filter::fromQueryString('%22Amazing%22=host.vars.tags')
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$this->assertFalse(
|
||||||
|
$matcher->matchesFilter(
|
||||||
|
Filter::fromQueryString('%22Amazingg%22=host.vars.tags')
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
protected function sampleHost()
|
protected function sampleHost()
|
||||||
{
|
{
|
||||||
return IcingaHost::create(array(
|
return IcingaHost::create(array(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user