Guest User

Untitled

a guest
Oct 27th, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. #!/usr/bin/env python
  2. from jnpr.junos import Device
  3. from lxml import etree
  4. host = '127.0.0.1'
  5. user = 'root'
  6. password = 'password'
  7. dev = Device(host=host, user=user, passwd=password)
  8.  
  9. dev.open()
  10. bgp = dev.rpc.get_bgp_summary_information()
  11. dev.close()
  12.  
  13. # 1. flap count check using xml output to get 'elapsed-time' attribute in seconds
  14. # 2. Assert that peer state is Established
  15. # 3. skip dummy peer neighbours
  16. # 4. make a csv file of output
  17.  
  18. #etree parsing
  19.  
  20. for i in bgp.findall('bgp-peer'):
  21. peer = i.find('peer-address').text
  22. peer_state = i.find('peer-state').text
  23. description = i.find('description').text
  24. elapsed_time = int(i.find('elapsed-time').attrib['seconds'])
  25. flap_count = int(i.find('flap-count').text)
  26. if elapsed_time < 86400 and flap_count > 0:
  27. if peer_state != 'Established':
  28. print ( '{} is DOWN and has flapped recently, peer ip is {}' .format(description, peer))
  29. else:
  30. print ( '{} has flapped recently, peer ip is {}' .format(description, peer))
  31. if peer_state != 'Established':
  32. print( '{} is DOWN! , peer is {}' .format(description,peer), 'peer-state is: ' + str(peer_state) )
  33. print('')
Add Comment
Please, Sign In to add comment