Пример #1
0
 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)))
Пример #2
0
    def send_notice(self):
        """
        Send job status update notifications if required.
        """
        if self.should_send_alert() or self.should_send_warning(
        ) or self.runargs['force']:
            # Send email notification to passed argument recipients if defined,
            #  otherwise send to stored recipients.
            recipients = self.runargs['emailrecipients']

            if recipients:
                status = 'Normal'
                if self.warningthresholdreached:
                    status = 'Warning'
                if self.alertthresholdreached:
                    status = 'Alert'
                # Jinja requires this entire data structure for the included
                # templates. recipients are automatically split by semicolon and sent to
                # individually.

                emaildata = {
                    "emailtitle":
                    "AWS Aware Status: {0}".format(status),
                    "date":
                    date.today().strftime('%m/%d/%Y'),
                    "monitors":
                    self.monitorjobs,
                    "costcenter":
                    self.eval_filter('costcenter'),
                    "environment":
                    self.eval_filter('environment'),
                    "appname":
                    self.eval_filter('appname'),
                    "instances":
                    self.get_instances(),
                    "allinstances":
                    self.get_instances(filtered=True),
                    "view":
                    self.view,
                    "additionalnotes":
                    'Please review these thresholds and take appropriate action to reduce instance counts down to the approved level. Below are all instances with tag filters matching your CostCenter, Environment, and Application Name (but grouped by Process Name). Attached is a report of all instances returned in this environment for further review.'
                }
                CFG.emailhandler.send_email_template(
                    jinjatemplate='email-html_instance_monitor',
                    jinjadata=emaildata,
                    subject="AWS Aware Status: {0}".format(status),
                    recipients=str(recipients).split(';'))
            else:
                OUTPUT.warning(
                    'There are no recipients passed or defined for this job. Exiting.'
                )
Пример #3
0
    def send_instance_report(self, filteredinstances=False):
        """
        Send instance report.
        """
        # Send email notification to passed argument recipients if defined,
        #  otherwise send to stored recipients.
        recipients = self.runargs['emailrecipients']
        instances = self.get_instances(filtered=filteredinstances)
        instancecounts = self.get_all_instance_counts(instances=instances)
        if recipients:
            status = 'Normal'
            if self.warningthresholdreached:
                status = 'Warning'
            if self.alertthresholdreached:
                status = 'Alert'
            # Get instance counts
            # Jinja requires this entire data structure for the included
            # templates. recipients are automatically split by semicolon and sent to
            # individually.
            reportdata = {
                "title": 'Instance Report - {0}'.format(status),
                "date": date.today().strftime('%m/%d/%Y'),
                "view": self.view,
                "monitors": self.monitorjobs,
                "costcenter": self.eval_filter('costcenter'),
                "environment": self.eval_filter('environment'),
                "appname": self.eval_filter('appname'),
                "instances": instances,
                "instancecounts": instancecounts,
                "additionalnotes": '(Includes running instances only.)'
            }

            CFG.emailhandler.save_html_report(
                jinjatemplate='report-html_instance_details',
                jinjadata=reportdata)

            emaildata = {
                "emailtitle":
                "AWS Instances: Status = {0}".format(status),
                "date":
                date.today().strftime('%m/%d/%Y'),
                "view":
                self.view,
                "monitors":
                self.monitorjobs,
                "costcenter":
                self.eval_filter('costcenter'),
                "environment":
                self.eval_filter('environment'),
                "appname":
                self.eval_filter('appname'),
                "instances":
                None,
                "additionalnotes":
                'To view this report please save it locally then open in your browser. Only running instances are included. Clusters are sorted by name then instance type. Review all clusters to ensure they are aligned with your application requirements.'
            }

            emaildata['instances'] = self.get_instances(
                filtered=filteredinstances)
            emaildata['costcenter'] = self.eval_filter('costcenter')
            emaildata['environment'] = self.eval_filter('environment')
            emaildata['appname'] = self.eval_filter('appname')

            CFG.emailhandler.send_email_template(
                jinjatemplate='email-html_instance_monitor',
                jinjadata=emaildata,
                subject="AWS Aware Instance Report",
                recipients=str(recipients).split(';'),
                attachments=['./aws-instance-report.html'])
        else:
            OUTPUT.warning(
                'There are no recipients passed or defined for this job. Exiting.'
            )
Пример #4
0
    def send_notice_with_report(self):
        """
        Send job status update notifications if required.
        """
        if self.should_send_alert() or self.should_send_warning(
        ) or self.runargs['force']:
            # Send email notification to passed argument recipients if defined,
            #  otherwise send to stored recipients.
            recipients = self.runargs['emailrecipients']

            if recipients:
                status = 'Normal'
                if self.warningthresholdreached:
                    status = 'Warning'
                if self.alertthresholdreached:
                    status = 'Alert'
                # Jinja requires this entire data structure for the included
                # templates. recipients are automatically split by semicolon and sent to
                # individually.

                reportdata = {
                    "title": 'All Instances',
                    "date": date.today().strftime('%m/%d/%Y'),
                    "monitors": self.monitorjobs,
                    "costcenter": '*',
                    "environment": '*',
                    "appname": '*',
                    "instances": self.get_instances(),
                    "allinstances": self.get_instances(filtered=True),
                    "additionalnotes": 'Includes running instances only.'
                }
                CFG.emailhandler.save_html_report(
                    jinjatemplate='report-html_instance_details',
                    jinjadata=reportdata)

                emaildata = {
                    "emailtitle":
                    "AWS Aware Status: {0}".format(status),
                    "date":
                    date.today().strftime('%m/%d/%Y'),
                    "monitors":
                    self.monitorjobs,
                    "costcenter":
                    self.eval_filter('costcenter'),
                    "environment":
                    self.eval_filter('environment'),
                    "appname":
                    self.eval_filter('appname'),
                    "instances":
                    self.get_instances(),
                    "view":
                    self.view,
                    "additionalnotes":
                    'Please review these thresholds and take appropriate action to reduce instance counts to the approved level. (Save, then open the attached report for further instance details grouped by the ProcessName tag)'
                }
                CFG.emailhandler.send_email_template(
                    jinjatemplate='email-html_instance_monitor',
                    jinjadata=emaildata,
                    subject="AWS Aware Status: {0}".format(status),
                    recipients=str(recipients).split(';'),
                    attachments=['./aws-instance-report.html'])
            else:
                OUTPUT.warning(
                    'There are no recipients passed or defined for this job. Exiting.'
                )