Skip to content

Instantly share code, notes, and snippets.

@discentem
Last active October 12, 2016 02:26
Show Gist options
  • Select an option

  • Save discentem/9b46aeb10a230ea5a4974a56db25ff2c to your computer and use it in GitHub Desktop.

Select an option

Save discentem/9b46aeb10a230ea5a4974a56db25ff2c to your computer and use it in GitHub Desktop.

Revisions

  1. discentem revised this gist Oct 12, 2016. 1 changed file with 27 additions and 10 deletions.
    37 changes: 27 additions & 10 deletions ohai_experiments.py
    Original 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_u = json.loads(report)
    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'
    return ohai
    ohai = json.loads(report)
    return hashrocket_flatten_dict(ohai)

    print(get_ohai_report('/Users/Brandon/Desktop/log'))
    ohai = get_ohai_report('/Users/Brandon/Desktop/log')
    for key, val in ohai.items():
    print key, val
  2. discentem revised this gist Oct 12, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ohai_experiments.py
    Original 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')
    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'
  3. discentem created this gist Oct 12, 2016.
    20 changes: 20 additions & 0 deletions ohai_experiments.py
    Original 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'))