1# function that contains logging info
2def run_jamf_policy(run_list):
3 """run through all jamf policies that need to be done"""
4 write_to_dnlog("Status: Installing software...")
5 number_of_policies = len(run_list)
6 write_to_dnlog("Command: DeterminateManual: %s" % number_of_policies)
7 for index, policy in enumerate(run_list, 1):
8 # get the vanity name from the MAIN_POLICY_DICT
9 name = MAIN_POLICY_DICT[policy]
10 write_to_dnlog("Status: Deploying %s" % name)
11 write_to_dnlog("Command: DeterminateManualStep:")
12 logging.info("starting %s policy..." % policy)
13 cmd = ["jamf", "policy", "-event", str(policy)]
14 proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
15 out, errors = proc.communicate()
16 if proc.returncode != 0:
17 error_msg = "%s code %s" % (errors.strip(), proc.returncode)
18 logging.error("jamf binary failed to install %s, %s", policy, error_msg)
19 write_to_dnlog("Status: %s policy failed, please see logs..." % policy)
20 elif proc.returncode == 0:
21 logging.info("jamf policy %s returned successful.." % policy)
22 write_to_dnlog("Status: %s was successfully installed..." % name)
23 write_to_dnlog("Command: DeterminateOff:")
24 write_to_dnlog("Command: DeterminateOffReset:")
25
26# function to write to the DEP Notify log
27def write_to_dnlog(text):
28 """function to modify the DEP log and send it commands"""
29 depnotify = "/private/var/tmp/depnotify.log"
30 with open(depnotify, "a+") as log:
31 log.write(text + "
32")