Last active
August 26, 2019 13:02
-
-
Save FlorianHeigl/bbbe92359053f4a833ff59ccab3416cc to your computer and use it in GitHub Desktop.
cleanup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# | |
# LLDP Inventory Extension - Shows LLDP Neighbors of a TP-Link switch | |
# | |
# Version 1.0 | |
# Written 2019 - Florian Heigl | |
# Based on my_cdp.py by Maximilian Thoma | |
# | |
# 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 2 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, | |
# write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA | |
# | |
#.1.3.6.1.4.1.11863.6.35.1.2.2.1.1.99353.1 Te1/0/25 #lldpNeighborPortId | |
#.1.3.6.1.4.1.11863.6.35.1.2.2.1.2.99353.1 1 #lldpNeighborPortIndexId | |
#.1.3.6.1.4.1.11863.6.35.1.2.2.1.3.99353.1 MAC address #lldpNeighborChassisIdType | |
#.1.3.6.1.4.1.11863.6.35.1.2.2.1.4.99353.1 00:XXXXXXXXXXXXXX #lldpNeighborChassisId | |
#.1.3.6.1.4.1.11863.6.35.1.2.2.1.5.99353.1 MAC address #lldpNeighborPortIdType | |
#.1.3.6.1.4.1.11863.6.35.1.2.2.1.6.99353.1 00:XXXXXXXXXXXXXX #lldpNeighborPortIdDescr | |
#.1.3.6.1.4.1.11863.6.35.1.2.2.1.7.99353.1 120 #lldpNeighborTtl | |
#.1.3.6.1.4.1.11863.6.35.1.2.2.1.8.99353.1 Port 25 #ldpNeighborPortDescr | |
#.1.3.6.1.4.1.11863.6.35.1.2.2.1.9.99353.1 HostNAMEHERE #lldpNeighborDeviceName | |
def inv_tplink_lldp(info, params): | |
node = inv_tree_list("networking.lldp:") | |
oidnames = { | |
"1" : "l_ifname", | |
"8" : "r_ifname", | |
"9" : "r_hostname", | |
} | |
for lldp_entry in info: | |
d = {} | |
for snmpkey, snmpdata in lldp_entry: | |
#oid = snmpkey.split(".")[1] | |
#idx = snmpkey.split(".")[2] | |
oid, idx = snmpkey.split(".") | |
# i suppose the index is 99353.1, not 99353, but we need an integer. | |
d["index"] = int(idx) | |
if oid not in [ "1", "8", "9" ]: | |
continue | |
d[oidnames[oid]] = snmpdata | |
node.append(d) | |
inv_info["inv_tplink_lldp"] = { | |
"inv_function" : inv_tplink_lldp, | |
"snmp_info" : [(".1.3.6.1.4.1.11863.6.35.1.2", [OID_END, # lldpNeighborInfoTable | |
"2" | |
]), | |
], | |
"snmp_scan_function" : lambda oid: oid(".1.3.6.1.2.1.1.2.0") in [".1.3.6.1.4.1.11863.5.31"], | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
refactor info: https://stackoverflow.com/questions/57333936/mapping-a-list-to-a-dict-when-the-keys-are-weird/57333992#57333992