示例#1
0
    def run(self):
        """Run device and agent checks"""

        # Main loop
        devices = self.api.get_devices()
        for device in devices:

            # Begin
            device = Device(device, self.results)
            logger.debug('---- Device: %s ----', device.name)

            # Device checks
            if device.is_inactive():
                logger.debug('    Device is archived or paused')
                continue
            device.run_device_checks()
            if device.is_offline:
                logger.debug(
                    '    Device is offline; skipping remaining checks')
                continue

            # Agent checks
            asset_details = self.api.get_asset_details(device.serial_number)
            for agent in asset_details:
                agent = Agent(self.api, agent, device, self.results,
                              self.include_unprotected)
                logger.debug('    ---- Agent: %s ----', agent.name)
                if agent.is_inactive():
                    logger.debug(' ' * 8 + 'Agent is archived or paused')
                    continue
                agent.run_agent_checks()
        self.api.session_close()
        logger.info('All checks complete')

        # Main loop done; send report
        if config.EMAIL_TO:
            mailer = Email()

            d = datetime.today()
            subject = 'Daily Datto Check: {}'.format(d.strftime('%m/%d/%Y'))

            report = mailer.build_html_report(self.results.results)
            mailer.send_email(config.EMAIL_TO, config.EMAIL_FROM, subject,
                              report, config.EMAIL_CC)
示例#2
0
def setup_mail(to, files):
    email = Email()

    email.prepare_msg(to)
    email.attach_msg(email.set_msg(files))
    email.send_email()