def _add_log(self, mylog, logtype='info'): """Add a log generated from this module""" if logtype == 'error': OUTPUT.error('{0}: {1}'.format(str(self.__class__.__name__), str(mylog))) elif logtype == 'warning': OUTPUT.warning('{0}: {1}'.format(str(self.__class__.__name__), str(mylog))) else: OUTPUT.info('{0}: {1}'.format(str(self.__class__.__name__), str(mylog)))
def send_email_template(self, jinjatemplate, jinjadata, subject, recipients, ccrecipients=None, attachments=None): try: # Render our jinja template html = self.render_jinja_template(jinjadata, jinjatemplate) except Exception as jinjaexception: OUTPUT.error('Unable to render jinja template!') raise jinjaexception return self.send_email(html=html, subject=subject, recipients=recipients, ccrecipients=ccrecipients, attachments=attachments)
def save_html_report(self, jinjatemplate, jinjadata, filename=None): """Save an html file instead of sending email""" try: # Render our jinja template html = self.render_jinja_template(jinjadata, jinjatemplate) except Exception as jinjaexception: OUTPUT.error('Unable to render jinja template!') raise jinjaexception if not filename: htmlfilepath = os.path.join(os.getcwd(), 'aws-instance-report.html') else: htmlfilepath = filename try: outputfile = open(htmlfilepath, "w") outputfile.write(html) outputfile.close() except Exception as smtplibraryexception: OUTPUT.error('Unable to save {0}!'.format(htmlfilepath)) raise smtplibraryexception