'Send reports to Foreman to be parsed by its config report
importer. THe data is in a format that Foreman can handle
without writing another report importer.'

def send_reports(self, stats):

    status = defaultdict((lambda : 0))
    metrics = {}
    for host in stats.processed.keys():
        sum = stats.summarize(host)
        status['applied'] = sum['changed']
        status['failed'] = (sum['failures'] + sum['unreachable'])
        status['skipped'] = sum['skipped']
        log = self._build_log(self.items[host])
        metrics['time'] = {'total': (int(time.time()) - self.start_time)}
        now = datetime.now().strftime(self.TIME_FORMAT)
        report = {'report': {'host': host, 'reported_at': now, 'metrics': metrics, 'status': status, 'logs': log}}
        requests.post(url=(self.FOREMAN_URL + '/api/v2/reports'), data=json.dumps(report), headers=self.FOREMAN_HEADERS, cert=self.FOREMAN_SSL_CERT, verify=self.ssl_verify)
        self.items[host] = []
