Allows GEO lookup with detailed internal Location information wrapped inside parentheses. (#14799)

* Ignore everyting inside () during GEO lookup

I location info is: "1100 Congress Ave, Austin, TX 78701 (3rd floor meeting room)" then the GEO locator will look up "1100 Congress Ave, Austin, TX 78701"

* update info

* small typo

* typo fix

* getting verify

* style fix

* commitment issues

* updating wiki

* tweaking the document format

* more tweaks

* Im starting to hate md

* cleanup
This commit is contained in:
Skylark 2023-03-19 03:07:52 +00:00 committed by GitHub
parent 7ccccdf914
commit 473a7d360b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 43 additions and 2 deletions

View File

@ -45,6 +45,7 @@ class Location extends Model
protected $casts = ['lat' => 'float', 'lng' => 'float', 'fixed_coordinates' => 'bool'];
private $location_regex = '/\[\s*(?<lat>[-+]?(?:[1-8]?\d(?:\.\d+)?|90(?:\.0+)?))\s*,\s*(?<lng>[-+]?(?:180(?:\.0+)?|(?:(?:1[0-7]\d)|(?:[1-9]?\d))(?:\.\d+)?))\s*\]/';
private $location_ignore_regex = '/\(.*?\)/';
// ---- Helper Functions ----
@ -127,7 +128,9 @@ class Location extends Model
try {
/** @var \LibreNMS\Interfaces\Geocoder $api */
$api = app(\LibreNMS\Interfaces\Geocoder::class);
$this->fill($api->getCoordinates($this->location));
// Removes Location info inside () when looking up lat/lng
$this->fill($api->getCoordinates(preg_replace($this->location_ignore_regex, '', $this->location)));
return true;
} catch (BindingResolutionException $e) {

View File

@ -28,8 +28,9 @@ Example:
or
```
1100 Congress Ave, Austin, TX 78701
1100 Congress Ave, Austin, TX 78701 (3rd floor cabinet)
```
*Information inside parentheses is ignored during GEO lookup*
We have two current mapping engines available:

View File

@ -752,6 +752,38 @@ Please refer to [Smokeping](../Extensions/Smokeping.md)
Please refer to [NFSen](../Extensions/NFSen.md)
### Location parsing
LibreNMS can interpret sysLocation information and map the device loction based on GeoCoordinates or GeoCoding information.
- Info-keywords
- `[]` contains optional Latitude and Longitude information if manual GeoCoordinate positioning is desired.
- `()` contains optional information that is ignored during GeoCoding lookups.
#### **GeoCoordinates**
If device sysLocation information contains [lat, lng] (note the comma and square brackets), that is used to determin the GeoCoordinates.
Example:
```bash
name_that_can_not_be_looked_up [40.424521, -86.912755]
```
#### **GeoCoding**
Next it will attempt to look up the sysLocation with a map engine provided you have configured one under $config['geoloc']['engine']. The information has to be accurate or no result is returned, when it does it will ignore any information inside parentheses, allowing you to add details that would otherwise interfeeer with the lookup.
Example:
```bash
1100 Congress Ave, Austin, TX 78701 (3rd floor)
Geocoding lookup is:
1100 Congress Ave, Austin, TX 78701
```
#### **Overrides**
1. You can overwrite each device sysLocation information in the webGUI under "Device settings".
2. You can overwrite the location coordinates n in the webGUI under Device>GEO Locations
### Location mapping
If you just want to set GPS coordinates on a location, you should

View File

@ -7940,6 +7940,11 @@ parameters:
count: 1
path: app/Models/Location.php
-
message: "#^Property App\\\\Models\\\\Location\\:\\:\\$location_ignore_regex has no type specified\\.$#"
count: 1
path: app/Models/Location.php
-
message: "#^Method App\\\\Models\\\\Mempool\\:\\:calculateTotal\\(\\) has no return type specified\\.$#"
count: 1