forked from cms-sw/cms-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
es_ibs_log.py
executable file
·61 lines (58 loc) · 1.98 KB
/
es_ibs_log.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
#!/bin/env python
from hashlib import sha1
import os, sys,json , re , datetime
from os import getenv
from os.path import exists
from time import strftime , strptime
from es_utils import send_payload
import commands
def process_ib_utests(logFile):
t = os.path.getmtime(logFile)
timestp = datetime.datetime.fromtimestamp(int(t)).strftime('%Y-%m-%d %H:%M:%S')
payload = {}
pathInfo = logFile.split('/')
architecture = pathInfo[4]
release = pathInfo[8]
#dat = re.findall('\d{4}-\d{2}-\d{2}',release)[0]
index = "ibs"
document = "unittests"
payload["release"] = release
payload["architecture"] = architecture
payload["@timestamp"] = timestp
if exists(logFile):
with open(logFile) as f:
try:
it = iter(f)
line = it.next()
while '--------' not in line:
line = it.next()
while True:
line=it.next().strip()
if ":" in line:
pkg = line.split(':')[0].strip()
payload["url"] = 'https://cmssdt.cern.ch/SDT/cgi-bin/buildlogs/'+ architecture +'/'+ release +'/unitTestLogs/' + pkg
line = it.next().strip()
while ':' not in line:
if "had ERRORS" in line:
payload["status"] = 1
else:
payload["status"] = 0
utest= line.split(' ')[0]
payload["package"] = pkg
payload["name"] = utest
id = sha1(release + architecture + utest).hexdigest()
send_payload(index,document,id,json.dumps(payload))
line = it.next().strip()
except Exception as e:
print "File processed:", e
else:
print "Invalid File Path"
#get log files
logs = commands.getstatusoutput("find /data/sdt/buildlogs -mindepth 6 -maxdepth 6 -name 'unitTests-summary.log'")
logs = logs[1].split('\n')
#process log files
for logFile in logs:
flagFile = logFile + '.checked'
if not os.path.exists(flagFile):
process_ib_utests(logFile)
os.system('touch "' + flagFile + '"')