-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbackup_status_prtg.py
86 lines (67 loc) · 2.46 KB
/
backup_status_prtg.py
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import os
import datetime as dt
import re
backup_state_file_path = '/root/configuration-backup-manager/backup_state.txt'
def is_file_current(filename):
try:
today = dt.datetime.now().date()
filetime = dt.datetime.fromtimestamp(os.path.getmtime(filename))
if filetime.date() == today:
return True
else:
return False
except Exception as e:
return False
def is_no_errors_count(filename):
try:
pattern = re.compile("Errored Backups: (\\d)")
for line in open(filename):
for match in re.finditer(pattern, line):
if match.group(1) == '0':
return True
else:
return False
return False
except Exception as e:
return False
def is_no_s3_errors(filename):
try:
pattern = re.compile("(S3 SYNC SUCCESSFUL)")
for line in open(filename):
for match in re.finditer(pattern, line):
if match.group(1) == 'S3 SYNC SUCCESSFUL':
return True
else:
return False
return False
except Exception as e:
return False
def is_total_match(filename):
try:
pattern1 = re.compile("Errored Backups: (\\d)")
for line in open(filename):
for match in re.finditer(pattern1, line):
total_errors = match.group(1)
pattern2 = re.compile("Successful Backups: (\\d)")
for line in open(filename):
for match in re.finditer(pattern2, line):
total_success = match.group(1)
pattern3 = re.compile("Total Devices Tagged for Backup: (\\d)")
for line in open(filename):
for match in re.finditer(pattern3, line):
total_hosts = match.group(1)
if int(total_errors) + int(total_hosts) == int(total_success):
return True
else:
return False
except Exception as e:
return False
def main():
backup_status = is_file_current(backup_state_file_path) and is_no_errors_count(backup_state_file_path) and is_no_s3_errors(backup_state_file_path) and is_total_match(backup_state_file_path)
if os.path.exists("/usr/share/nginx/html/backup_status.txt"):
os.remove("/usr/share/nginx/html/backup_status.txt")
f = open("/usr/share/nginx/html/backup_status.txt", "a")
f.write(str(backup_status))
f.close()
if __name__ == "__main__":
main()