mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Added parsing support for lat/lng coords from device location
This commit is contained in:
@@ -122,17 +122,17 @@ var greenMarker = L.AwesomeMarkers.icon({
|
|||||||
// Checking user permissions
|
// Checking user permissions
|
||||||
if (is_admin() || is_read()) {
|
if (is_admin() || is_read()) {
|
||||||
// Admin or global read-only - show all devices
|
// Admin or global read-only - show all devices
|
||||||
$sql = "SELECT DISTINCT(`device_id`),`hostname`,`os`,`status`,`lat`,`lng` FROM `devices`
|
$sql = "SELECT DISTINCT(`device_id`),`devices`.`location`,`hostname`,`os`,`status`,`lat`,`lng` FROM `devices`
|
||||||
LEFT JOIN `locations` ON `devices`.`location`=`locations`.`location`
|
LEFT JOIN `locations` ON `devices`.`location`=`locations`.`location`
|
||||||
WHERE `disabled`=0 AND `ignore`=0 AND `lat` != '' AND `lng` != ''
|
WHERE `disabled`=0 AND `ignore`=0 AND ((`lat` != '' AND `lng` != '') OR (`devices`.`location` REGEXP '\[[0-9\.\, ]+\]'))
|
||||||
ORDER BY `status` ASC, `hostname`";
|
ORDER BY `status` ASC, `hostname`";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Normal user - grab devices that user has permissions to
|
// Normal user - grab devices that user has permissions to
|
||||||
$sql = "SELECT DISTINCT(`devices`.`device_id`) as `device_id`,`hostname`,`os`,`status`,`lat`,`lng`
|
$sql = "SELECT DISTINCT(`devices`.`device_id`) as `device_id`,`devices`.`location`,`hostname`,`os`,`status`,`lat`,`lng`
|
||||||
FROM `devices_perms`, `devices`
|
FROM `devices_perms`, `devices`
|
||||||
LEFT JOIN `locations` ON `devices`.`location`=`locations`.`location`
|
LEFT JOIN `locations` ON `devices`.`location`=`locations`.`location`
|
||||||
WHERE `disabled`=0 AND `ignore`=0 AND `lat` != '' AND `lng` != ''
|
WHERE `disabled`=0 AND `ignore`=0 AND ((`lat` != '' AND `lng` != '') OR (`devices`.`location` REGEXP '\[[0-9\.\, ]+\]'))
|
||||||
AND `devices`.`device_id` = `devices_perms`.`device_id`
|
AND `devices`.`device_id` = `devices_perms`.`device_id`
|
||||||
AND `devices_perms`.`user_id` = ?
|
AND `devices_perms`.`user_id` = ?
|
||||||
ORDER BY `status` ASC, `hostname`";
|
ORDER BY `status` ASC, `hostname`";
|
||||||
@@ -140,6 +140,11 @@ var greenMarker = L.AwesomeMarkers.icon({
|
|||||||
foreach (dbFetchRows($sql, array($_SESSION['user_id'])) as $map_devices) {
|
foreach (dbFetchRows($sql, array($_SESSION['user_id'])) as $map_devices) {
|
||||||
$icon = 'greenMarker';
|
$icon = 'greenMarker';
|
||||||
$z_offset = 0;
|
$z_offset = 0;
|
||||||
|
$tmp_loc = parse_location($map_devices['location']);
|
||||||
|
if (!empty($tmp_loc['lat']) && !empty($tmp_loc['lng'])) {
|
||||||
|
$map_devices['lat'] = $tmp_loc['lat'];
|
||||||
|
$map_devices['lng'] = $tmp_loc['lng'];
|
||||||
|
}
|
||||||
if ($map_devices['status'] == 0) {
|
if ($map_devices['status'] == 0) {
|
||||||
$icon = 'redMarker';
|
$icon = 'redMarker';
|
||||||
$z_offset = 10000; // move marker to foreground
|
$z_offset = 10000; // move marker to foreground
|
||||||
|
@@ -78,7 +78,10 @@ if ($device['location']) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$loc = dbFetchRow("SELECT `lat`,`lng` FROM `locations` WHERE `location`=? LIMIT 1", array($device['location']));
|
$loc = parse_location($device['location']);
|
||||||
|
if (!is_array($loc)) {
|
||||||
|
$loc = dbFetchRow("SELECT `lat`,`lng` FROM `locations` WHERE `location`=? LIMIT 1", array($device['location']));
|
||||||
|
}
|
||||||
if (is_array($loc)) {
|
if (is_array($loc)) {
|
||||||
echo '<tr>
|
echo '<tr>
|
||||||
<td>Lat / Lng</td>
|
<td>Lat / Lng</td>
|
||||||
|
@@ -1249,3 +1249,4 @@ function generate_dynamic_config_panel($title,$end_panel=true,$config_groups,$it
|
|||||||
}
|
}
|
||||||
return $output;
|
return $output;
|
||||||
}//end generate_dynamic_config_panel()
|
}//end generate_dynamic_config_panel()
|
||||||
|
|
||||||
|
@@ -795,3 +795,15 @@ function ceph_rrd($gtype) {
|
|||||||
$rrd = join('-', array('app', 'ceph', $vars['id'], $gtype, $var)).'.rrd';
|
$rrd = join('-', array('app', 'ceph', $vars['id'], $gtype, $var)).'.rrd';
|
||||||
return join('/', array($config['rrd_dir'], $device['hostname'], $rrd));
|
return join('/', array($config['rrd_dir'], $device['hostname'], $rrd));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse location field for coordinates
|
||||||
|
* @param string location The location field to look for coords in.
|
||||||
|
* @return array Containing the lat and lng coords
|
||||||
|
**/
|
||||||
|
function parse_location($location) {
|
||||||
|
preg_match('/(\[)([0-9\. ]+), ([0-9\. ]+)(\])/', $location, $tmp_loc);
|
||||||
|
if (!empty($tmp_loc[2]) && !empty($tmp_loc[3])) {
|
||||||
|
return array('lat' => $tmp_loc[2], 'lng' => $tmp_loc[3]);
|
||||||
|
}
|
||||||
|
}//end parse_location()
|
||||||
|
@@ -445,7 +445,10 @@ function location_to_latlng($device) {
|
|||||||
if (!empty($device_location)) {
|
if (!empty($device_location)) {
|
||||||
$new_device_location = preg_replace("/ /","+",$device_location);
|
$new_device_location = preg_replace("/ /","+",$device_location);
|
||||||
// We have a location string for the device.
|
// We have a location string for the device.
|
||||||
$loc = dbFetchRow("SELECT `lat`,`lng` FROM `locations` WHERE `location`=? LIMIT 1", array($device_location));
|
$loc = parse_location($device_location);
|
||||||
|
if (!is_array($loc)) {
|
||||||
|
$loc = dbFetchRow("SELECT `lat`,`lng` FROM `locations` WHERE `location`=? LIMIT 1", array($device_location));
|
||||||
|
}
|
||||||
if (is_array($loc) === false) {
|
if (is_array($loc) === false) {
|
||||||
// Grab data from which ever Geocode service we use.
|
// Grab data from which ever Geocode service we use.
|
||||||
switch ($config['geoloc']['engine']) {
|
switch ($config['geoloc']['engine']) {
|
||||||
|
Reference in New Issue
Block a user