mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Merge pull request #1998 from f0o/issue-1997
Add RegEx support to alert rules and device groups
This commit is contained in:
@ -66,7 +66,7 @@ __Conditions__ can be any of:
|
||||
__Values__ can be Entities or any single-quoted data.
|
||||
__Glues__ can be either `&&` for `AND` or `||` for `OR`.
|
||||
|
||||
__Note__: The difference between `Equals` and `Matches` (and it's negation) is that `Equals` does a strict comparison and `Matches` allows the usage of the placeholder `@`. The placeholder `@` is comparable with `.*` in RegExp.
|
||||
__Note__: The difference between `Equals` and `Matches` (and it's negation) is that `Equals` does a strict comparison and `Matches` allows the usage of RegExp.
|
||||
Arithmetics are allowed as well.
|
||||
|
||||
## <a name="rules-examples">Examples</a>
|
||||
|
@ -8,12 +8,12 @@ Patterns work in the same was as Entities within the alerting system, the format
|
||||
as __tablename.columnname__. If you are ensure of what the entity is you want then have a browse around inside MySQL using `show tables` and `desc <tablename>`.
|
||||
|
||||
As a working example and a common question, let's assume you want to group devices by hostname. If you hostname format is dcX.[devicetype].example.com. You would use the pattern
|
||||
devices.hostname. Select the condition which in this case would Like and then enter dc1.@.example.com. This would then match dc1.sw01.example.com, dc1.rtr01.example.com but not
|
||||
devices.hostname. Select the condition which in this case would Like and then enter `dc1\..*\.example.com`. This would then match dc1.sw01.example.com, dc1.rtr01.example.com but not
|
||||
dc2.sw01.example.com.
|
||||
|
||||
#### Wildcards
|
||||
|
||||
As used in the example above, wildcards are represented by the @ symbol. I.e @.example.com would match any hostnames under example.com.
|
||||
As with alerts, the `Like` operation allows RegExp.
|
||||
|
||||
A list of common entities is maintained in our [Alerting docs](http://docs.librenms.org/Extensions/Alerting/#entities).
|
||||
|
||||
|
@ -91,7 +91,7 @@ function GenSQL($rule) {
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
$sql = "SELECT * FROM ".implode(",",$tables)." WHERE (".$join."".str_replace("(","",$tables[0]).".device_id = ?) && (".str_replace(array("%","@","!~","~"),array("","%","NOT LIKE","LIKE"),$rule).")";
|
||||
$sql = "SELECT * FROM ".implode(",",$tables)." WHERE (".$join."".str_replace("(","",$tables[0]).".device_id = ?) && (".str_replace(array("%","@","!~","~"),array("",".*","NOT REGEXP","REGEXP"),$rule).")";
|
||||
return $sql;
|
||||
}
|
||||
|
||||
|
@ -63,7 +63,7 @@ function GenGroupSQL($pattern, $search='') {
|
||||
$search .= ' &&';
|
||||
}
|
||||
|
||||
$sql = 'SELECT DISTINCT('.str_replace('(', '', $tables[0]).'.device_id) FROM '.implode(',', $tables).' WHERE '.$search.' ('.str_replace(array('%', '@', '!~', '~'), array('', '%', 'NOT LIKE', 'LIKE'), $pattern).')';
|
||||
$sql = 'SELECT DISTINCT('.str_replace('(', '', $tables[0]).'.device_id) FROM '.implode(',', $tables).' WHERE '.$search.' ('.str_replace(array('%', '@', '!~', '~'), array('', '.*', 'NOT REGEXP', 'REGEXP'), $pattern).')';
|
||||
return $sql;
|
||||
|
||||
}//end GenGroupSQL()
|
||||
|
Reference in New Issue
Block a user