Advertisement
Krakozaber

Untitled

Dec 29th, 2015
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. ##----------------------------------------------------------------------
  3. ## NAG.SNR.get_lldp_neighbors
  4. ##----------------------------------------------------------------------
  5. ## Copyright (C) 2007-2012 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 import IGetLLDPNeighbors
  12. from noc.sa.interfaces.base import MACAddressParameter
  13. from noc.lib.validators import is_int, is_ipv4
  14.  
  15.  
  16. class Script(NOCScript):
  17. name = "DLink.DxS_Smart.get_lldp_neighbors"
  18. implements = [IGetLLDPNeighbors]
  19.  
  20. def execute(self):
  21. r = []
  22. # Try SNMP first
  23. if self.snmp and self.access_profile.snmp_ro:
  24. try:
  25.  
  26. # lldpRemLocalPortNum
  27. # lldpRemChassisIdSubtype lldpRemChassisId
  28. # lldpRemPortIdSubtype lldpRemPortId
  29. # lldpRemSysName lldpRemSysCapEnabled
  30. for v in self.snmp.get_tables(
  31. ["1.3.6.1.2.1.2.2.1.1",
  32. "1.0.8802.1.1.2.1.4.1.1.4", "1.0.8802.1.1.2.1.4.1.1.5",
  33. "1.0.8802.1.1.2.1.4.1.1.6", "1.0.8802.1.1.2.1.4.1.1.7",
  34. "1.0.8802.1.1.2.1.4.1.1.9", "1.0.8802.1.1.2.1.4.1.1.12"
  35. ], bulk=True):
  36. if v[6]:
  37. local_interface = int(v[0].split('.')[1])
  38. remote_chassis_id_subtype = v[2]
  39. remotechassisid = ":".join(["%02x" % ord(c) for c in v[3]])
  40. remote_port_subtype = v[4]
  41. remote_system_name = v[6]
  42. remote_port = v[5]
  43. remote_capabilities = (["%02x" % ord(x) for x in v[7]])[0][0:1]
  44. i = {"local_interface": local_interface, "neighbors": []}
  45. n = {
  46. "remote_chassis_id_subtype": remote_chassis_id_subtype,
  47. "remote_chassis_id": remotechassisid,
  48. "remote_port_subtype": remote_port_subtype,
  49. "remote_port": remote_port,
  50. "remote_capabilities": remote_capabilities,
  51. }
  52. if remote_system_name:
  53. n["remote_system_name"] = remote_system_name
  54. i["neighbors"].append(n)
  55. r.append(i)
  56. if r:
  57. return r
  58.  
  59. except self.snmp.TimeOutError:
  60. pass
  61. return r
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement