Created
March 18, 2013 18:33
-
-
Save timsutton/5189575 to your computer and use it in GitHub Desktop.
Simple script to map board IDs to Mac Model names, taken from a MunkiWebAdmin/MunkiReport db.
This file contains 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
#!/usr/bin/env python | |
# Print out a list of board-id to model mappings from a munkiwebadmin/munkireport | |
# database. Requires the machine's board-id to be present at the admin-provided condition | |
# called 'machine_board_id'. A custom condition script to populate this can be found at: | |
# https://github.com/timsutton/munki-conditions/blob/master/hardware_id | |
# Hardcoded assumptions: | |
# - script is being run from a working directory where 'munkiadmin.db' can be found | |
# - if a virtualenv is being used, it is already activated (ie. 'source /path/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