Esempio n. 1
0
    def send_mails(self, title, dryrun=False):
        if not self.send_nag_mail:
            return

        env = Environment(loader=FileSystemLoader('templates'))
        common = env.get_template('common.html')
        login_info = utils.get_login_info()
        From = Nag.get_from()
        Default_Cc = self.get_cc()
        mails = self.prepare_mails()

        for m in mails:
            Cc = Default_Cc.copy()
            if m['manager']:
                Cc.add(m['manager'])
            body = common.render(message=m['body'], query_url=None)
            receivers = set(m['to']) | set(Cc)
            status = 'Success'
            try:
                mail.send(
                    From,
                    sorted(m['to']),
                    title,
                    body,
                    Cc=sorted(Cc),
                    html=True,
                    login=login_info,
                    dryrun=dryrun,
                )
            except:  # NOQA
                logger.exception('Tool {}'.format(self.name()))
                status = 'Failure'

            db.Email.add(self.name(), receivers, 'individual', status)
Esempio n. 2
0
    def gather(self):
        env = Environment(loader=FileSystemLoader("templates"))
        common = env.get_template("common.html")
        login_info = utils.get_login_info()
        From = Nag.get_from()
        Default_Cc = set(utils.get_config("auto_nag", "cc", []))

        all_mails = {}
        for nagger in self.naggers:
            mails = nagger.prepare_mails()
            for m in mails:
                manager = m["manager"]
                if manager not in all_mails:
                    all_mails[manager] = {"to": m["to"], "body": m["body"]}
                else:
                    all_mails[manager]["to"] |= m["to"]
                    all_mails[manager]["body"] += "\n" + m["body"]

        for manager, m in all_mails.items():
            Cc = Default_Cc.copy()
            Cc.add(manager)
            body = common.render(message=m["body"], has_table=True)
            mail.send(
                From,
                list(sorted(m["to"])),
                self.title(),
                body,
                Cc=list(sorted(Cc)),
                html=True,
                login=login_info,
                dryrun=self.is_dryrun,
            )
            time.sleep(1)
Esempio n. 3
0
    def send_mails(self, title, dryrun=False):
        if not self.send_nag_mail:
            return

        env = Environment(loader=FileSystemLoader("templates"))
        common = env.get_template("common.html")
        login_info = utils.get_login_info()
        From = Nag.get_from()
        Default_Cc = self.get_cc()
        mails = self.prepare_mails()

        for m in mails:
            Cc = Default_Cc.copy()
            if m["manager"]:
                Cc.add(m["manager"])
            body = common.render(message=m["body"], query_url=None)
            receivers = set(m["to"]) | set(Cc)
            status = "Success"
            try:
                mail.send(
                    From,
                    sorted(m["to"]),
                    title,
                    body,
                    Cc=sorted(Cc),
                    html=True,
                    login=login_info,
                    dryrun=dryrun,
                )
            except Exception:
                logger.exception("Tool {}".format(self.name()))
                status = "Failure"

            db.Email.add(self.name(), receivers, "individual", status)
Esempio n. 4
0
    def gather(self, dryrun):
        env = Environment(loader=FileSystemLoader('templates'))
        common = env.get_template('common.html')
        login_info = utils.get_login_info()
        From = Nag.get_from()
        Default_Cc = Nag.get_cc()

        all_mails = {}
        for nagger in self.naggers:
            mails = nagger.prepare_mails()
            for m in mails:
                manager = m['manager']
                if manager not in all_mails:
                    all_mails[manager] = {'to': m['to'], 'body': m['body']}
                else:
                    all_mails[manager]['to'] |= m['to']
                    all_mails[manager]['body'] += '\n' + m['body']

        for manager, m in all_mails.items():
            Cc = Default_Cc.copy()
            Cc.add(manager)
            body = common.render(message=m['body'], has_table=True)
            mail.send(
                From,
                list(sorted(m['to'])),
                self.title(),
                body,
                Cc=list(sorted(Cc)),
                html=True,
                login=login_info,
                dryrun=dryrun,
            )
            time.sleep(1)
Esempio n. 5
0
    def send_mails(self, title, dryrun=False):
        if not self.send_nag_mail:
            return

        env = Environment(loader=FileSystemLoader('templates'))
        common = env.get_template('common.html')
        login_info = utils.get_login_info()
        From = Nag.get_from()
        Default_Cc = Nag.get_cc()
        mails = self.prepare_mails()

        for m in mails:
            Cc = Default_Cc.copy()
            if m['manager']:
                Cc.add(m['manager'])
            body = common.render(message=m['body'], query_url=None)
            receivers = set(m['to']) | set(Cc)
            status = 'Success'
            try:
                mail.send(
                    From,
                    sorted(m['to']),
                    title,
                    body,
                    Cc=sorted(Cc),
                    html=True,
                    login=login_info,
                    dryrun=dryrun,
                )
            except:  # NOQA
                logger.exception('Tool {}'.format(self.name()))
                status = 'Failure'

            db.Email.add(self.name(), receivers, 'individual', status)
    def send_mails(self, title, dryrun=False):
        if not self.send_nag_mail:
            return

        env = Environment(loader=FileSystemLoader('templates'))
        common = env.get_template('common.html')
        login_info = utils.get_login_info()
        From = Nag.get_from()
        Default_Cc = Nag.get_cc()
        mails = self.prepare_mails()

        for m in mails:
            Cc = Default_Cc.copy()
            if m['manager']:
                Cc.add(m['manager'])
            body = common.render(message=m['body'],
                                 query_url=None,
                                 has_table=True)
            mail.send(
                From,
                sorted(m['to']),
                title,
                body,
                Cc=sorted(Cc),
                html=True,
                login=login_info,
                dryrun=dryrun,
            )
