mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Fix 10853 os specific syslocation (#11082)
* added functionality to set sysLocation override in $os.inc.php files
* php styling fixes
* updated docs for location override in $os.inc.php
* patch poweralert.inc.php to use $location override
* added location override for enexus (Eltek)
* update phpdoc for set_device_location()
* converged location code in core.inc.php to use set_device_location()
* added new snmprec test data for enexus os
* Travis test data
* remove enexus_smartpacks2 test data
* Revert "remove enexus_smartpacks2 test data"
This reverts commit 36c8fc7036
.
* updated enexus_smartpacks2 test data with generic syslocation
* kick travis CI
* kick travis CI
This commit is contained in:
@@ -58,19 +58,12 @@ if ($uptime != 0 && Config::get("os.{$device['os']}.bad_uptime") !== true) {
|
||||
$device['uptime'] = $uptime;
|
||||
}//end if
|
||||
|
||||
$poll_device['sysLocation'] = str_replace('"', '', $poll_device['sysLocation']);
|
||||
|
||||
// Rewrite sysLocation if there is a mapping array (database too?)
|
||||
if (!empty($poll_device['sysLocation']) && (is_array(Config::get('location_map')) || is_array(Config::get('location_map_regex')) || is_array(Config::get('location_map_regex_sub')))) {
|
||||
$poll_device['sysLocation'] = rewrite_location($poll_device['sysLocation']);
|
||||
}
|
||||
set_device_location($poll_device['sysLocation'], $device, $update_array);
|
||||
|
||||
$poll_device['sysContact'] = str_replace('"', '', $poll_device['sysContact']);
|
||||
|
||||
foreach (array('sysLocation', 'sysContact') as $elem) {
|
||||
if ($poll_device[$elem] == 'not set') {
|
||||
$poll_device[$elem] = '';
|
||||
}
|
||||
if ($poll_device['sysContact'] == 'not set') {
|
||||
$poll_device['sysContact'] = '';
|
||||
}
|
||||
|
||||
// Save results of various polled values to the database
|
||||
@@ -82,23 +75,4 @@ foreach (array('sysContact', 'sysObjectID', 'sysName', 'sysDescr') as $elem) {
|
||||
}
|
||||
}
|
||||
|
||||
if ($device['override_sysLocation'] == 0 && $poll_device['sysLocation']) {
|
||||
/** @var Location $location */
|
||||
$location = Location::firstOrCreate(['location' => $poll_device['sysLocation']]);
|
||||
|
||||
if ($device['location_id'] != $location->id) {
|
||||
$device['location_id'] = $location->id;
|
||||
$update_array['location_id'] = $location->id;
|
||||
log_event('Location -> ' . $location->location, $device, 'system', 3);
|
||||
}
|
||||
}
|
||||
|
||||
// make sure the location has coordinates
|
||||
if (Config::get('geoloc.latlng', true) && ($location || $location = Location::find($device['location_id']))) {
|
||||
if (!$location->hasCoordinates()) {
|
||||
$location->lookupCoordinates();
|
||||
$location->save();
|
||||
}
|
||||
}
|
||||
|
||||
unset($snmpdata, $uptime_data, $uptime, $tags, $poll_device);
|
||||
|
@@ -9,6 +9,7 @@ use LibreNMS\Exceptions\JsonAppBlankJsonException;
|
||||
use LibreNMS\Exceptions\JsonAppMissingKeysException;
|
||||
use LibreNMS\Exceptions\JsonAppWrongVersionException;
|
||||
use LibreNMS\Exceptions\JsonAppExtendErroredException;
|
||||
use App\Models\Location;
|
||||
|
||||
function bulk_sensor_snmpget($device, $sensors)
|
||||
{
|
||||
@@ -782,3 +783,41 @@ function data_flatten($array, $prefix = '', $joiner = '_')
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sysLocation location override (instead of sysLocation.0)
|
||||
* @param &$device
|
||||
* @param &$update_array
|
||||
*/
|
||||
function set_device_location($sysLocation, &$device, &$update_array)
|
||||
{
|
||||
$sysLocation = str_replace('"', '', $sysLocation);
|
||||
|
||||
// Rewrite sysLocation if there is a mapping array (database too?)
|
||||
if (!empty($sysLocation) && (is_array(Config::get('location_map')) || is_array(Config::get('location_map_regex')) || is_array(Config::get('location_map_regex_sub')))) {
|
||||
$sysLocation = rewrite_location($sysLocation);
|
||||
}
|
||||
|
||||
if ($sysLocation == 'not set') {
|
||||
$sysLocation = '';
|
||||
}
|
||||
|
||||
if ($device['override_sysLocation'] == 0 && $sysLocation) {
|
||||
/** @var Location $location */
|
||||
$location = Location::firstOrCreate(['location' => $sysLocation]);
|
||||
|
||||
if ($device['location_id'] != $location->id) {
|
||||
$device['location_id'] = $location->id;
|
||||
$update_array['location_id'] = $location->id;
|
||||
log_event('Location -> ' . $location->location, $device, 'system', 3);
|
||||
}
|
||||
}
|
||||
|
||||
// make sure the location has coordinates
|
||||
if (Config::get('geoloc.latlng', true) && ($location || $location = Location::find($device['location_id']))) {
|
||||
if (!$location->hasCoordinates()) {
|
||||
$location->lookupCoordinates();
|
||||
$location->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -31,7 +31,11 @@ if ($serial != $device['serial']) {
|
||||
}
|
||||
|
||||
update_device_logo($device);
|
||||
if (!empty($location)) {
|
||||
set_device_location($location, $device, $update_array);
|
||||
}
|
||||
|
||||
echo 'Location: ' . $location . PHP_EOL;
|
||||
echo 'Hardware: ' . $hardware . PHP_EOL;
|
||||
echo 'Version: ' . $version . PHP_EOL;
|
||||
echo 'Features: ' . $features . PHP_EOL;
|
||||
|
@@ -23,6 +23,7 @@
|
||||
* @author BArry O'Donovan <barry@lightnet.ie>
|
||||
*/
|
||||
|
||||
$location = snmp_get($device, 'powerSystemSite.0', '-Ovqa', 'SP2-MIB');
|
||||
$hardware = snmp_get($device, 'powerSystemModel.0', '-Ovqa', 'SP2-MIB');
|
||||
$sw_version1 = snmp_get($device, 'controlUnitSwVersion.1', '-Ovqa', 'SP2-MIB');
|
||||
$sw_version2 = snmp_get($device, 'controlUnitSwVersion.2', '-Ovqa', 'SP2-MIB');
|
||||
|
@@ -8,7 +8,7 @@
|
||||
$hardware = snmp_get($device, 'upsIdentModel.0', '-Ovq', 'UPS-MIB');
|
||||
$hardware = preg_split('/TRIPP\ LITE/', $hardware);
|
||||
$hardware = $hardware[1];
|
||||
$sysLocation = trim(snmp_get($device, '.1.3.6.1.4.1.850.10.2.2.1.12.1', '-Ovq', 'TRIPPLITE-MIB'), '"');
|
||||
$location = trim(snmp_get($device, '.1.3.6.1.4.1.850.10.2.2.1.12.1', '-Ovq', 'TRIPPLITE-MIB'), '"');
|
||||
$sysName = trim(snmp_get($device, '.1.3.6.1.2.1.33.1.1.5.0', '-Ovq', 'TRIPPLITE-MIB'), '"');
|
||||
$serial = trim(snmp_get($device, '.1.3.6.1.4.1.850.100.1.1.4.0', '-Ovq', 'TRIPPLITE-MIB'), '"');
|
||||
$version = snmp_get($device, 'upsIdentAgentSoftwareVersion.0', '-Ovq', 'UPS-MIB');
|
||||
|
Reference in New Issue
Block a user