X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=support-scripts%2Frenew_reminder.py;h=be377bc349d988d71dd047326cb04935cf929bb1;hb=27ae61d51ba27a22a2e9048b90fe158dd3fac592;hp=499a7d33c831330b9b4fdf9943cc5dfae9c3e3a4;hpb=ef1aa2c9f3c231f067e9b90d82f85dc7ee00a81f;p=myplc.git diff --git a/support-scripts/renew_reminder.py b/support-scripts/renew_reminder.py index 499a7d3..be377bc 100755 --- a/support-scripts/renew_reminder.py +++ b/support-scripts/renew_reminder.py @@ -5,9 +5,8 @@ # Mark Huang # Copyright (C) 2005 The Trustees of Princeton University # -# $Id$ -# +import os import sys import time from optparse import OptionParser @@ -20,6 +19,21 @@ plc = Shell(globals()) PLC_WWW_HOST = plc.config.PLC_WWW_HOST PLC_NAME = plc.config.PLC_NAME +LOGFILE = '/var/log/renew_reminder' +class Logfile: + def __init__(self, filename): + self.filename = filename + def write(self, data): + try: + fd = os.open(self.filename, os.O_WRONLY | os.O_CREAT | os.O_APPEND, 0644) + os.write(fd, '%s' % data) + os.close(fd) + except OSError: + sys.stderr.write(data) + sys.stderr.flush() + +log = Logfile(LOGFILE) + # Debug verbose = False; @@ -88,13 +102,22 @@ To update, renew, or delete this slice, visit the URL: %(slice_url)s%(slice_id)d """ + emails = [person['email'] for person in GetPersons(slice['person_ids'], ['email'])] + if not emails: emails = ['no contacts'] + log_details = [time.ctime(now), slice['name'], time.ctime(slice['expires'])] + log_data = "%s\t%s" % ("\t".join(log_details), ",".join(emails)) + # Send it if slice['person_ids']: if options.dryrun: print message % locals() + print "log >> %s" % log_data else: NotifyPersons(slice['person_ids'], "%(PLC_NAME)s slice %(name)s expires in %(days)s" % locals(), message % locals()) + print >> log, log_data + elif options.verbose: print slice['name'], "has no users, skipping" + print >> log, log_data