def email(query, emails, rule_name): ''' Sends out an email with the script attached ''' # for gzip compressed use file extension .tar.gz and modifier "w:gz" os.rename('wget_script.sh', 'wget_script.bash') tar = tarfile.open("wget.tar.gz", "w:gz") tar.add('wget_script.bash') tar.close() attachments = None cc_recipients = [i.strip() for i in emails.split(',')] bcc_recipients = [] subject = "[monitor] (wget_script:%s)" % (rule_name) body = "Product was ingested from query: %s" % query body += "\n\nYou can use this wget script attached to download products.\n" body += "Please rename wget_script.bash to wget_script.sh before running it." if os.path.isfile('wget.tar.gz'): wget_content = open('wget.tar.gz', 'r').read() attachments = {'wget.tar.gz': wget_content} notify_by_email.send_email(getpass.getuser(), cc_recipients, bcc_recipients, subject, body, attachments=attachments)
def email_to_user(emails, project_name, rule_names, rules_info): logger.debug("New rule(s) triggered. \nNeed to send email to admin") print("New rule(s) triggered. \nNeed to send email to admin") attachments = None if emails != '': to_recipients = [i.strip() for i in emails.split(',')] else: to_recipients = '' bcc_recipients = '' subject = "[Rule Added] (%s)" % (project_name) body = "Hi,\n" body += "New trigger rules have been added using the 'Add trigger rules' action. To see the parameters and conditions for each rule created, please check 'My Rules' in the Aria Search interface.\n" body += "\nFor project: " + project_name + "\n" body += "Rule names: " + ",".join([str(i) for i in rule_names]) + "\n" body += rules_info body += "If you have any questions, please email [email protected]\n" body += "Thanks,\n Aria" notify_by_email.send_email("*****@*****.**", to_recipients, bcc_recipients, subject, body, attachments=attachments) logger.info("Email sent to %s", emails) print("Email sent to %s", emails)
def email_to_ops(aoi_list, expired_aois): LOGGER.debug("\nNeed to send email to ops with list of expiring") print("\nNeed to send email to ops with list of expiring") attachments = None bcc_recipients = '' cc_recipients = '*****@*****.**' subject = "Test: Expiring AOIs" body = "Hi,\n" body += "\nBelow is the list of AOIs expiring within the next 7 days. \n" for aoi in aoi_list: body += aoi + '\n' body += "\nBelow is the list of AOIs that have been marked inactive (Not really. This is a test)\n" for aoi in expired_aois: body += aoi + '\n' body += "\nIf you have any questions, please email [email protected]\n" body += "Thanks,\n Aria" notify_by_email.send_email("*****@*****.**", cc_recipients, bcc_recipients, subject, body, attachments) LOGGER.info("Email sent to %s", cc_recipients) print("Email sent to %s", cc_recipients)
if __name__ == "__main__": ''' Main program of aws_get_script ''' # encoding to a JSON object query = json.loads(sys.argv[1]) emails = sys.argv[2] rule_name = sys.argv[3] # getting the script aws_get_script(query) # now email the query attachments = None cc_recipients = [i.strip() for i in emails.split(',')] bcc_recipients = [] subject = "[monitor] (aws_get_script:%s)" % (rule_name) body = "Product was ingested from query: %s" % query body += "\n\nYou can use this AWS get script attached to download products.\n" body += "Please rename aws_get_script.bash to aws_get_script.sh before running it." if os.path.isfile('aws_get.tar.gz'): aws_get_content = open('aws_get.tar.gz', 'rb').read() attachments = {'aws_get.tar.gz': aws_get_content} notify_by_email.send_email(getpass.getuser(), cc_recipients, bcc_recipients, subject, body, attachments=attachments)