Skip to content

Commit

Permalink
Merge pull request #787 from Icinga/fix/migration-false-positives-786
Browse files Browse the repository at this point in the history
Fix migration false positives
  • Loading branch information
nilmerg authored Jun 26, 2023
2 parents 67fc7f5 + 75f6fa1 commit 64c83be
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions application/controllers/MigrateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function monitoringUrlAction()
$url = Url::fromPath($urlString);
if (UrlMigrator::isSupportedUrl($url)) {
try {
$urlString = UrlMigrator::transformUrl($url)->getAbsoluteUrl();
$urlString = rawurldecode(UrlMigrator::transformUrl($url)->getAbsoluteUrl());
} catch (Exception $e) {
$errors[$urlString] = [
IcingaException::describe($e),
Expand Down Expand Up @@ -108,7 +108,7 @@ public function searchUrlAction()
$url = Url::fromPath($urlString);
$filter = QueryString::parse($url->getQueryString());
$filter = $traverseFilter($filter) ?? $filter;
$result[] = $url->setQueryString(QueryString::render($filter))->getAbsoluteUrl();
$result[] = rawurldecode($url->setQueryString(QueryString::render($filter))->getAbsoluteUrl());
}

$response = $this->getResponse()->json();
Expand Down
16 changes: 16 additions & 0 deletions library/Icingadb/Compat/UrlMigrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ protected function rewrite(Filter\Rule $filter, array $legacyColumns, Filter\Cha
default:
$filter->setValue($exprRule);
}

$rewritten = $this->transformWildcardFilter($rewritten);
} elseif ($column === 'sort') {
$column = $filter->getValue();
if (isset($legacyColumns[$column])) {
Expand Down Expand Up @@ -178,6 +180,7 @@ protected function rewrite(Filter\Rule $filter, array $legacyColumns, Filter\Cha
return false;
} elseif (preg_match('/^_(host|service)_([\w.]+)/i', $column, $groups)) {
$rewritten = $filter->setColumn($groups[1] . '.vars.' . $groups[2]);
$rewritten = $this->transformWildcardFilter($rewritten);
}
} else {
/** @var Filter\Chain $filter */
Expand All @@ -198,6 +201,19 @@ protected function rewrite(Filter\Rule $filter, array $legacyColumns, Filter\Cha
return $rewritten;
}

private function transformWildcardFilter(Filter\Condition $filter)
{
if (is_string($filter->getValue()) && strpos($filter->getValue(), '*') !== false) {
if ($filter instanceof Filter\Equal) {
return Filter::like($filter->getColumn(), $filter->getValue());
} elseif ($filter instanceof Filter\Unequal) {
return Filter::unlike($filter->getColumn(), $filter->getValue());
}
}

return $filter;
}

protected static function commonColumns(): array
{
return [
Expand Down

0 comments on commit 64c83be

Please sign in to comment.