Skip to content

Instantly share code, notes, and snippets.

@apahim
Created October 28, 2015 11:24
Show Gist options
  • Save apahim/6e0df2ef6ae440ea6f33 to your computer and use it in GitHub Desktop.
Save apahim/6e0df2ef6ae440ea6f33 to your computer and use it in GitHub Desktop.
#!/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