Skip to content

Instantly share code, notes, and snippets.

@timsutton
Last active December 12, 2015 04:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timsutton/4716084 to your computer and use it in GitHub Desktop.
Save timsutton/4716084 to your computer and use it in GitHub Desktop.
Scrape board IDs from munkiwebadmin reports, given that clients are using an admin-provided condition: 'machine_board_id'.
#!/usr/bin/env python
# run from the same directory that contains the munkiwebadmin database,
# with the app's virtualenv activated (ie. 'source /paht/to/env/bin/activate')
import sqlite3
import plistlib
import sys
from django.utils.encoding import smart_str
from pprint import pprint
DB = 'munkiadmin.db'
conn = sqlite3.connect(DB)
c = conn.cursor()
reports = c.execute('''SELECT report from reports_munkireport''')
boards_populated = 0
boards = {}
for r in reports.fetchall():
smrt = smart_str(r[0])
p = plistlib.readPlistFromString(smrt)
if 'Conditions' in p.keys():
if 'machine_board_id' in p['Conditions']:
if p['Conditions']['machine_board_id'] and p['Conditions']['machine_board_id'] != '440BX':
boards_populated += 1
boards[p['Conditions']['machine_board_id']] = p['Conditions']['machine_model']
conn.close()
print "%s clients with board-id configs." % str(boards_populated)
print "%s board-id values populated." % len(boards.keys())
pprint(boards)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment