def main(): results = {} state_pref = sal.sal_pref("ReportPuppetState", True) if os.path.exists(PUPPET_LAST_RUN_SUMMARY) and state_pref: results["managed_items"] = get_puppet_state() results["facts"] = get_facter_report() sal.set_checkin_results("Puppet", results)
def main(): profiles = get_profiles() submission = {} submission['facts'] = {'checkin_module_version': __version__} submission['managed_items'] = {} for profile in profiles.get('_computerlevel', []): name = profile['ProfileDisplayName'] submission_item = {} submission_item['name'] = name submission_item['date_managed'] = profile['ProfileInstallDate'] submission_item['status'] = 'PRESENT' data = {} payloads = profile.get('ProfileItems', []) for count, payload in enumerate(payloads, start=1): data[f'payload {count}'] = payload data['payload_types'] = ', '.join(p['PayloadType'] for p in payloads) data['profile_description'] = profile.get('ProfileDescription', 'None') data['identifier'] = profile['ProfileIdentifier'] data['organization'] = profile.get('ProfileOrganization' or 'None') data['uuid'] = profile['ProfileUUID'] data['verification_state'] = profile.get('ProfileVerificationState', '') submission_item['data'] = data submission['managed_items'][name] = submission_item sal.set_checkin_results('Profiles', submission)
def main(): profiles = get_profiles() submission = {} submission["facts"] = {"checkin_module_version": __version__} submission["managed_items"] = {} for profile in profiles.get("_computerlevel", []): name = profile["ProfileDisplayName"] submission_item = {} submission_item["name"] = name submission_item["date_managed"] = profile["ProfileInstallDate"] submission_item["status"] = "PRESENT" data = {} payloads = profile.get("ProfileItems", []) for count, payload in enumerate(payloads, start=1): data[f"payload {count}"] = payload data["payload_types"] = ", ".join(p["PayloadType"] for p in payloads) data["profile_description"] = profile.get("ProfileDescription", "None") data["identifier"] = profile["ProfileIdentifier"] data["organization"] = profile.get("ProfileOrganization" or "None") data["uuid"] = profile["ProfileUUID"] data["verification_state"] = profile.get("ProfileVerificationState", "") submission_item["data"] = data submission["managed_items"][name] = submission_item sal.set_checkin_results("Profiles", submission)
def main(): machine_results = {'facts': {'checkin_module_version': __version__}} extras = {} extras['hostname'] = get_hostname() extras['os_family'] = 'Darwin' extras['console_user'] = get_console_user()[0] extras.update(process_system_profile()) machine_results['extra_data'] = extras sal.set_checkin_results('Machine', machine_results)
def main(): machine_results = {"facts": {"checkin_module_version": __version__}} extras = {} extras["hostname"] = get_hostname() extras["os_family"] = "Darwin" extras["console_user"] = get_console_user()[0] extras.update(process_system_profile()) machine_results["extra_data"] = extras sal.set_checkin_results("Machine", machine_results)
def main(): sal_submission = { "extra_data": { "sal_version": sal.__version__, "key": sal.sal_pref("key"), }, "facts": { "checkin_module_version": __version__ }, } sal.set_checkin_results("Sal", sal_submission)
def main(): sus_submission = {} sus_submission['facts'] = get_sus_facts() # Process managed items and update histories. sus_submission['managed_items'] = get_sus_install_report() sus_submission['update_history'] = [] pending = get_pending() sus_submission['managed_items'].update(pending) sal.set_checkin_results('Apple Software Update', sus_submission)
def main(): _, _, bu_key = sal.get_server_prefs() sal_submission = { 'extra_data': { 'sal_version': sal.__version__, 'key': bu_key, }, 'facts': { 'checkin_module_version': __version__ } } sal.set_checkin_results('Sal', sal_submission)
def main(): # If we haven't successfully submitted to Sal, pull the existing # munki section rather than start from scratch, as we want to # keep any install/removal history that may be there. munki_submission = sal.get_checkin_results().get('munki', {}) munki_report = get_managed_install_report() extras = {} extras['munki_version'] = munki_report['MachineInfo'].get('munki_version') extras['manifest'] = munki_report.get('ManifestName') extras['runtype'] = munki_report.get('RunType', 'custom') munki_submission['extra_data'] = extras munki_submission['facts'] = { 'checkin_module_version': __version__, 'RunType': munki_report['RunType'], 'StartTime': munki_report['StartTime'], 'EndTime': munki_report['EndTime'], } if munki_report.get('Conditions'): for condition, value in munki_report['Conditions'].items(): # Join lists of strings into a comma-delimited string, as # the server wants just text. if hasattr(value, 'append'): value = ', '.join(value) munki_submission['facts'][condition] = value munki_submission['messages'] = [] for key in ('Errors', 'Warnings'): for msg in munki_report[key]: # We need to drop the final 'S' to match Sal's message types. munki_submission['messages'].append({'message_type': key.upper()[:-1], 'text': msg}) now = datetime.datetime.now().astimezone(datetime.timezone.utc).isoformat() # Process managed items and update histories. munki_submission['managed_items'] = {} optional_manifest = get_optional_manifest() for item in munki_report.get('ManagedInstalls', []): submission_item = {'date_managed': now} submission_item['status'] = 'PRESENT' if item['installed'] else 'PENDING' version_key = 'version_to_install' if not item['installed'] else 'installed_version' version = item[version_key] name = f'{item["name"]} {version}' submission_item['name'] = name # Pop off these two since we already used them. item.pop('name') item.pop('installed') item['type'] = 'ManagedInstalls' self_serve = 'True' if name in optional_manifest.get('managed_installs', []) else 'False' item['self_serve'] = self_serve submission_item['data'] = item munki_submission['managed_items'][name] = submission_item for item in munki_report.get('managed_uninstalls_list', []): submission_item = {'date_managed': now, 'status': 'ABSENT'} self_serve = 'True' if name in optional_manifest.get('managed_uninstalls', []) else 'False' submission_item['data'] = {'self_serve': self_serve, 'type': 'ManagedUninstalls'} munki_submission['managed_items'][item] = submission_item # Process InstallResults and RemovalResults into update history for report_key, result_type in (('InstallResults', 'PRESENT'), ('RemovalResults', 'ABSENT')): for item in munki_report.get(report_key, []): # Skip Apple software update items. if item.get('applesus'): continue history = {} # history = {'update_type': 'apple' if item.get('applesus') else 'third_party'} history['status'] = 'ERROR' if item.get('status') != 0 else result_type # This UTC datetime gets converted to a naive datetime by # plistlib. Fortunately, we can just tell it that it's UTC. history['date_managed'] = item['time'].replace( tzinfo=datetime.timezone.utc).isoformat() history['data'] = {'version': item.get('version', '0')} # Add over top of any pending items we may have already built. if item['name'] in munki_submission['managed_items']: munki_submission['managed_items'][item['name']].update(history) else: munki_submission['managed_items'][item['name']] = history sal.set_checkin_results('Munki', munki_submission)
def main(): # If we haven't successfully submitted to Sal, pull the existing # munki section rather than start from scratch, as we want to # keep any install/removal history that may be there. munki_submission = sal.get_checkin_results().get("munki", {}) munki_report = get_managed_install_report() extras = {} extras["munki_version"] = munki_report["MachineInfo"].get("munki_version") extras["manifest"] = munki_report.get("ManifestName") extras["runtype"] = munki_report.get("RunType", "custom") munki_submission["extra_data"] = extras munki_submission["facts"] = { "checkin_module_version": __version__, "RunType": munki_report["RunType"], "StartTime": munki_report["StartTime"], "EndTime": munki_report["EndTime"], } if munki_report.get("Conditions"): for condition, value in munki_report["Conditions"].items(): # Join lists of strings into a comma-delimited string, as # the server wants just text. try: if hasattr(value, "append"): value = ", ".join(value) except Exception as e: # We god something weird from a condtion that probably wouldn't work anyway continue munki_submission["facts"][condition] = value munki_submission["messages"] = [] for key in ("Errors", "Warnings"): for msg in munki_report[key]: # We need to drop the final 'S' to match Sal's message types. munki_submission["messages"].append({ "message_type": key.upper()[:-1], "text": msg }) now = datetime.datetime.now().astimezone(datetime.timezone.utc).isoformat() # Process managed items and update histories. munki_submission["managed_items"] = {} optional_manifest = get_optional_manifest() for item in munki_report.get("ManagedInstalls", []): submission_item = {"date_managed": now} submission_item[ "status"] = "PRESENT" if item["installed"] else "PENDING" version_key = ("version_to_install" if not item["installed"] else "installed_version") version = item[version_key] name = f'{item["name"]} {version}' submission_item["name"] = name # Pop off these two since we already used them. item.pop("name") item.pop("installed") item["type"] = "ManagedInstalls" self_serve = ("True" if name in optional_manifest.get( "managed_installs", []) else "False") item["self_serve"] = self_serve submission_item["data"] = item munki_submission["managed_items"][name] = submission_item for item in munki_report.get("managed_uninstalls_list", []): submission_item = {"date_managed": now, "status": "ABSENT"} self_serve = ("True" if name in optional_manifest.get( "managed_uninstalls", []) else "False") submission_item["data"] = { "self_serve": self_serve, "type": "ManagedUninstalls", } munki_submission["managed_items"][item] = submission_item # Process InstallResults and RemovalResults into update history for report_key in ("InstallResults", "RemovalResults"): for item in munki_report.get(report_key, []): # Skip Apple software update items. if item.get("applesus"): continue # Construct key; we pop the name off because we don't need # to submit it again when we stuff `item` into `data`. name = f'{item.pop("name")} {item["version"]}' submission_item = munki_submission["managed_items"].get( name, {"name": name}) if item.get("status") != 0: # Something went wrong, so change the status. submission_item["status"] = "ERROR" if "data" in submission_item: submission_item["data"].update(item) else: submission_item["data"] = item if "type" not in submission_item["data"]: submission_item["data"]["type"] = ( "ManagedInstalls" if report_key == "InstallResults" else "ManagedUninstalls") # This UTC datetime gets converted to a naive datetime by # plistlib. Fortunately, we can just tell it that it's UTC. submission_item["date_managed"] = (item["time"].replace( tzinfo=datetime.timezone.utc).isoformat()) munki_submission["managed_items"][name] = submission_item sal.set_checkin_results("Munki", munki_submission)