Files
librenms-librenms/includes/discovery/sensors/pre-cache/avtech.inc.php
Tony Murray 3e7970b814 Fixed Avtech discovery (#10163)
* Fix Avtech discovery
pre-cache stored the data incorrectly

* Fix RA-4E external sensors
sen1 had incorrect oids (duplicate of sen2)
Description oid from data doesn't match the mib, perhaps outdated MIB?

* add test data

* Updated 4E MIB
2019-05-02 21:37:00 +01:00

59 lines
2.0 KiB
PHP

<?php
/**
* avtech.inc.php
*
* Grab all data under avtech enterprise oid and process it for yaml consumption
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package LibreNMS
* @link http://librenms.org
* @copyright 2017 Tony Murray
* @author Tony Murray <murraytony@gmail.com>
*/
// table name => regex (first group is index, second group is id)
$virtual_tables = [
'ra32-analog' => '/\.1\.3\.6\.1\.4\.1\.20916\.1\.8\.1\.1\.5\.((\d+)\.0)/',
'ra32-relay' => '/\.1\.3\.6\.1\.4\.1\.20916\.1\.8\.1\.1\.6\.((\d+)\.0)/',
'ra32-ext-temp' => '/\.1\.3\.6\.1\.4\.1\.20916\.1\.8\.1\.2\.((\d+)\.1\.0)/',
'ra32-switch' => '/\.1\.3\.6\.1\.4\.1\.20916\.1\.8\.1\.3\.((\d+)\.0)/',
'ra32-wish-temp' => '/\.1\.3\.6\.1\.4\.1\.20916\.1\.8\.1\.4\.((\d+)\.4\.1\.2\.0)/',
];
$data = snmp_walk($device, '.1.3.6.1.4.1.20916.1', '-OQn');
foreach (explode(PHP_EOL, $data) as $line) {
list($oid, $value) = explode(' = ', $line);
$processed = false;
foreach ($virtual_tables as $vt_name => $vt_regex) {
if (preg_match($vt_regex, $oid, $matches)) {
$index = $matches[1];
$id = $matches[2];
$pre_cache[$vt_name][$index] = ['value' => $value, 'id' => $id];
$processed = true;
break; // skip rest
}
}
if (!$processed) {
$pre_cache[$oid] = [[$oid => $value]];
}
}
unset($data);