· 5 years ago · May 03, 2020, 10:18 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 str_data = open(directory+filename)
43 for line in str_data:
44 timedate = line.lstrip().rstrip()
45 break
46
47 for line in str_data:
48 if "free" in line:
49 freespace = line.lstrip().rstrip()
50 if "Temperature" in line:
51 temp = line.lstrip().rstrip()
52 if "Logical devices/Failed/Degraded" in line:
53 rstatus = line.lstrip().rstrip()
54
55 print(timedate)
56 print(freespace)
57 print(temp)
58 print(rstatus)