Fix redeclare of function breaking tests in OS eltex-mes23xx (#14227)

* eltex
* function in Class file
* style
This commit is contained in:
PipoCanaja
2022-08-24 23:05:38 +02:00
committed by GitHub
parent 5b10d5a1ce
commit 2ae0e84091
2 changed files with 42 additions and 10 deletions
+40
View File
@@ -0,0 +1,40 @@
<?php
/**
* EltexMes23xx.php
*
* 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 <https://www.gnu.org/licenses/>.
*
* @link https://www.librenms.org
*
* @copyright 2022 PipoCanaja
* @author PipoCanaja
*/
namespace LibreNMS\OS;
use LibreNMS\OS;
class EltexMes23xx extends OS
{
/**
* Specific HexToString for Eltex
*/
public function normData(string $par = ''): string
{
$tmp = str_replace([':', ' '], '', trim(strtoupper($par)));
$ret = preg_match('/^[0-9A-F]+$/', $tmp) ? hex2str($tmp) : $par; //if string is pure hex, convert to ascii
return $ret;
}
}
@@ -29,14 +29,6 @@ $trans = snmpwalk_cache_multi_oid($device, 'eltPhdTransceiverInfoEntry', [], 'EL
echo ' entAliasMappingIdentifier';
$mapping = snmpwalk_cache_multi_oid($device, 'entAliasMappingIdentifier', [], 'ENTITY-MIB:IF-MIB');
function normData($par = null)
{
$tmp = str_replace([':', ' '], '', trim(strtoupper($par)));
$ret = preg_match('/^[0-9A-F]+$/', $tmp) ? hex2str($tmp) : $par; //if string is pure hex, convert to ascii
return $ret;
}
foreach ($trans as $index => $data) {
unset($connectedto);
foreach ($mapping as $ekey => $edata) {
@@ -50,11 +42,11 @@ foreach ($trans as $index => $data) {
'entPhysicalDescr' => $data['eltPhdTransceiverInfoType'],
'entPhysicalClass' => 'sfp-cage',
'entPhysicalName' => strtoupper($data['eltPhdTransceiverInfoConnectorType']),
'entPhysicalModelName' => normData($data['eltPhdTransceiverInfoPartNumber']),
'entPhysicalModelName' => \LibreNMS\OS\EltexMes23xx::normData($data['eltPhdTransceiverInfoPartNumber']),
'entPhysicalSerialNum' => $data['eltPhdTransceiverInfoSerialNumber'],
'entPhysicalContainedIn' => $connectedto,
'entPhysicalMfgName' => $data['eltPhdTransceiverInfoVendorName'],
'entPhysicalHardwareRev' => normData($data['eltPhdTransceiverInfoVendorRev']),
'entPhysicalHardwareRev' => \LibreNMS\OS\EltexMes23xx::normData($data['eltPhdTransceiverInfoVendorRev']),
'entPhysicalIsFRU' => 'true',
];
}