phsmith / python

Python scripts
1 stars 0 forks source link

KeyError #1

Closed arzWZM closed 4 years ago

arzWZM commented 4 years ago

Hi, I'm unable to get it working. What is the issue here?

Traceback (most recent call last): File "fusioninventory-xmlgenerator", line 271, in ifInfo[index].update({'ipaddr': ipaddr[index]}) KeyError: 'INTEGER: 1'

The SNMP OID has the following data for ipAdEntIfIndex

IP-MIB::ipAdEntIfIndex.127.0.0.1 = INTEGER: 1 IP-MIB::ipAdEntIfIndex.10.10.10.10 = INTEGER: 4 IP-MIB::ipAdEntIfIndex.10.10.10.20 = INTEGER: 3 IP-MIB::ipAdEntIfIndex.1.2.3.4 = INTEGER: 2

Just to see if it works, I got past the error by creating a empty dict ifInfo[index] = {} before assignment but then it produces another error for 'macaddr'.

Traceback (most recent call last): File "fusioninventory-xmlgenerator", line 365, in SubElement(networks, 'MACADDR').text = info['macaddr'] KeyError: 'macaddr'

Something is broken in the script. Can you suggest a fix?

phsmith commented 4 years ago

@arzWZM There is a long time that I didn't work with Fusion Inventory, but let's try to get the script to work. First you must generate the snmp file with: snmpwalk -OQ ...

arzWZM commented 4 years ago

Oh nice... when I used snmpwalk -OQ the script did not report any error. During the first attempt I just used snmpwalk -v 1 -c public 10.10.10.10 > outputfile and then used python fusioninventory-xmlgenerator -f outputfile -o test.xml.

But now I used snmpwalk -v 1 -c public -OQ localhost > outputfile and then python fusioninventory-xmlgenerator -f outputfile -o test.xml and no more errors. XML file has been generated.

I'm testing the XML right now by injecting it to fusion inventory.

phsmith commented 4 years ago

Great @arzWZM! Hope that works well.