def mail_summary(mail_recipients, mail_server = "mail.hackingteam.com"): logging.info("sending mail to %s" % mail_recipients) # Import smtplib for the actual sending function import smtplib # Import the email modules we'll need from email.mime.text import MIMEText report = Report() # Open a plain text file for reading. For this example, assume that # the text file contains only ASCII characters. sum = summary() # Create a text/plain message for recipient in mail_recipients: msg = MIMEText(sum) # me == the sender's email address # you == the recipient's email address hostname = helper.get_hostname() msg['Subject'] = '%s@%s: %s' % (report.name, hostname, report.timestamp) msg['From'] = "*****@*****.**" msg['To'] = recipient logging.debug(" msg to: %s" % msg['To']) # Send the message via our own SMTP server, but don't include the # envelope header. s = smtplib.SMTP(mail_server) s.sendmail(msg['From'], [msg['To']], msg.as_string()) s.quit()
def __init__(self, backend, frontend=None, platform='windows', kind='silent', ftype='desktop', blacklist=[], soldierlist=[], param=None, puppet="puppet", asset_dir="AVAgent/assets", factory=None): self.kind = kind self.host = (backend, frontend) self.hostname = helper.get_hostname() self.prefix = puppet self.blacklist = blacklist self.soldierlist = soldierlist self.platform = platform self.asset_dir = asset_dir self.ftype = ftype self.param = param self.factory = factory logging.debug("DBG blacklist: %s" % self.blacklist) logging.debug("DBG soldierlist: %s" % self.soldierlist) logging.debug("DBG hostname: %s" % self.hostname)
def mail_summary(mail_recipients, mail_server="mail.hackingteam.com"): logging.info("sending mail to %s" % mail_recipients) # Import smtplib for the actual sending function import smtplib # Import the email modules we'll need from email.mime.text import MIMEText report = Report() # Open a plain text file for reading. For this example, assume that # the text file contains only ASCII characters. sum = summary() # Create a text/plain message for recipient in mail_recipients: msg = MIMEText(sum) # me == the sender's email address # you == the recipient's email address hostname = helper.get_hostname() msg['Subject'] = '%s@%s: %s' % (report.name, hostname, report.timestamp) msg['From'] = "*****@*****.**" msg['To'] = recipient logging.debug(" msg to: %s" % msg['To']) # Send the message via our own SMTP server, but don't include the # envelope header. s = smtplib.SMTP(mail_server) s.sendmail(msg['From'], [msg['To']], msg.as_string()) s.quit()
def summary(): report = Report() report.vm = {} hostname = helper.get_hostname() summary_header = "SUMMARY @%s \n-- %s --\n %s\n" % (hostname, report.name, report.timestamp) summary = "\n" failed = OrderedDict() failed_kind = OrderedDict() important_commands = [] # ["BUILD", "CHECK_STATIC"] for vm in report.c_received.keys(): report.vm[vm] = [] current_proc = None summary += "\n[ %s ]\n" % vm one_report = False for cmd in report.c_received[vm]: #cmd = Cmd(c) if cmd.name == "REPORT_KIND_END": current_proc, report_args = cmd.args report.vm[vm].append(current_proc) success = "SUCCESS" if cmd.success else "FAILED" if not cmd.success: if vm not in failed: failed[vm] = [] if current_proc not in failed_kind: failed_kind[current_proc] = [] failed_kind[current_proc].append(vm) failed[vm].append(current_proc) summary += " %s: %s\n" % (current_proc, success) one_report = True else: if current_proc: if cmd.success == False: summary += " %s\n" % (str(cmd)) elif cmd.name in important_commands and cmd.success: #check = ['+ ERROR','+ FAILED'] #errors = any([ s in c for s in check ]) #if errors: summary += " %s\n" % (red(str(cmd), 80)) if not one_report: if vm not in failed: failed[vm] = [] failed[vm].append("NO REPORT") if failed: fail_err = "\nFAILED VM:\n" for vm, err in failed.items(): fail_err += "%s %s\n" % (vm, err) summary = fail_err + summary if failed_kind: fail_err = "\nFAILED KIND:\n" for kind, err in failed_kind.items(): fail_err += "%s %s\n" % (kind, err) summary = fail_err + summary append_retest(failed_kind) return summary_header + summary
def summary(): report = Report() report.vm = {} hostname = helper.get_hostname() summary_header = "SUMMARY @%s \n-- %s --\n %s\n" % (hostname, report.name, report.timestamp) summary = "\n" failed = OrderedDict() failed_kind = OrderedDict() important_commands = [] # ["BUILD", "CHECK_STATIC"] for vm in report.c_received.keys(): report.vm[vm] = [] current_proc = None summary += "\n[ %s ]\n" % vm one_report = False for cmd in report.c_received[vm]: #cmd = Cmd(c) if cmd.name == "REPORT_KIND_END": current_proc, report_args = cmd.args report.vm[vm].append(current_proc) success = "SUCCESS" if cmd.success else "FAILED" if not cmd.success: if vm not in failed: failed[vm] = [] if current_proc not in failed_kind: failed_kind[current_proc] = [] failed_kind[current_proc].append(vm) failed[vm].append(current_proc) summary += " %s: %s\n" % (current_proc, success) one_report = True else: if current_proc: if cmd.success == False: summary+=" %s\n" % (str(cmd)) elif cmd.name in important_commands and cmd.success: #check = ['+ ERROR','+ FAILED'] #errors = any([ s in c for s in check ]) #if errors: summary+=" %s\n" % (red(str(cmd), 80)) if not one_report: if vm not in failed: failed[vm] = [] failed[vm].append("NO REPORT") if failed: fail_err = "\nFAILED VM:\n" for vm, err in failed.items(): fail_err += "%s %s\n" % (vm, err) summary = fail_err + summary if failed_kind: fail_err = "\nFAILED KIND:\n" for kind, err in failed_kind.items(): fail_err += "%s %s\n" % (kind, err) summary = fail_err + summary append_retest(failed_kind) return summary_header + summary
def execute(vm, protocol, args): # change the kind for the vm from AVMaster import report from AVMaster import testrail_api proc_name, report_args = args logging.debug(" CS REPORT_KIND_END: %s, %s, %s" % (vm, proc_name, report_args)) #assert vm in command.context["report"], "report: %s" % command.context["report"] success = not protocol.error logging.debug("%s, success: %s" % (vm, success)) elapsed = (time.time() - protocol.elapsed) / 60 try: # ['AV Invisibility', 'Melt'] # ['AV Invisibility', 'Melt', INVERT] if report_args: run_name = report_args.pop(0) test_case = report_args.pop(0) proj_id = 1 hostname = helper.get_hostname() plan_name = "Continuous Testing %s" % hostname if "INVERT" in report_args: result = 'failed' if success else 'passed' else: result = 'passed' if success else 'failed' configs = { 'AV Invisibility': "%s, Windows" % vm, 'AV Invisibility Static': "%s, Windows" % vm } config = configs.get(run_name, vm) logging.debug("search plan %s on %s" % (proj_id, plan_name)) plan = testrail_api.search_plan(proj_id, plan_name=plan_name) plan_id = plan["id"] errors = "\n".join(protocol.errors) testrail_api.add_plan_result(proj_id, plan_id, config, run_name, test_case, result, int(elapsed), errors) except: logging.exception("error testrail") return success, "%s| %s" % (vm, proc_name)
def execute(vm, protocol, args): # change the kind for the vm from AVMaster import report from AVMaster import testrail_api proc_name, report_args = args logging.debug(" CS REPORT_KIND_END: %s, %s, %s" % (vm, proc_name, report_args)) #assert vm in command.context["report"], "report: %s" % command.context["report"] success = not protocol.error logging.debug("%s, success: %s" % (vm, success)) elapsed = (time.time() - protocol.elapsed) / 60 try: # ['AV Invisibility', 'Melt'] # ['AV Invisibility', 'Melt', INVERT] if report_args: run_name = report_args.pop(0) test_case = report_args.pop(0) proj_id = 1 hostname = helper.get_hostname() plan_name = "Continuous Testing %s" % hostname if "INVERT" in report_args: result = 'failed' if success else 'passed' else: result = 'passed' if success else 'failed' configs={ 'AV Invisibility': "%s, Windows" % vm, 'AV Invisibility Static': "%s, Windows" % vm} config = configs.get(run_name, vm) logging.debug("search plan %s on %s" % (proj_id, plan_name)) plan = testrail_api.search_plan(proj_id, plan_name=plan_name) plan_id = plan["id"] errors = "\n".join(protocol.errors) testrail_api.add_plan_result(proj_id, plan_id, config, run_name, test_case, result, int(elapsed), errors) except: logging.exception("error testrail") return success, "%s| %s" % (vm, proc_name)
def get_target_name(): return 'VM_%s' % helper.get_hostname()