ATLAS Offline Software
TRTCalibrationMessage.py
Go to the documentation of this file.
1 """
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 """
4 import sys, os, smtplib
5 
6 def EmailNotification(jobStatus):
7 
8  AtlasBuildBranch=os.environ.get("AtlasBuildBranch" , "UNDEFINED")
9  AthenaPlatform =os.environ.get("Athena_PLATFORM" , "UNDEFINED")
10  AtlasRelease =os.environ.get("ATLAS_RELEASE_BASE", "UNDEFINED")
11  Atlasbuild =os.environ.get("AtlasBuildStamp" , "UNDEFINED")
12 
13  if AtlasBuildBranch != "24.0" and AtlasBuildBranch != "main":
14  print("AtlasBuildBranch not 24.0 or main. Exiting.")
15  sys.exit(0)
16 
17 
18  mserver = "cernmx.cern.ch"
19  mfrom = "no-reply@cern.ch"
20  mto = ["atlas-trt-offline-shifts@cern.ch","atlas-trt-expert-shifters@cern.ch"]
21  msubject = "ART test notification: TRT calibration Workflow for %s" % (AtlasBuildBranch)
22 
23  status="*SUCCEEDED*"
24  if jobStatus.ACCU != 0 or jobStatus.MERGE != 0:
25  status = "*FAILED*\n"
26  status += "\t- The TRT ACCU transform %s.\n" % ("*is broken*" if jobStatus.ACCU else "works")
27  status += "\t- The TRT MERGE transform %s." % ("*is broken*" if jobStatus.MERGE else "works")
28 
29  # assemble mail body
30  mbody = "Dear TRT expert/shifter\n\n"
31  mbody += " This email is generated by the ART test InnerDetector/InDetCalibAlgs/TRT_CalibAlgs/test/test_TRTCalibration.sh \n\n"
32  mbody += " The test has %s\n\n" % (status)
33  mbody += " For %s\n\n" % (AtlasRelease)
34  mbody += " You can check the results in https://atlas-art-data.web.cern.ch/atlas-art-data/local-output/\n"
35  mbody += " Outputs are in /eos/atlas/atlascerngroupdisk/data-art/local-output/%s/Athena/%s/%s/\n\n" % (AtlasBuildBranch,AthenaPlatform,Atlasbuild)
36  mbody += "Cheers\n"
37  mbody += "\tYour amazing TRT Calibration test"
38 
39  fullmsg = "To: %s\nSubject: %s\n\n%s" % ("".join(("%s," % str(_mto_)) for _mto_ in mto ), msubject, mbody)
40 
41  print("Email body:\n")
42  print(fullmsg)
43  print("Email sent to:")
44 
45  try :
46  con = smtplib.SMTP(mserver)
47  print("\t- %s"% (mto))
48  con.sendmail(mfrom, mto, fullmsg)
49  con.quit()
50  except OSError as e:
51  print("ERROR: Failed sending email notification\n",e)
52  exit(e.errno)
53 
54 
55 
56 if __name__ == '__main__':
57 
58  import argparse
59  parser = argparse.ArgumentParser(prog='python -m TRT_CalibAlgs.TRTCalibrationMessage',
60  description="""Email notification for ART test - R-t TRT calibration.\n\n
61  Example: python -m TRT_CalibAlgs.TRTCalibrationMessage --ACCU [status]...""")
62 
63  parser.add_argument('--ACCU' ,type=int, help="Stores the status of the job")
64  parser.add_argument('--MERGE' ,type=int, help="Stores the status of the job")
65  args = parser.parse_args()
66 
67  EmailNotification(args)
68 
69  sys.exit(0)
70 
TRTCalibrationMessage.EmailNotification
def EmailNotification(jobStatus)
Definition: TRTCalibrationMessage.py:6
calibdata.exit
exit
Definition: calibdata.py:236
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
str
Definition: BTagTrackIpAccessor.cxx:11
dbg::print
void print(std::FILE *stream, std::format_string< Args... > fmt, Args &&... args)
Definition: SGImplSvc.cxx:70