ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/TMISoftware/ErrorStream/errorStreamCron.py
Revision: 1.1
Committed: Wed Oct 9 13:35:29 2013 UTC (11 years, 6 months ago) by fantasia
Content type: text/x-python
Branch: MAIN
CVS Tags: HEAD
Log Message:
cron script to report error stream events

File Contents

# Content
1 #! /usr/bin/env python
2 #Run with acrontab line:
3 #0 * * * * lxplus404.cern.ch /afs/cern.ch/user/f/fantasia/public/HLT/ErrorStream/errorStreamCron.py Data >& /dev/null
4
5 import os
6 import sys
7 import time
8 if len(sys.argv) != 2:
9 print "usage ./errorStreamCron.py ERA"
10 print "to display the available ERA labels "
11 print "/afs/cern.ch/user/c/chenders/public/hlt/error_stream_collector/error_stream_collector.pl --showEras"
12 sys.exit(1)
13 ERA = sys.argv[1]
14 #RUNNUMBER = sys.argv[2]
15
16 #Get Last Run Number Looked at
17 file = open("/afs/cern.ch/user/f/fantasia/public/HLT/ErrorStream/lastErrorStreamRun.dat")
18 line = file.readline()
19 RUNNUMBER = line.rstrip()
20 #print "Using last runnumber "+RUNNUMBER
21 file.close()
22 # if the old list does not exist, create an empty one
23 if not os.path.exists("/tmp/errorStream.list"): os.system("echo none > /tmp/errorStream.list")
24 ########### get the list of available runs
25 os.system("/afs/cern.ch/user/c/chenders/public/hlt/error_stream_collector/error_stream_collector.pl --era="+ERA+" "+RUNNUMBER+" > /tmp/error_stream_collector.tmp")
26 os.system("touch /tmp/errorStream.list")
27 os.system("mv /tmp/errorStream.list /tmp/errorStream_old.list")
28 os.system("grep .dat /tmp/error_stream_collector.tmp > /tmp/errorStream.list")
29 os.system("diff /tmp/errorStream.list /tmp/errorStream_old.list | grep .dat > /tmp/error_diff.list")
30
31 LastRun = int(RUNNUMBER)
32 # check for new events
33 file = open("/tmp/error_diff.list")
34 line = file.readline()
35 newError = False
36 if line: newError = True
37 file.close()
38 #print "Old LastRun is ",LastRun
39 if newError:
40 # prepare the email body
41 message = "New HLT error event ["+ERA+"]:"
42 file = open("/tmp/error_diff.list")
43 runnumber = "none"
44 for line in file:
45 newRunString = line.split(ERA)[1].split(".")[1]
46 newRun = int(newRunString)
47 # print "new run is "+newRunString+" or as an int ",newRun
48 errorEvent = "run "+newRunString
49 if runnumber != errorEvent:
50 # print "run number is "+runnumber+" and the newRun is ",newRun
51 runnumber = errorEvent
52 if newRun > LastRun:
53 LastRun = newRun
54 # print "new last run is ",LastRun
55 message = message+" "+runnumber+" "
56 continue
57 file.close()
58 hour = time.localtime()[3]
59 # send alerts to TMI
60 os.system("echo "+message+" | mail -s \"new entry in Error Stream\" hlt-tmi-oncall@cern.ch")
61 # send alerts to Tulika
62 os.system("echo "+message+" | mail -s \"new entry in Error Stream\" tulika@mail.cern.ch")
63 # send sms messages if daytime
64 if hour > -3 and hour < 200:
65 smsmessage = message
66 if len(smsmessage) > 160: smsmessage = "New HLT error event ["+ERA+"]. Message too long to display"
67 # send alerts to Maurizio's CERN PHONE
68 # os.system("echo "+smsmessage+" | mail -s \"new entry in Error Stream\" 0041764871355@sms.switch.ch")
69 # send alerts to HLT PHONE
70 #os.system("echo "+smsmessage+" | mail -s \"new entry in Error Stream\" 0041764875575@sms.switch.ch")
71 # clean up
72 os.system("rm /tmp/error_diff.list")
73 os.system("rm /tmp/errorStream_old.list")
74 os.system("rm /tmp/error_stream_collector.tmp")
75 #Update last run used
76 f = open('/afs/cern.ch/user/f/fantasia/public/HLT/ErrorStream/lastErrorStreamRun.dat','w')
77 print >>f, LastRun