Skip to content

Commit

Permalink
Merge pull request #9 from tuxudo/patch-1
Browse files Browse the repository at this point in the history
Update for python 3
  • Loading branch information
tuxudo authored Dec 12, 2022
2 parents aef6e80 + 3120f1e commit b768053
Showing 1 changed file with 17 additions and 21 deletions.
38 changes: 17 additions & 21 deletions scripts/munkireportinfo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/local/munkireport/munkireport-python2
#!/usr/local/munkireport/munkireport-python3

import subprocess
import os
Expand All @@ -13,17 +13,6 @@ sys.path.insert(0, '/usr/local/munkireport')
from munkilib import FoundationPlist
from Foundation import CFPreferencesCopyAppValue

def get_pref_value(key, domain):

value = CFPreferencesCopyAppValue(key, domain)

if(value is not None):
return value
elif(value is not None and len(value) == 0 ):
return ""
else:
return ""

def get_log(result):

# Check if the log exists
Expand All @@ -38,29 +27,29 @@ def get_log(result):

# Process log from bottom up to get last full run
for line in reversed(open("/Library/MunkiReport/Logs/MunkiReport.log").readlines()):
if "## Starting MunkiReport run" in line and current_run is 1:
if "## Starting MunkiReport run" in line and current_run == 1:
# Check if we've passed through the current run logs and change flag
current_run = 0
elif "## Starting MunkiReport run" in line and current_run is 0:
elif "## Starting MunkiReport run" in line and current_run == 0:
mr_log.append(line.strip())
time_line = line.replace("## Starting MunkiReport run", "").strip()
try:
result["start_time"] = munki_log_to_timestamp(time_line)
except:
result["start_time"] = int(time.time())
break
elif "## Finished run" in line and current_run is 0:
elif "## Finished run" in line and current_run == 0:
mr_log.append(line.strip())
time_line = line.replace("## Finished run", "").strip()
try:
result["end_time"] = munki_log_to_timestamp(time_line)
except:
result["end_time"] = int(time.time())
elif "Sending items (" in line and current_run is 0:
elif "Sending items (" in line and current_run == 0:
mr_log.append(line.strip())
upload_size = line.split("Sending items (")[-1].replace(")", "").strip()
result["upload_size"] = upload_size
elif current_run is 0:
elif current_run == 0:

# Log the errors and warnings
if " ERROR: " in line:
Expand Down Expand Up @@ -115,6 +104,17 @@ def munki_log_to_timestamp(time_string):
utc_naive = dt.replace(tzinfo=None) - dt.utcoffset()
return int((utc_naive - datetime(1970, 1, 1)).total_seconds())

def get_pref_value(key, domain):

value = CFPreferencesCopyAppValue(key, domain)

if(value is not None):
return value
elif(value is not None and len(value) == 0 ):
return ""
else:
return ""

class FixedOffset(tzinfo):
"""offset_str: Fixed offset in str: e.g. '-0400'"""
def __init__(self, offset_str):
Expand All @@ -137,10 +137,6 @@ class FixedOffset(tzinfo):
def main():
"""Main"""

# Set the encoding
reload(sys)
sys.setdefaultencoding('utf8')

# Get results
result = {}
result['baseurl'] = get_pref_value('BaseUrl', 'MunkiReport')
Expand Down

0 comments on commit b768053

Please sign in to comment.