Advertisement
Guest User

Untitled

a guest
Sep 3rd, 2014
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. ##----------------------------------------------------------------------
  3. ## Cisco.IOS.get_fqdn
  4. ##----------------------------------------------------------------------
  5. ## Copyright (C) 2007-2013 The NOC Project
  6. ## See LICENSE for details
  7. ##----------------------------------------------------------------------
  8.  
  9. ## Python modules
  10. import re
  11. ## NOC modules
  12. from noc.sa.script import Script as NOCScript
  13. from noc.sa.interfaces import IGetFQDN
  14.  
  15.  
  16. class Script(NOCScript):
  17. name = "EdgeCore.ES.get_fqdn"
  18. implements = [IGetFQDN]
  19. rx_hostname = re.compile(r"^hostname\s+(?P<hostname>\S+)", re.MULTILINE)
  20. rx_domain_name = re.compile(r"^ip domain[ \-]name\s+(?P<domain>\S+)",
  21. re.MULTILINE)
  22.  
  23. def execute(self):
  24. if self.snmp and self.access_profile.snmp_ro:
  25. try:
  26. # sysName.0
  27. v = self.snmp.get("1.3.6.1.2.1.1.5.0", cached=True)
  28. if v:
  29. return v
  30. except self.snmp.TimeOutError:
  31. pass
  32. v = self.cli(
  33. "show running-config | include ^(hostname|ip domain.name)")
  34. fqdn = []
  35. match = self.rx_hostname.search(v)
  36. if match:
  37. fqdn += [match.group("hostname")]
  38. match = self.rx_domain_name.search(v)
  39. if match:
  40. fqdn += [match.group("domain")]
  41. return ".".join(fqdn)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement