05-11-2020 02:42 AM
I am trying to find out which ports have been used or which ports have status changes within the day i.e between ports that have gone from down to up during the hours of 6am and 6pm etc.
Is there a way to report port or track status changes during the day?
Caan be from Cisco Prime or directly from the switch, script would be easier, but if there is even a manual way, then it's worth a shot.
Cisco 3850 Running 16.3.6
Solved! Go to Solution.
05-11-2020 04:22 AM
You could do something like this ..
#!/usr/bin/env python
from netmiko import ConnectHandler import re from datetime import datetime today = datetime.today().strftime('%B %d') print(today) cisco = { 'device_type': 'cisco_ios', 'host': 'REPLACE_WITH_IP', 'username': 'REPLACE_WITH_USERNAME', 'password': 'REPLACE_WITH_PASSWORD' 'port': '22' } net_connect = ConnectHandler(**cisco) output = net_connect.send_command('',expect_string=r'#',strip_command=False, strip_prompt=False) output += net_connect.send_command('show log | i UPDOWN',expect_string=r'#',strip_command=False, strip_prompt=False) net_connect.disconnect() DATE_RE = today + '.*' matched = re.findall(DATE_RE,output) for line in matched: print(line) #print(output)
tested on sandbox -
05-11-2020 03:07 AM
Hi
You could use syslog and log the info.
You can also script ..
Manually .. sh logging | i UPDOWN
05-11-2020 03:28 AM
Great Thanks for you help!
I will give it a go and come back and let you know how it goes.
Thanks again!
05-11-2020 04:22 AM
You could do something like this ..
#!/usr/bin/env python
from netmiko import ConnectHandler import re from datetime import datetime today = datetime.today().strftime('%B %d') print(today) cisco = { 'device_type': 'cisco_ios', 'host': 'REPLACE_WITH_IP', 'username': 'REPLACE_WITH_USERNAME', 'password': 'REPLACE_WITH_PASSWORD' 'port': '22' } net_connect = ConnectHandler(**cisco) output = net_connect.send_command('',expect_string=r'#',strip_command=False, strip_prompt=False) output += net_connect.send_command('show log | i UPDOWN',expect_string=r'#',strip_command=False, strip_prompt=False) net_connect.disconnect() DATE_RE = today + '.*' matched = re.findall(DATE_RE,output) for line in matched: print(line) #print(output)
tested on sandbox -
05-11-2020 03:29 AM - edited 05-11-2020 03:29 AM
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide