continuing from Lab-7 below is an example of XML parsing using etree.
Precondition:
- Juniper srx with NETCONF enabled
- set system services netconf ssh
- NETCONF ncclient installed
- sudo pip install ncclient
Procedure:
- This script follows these steps
- connect to Juniper srx using NETCONF
- get interface counts for interface ge-0/0/0 using this command ‘show interface ge-0/0/0 detail statistics’
- search for stats group ‘traffic-statistics’, ‘input-error-list’, ‘output-error-list’ and print individual stats under the group also store them in Python dictionary
- Python file (get_interface_stats.py) located here
Output:
sjakhwal@rtxl3rld05:~/scripts$ ./get_interface_statistics.py
================= Traffic Statistics ================
input-bytes =
32690246
input-bps =
200
output-bytes =
4419133
output-bps =
0
input-packets =
615902
input-pps =
0
output-packets =
16620
output-pps =
0
================ Input Error Statistics =============
input-errors =
0
input-drops =
0
framing-errors =
0
input-runts =
0
input-discards =
0
input-l3-incompletes =
0
input-l2-channel-errors =
0
input-l2-mismatch-timeouts =
0
input-fifo-errors =
0
input-resource-errors =
0
================ Output Error Statistics ===========
carrier-transitions =
1
output-errors =
0
output-collisions =
0
output-drops =
0
aged-packets =
0
mtu-errors =
0
hs-link-crc-errors =
0
output-fifo-errors =
0
output-resource-errors =
0
sjakhwal@rtxl3rld05:~/scripts
One thought on “Lab-8:Python for network automation – XML parsing”