This time it’s a dry-run, so instead of polling routers, i use ready strings ‚processor is …’. If you haven’t read the previous posts: in the full version of the script, i poll the router using Netmiko, issue the command ”show version”, take the bit with the uptime and process this paragraph to create a report, for example i want to know if the router has reloaded recently.
I’m using pandas with a nested dictionary to create a HTML table with values. If the script finds the word ”week”, and if the number > 4, it’s a success, otherwise it’s a partial failure (=<4) or a failure (word ”week” not found).
import re import pandas as pd test_results = {} endresultstring = "processor is 3 days" if bool(re.findall(r'(week)', endresultstring)): if int(str(re.findall(r'[0-9]+', endresultstring)[0])) > 4: test_results.update( {'R1' : {'uptime test': 'success'}}) else: test_results.update( {'R1' : {'uptime test': 'partial failure'}}) else: test_results.update( {'R1' : {'uptime test': 'failure'}}) endresultstring = "processor is 3 weeks" if bool(re.findall(r'(week)', endresultstring)): if int(str(re.findall(r'[0-9]+', endresultstring)[0])) > 4: test_results.update( {'R2' : {'uptime test': 'success'}}) else: test_results.update( {'R2' : {'uptime test': 'partial failure'}}) else: test_results.update( {'R2' : {'uptime test': 'failure'}}) endresultstring = "processor is 5 weeks" if bool(re.findall(r'(week)', endresultstring)): if int(str(re.findall(r'[0-9]+', endresultstring)[0])) > 4: test_results.update( {'R3' : {'uptime test': 'success'}}) else: test_results.update( {'R3' : {'uptime test': 'partial failure'}}) else: test_results.update( {'R3' : {'uptime test': 'failure'}}) df = pd.DataFrame(data=test_results) df = df.fillna(' ').T print(df)
Output is very nice:
