Advertisement
Guest User

Untitled

a guest
Jul 30th, 2015
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.40 KB | None | 0 0
  1. $ cat __init__.py
  2. # -*- coding: utf-8 -*-
  3. ##----------------------------------------------------------------------
  4. ## Vendor: NAG
  5. ## OS:     ERD
  6. ##----------------------------------------------------------------------
  7. ## Copyright (C) 2007-2015 The NOC Project
  8. ## See LICENSE for details
  9. ##----------------------------------------------------------------------
  10.  
  11. ## Python modules
  12. from HTMLParser import HTMLParser
  13. ## NOC modules
  14. from noc.sa.profiles import Profile as NOCProfile
  15. from noc.sa.protocols.sae_pb2 import HTTP
  16.  
  17.  
  18. dat = []
  19. class Profile(NOCProfile):
  20.     name = "NAG.ERD"
  21.     supported_schemes = [NOCProfile.HTTP]
  22.  
  23.     nag_erd_plat={
  24.         "1": "1",
  25.         "2": "2",
  26.         "3": "3",
  27.         "4": "3S",  # "3S",
  28.         "5": "Pro",
  29.         }
  30.  
  31.     class MyHTMLParser(HTMLParser):
  32. #        dat = []
  33.         def handle_data(self, data):
  34.             global dat
  35.             dat.append(data)
  36. #            dat += [data]
  37.             print dat # Отработал хорошо!
  38.             return dat
  39.  
  40.  
  41.  
  42. $ cat get_chassis_id.py
  43. # -*- coding: utf-8 -*-
  44. ##----------------------------------------------------------------------
  45. ## NAG.ERD.get_chassis_id
  46. ##----------------------------------------------------------------------
  47. ## Copyright (C) 2007-2015 The NOC Project
  48. ## See LICENSE for details
  49. ##----------------------------------------------------------------------
  50.  
  51. ## Python modules
  52. #from HTMLParser import HTMLParser
  53. ## NOC modules
  54. from noc.sa.script import Script as NOCScript
  55. from noc.sa.interfaces import IGetChassisID
  56. #from noc.sa.profiles.NAG.ERD import MyHTMLParser
  57.  
  58. """
  59. dat = []
  60. class MyHTMLParser(HTMLParser):
  61.    def handle_data(self, data):
  62.        global dat
  63.        dat.append(data)
  64. #        dat += [data]
  65. #        print dat
  66.        return dat
  67. """
  68.  
  69. class Script(NOCScript):
  70.     name = "NAG.ERD.get_chassis_id"
  71.     implements = [IGetChassisID]
  72.     cache = True
  73.  
  74.     def execute(self):
  75.         # Try SNMP first
  76.         if self.snmp and self.access_profile.snmp_ro:
  77.             try:
  78.                 mac = self.snmp.get("1.3.6.1.2.1.2.2.1.6.0", cached=True)
  79.                 return {
  80.                         "first_chassis_mac": mac,
  81.                         "last_chassis_mac": mac
  82.                         }
  83.             except self.snmp.TimeOutError:
  84.                 pass
  85.  
  86.         # Fallback to HTTP
  87.         dat = self.profile.MyHTMLParser().feed(self.http.get("/ipconf=1"))
  88. #        MyHTMLParser().feed(self.http.get("/ipconf=1"))
  89. #        print dat
  90.         return {
  91.                 "first_chassis_mac": dat[1],
  92.                 "last_chassis_mac": dat[1]
  93.                 }
  94.  
  95.  
  96. <type 'exceptions.TypeError'>
  97. 'NoneType' object has no attribute '__getitem__'
  98. START OF TRACEBACK
  99. ------------------------------------------------------------------------
  100. File: sa/profiles/NAG/ERD/get_chassis_id.py (Line: 49)
  101. Function: execute
  102.    42                     pass
  103.    43
  104.    44             # Fallback to HTTP
  105.    45             dat = self.profile.MyHTMLParser().feed(self.http.get("/ipconf=1"))
  106.    46     #        MyHTMLParser().feed(self.http.get("/ipconf=1"))
  107.    47     #        print dat
  108.    48             return {
  109.    49 ==>                 "first_chassis_mac": dat[1],
  110.    50                     "last_chassis_mac": dat[1]
  111.    51                     }
  112. Variables:
  113.                  dat = None
  114.                 self = <Script(Thread-2, started daemon 133026902517504)>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement