@app.route('/', defaults={'env': app.config['DEFAULT_ENVIRONMENT']})
@app.route('/<env>/')
def index(env):
    envs = environments()
    metrics = {
        'num_nodes': 0,
        'num_resources': 0,
        'avg_resources_node': 0}
    check_env(env, envs)

    if env == '*':
        query = None

        prefix = 'puppetlabs.puppetdb.population'
        num_nodes = get_or_abort(
            puppetdb.metric,
            "{0}{1}".format(prefix, ':name=num-nodes'))
        num_resources = get_or_abort(
            puppetdb.metric,
            "{0}{1}".format(prefix, ':name=num-resources'))
        avg_resources_node = get_or_abort(
            puppetdb.metric,
            "{0}{1}".format(prefix, ':name=avg-resources-per-node'))
        metrics['num_nodes'] = num_nodes['Value']
        metrics['num_resources'] = num_resources['Value']
        metrics['avg_resources_node'] = "{0:10.0f}".format(
            avg_resources_node['Value'])
    else:
        query = '["and", {0}]'.format(
                ", ".join('["=", "{0}", "{1}"]'.format(field, env)
                    for field in ['catalog_environment', 'facts_environment']))
        num_nodes = get_or_abort(
            puppetdb._query,
            'nodes',
            query='["extract", [["function", "count"]],["and", {0}]]'.format(
                    ",".join('["=", "{0}", "{1}"]'.format(field, env)
                        for field in ['catalog_environment', 'facts_environment'])))
        num_resources = get_or_abort(
            puppetdb._query,
            'resources',
            query='["extract", [["function", "count"]],' \
                '["=", "environment", "{0}"]]'.format(
                    env))
        metrics['num_nodes'] = num_nodes[0]['count']
        metrics['num_resources'] = num_resources[0]['count']
        metrics['avg_resources_node'] = "{0:10.0f}".format(
            (num_resources[0]['count'] / num_nodes[0]['count']))

    nodes = get_or_abort(puppetdb.nodes,
        query=query,
        unreported=app.config['UNRESPONSIVE_HOURS'],
        with_status=True)

    nodes_overview = []
    stats = {
        'changed': 0,
        'unchanged': 0,
        'failed': 0,
        'unreported': 0,
        'noop': 0
        }

    for node in nodes:
        if node.status == 'unreported':
            stats['unreported'] += 1
        elif node.status == 'changed':
            stats['changed'] += 1
        elif node.status == 'failed':
            stats['failed'] += 1
        elif node.status == 'noop':
            stats['noop'] += 1
        else:
            stats['unchanged'] += 1

        if node.status != 'unchanged':
            nodes_overview.append(node)

    return render_template(
        'index.html',
        metrics=metrics,
        nodes=nodes_overview,
        stats=stats,
        envs=envs,
        current_env=env
        )
This view generates the index page and displays a set of metrics and
dataset/ETHPy150Open voxpupuli/puppetboard/puppetboard/app.py/index