#!/usr/bin/env python

from urllib import urlencode
import urllib2
import json
import sys

if len(sys.argv) > 1:
    host = sys.argv[1]
else:
    sys.stderr.write("Usage: %s NODE\n" % sys.argv[0])
    sys.exit(1)
url = 'http://localhost:8080/v3/nodes/%s' % host

r = urllib2.Request(url)
r.add_header('Accept', 'application/json')
u = urllib2.urlopen(r)

j = json.load(u)
for k in j.keys():
    print('%s: %s' % (k, j[k]))
u.close()

sys.exit(0)
url = 'http://localhost:8080/v3/aggregate-event-counts'
data = urlencode({
    'query': [ '=', 'certname', host ],
    'summarize-by': 'certname'
    })
print(data)
r = urllib2.Request(url, data)
r.add_header('Accept', 'application/json')
u = urllib2.urlopen(r)

j = json.load(u)
for k in j.keys():
    print('%s: %s' % (k, j[k]))
u.close()
