Skip to content

Commit

Permalink
Now timestamps are used from sacct for start and end time. Added date…
Browse files Browse the repository at this point in the history
…timeFormat config option to allow users to set date/time format. Issue #4 implemented as a result
  • Loading branch information
neilmunday committed Nov 4, 2019
1 parent ec60898 commit 830ac2a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
13 changes: 10 additions & 3 deletions bin/slurm-send-mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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)

Expand All @@ -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):
Expand Down Expand Up @@ -192,15 +197,17 @@ 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]
nodelist = data[13]
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?
Expand Down Expand Up @@ -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)
5 changes: 3 additions & 2 deletions conf.d/slurm-mail.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 830ac2a

Please sign in to comment.