#! /usr/bin/env python

import sys
import os
import json

STATS_PATH = '/var/lib/authentic2/static/stats.json'

if len(sys.argv) == 2 and sys.argv[1] == 'autoconf':
    if os.path.exists(STATS_PATH):
        print 'yes'
        sys.exit(0)
    else:
        print 'no'
        sys.exit(1)

stats = json.load(file(STATS_PATH))
graph_keys = []
for key in stats:
    if key == 'active_federations':
        continue
    if not key.startswith('users_last'):
        continue
    graph_keys.append(key)

if len(sys.argv) == 2 and sys.argv[1] == 'config':
    print 'graph_title Authentic activity'
    print 'graph_category authentic'
    print 'graph_args --lower-limit 0'
    print 'graph_vlabel n'
    print ''
    for key in graph_keys:
        print '%s.label %s' % (key, key)
    sys.exit(0)


for key in graph_keys:
    print '%s.value %s' % (key, stats.get(key))

