-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathVeeamBackupAnalyzer.py
More file actions
72 lines (61 loc) · 1.7 KB
/
VeeamBackupAnalyzer.py
File metadata and controls
72 lines (61 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/python
# !!! SORRY for the messy code, I'm not a programmer
import email, imaplib
import mysql.connector
import datetime
#eMail connection
username = 'pcbackups@example.com'
password = 'emailpassword'
imap = imaplib.IMAP4_SSL('192.168.1.100')
imap.login(username, password)
imap.select("Inbox")
now = str(datetime.datetime.now())
day = str(datetime.date.today())
#MySQL
mydb = mysql.connector.connect(
host="localhost",
user="pi",
passwd="raspberry",
database="pcbv2"
)
mycursor = mydb.cursor()
# MySQL write
def mysqlWrite(pcname,status,message):
global now
sql = "INSERT INTO pc (pcname,status,date) VALUES (%s, %s, %s) ON DUPLICATE KEY UPDATE status = %s, date = %s"
val = (pcname, status, now, status, now)
mycursor.execute(sql, val)
sqlmsg = "INSERT INTO messages (pcname,message) VALUES (%s, %s)"
valmsg = (pcname, message)
mycursor.execute(sqlmsg, valmsg)
mydb.commit()
resp, items = imap.search(None, "UNSEEN")
for n, num in enumerate(items[0].split(), 1):
resp, data = imap.fetch(num, '(RFC822)')
body = data[0][1]
msg = email.message_from_string(body)
content = msg.get_payload(decode=True)
# print(content)
start = content.find("Backup Job ") + len("Backup Job ")
end = content.find('<div class="jobDescription"')
pcname = content[start:end]
if pcname.endswith(" (Retry)"):
pcname = pcname[:-8]
if pcname.endswith(" (Full)"):
pcname = pcname[:-7]
# print(content)
if "#00B050" in content:
# print("Success")
status = 1
elif "#ffd96c" in content:
# print("Warning")
status = 2
elif "#fb9895" in content:
# print("Failure")
status = 3
else:
# print("No status data")
status = 0
#print(pcname)
#write data to mysql DB
mysqlWrite(pcname,status,content)