-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreset-sflow.py
executable file
·58 lines (48 loc) · 2.17 KB
/
reset-sflow.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#! /usr/bin/env python3
# This script is designed to use check for my Juniper EX switch adapting its
# sflow rate to something other than 2048 for and put it back to 2048
#
# Written by: Justin Ryburn ([email protected])
# standard modules
import time
from jnpr.junos import Device
from jnpr.junos.utils.config import Config
switch = '' # IP for switch
username = '' #Username for device
password = '' #Password for the Device
dev = Device(host=switch, user=username, password=password)
print('Logging in to ' + switch)
dev.open()
# Check for sflow sampling rate
result = dev.rpc.get_sflow_interface()
print('sflow data pulled from device')
reset_flow = False
for i in result.xpath('.//interface-adapt-sample-rate-ingress'):
if int(i.text) > 2048:
reset_flow = True
# Set sampling rate back to 2048
if reset_flow is True:
# Disable sflow protocol
print('Disabling sflow')
cu = Config(dev)
data = """protocols {
inactive: sflow {
}
}
"""
cu.load(data, format='text')
print('Committing... ')
cu.pdiff()
cu.commit(timeout=60)
# Wait 10 seconds
time.sleep(10)
# Enable the interface
cu.rollback(1)
print('Committing... ')
cu.pdiff()
cu.commit(timeout=60)
# Close the device
dev.close()
else:
print('sflow does not need resetting')
dev.close()