Creating a nice html-like uptime report with Pandas

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:

Skomentuj

Wprowadź swoje dane lub kliknij jedną z tych ikon, aby się zalogować:

Logo WordPress.com

Komentujesz korzystając z konta WordPress.com. Wyloguj /  Zmień )

Zdjęcie na Google

Komentujesz korzystając z konta Google. Wyloguj /  Zmień )

Zdjęcie z Twittera

Komentujesz korzystając z konta Twitter. Wyloguj /  Zmień )

Zdjęcie na Facebooku

Komentujesz korzystając z konta Facebook. Wyloguj /  Zmień )

Połączenie z %s