How to use the ara.models.Stats function in ara

To help you get started, we’ve selected a few ara examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ansible-community / ara / ara / callback / ara.py View on Github external
def log_stats(self, stats):
        hosts = sorted(stats.processed.keys())
        for host in hosts:
            host_stats = stats.summarize(host)
            data = models.Stats(**{
                'id': str(uuid.uuid4()),
                'playbook_uuid': self.playbook_uuid,
                'host': host,
                'changed': host_stats['changed'],
                'unreachable': host_stats['unreachable'],
                'failures': host_stats['failures'],
                'ok': host_stats['ok'],
                'skipped': host_stats['skipped']
            })
            db.session.add(data)
            db.session.commit()
github dmsimard / ara-archive / ara / plugins / callbacks / log_ara.py View on Github external
def log_stats(self, stats):
        """
        Logs playbook statistics to the database.
        """
        LOG.debug('logging stats')
        hosts = sorted(stats.processed.keys())
        for hostname in hosts:
            host = self.get_or_create_host(hostname)
            host_stats = stats.summarize(hostname)
            db.session.add(models.Stats(
                playbook=self.playbook,
                host=host,
                changed=host_stats['changed'],
                unreachable=host_stats['unreachable'],
                failed=host_stats['failures'],
                ok=host_stats['ok'],
                skipped=host_stats['skipped']
            ))
            db.session.commit()
github ansible-community / ara / ara / plugins / callbacks / log_ara.py View on Github external
def log_stats(self, stats):
        """
        Logs playbook statistics to the database.
        """
        log.debug('logging stats')
        hosts = sorted(stats.processed.keys())
        for hostname in hosts:
            host = self.get_or_create_host(hostname)
            host_stats = stats.summarize(hostname)
            db.session.add(models.Stats(
                playbook=self.playbook,
                host=host,
                changed=host_stats['changed'],
                unreachable=host_stats['unreachable'],
                failed=host_stats['failures'],
                ok=host_stats['ok'],
                skipped=host_stats['skipped']
            ))
            db.session.commit()
github ansible-community / ara / ara / views / reports.py View on Github external
def ajax_stats(playbook):
    stats = (models.Stats.query
             .filter(models.Stats.playbook_id == playbook))
    if not utils.fast_count(stats):
        abort(404)

    jinja = current_app.jinja_env
    host_link = jinja.get_template('ajax/stats.html')

    results = dict()
    results['data'] = list()

    log.debug('Loading host statistics and facts')
    for stat in stats:
        host = host_link.render(host=stat.host)
        ok = stat.ok if stat.ok >= 1 else 0
        changed = stat.changed if stat.changed >= 1 else 0
        failed = stat.failed if stat.failed >= 1 else 0
        skipped = stat.skipped if stat.skipped >= 1 else 0
github dmsimard / ara-archive / ara / cli / stats.py View on Github external
def take_action(self, parsed_args):
        stats = (models.Stats.query
                 .join(models.Playbook)
                 .join(models.Host)
                 .filter(models.Stats.playbook_id == models.Playbook.id)
                 .filter(models.Stats.host_id == models.Host.id)
                 .order_by(models.Playbook.time_start, models.Host.name))

        return [[field.name for field in LIST_FIELDS],
                [[field(stat) for field in LIST_FIELDS]
                 for stat in stats]]
github ansible-community / ara / ara / utils.py View on Github external
def get_summary_stats(items, attr):
    """
    Returns a dictionary of aggregated statistics for 'items' filtered by
    "attr'. For example, it will aggregate statistics for a host across all
    the playbook runs it has been a member of, with the following structure:

        data[host.id] = {
            'ok': 4
            'changed': 4
            ...
        }
    """
    data = {}
    for item in items:
        stats = models.Stats.query.filter_by(**{attr: item.id})
        data[item.id] = {
            'ok': sum([int(stat.ok) for stat in stats]),
            'changed': sum([int(stat.changed) for stat in stats]),
            'failed': sum([int(stat.failed) for stat in stats]),
            'skipped': sum([int(stat.skipped) for stat in stats]),
            'unreachable': sum([int(stat.unreachable) for stat in stats])
        }

        # If we're aggregating stats for a playbook, also infer status
        if attr is "playbook_id":
            data[item.id]['status'] = _infer_status(item, data[item.id])

    return data
github dmsimard / ara-archive / ara / utils.py View on Github external
def get_summary_stats(items, attr):
    """
    Returns a dictionary of aggregated statistics for 'items' filtered by
    "attr'. For example, it will aggregate statistics for a host across all
    the playbook runs it has been a member of, with the following structure:

        data[host.id] = {
            'ok': 4
            'changed': 4
            ...
        }
    """
    data = {}
    for item in items:
        stats = models.Stats.query.filter_by(**{attr: item.id})
        data[item.id] = {
            'ok': sum([int(stat.ok) for stat in stats]),
            'changed': sum([int(stat.changed) for stat in stats]),
            'failed': sum([int(stat.failed) for stat in stats]),
            'skipped': sum([int(stat.skipped) for stat in stats]),
            'unreachable': sum([int(stat.unreachable) for stat in stats])
        }

        # If we're aggregating stats for a playbook, also infer status
        if attr is "playbook_id":
            data[item.id]['status'] = _infer_status(item, data[item.id])

    return data
github dmsimard / ara-archive / ara / views / reports.py View on Github external
def ajax_stats(playbook):
    stats = (models.Stats.query
             .filter(models.Stats.playbook_id.in_([playbook])))
    if not utils.fast_count(stats):
        abort(404)

    jinja = current_app.jinja_env
    host_link = jinja.get_template('ajax/stats.html')

    results = dict()
    results['data'] = list()

    for stat in stats:
        host = host_link.render(stat=stat)
        ok = stat.ok if stat.ok >= 1 else 0
        changed = stat.changed if stat.changed >= 1 else 0
        failed = stat.failed if stat.failed >= 1 else 0
        skipped = stat.skipped if stat.skipped >= 1 else 0
        unreachable = stat.unreachable if stat.unreachable >= 1 else 0