Hey Marius, how are you?
Thanks again, i did some little adjustments by your script to get the values from the sensor dic (I just renamed 2 or 3 variables). But insane how close it was with your first try… Chapeau!
I have one question left regarding to your script. I am not quite sure, but is the “parsed = ” really used? Because we create it in line 12 or sth and after we do not fill it at any point? I am a little bit confused . I added to debug a little bit two more print outs print("portId not in sensorContained")
and print("sensorId not in snesors")
. I noticed that the port['sensors'].append(sensors[sensorId])
is never used.
Here the new edit from your script:
from .agent_based_api.v1 import *
def parse_arista_port(string_table):
print(string_table)
# Parse Sensor List into a dict
sensors = {}
for sensorId, sensorType, sensorScale, sensorValue, sensorStatus, sensorUnit in string_table[1]:
sensors[sensorId] = (sensorType, sensorScale, sensorValue, sensorStatus, sensorUnit)
# Parse the Ports
parsed = []
for portId, portDesc, portContained, portClass in string_table[0]:
if portClass != '10': # not a port
continue
port = {'id': portId, 'desc': portDesc, 'sensors': []}
for sensorId, sensorDesc, sensorContained, sensorClass in string_table[0]:
if portId != sensorContained:
print("portId not in sensorContained")
continue
if sensorId not in sensors:
print("sensorId not in snesors")
continue
port['sensors'].append(sensors[sensorId])
print(sensors)
print(parsed)
return parsed
register.snmp_section(
name = "arista_port",
detect = startswith(".1.3.6.1.2.1.1.1.0", "Arista"),
parse_function=parse_arista_port,
fetch = [
SNMPTree(
base = '.1.3.6.1.2.1.47.1.1.1.1',
oids = [
OIDEnd(),
'2', # entPhysicalDescr
'4', # entPhysicalContainedIn
'5', # entPhysicalClass
],
),
SNMPTree(
base = '.1.3.6.1.2.1.99.1.1.1',
oids = [
OIDEnd(),
'1', # entPhySensorType
'2', # entPhySensorScale
'4', # entPhySensorValue
'5', # entPhySensorOperStatus
'6', # entPhySensorUnitsDisplay
],
),
]
)
The sensor prints something like:
'100006001': ('8', '9', '412', '1', 'Celsius'), '100006002': ('8', '9', '338', '1', 'Celsius'), '100006003': ('8', '9', '250', '1', 'Celsius')
However the parsed dic is empty and returns only []
.
For me it would make sense after the port (port['sensors'].append(sensors[sensorId])
) is created to add the whole thing to the parsed list
Regards Kai