Created
October 28, 2015 11:24
-
-
Save apahim/6e0df2ef6ae440ea6f33 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/python | |
# Amador Pahim <apahim AT redhat DOT com> | |
import sys | |
import json | |
try: | |
logfile = sys.argv[1] | |
except: | |
logfile = '/var/log/rhsm/rhsm.log' | |
in_section = False | |
with open(logfile, 'r') as f: | |
for line in f: | |
if in_section: | |
section.append(line) | |
if 'hosts-to-guests mapping' in line.strip(): | |
section = [] | |
in_section = True | |
timestamp = "%s %s" % (line.split()[0], line.split()[1]) | |
section.append('{') | |
if in_section and line == '}\n': | |
in_section = False | |
host_guest_map = json.loads("".join(section)) | |
section = [] | |
print(timestamp) | |
for host in host_guest_map: | |
print(" - Host: %s -> %s VMs" % (host, | |
len(host_guest_map[host]))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment