Skip to content

Commit

Permalink
Add debug option to postflight
Browse files Browse the repository at this point in the history
  • Loading branch information
grahamgilbert committed Dec 2, 2014
1 parent 0da9fd5 commit d53d575
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
2 changes: 1 addition & 1 deletion scripts/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
USE_PKGBUILD=1
include /usr/local/share/luggage/luggage.make
PACKAGE_VERSION=0.2.3
PACKAGE_VERSION=0.2.4
TITLE=sal_scripts
PACKAGE_NAME=sal_scripts
REVERSE_DOMAIN=com.grahamgilbert
Expand Down
29 changes: 28 additions & 1 deletion scripts/sal-postflight
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ import yaml
import bz2
import os
import sys
import optparse

BUNDLE_ID = 'com.grahamgilbert.sal'
default_debug = False

def get_disk_size(path='/'):
"""Returns total disk size in KBytes.
Expand Down Expand Up @@ -88,6 +91,16 @@ def pref(pref_name):
pref_value = str(pref_value)
return pref_value

usage = "%prog [options]"
o = optparse.OptionParser(usage=usage)

o.add_option("--debug",
default=default_debug, action="store_true",
help=("Enable debug output. "))

opts, args = o.parse_args()
debug = opts.debug

# read in the serverURL
ServerURL = pref('ServerURL');
checkinurl = ServerURL+'/checkin'
Expand All @@ -96,7 +109,9 @@ bu_key = pref('key')

# read in Munki Report
report = FoundationPlist.readPlist('/Library/Managed Installs/ManagedInstallReport.plist')

if debug:
print 'DEBUG: ManagedInstallReport.plist'
print report
# generate system profiler report
command = ['system_profiler', '-xml', 'SPNetworkDataType', 'SPHardwareDataType']
task = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
Expand All @@ -107,11 +122,17 @@ try:
f = open('/var/lib/puppet/state/last_run_summary.yaml', 'r')
puppetreport = yaml.load(f.read())
report['Puppet'] = puppetreport
if debug:
print 'DEBUG: Puppet Report'
print report['Puppet']
except:
pass

# Merge the system profiler report into the Munki report
report['MachineInfo']['SystemProfile'] = system_profile
if debug:
print 'DEBUG: System Profile'
print report['MachineInfo']['SystemProfile']

# Set the FACTERLIB environment variable if it's not already what we want it to be.
desiredfacter = '/usr/local/sal/facter'
Expand Down Expand Up @@ -142,6 +163,9 @@ try:
if stdout:
facter = yaml.load(stdout)
report['Facter'] = facter
if debug:
print 'DEBUG: Facter Output'
print report['Facter']
except:
print stderr

Expand All @@ -164,6 +188,9 @@ report['os_family'] = 'Darwin'

# Compress the report
plist = FoundationPlist.writePlistToString(report)
if debug:
print 'DEBUG: Final Report'
print plist
zipped = bz2.compress(plist)

data['base64bz2report'] = base64.b64encode(zipped)
Expand Down

0 comments on commit d53d575

Please sign in to comment.