Advertisement
Krakozaber

Untitled

Jan 12th, 2016
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. ##----------------------------------------------------------------------
  3. ## Cisco.SBM.get_lldp_neighbors
  4. ##----------------------------------------------------------------------
  5. ## Copyright (C) 2007-2016 The NOC Project
  6. ## See LICENSE for details
  7. ##----------------------------------------------------------------------
  8.  
  9. ## NOC modules
  10. from noc.sa.script import Script as NOCScript
  11. from noc.sa.interfaces.igetlldpneighbors import IGetLLDPNeighbors
  12.  
  13. class Script(NOCScript):
  14. name = "Cisco.SMB.get_lldp_neighbors"
  15. implements = [IGetLLDPNeighbors]
  16.  
  17. def execute(self):
  18. r = []
  19. if self.snmp and self.access_profile.snmp_ro:
  20. try:
  21.  
  22. # ifName
  23. # lldpRemChassisIdSubtype lldpRemChassisId
  24. # lldpRemPortIdSubtype lldpRemPortId
  25. # lldpRemSysName lldpRemSysCapEnabled
  26. for v in self.snmp.get_tables(
  27. ["1.3.6.1.2.1.31.1.1.1.1",
  28. "1.0.8802.1.1.2.1.4.1.1.4", "1.0.8802.1.1.2.1.4.1.1.5",
  29. "1.0.8802.1.1.2.1.4.1.1.6", "1.0.8802.1.1.2.1.4.1.1.7",
  30. "1.0.8802.1.1.2.1.4.1.1.9", "1.0.8802.1.1.2.1.4.1.1.12"
  31. ], bulk=True):
  32. if v[6]:
  33. local_interface = self.snmp.get("1.3.6.1.2.1.31.1.1.1.1." + v[0].split('.')[1], cached=True)
  34. remote_chassis_id_subtype = v[2]
  35. remotechassisid = ":".join(["%02x" % ord(c) for c in v[3]])
  36. remote_port_subtype = int(v[4])
  37. if remote_port_subtype == 3:
  38. remote_port = ":".join(["%02x" % ord(c) for c in v[5]])
  39. else:
  40. remote_port = v[5]
  41. remote_system_name = v[6]
  42. remote_capabilities = (["%02x" % ord(x) for x in v[7]])[0][0:1]
  43. i = {"local_interface": local_interface, "neighbors": []}
  44. n = {
  45. "remote_chassis_id_subtype": remote_chassis_id_subtype,
  46. "remote_chassis_id": remotechassisid,
  47. "remote_port_subtype": remote_port_subtype,
  48. "remote_port": remote_port,
  49. "remote_capabilities": remote_capabilities,
  50. }
  51. if remote_system_name:
  52. n["remote_system_name"] = remote_system_name
  53. i["neighbors"].append(n)
  54. r.append(i)
  55. if r:
  56. return r
  57.  
  58. except self.snmp.TimeOutError:
  59. pass
  60. return r
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement