Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- from jnpr.junos import Device
- from lxml import etree
- host = '127.0.0.1'
- user = 'root'
- password = 'password'
- dev = Device(host=host, user=user, passwd=password)
- dev.open()
- bgp = dev.rpc.get_bgp_summary_information()
- dev.close()
- # 1. flap count check using xml output to get 'elapsed-time' attribute in seconds
- # 2. Assert that peer state is Established
- # 3. skip dummy peer neighbours
- # 4. make a csv file of output
- #etree parsing
- for i in bgp.findall('bgp-peer'):
- peer = i.find('peer-address').text
- peer_state = i.find('peer-state').text
- description = i.find('description').text
- elapsed_time = int(i.find('elapsed-time').attrib['seconds'])
- flap_count = int(i.find('flap-count').text)
- if elapsed_time < 86400 and flap_count > 0:
- if peer_state != 'Established':
- print ( '{} is DOWN and has flapped recently, peer ip is {}' .format(description, peer))
- else:
- print ( '{} has flapped recently, peer ip is {}' .format(description, peer))
- if peer_state != 'Established':
- print( '{} is DOWN! , peer is {}' .format(description,peer), 'peer-state is: ' + str(peer_state) )
- print('')
Add Comment
Please, Sign In to add comment