· 5 years ago · May 03, 2020, 11:30 PM
1import os
2import re
3import sqlite3
4#os.system('raid.bat')
5
6#Initial definitions
7timedate = str()
8freespace = str()
9temp = str()
10rstatus = str()
11directory = 'raid_dump/'
12
13#Initialize DB
14conn = sqlite3.connect('core.sqlite')
15cur = conn.cursor()
16
17#Trash old data - FOR DEV!
18cur.execute('DROP TABLE IF EXISTS Host')
19cur.execute('DROP TABLE IF EXISTS Client')
20cur.execute('DROP TABLE IF EXISTS RAID')
21
22#Create tables
23cur.execute('''CREATE TABLE Client (
24 id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
25 clientname TEXT NOT NULL UNIQUE)''')
26
27cur.execute('''CREATE TABLE RAID (
28 id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
29 rtemp INTEGER NOT NULL,
30 rstatus TEXT NOT NULL)''')
31
32cur.execute('''CREATE TABLE Host (
33 id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
34 hostname TEXT NOT NULL UNIQUE,
35 client_id INTEGER,
36 raid_id INTEGER
37 )''')
38
39
40for filename in os.listdir(directory):
41 if filename.endswith(".txt"):
42 temp_gauge = int(0)
43 str_data = open(directory+filename)
44 for line in str_data:
45 timedate = line.lstrip().rstrip()
46 break
47 for line in str_data:
48
49 if "free" in line:
50 freespace = line.split()
51 print(type(freespace[2]))
52 if len(freespace[2]) > 12:
53 freespace = re.findall('(.+).{12}$', freespace[2])
54 else:
55 freespace = str('Less than a gigabyte remaining!')
56 if "Logical devices/Failed/Degraded" in line:
57 rstatus = line.lstrip().rstrip()
58 if temp_gauge == 0:
59 if "Temperature" in line:
60 temp = line.split()
61 temp_gauge += 1
62 print(timedate)
63 print(freespace[0], 'Gigabytes free')
64 print('Temperature is',temp[4],'F')
65 print(rstatus)