X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=monitor%2Fwrapper%2Fmailer.py;h=afa72eb24fe8f4736ef688137e69509cf883f6ea;hb=HEAD;hp=4a0d661917f63b5ebfe9a0ff23a04ff98afdab7f;hpb=258e40c53d1f6e79ea92548765d65bbb74eba004;p=monitor.git diff --git a/monitor/wrapper/mailer.py b/monitor/wrapper/mailer.py index 4a0d661..afa72eb 100755 --- a/monitor/wrapper/mailer.py +++ b/monitor/wrapper/mailer.py @@ -52,7 +52,7 @@ def getTicketStatus(ticket_id): if ticket_id == None or ticket_id == "": return {} - cmd = "rt show -t ticket -f id,subject,status,queue,created %s" % (ticket_id) + cmd = "rt show -t ticket -f id,subject,status,queue,created,told %s" % (ticket_id) print cmd (f_in, f_out, f_err) = os.popen3(cmd) value = f_out.read() @@ -65,7 +65,12 @@ def getTicketStatus(ticket_id): r_values[key] = ":".join(vals[1:]) r_values[key] = r_values[key].strip() - r_values['Created'] = calendar.timegm(time.strptime(r_values['Created'])) + #if 'Created' in r_values: + # r_values['Created'] = calendar.timegm(time.strptime(r_values['Created'])) + #else: + r_values['Created'] = calendar.timegm(time.localtime()) + + #r_values['Told'] = calendar.timegm(time.strptime(r_values['Told'])) return r_values def setAdminCCViaRT(ticket_id, to): @@ -79,7 +84,7 @@ def setAdminCCViaRT(ticket_id, to): # create a comma-separated list s_to = ",".join(to) - cmd = "rt edit ticket/%s set admincc='%s'" % (ticket_id, s_to) + cmd = "rt edit ticket/%s set cc='%s'" % (ticket_id, s_to) print cmd (f_in, f_out, f_err) = os.popen3(cmd) value = f_out.read() @@ -90,7 +95,7 @@ def setAdminCCViaRT(ticket_id, to): pass else: print "VALUE:", value - print "ERROR: RT failed to update AdminCC for ticket %s" % ticket_id + print "ERROR: RT failed to update CC for ticket %s" % ticket_id return @@ -194,7 +199,8 @@ def emailViaRT(subject, text, to, ticket_id=None): cmd = "rt correspond -m - %s" % ticket_id print cmd (f_in, f_out, f_err) = os.popen3(cmd) - f_in.write(text) + #f_in.write(input[:32000]) + f_in.write(text[:32000]) f_in.flush() f_in.close() value = f_out.read() @@ -223,14 +229,15 @@ def emailViaRT_NoTicket(subject, text, to): # Set ENV Variables/PATH _setupRTenvironment() - # NOTE: AdminCc: (in PLC's RT configuration) gets an email sent. + # NOTE: Cc: (in PLC's RT configuration) gets an email sent. # This is not the case (surprisingly) for Cc: input_text = "Subject: %s\n" input_text += "Requestor: %s\n"% FROM input_text += "id: ticket/new\n" input_text += "Queue: %s\n" % config.RT_QUEUE for recipient in to: - input_text += "AdminCc: %s\n" % recipient + input_text += "Cc: %s\n" % recipient + #input_text += "Cc: %s\n" % config.cc_email input_text += "Text: %s" # Add a space for each new line to get RT to accept the file. @@ -240,7 +247,12 @@ def emailViaRT_NoTicket(subject, text, to): cmd = "rt create -i -t ticket" print cmd (f_in, f_out, f_err) = os.popen3(cmd) - f_in.write(input_text % (subject, spaced_text)) + input = input_text % (subject, spaced_text) + print "length: %s" % len(input) + # NOTE: RT hangs with larger input, probably due to some internal + # buffering. So, chop off messages at 32000 + #f_in.write(input[:32000]) + f_in.write(input[:32000]) f_in.flush() f_in.close() value = f_out.read() @@ -331,12 +343,7 @@ def email(subject, text, to): for mta in [MTA, 'golf.cs.princeton.edu']: try: # This is normal operation - #print MTA - #print FROM - #print to - #print msg server = smtplib.SMTP(mta) - #server = smtplib.SMTP('golf.cs.princeton.edu') server.sendmail(FROM, to, msg) if config.bcc and not config.debug: server.sendmail(FROM, config.email, msg) @@ -353,17 +360,10 @@ def email(subject, text, to): except Exception, err: print "Mailer error2: failed using MTA(%s) with: %s" % (mta, err) else: - #print "Would mail %s" %to logger.debug("Would send mail to %s" % to) if __name__=="__main__": import smtplib import emailTxt import plc - #email("[spam] bcc test from golf.cs.princeton.edu", - # "It gets to both recipients", - # "soltesz@cs.utk.edu") - emailViaRT("mail via RT", "Let's see if this succeeds...", [FROM]) - #email("Re: [PL #21323] TEST 7", - # mailtxt.newbootcd_one[1] % {'hostname_list':"hostname list..."}, - # [FROM]) + emailViaRT("test monitor mail 9", "Let's see if this succeeds...", ["stephen.soltesz@gmail.com"])