diff --git a/app/Models/Location.php b/app/Models/Location.php index b9fb21eb17..b08d2e8397 100644 --- a/app/Models/Location.php +++ b/app/Models/Location.php @@ -45,6 +45,7 @@ class Location extends Model protected $casts = ['lat' => 'float', 'lng' => 'float', 'fixed_coordinates' => 'bool']; private $location_regex = '/\[\s*(?[-+]?(?:[1-8]?\d(?:\.\d+)?|90(?:\.0+)?))\s*,\s*(?[-+]?(?: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) { diff --git a/doc/Extensions/World-Map.md b/doc/Extensions/World-Map.md index a491778021..e7f6bbb3c3 100644 --- a/doc/Extensions/World-Map.md +++ b/doc/Extensions/World-Map.md @@ -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: diff --git a/doc/Support/Configuration.md b/doc/Support/Configuration.md index 91ef5ef9ba..0758af139c 100644 --- a/doc/Support/Configuration.md +++ b/doc/Support/Configuration.md @@ -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 diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 5e7e1f0d8f..aa995938e1 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -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