mirror of
https://github.com/Icinga/icingaweb2-module-graphite.git
synced 2026-05-28 04:34:57 -04:00
GraphiteQuery: allow to extract variable names
This commit is contained in:
parent
e07c78bca1
commit
4cb4bc63c7
1 changed files with 14 additions and 5 deletions
|
|
@ -14,6 +14,8 @@ class GraphiteQuery
|
|||
|
||||
protected $searchPattern;
|
||||
|
||||
protected $variablePattern = '/\$(\w+)/';
|
||||
|
||||
public function __construct(GraphiteWeb $web)
|
||||
{
|
||||
$this->web = $web;
|
||||
|
|
@ -112,15 +114,22 @@ class GraphiteQuery
|
|||
return $this->replaceRemainingVariables($this->search);
|
||||
}
|
||||
|
||||
public function extractVariableNames($pattern)
|
||||
{
|
||||
if (preg_match_all($this->variablePattern, $pattern, $m)) {
|
||||
return $m[1];
|
||||
}
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
protected function extractVars($string, $pattern)
|
||||
{
|
||||
$regexVar = '/\$(\w+)/';
|
||||
$vars = array();
|
||||
$varnames = $this->extractVariableNames($pattern);
|
||||
|
||||
if (preg_match_all($regexVar, $pattern, $m)) {
|
||||
$varnames = $m[1];
|
||||
|
||||
$parts = preg_split($regexVar, $pattern);
|
||||
if (! empty($varnames)) {
|
||||
$parts = preg_split($this->variablePattern, $pattern);
|
||||
foreach ($parts as $key => $val) {
|
||||
$parts[$key] = preg_quote($val, '/');
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue