Python Api  IE10.1
Functions | Variables
netbrain.sysapi.parserlibrary Namespace Reference

Functions

def get_parser_sample (device, parser, params=dict(), kws)
 get parser sample content on device, Notice: API parser is not supported More...
 
def get_parser_result (content, parser)
 get parsed result More...
 

Variables

 str_stack = traceback.format_exc();
 
 sample_result = namedtuple('sample_result', ['sample', 'success', 'error', 'livelog'])
 
 parser_result = namedtuple('parser_result', ['variables', 'success', 'error'])
 

Function Documentation

◆ get_parser_result()

def netbrain.sysapi.parserlibrary.get_parser_result (   content,
  parser 
)

get parsed result

Parameters
content(string)parser sample
parser(string)parser path
Returns
parser result
#parser.variables sample:
{'tables': [{'column': [{'name': 'process_id', 'type': 4, 'value': ['1']}, {'name': 'rid', 'type': 4, 'value': ['172.24.254.11']}, {'name': 'router_type', 'type': 4, 'value': ['area border router']}, {'name': 'total_area', 'type': 1, 'value': ['2']}, {'name': 'num_normal', 'type': 1, 'value': ['2']}, {'name': 'num_stub', 'type': 1, 'value': ['0']}, {'name': 'num_nssa', 'type': 1, 'value': ['0']}], 'hashCmp': '', 'hashSort': False, 'name': 'ospf_process', 'rowCount': 1, 'type': 11}], 'variables': None}

◆ get_parser_sample()

def netbrain.sysapi.parserlibrary.get_parser_sample (   device,
  parser,
  params = dict(),
  kws 
)

get parser sample content on device, Notice: API parser is not supported

Parameters
device(string)name of device
parser(string)path of paser
param(dict)parameter for parser with variables, value MUST be string
kws(dict)other options: live:liveaccess to device to get data, 1.default is True, 2.False means use baseline data 3.using show command format to cache data to baseline 4.show command is constructed in: parser.bizType:parser.command keep_raw:
  1. default is false
  2. True means save raw data to baseline
  3. using show command to save raw data to baseline
  4. show command is constructed in: parser.bizType:parser.command
  5. API parser and config parser is not supported by this option
Returns
sample defined in parser for target device
def run(input):
#parser = r'Built-in Files/CLI Command/Cisco IOS/BGP Neighbors [Cisco IOS]' #cli
#parser = r'Built-in Files/SNMP/CPU and Memory Usage' #snmp get parser
#parser = r'Built-in Files/SNMP/BGP Local AS' #snmp walk parser
#parser = r'Built-in Files/SNMP/Interface Information [SNMP]' #snmp table parser
#parser = r'Built-in Files/Configuration/Cisco IOS/EIGRP Basic Info [Cisco IOS]' #baseline config parser
#parser = r'Built-in Files/Configuration/Cisco IOS/EIGRP Configuration [Cisco IOS]' #live config parser
#parser = r'Built-in Files/CLI Command/Cisco IOS/Ping [Cisco Router&Switch]' #cli parser with param
#parser = r'Built-in Files/Network Vendors/Cisco/Cisco ACI/Consumer vs Provider [Cisco ACI Contract]' #api parser
parser = r'Built-in Files/Network Vendors/Cisco/Cisco IOS/show ip ospf [Cisco IOS]'
param = {'nbr_intf_ip':'1.1.1.1', 'this_intf_ip':'2.2.2.2'}
s = get_parser_sample('SanJose_Core', parser, param, live = False, keep_raw=True)
if not s.success:
pluginfw.AddLog(str(s.error), pluginfw.DEBUG)
pluginfw.AddLog(str(s.livelog), pluginfw.DEBUG)
return False
pluginfw.AddLog(s.sample, pluginfw.DEBUG)
parsed = get_parser_result(s.sample, parser)
if parsed.success:
pluginfw.AddLog(str(parsed.variables), pluginfw.DEBUG)
return True

Variable Documentation

◆ parser_result

netbrain.sysapi.parserlibrary.parser_result = namedtuple('parser_result', ['variables', 'success', 'error'])

◆ sample_result

netbrain.sysapi.parserlibrary.sample_result = namedtuple('sample_result', ['sample', 'success', 'error', 'livelog'])

◆ str_stack

netbrain.sysapi.parserlibrary.str_stack = traceback.format_exc();