Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $ cat __init__.py
- # -*- coding: utf-8 -*-
- ##----------------------------------------------------------------------
- ## Vendor: NAG
- ## OS: ERD
- ##----------------------------------------------------------------------
- ## Copyright (C) 2007-2015 The NOC Project
- ## See LICENSE for details
- ##----------------------------------------------------------------------
- ## Python modules
- from HTMLParser import HTMLParser
- ## NOC modules
- from noc.sa.profiles import Profile as NOCProfile
- from noc.sa.protocols.sae_pb2 import HTTP
- dat = []
- class Profile(NOCProfile):
- name = "NAG.ERD"
- supported_schemes = [NOCProfile.HTTP]
- nag_erd_plat={
- "1": "1",
- "2": "2",
- "3": "3",
- "4": "3S", # "3S",
- "5": "Pro",
- }
- class MyHTMLParser(HTMLParser):
- # dat = []
- def handle_data(self, data):
- global dat
- dat.append(data)
- # dat += [data]
- print dat # Отработал хорошо!
- return dat
- $ cat get_chassis_id.py
- # -*- coding: utf-8 -*-
- ##----------------------------------------------------------------------
- ## NAG.ERD.get_chassis_id
- ##----------------------------------------------------------------------
- ## Copyright (C) 2007-2015 The NOC Project
- ## See LICENSE for details
- ##----------------------------------------------------------------------
- ## Python modules
- #from HTMLParser import HTMLParser
- ## NOC modules
- from noc.sa.script import Script as NOCScript
- from noc.sa.interfaces import IGetChassisID
- #from noc.sa.profiles.NAG.ERD import MyHTMLParser
- """
- dat = []
- class MyHTMLParser(HTMLParser):
- def handle_data(self, data):
- global dat
- dat.append(data)
- # dat += [data]
- # print dat
- return dat
- """
- class Script(NOCScript):
- name = "NAG.ERD.get_chassis_id"
- implements = [IGetChassisID]
- cache = True
- def execute(self):
- # Try SNMP first
- if self.snmp and self.access_profile.snmp_ro:
- try:
- mac = self.snmp.get("1.3.6.1.2.1.2.2.1.6.0", cached=True)
- return {
- "first_chassis_mac": mac,
- "last_chassis_mac": mac
- }
- except self.snmp.TimeOutError:
- pass
- # Fallback to HTTP
- dat = self.profile.MyHTMLParser().feed(self.http.get("/ipconf=1"))
- # MyHTMLParser().feed(self.http.get("/ipconf=1"))
- # print dat
- return {
- "first_chassis_mac": dat[1],
- "last_chassis_mac": dat[1]
- }
- <type 'exceptions.TypeError'>
- 'NoneType' object has no attribute '__getitem__'
- START OF TRACEBACK
- ------------------------------------------------------------------------
- File: sa/profiles/NAG/ERD/get_chassis_id.py (Line: 49)
- Function: execute
- 42 pass
- 43
- 44 # Fallback to HTTP
- 45 dat = self.profile.MyHTMLParser().feed(self.http.get("/ipconf=1"))
- 46 # MyHTMLParser().feed(self.http.get("/ipconf=1"))
- 47 # print dat
- 48 return {
- 49 ==> "first_chassis_mac": dat[1],
- 50 "last_chassis_mac": dat[1]
- 51 }
- Variables:
- dat = None
- self = <Script(Thread-2, started daemon 133026902517504)>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement