feature Location map regex replace pattern only (#6485)

* Update core.inc.php

* Update rewrites.php

* Update rewrites.php

* Update rewrites.php

* Update Configuration.md

Adding "location_map_regex_sub" documentation

* Update Configuration.md

Better(?) example/explanation for location_map_regex_sub.
This commit is contained in:
Frank Mogaddedi 2017-04-24 15:06:22 -04:00 committed by Neil Lathwood
parent b2e6d8abef
commit dcc6c96ec4
3 changed files with 17 additions and 2 deletions

View File

@ -394,6 +394,12 @@ Regex Matching:
```php
$config['location_map_regex']['/Sink/'] = "Under The Sink, The Office, London, UK";
```
Regex Match Substitution:
```php
$config['location_map_regex_sub']['/Sink/'] = "Under The Sink, The Office, London, UK [lat, long]";
```
If you have an SNMP SysLocation of "Rack10,Rm-314,Sink", Regex Match Substition yields "Rack10,Rm-314,Under The Sink, The Office, London, UK [lat, long]". This allows you to keep the SysLocation string short and keeps Rack/Room/Building information intact after the substitution.
The above are examples, these will rewrite device snmp locations so you don't need to configure full location within snmp.
### Interfaces to be ignored

View File

@ -72,7 +72,7 @@ $poll_device['sysLocation'] = str_replace('"', '', $poll_device['sysLocation']);
$poll_device['sysLocation'] = trim($poll_device['sysLocation'], '\\');
// Rewrite sysLocation if there is a mapping array (database too?)
if (!empty($poll_device['sysLocation']) && (is_array($config['location_map']) || is_array($config['location_map_regex']))) {
if (!empty($poll_device['sysLocation']) && (is_array($config['location_map']) || is_array($config['location_map_regex']) || is_array($config['location_map_regex_sub']))) {
$poll_device['sysLocation'] = rewrite_location($poll_device['sysLocation']);
}

View File

@ -14,7 +14,16 @@ function rewrite_location($location)
}
}
}
if (is_array($config['location_map_regex_sub'])) {
foreach ($config['location_map_regex_sub'] as $reg => $val) {
if (preg_match($reg, $location)) {
$location = preg_replace($reg, $val, $location);
break;
}
}
}
if (isset($config['location_map'][$location])) {
$location = $config['location_map'][$location];
}