Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- ##----------------------------------------------------------------------
- ## Cisco.SBM.get_lldp_neighbors
- ##----------------------------------------------------------------------
- ## Copyright (C) 2007-2016 The NOC Project
- ## See LICENSE for details
- ##----------------------------------------------------------------------
- ## NOC modules
- from noc.sa.script import Script as NOCScript
- from noc.sa.interfaces.igetlldpneighbors import IGetLLDPNeighbors
- class Script(NOCScript):
- name = "Cisco.SMB.get_lldp_neighbors"
- implements = [IGetLLDPNeighbors]
- def execute(self):
- r = []
- if self.snmp and self.access_profile.snmp_ro:
- try:
- # ifName
- # lldpRemChassisIdSubtype lldpRemChassisId
- # lldpRemPortIdSubtype lldpRemPortId
- # lldpRemSysName lldpRemSysCapEnabled
- for v in self.snmp.get_tables(
- ["1.3.6.1.2.1.31.1.1.1.1",
- "1.0.8802.1.1.2.1.4.1.1.4", "1.0.8802.1.1.2.1.4.1.1.5",
- "1.0.8802.1.1.2.1.4.1.1.6", "1.0.8802.1.1.2.1.4.1.1.7",
- "1.0.8802.1.1.2.1.4.1.1.9", "1.0.8802.1.1.2.1.4.1.1.12"
- ], bulk=True):
- if v[6]:
- local_interface = self.snmp.get("1.3.6.1.2.1.31.1.1.1.1." + v[0].split('.')[1], cached=True)
- remote_chassis_id_subtype = v[2]
- remotechassisid = ":".join(["%02x" % ord(c) for c in v[3]])
- remote_port_subtype = int(v[4])
- if remote_port_subtype == 3:
- remote_port = ":".join(["%02x" % ord(c) for c in v[5]])
- else:
- remote_port = v[5]
- remote_system_name = v[6]
- remote_capabilities = (["%02x" % ord(x) for x in v[7]])[0][0:1]
- i = {"local_interface": local_interface, "neighbors": []}
- n = {
- "remote_chassis_id_subtype": remote_chassis_id_subtype,
- "remote_chassis_id": remotechassisid,
- "remote_port_subtype": remote_port_subtype,
- "remote_port": remote_port,
- "remote_capabilities": remote_capabilities,
- }
- if remote_system_name:
- n["remote_system_name"] = remote_system_name
- i["neighbors"].append(n)
- r.append(i)
- if r:
- return r
- except self.snmp.TimeOutError:
- pass
- return r
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement