From 830ac2a10f1241215ce3f7e44dccec2795d70786 Mon Sep 17 00:00:00 2001 From: Neil Munday Date: Mon, 4 Nov 2019 21:52:03 +0000 Subject: [PATCH] Now timestamps are used from sacct for start and end time. Added datetimeFormat config option to allow users to set date/time format. Issue #4 implemented as a result --- bin/slurm-send-mail.py | 13 ++++++++++--- conf.d/slurm-mail.conf | 5 +++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/bin/slurm-send-mail.py b/bin/slurm-send-mail.py index baffc22..5832955 100755 --- a/bin/slurm-send-mail.py +++ b/bin/slurm-send-mail.py @@ -53,6 +53,7 @@ import sys import time import smtplib +from datetime import datetime from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText from string import Template @@ -100,6 +101,8 @@ def runCommand(cmd): if args.verbose: logLevel = logging.DEBUG + os.environ['SLURM_TIME_FORMAT'] = '%s' + baseDir = os.path.abspath('%s%s../' % (os.path.dirname(os.path.realpath(__file__)), os.sep)) confDir = os.path.join(baseDir, 'conf.d') confFile = os.path.join(confDir, 'slurm-mail.conf') @@ -130,6 +133,7 @@ def runCommand(cmd): emailFromName = config.get(section, 'emailFromName') sacctExe = config.get(section, 'sacctExe') scontrolExe = config.get(section, 'scontrolExe') + datetimeFormat = config.get(section, 'datetimeFormat') except Exception as e: die('Error: %s' % e) @@ -139,6 +143,7 @@ def runCommand(cmd): logging.basicConfig(format='%(asctime)s:%(levelname)s: %(message)s', datefmt='%Y/%m/%d %H:%M:%S', level=logLevel) checkFile(sacctExe) + checkFile(scontrolExe) css = getFileContents(stylesheet) if not os.access(spoolDir, os.R_OK | os.W_OK): @@ -192,7 +197,8 @@ def runCommand(cmd): jobName = data[2] cluster = data[11] workDir = data[7] - start = data[3].replace('T', ' ') + startTS = int(data[3]) + start = datetime.fromtimestamp(startTS).strftime(datetimeFormat) comment = data[10] nodes = data[6] user = data[12] @@ -200,7 +206,8 @@ def runCommand(cmd): wallclock = data[14].replace('T', ' ') wallclockSeconds = int(data[15]) * 60 if state != 'Began': - end = data[4].replace('T', ' ') + endTS = int(data[4]) + end = datetime.fromtimestamp(endTS).strftime(datetimeFormat) elapsed = data[8] # [days-]hours:minutes:seconds # convert elapsed to seconds # do we have days? @@ -299,4 +306,4 @@ def runCommand(cmd): except Exception as e: logging.error("failed to process: %s" % f) - logging.error(e) + logging.error(e, exc_info=True) diff --git a/conf.d/slurm-mail.conf b/conf.d/slurm-mail.conf index 713adb6..1153373 100644 --- a/conf.d/slurm-mail.conf +++ b/conf.d/slurm-mail.conf @@ -11,5 +11,6 @@ logFile = /var/log/slurm-mail/slurm-spool-mail.log logFile = /var/log/slurm-mail/slurm-send-mail.log emailFromUserAddress = root emailFromName = Slurm Admin -sacctExe = /usr/bin/sacct -scontrolExe = /usr/bin/scontrol +datetimeFormat = %d/%m/%Y %H:%M:%S +sacctExe = /opt/slurm/bin/sacct +scontrolExe = /opt/slurm/bin/scontrol