Esempio n. 7
0
    def send_email(self, date="today"):
        """Send the email"""
        if date:
            date = lmdutils.get_date(date)
            d = lmdutils.get_date_ymd(date)
            if isinstance(self, Nag):
                self.nag_date = d

            if not self.must_run(d):
                return

        if not self.has_enough_data():
            logger.info("The tool {} hasn't enough data to run".format(
                self.name()))
            return

        login_info = utils.get_login_info()
        title, body = self.get_email(date)
        if title:
            receivers = self.get_receivers()
            status = "Success"
            try:
                mail.send(
                    login_info["ldap_username"],
                    receivers,
                    title,
                    body,
                    html=True,
                    login=login_info,
                    dryrun=self.dryrun,
                )
            except Exception:
                logger.exception("Tool {}".format(self.name()))
                status = "Failure"

            db.Email.add(self.name(), receivers, "global", status)
            if isinstance(self, Nag):
                self.send_mails(title, dryrun=self.dryrun)
        else:
            name = self.name().upper()
            if date:
                logger.info("{}: No data for {}".format(name, date))
            else:
                logger.info("{}: No data".format(name))
            logger.info("Query: {}".format(self.query_url))
Esempio n. 8
0
    def send_email(self, date='today'):
        """Send the email"""
        if date:
            date = lmdutils.get_date(date)
            d = lmdutils.get_date_ymd(date)
            if isinstance(self, Nag):
                self.nag_date = d

            if not self.must_run(d):
                return

        if not self.has_enough_data():
            logger.info('The tool {} hasn\'t enough data to run'.format(
                self.name()))
            return

        login_info = utils.get_login_info()
        title, body = self.get_email(date)
        if title:
            receivers = self.get_receivers()
            status = 'Success'
            try:
                mail.send(
                    login_info['ldap_username'],
                    receivers,
                    title,
                    body,
                    html=True,
                    login=login_info,
                    dryrun=self.dryrun,
                )
            except:  # NOQA
                logger.exception('Tool {}'.format(self.name()))
                status = 'Failure'

            db.Email.add(self.name(), receivers, 'global', status)
            if isinstance(self, Nag):
                self.send_mails(title, dryrun=self.dryrun)
        else:
            name = self.name().upper()
            if date:
                logger.info('{}: No data for {}'.format(name, date))
            else:
                logger.info('{}: No data'.format(name))
            logger.info('Query: {}'.format(self.query_url))
Esempio n. 9
0
    def send_email(self, date='today'):
        """Send the email"""
        if date:
            date = lmdutils.get_date(date)
            d = lmdutils.get_date_ymd(date)
            if isinstance(self, Nag):
                self.nag_date = d

            if not self.must_run(d):
                return

        if not self.has_enough_data():
            logger.info('The tool {} hasn\'t enough data to run'.format(self.name()))
            return

        login_info = utils.get_login_info()
        title, body = self.get_email(date)
        if title:
            receivers = self.get_receivers()
            status = 'Success'
            try:
                mail.send(
                    login_info['ldap_username'],
                    receivers,
                    title,
                    body,
                    html=True,
                    login=login_info,
                    dryrun=self.dryrun,
                )
            except:  # NOQA
                logger.exception('Tool {}'.format(self.name()))
                status = 'Failure'

            db.Email.add(self.name(), receivers, 'global', status)
            if isinstance(self, Nag):
                self.send_mails(title, dryrun=self.dryrun)
        else:
            name = self.name().upper()
            if date:
                logger.info('{}: No data for {}'.format(name, date))
            else:
                logger.info('{}: No data'.format(name))
            logger.info('Query: {}'.format(self.query_url))
Esempio n. 10
0
    def send_email(self, date='today', dryrun=False):
        """Send the email"""
        if date:
            date = lmdutils.get_date(date)
            d = lmdutils.get_date_ymd(date)
            if isinstance(self, Nag):
                self.nag_date = d

            if not self.must_run(d):
                return

        if not self.has_enough_data():
            logger.info('The tool {} hasn\'t enough data to run'.format(
                self.name()))
            return

        login_info = utils.get_login_info()
        title, body = self.get_email(login_info['bz_api_key'], date, dryrun)
        if title:
            mail.send(
                login_info['ldap_username'],
                utils.get_config(self.name(), 'receivers'),
                title,
                body,
                html=True,
                login=login_info,
                dryrun=dryrun,
            )

            if isinstance(self, Nag):
                self.send_mails(title, dryrun=dryrun)
        else:
            name = self.name().upper()
            if date:
                logger.info('{}: No data for {}'.format(name, date))
            else:
                logger.info('{}: No data'.format(name))