ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/RateMonShiftTool_dev/mailAlert.py
Revision: 1.3
Committed: Wed Apr 4 08:57:56 2012 UTC (13 years ago) by grchrist
Content type: text/x-python
Branch: MAIN
CVS Tags: V00-02-06, V00-02-05, V00-02-04, V00-02-03, V00-02-01, V00-01-10, V-00-01-10, V00-01-09, V00-01-08, V00-01-07, V00-01-06, V00-01-05, V00-01-04, V00-01-03, V00-01-02, V00-01-01, V00-00-34, V00-00-33, MenuAnalyzer_V00-00-02, MenuAnalyzer_V00-00-01, MenuAnalyzer_V1, V00-00-32, V00-00-31, V00-00-30, V00-00-29, V00-00-28, V00-00-27, V00-00-26, HEAD
Changes since 1.2: +2 -2 lines
Log Message:
put an exception message in GetLatestRunNumber where there is no trigger key

File Contents

# User Rev Content
1 amott 1.2 #!/usr/bin/env python
2 amott 1.1 import os
3     import smtplib
4     from email.mime.text import MIMEText
5     import time
6     import DatabaseParser
7     from datetime import datetime,timedelta
8     import sys
9     sys.path.append('/nfshome0/hltpro/scripts')
10     try: ## so that we don't publish the list of on-calls in CVS
11     import emailList
12     eList=True
13     except:
14     eList=False
15     def getLastRuns(h=24):
16 grchrist 1.3 lastRun,isCol,isGood = DatabaseParser.GetLatestRunNumber()
17 amott 1.1
18     curs = DatabaseParser.ConnectDB()
19 amott 1.2 query ="""SELECT A.RUNNUMBER,B.STARTTIME, B.STOPTIME,B.TRIGGERS
20 amott 1.1 FROM CMS_RUNINFO.RUNNUMBERTBL A, CMS_WBM.RUNSUMMARY B
21 amott 1.2 WHERE A.RUNNUMBER=B.RUNNUMBER AND B.TRIGGERS>100 AND A.RUNNUMBER > %d-1000""" % (lastRun,)
22 amott 1.1 #query = query +repr(datetime.now()+timedelta(days=-1))
23     curs.execute(query)
24     runs = []
25     past = datetime.now()+timedelta(hours=-h)
26 amott 1.2 for r,starttime,stoptime,trig in curs.fetchall():
27     if not stoptime or stoptime > past:
28     runs.append((r,trig,stoptime))
29 amott 1.1 return runs
30    
31     def digest(hours,maxRate=35,printAll=False):
32     isBadRun=False
33     text=""
34     runs = getLastRuns(hours)
35     for run,nTrig,time in runs:
36 grchrist 1.3 run,isCol,isGood = DatabaseParser.GetLatestRunNumber(run)
37 amott 1.1 runParser = DatabaseParser.DatabaseParser()
38     runParser.RunNumber = run
39     runParser.ParseRunSetup()
40     #lumiRange = runParser.GetLSRange(0,99999,isCol)
41     expressRates = {}
42     if isCol:
43     expressRates = runParser.GetTriggerRatesByLS("ExpressOutput")
44     else:
45     expressRates = runParser.GetTriggerRatesByLS("ExpressCosmicsOutput")
46     ExpRate = sum(expressRates.values())/len(expressRates.values())
47     #for ls in lumiRange:
48     # ExpRate+=expressRates.get(ls,0)
49     #ExpRate/=len(lumiRange)
50     if ExpRate > maxRate or printAll:
51     text=text+"%s Run %d: %d Triggers, Average Express Rate %0.1f Hz\n" %(str(time),run,nTrig,ExpRate,)
52     if ExpRate > maxRate:
53     isBadRun = True
54     try:
55     text = text+" >> Processed Runs: %d-%d\n" % (runs[0][0],runs[-1][0],)
56     except:
57     text = text+" >> No Runs in last %d hours" % (hours,)
58     return isBadRun,text
59    
60     def sendMail(email,subject,to,fro,msgtxt):
61     msg = MIMEText(msgtxt)
62     msg['Subject'] = subject
63     msg['From'] = fro
64     msg['To'] = to
65     s = smtplib.SMTP('localhost')
66     s.sendmail("hlt@cern.ch", email, msg.as_string())
67     s.quit()
68    
69     if __name__=='__main__':
70     isBad,text = digest(1)
71 amott 1.2 sendMail("alex.mott@cern.ch","[HLTRateMonDebug] Express Rate Digest","HLTDebug","HLTDebug",text)
72 amott 1.1 if eList:
73     if isBad:
74     for email in emailList.emailList:
75     sendMail(email,"[HLTRateMon] Express Rate Digest","HLT","HLT",text)
76     else:
77     print text