This repository has been archived by the owner on Dec 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlogcheck.py
executable file
·54 lines (49 loc) · 1.73 KB
/
logcheck.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
#!/usr/bin/python2
import optparse
import time
import re
L = {}
R = {}
def parse_options():
parser = optparse.OptionParser()
parser.add_option("-l", "--logfile", dest="logfile", action="store",
help="Logfile", default="/var/log/psync/psync.log")
parser.add_option("-g", "--gap", dest="gap", action="store",
help="Gap (in seconds)", default=900)
return parser.parse_args()
def scanlines():
with open(options.logfile) as log:
for line in log:
if 'f+++++++++' not in line and 'f.s.......' not in line:
continue
match = re.search('\[(.*)\] \[.*\] \[.*\] \[.*\] \[.*\] ' +
'<f.[s+]....... (.*)', line)
if match:
timestamp = time.mktime(time.strptime(match.group(1),
"%Y-%m-%d %H:%M:%S"))
L[match.group(2)].append(timestamp)
continue
match = re.search('\[(.*)\] \[.*\] \[.*\] \[.*\] \[.*\] ' +
'>f.[s+]....... (.*)', line)
if match:
timestamp = time.mktime(time.strptime(match.group(1),
"%Y-%m-%d %H:%M:%S"))
R[match.group(2)].append(timestamp)
continue
def compare():
found = False
for left_entry in L:
if left_entry in R:
ltime = L[left_entry]
rtime = R[left_entry]
if abs(ltime-rtime) < options.gap:
print "Double-edited entry: "+left_entry
found = True
return found
(options, args) = parse_options()
scanlines()
found = compare()
if found:
quit(1)
else:
quit(0)