Last active
October 12, 2016 02:26
-
-
Save discentem/9b46aeb10a230ea5a4974a56db25ff2c to your computer and use it in GitHub Desktop.
Revisions
-
discentem revised this gist
Oct 12, 2016 . 1 changed file with 27 additions and 10 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,20 +1,37 @@ import subprocess import json def hashrocket_flatten_dict(input_dict): """Flattens the output from Facter 3""" result_dict = {} for fact_name, fact_value in input_dict.items(): if type(fact_value) == dict: # Need to recurse at this point # pylint: disable=line-too-long for new_key, new_value in hashrocket_flatten_dict( fact_value).items(): fact_name = fact_name.encode('ascii', 'ignore') new_key = new_key.encode('ascii', 'ignore') try: new_value = new_value.encode('ascii', 'ignore') except AttributeError: pass result_dict['=>'.join([fact_name, new_key])] = new_value else: result_dict[fact_name] = fact_value return result_dict def get_ohai_report(log_path): report = None ohai_path = '/usr/local/bin/ohai' command = [ohai_path, '-L', log_path] report = subprocess.check_output(command) ohai = json.loads(report) return hashrocket_flatten_dict(ohai) ohai = get_ohai_report('/Users/Brandon/Desktop/log') for key, val in ohai.items(): print key, val -
discentem revised this gist
Oct 12, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -11,7 +11,7 @@ def get_ohai_report(log_path): ohai = {} for key, val in ohai_u.items(): key = key.encode('ascii', 'ignore') val = val.encode('ascii', 'ignore') # might be another dictionary (containing more dictionaries...more) ohai[key] = ohai_u[key] if ohai[key] is None: ohai[key] = 'null' -
discentem created this gist
Oct 12, 2016 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ import subprocess import json def get_ohai_report(log_path): report = None ohai_path = '/usr/local/bin/ohai' command = [ohai_path, '-L', log_path] report = subprocess.check_output(command) ohai_u = json.loads(report) ohai = {} for key, val in ohai_u.items(): key = key.encode('ascii', 'ignore') val = val.encode('ascii', 'ignore') ohai[key] = ohai_u[key] if ohai[key] is None: ohai[key] = 'null' return ohai print(get_ohai_report('/Users/Brandon/Desktop/log'))