def submit(request): if request.method == 'POST': submit = request.POST elif request.method == 'GET': submit = request.GET else: raise Http404 mac = submit.get('mac') machine = None if mac: try: machine = Machine.objects.get(mac=mac) except Machine.DoesNotExist: machine = Machine(mac=mac) if machine: if submit.get('hostname'): machine.hostname = submit.get('hostname') machine.last_checkin = timezone.now() machine.save() response = '' facts = submit.get('Facts') if facts is not None: facts = json.loads(facts) for key in facts: try: fact = Fact.objects.get(machine=machine, name=key) except: fact = Fact(machine=machine, name=key) fact.last_update = timezone.now() fact.value = facts[key] fact.save() facts = submit.get('HistoricalFacts') if facts is not None: facts = json.loads(facts) for key in facts: fact = HistoricalFact(machine=machine, name=key) fact.timestamp = timezone.now() fact.value = facts[key] fact.save() return HttpResponse('Report submitted.\n') return HttpResponse('Report not submitted.\n')
def submit(request, submission_type): if request.method != 'POST': raise Http404 submit = request.POST mac = submit.get('mac') client = None if mac: try: machine = Machine.objects.get(mac=mac) except Machine.DoesNotExist: machine = Machine(mac=mac) if machine: try: report = MunkiReport.objects.get(machine=machine) except MunkiReport.DoesNotExist: report = MunkiReport(machine=machine) if machine and report: machine.hostname = submit.get('name', '<NO NAME>') machine.remote_ip = request.META['REMOTE_ADDR'] machine.last_munki_update = datetime.now() if 'username' in submit: machine.username = submit.get('username') if 'location' in submit: machine.location = submit.get('location') report.runtype = submit.get('runtype') report.timestamp = datetime.now() if submission_type == 'postflight': report.runstate = u"done" if 'base64bz2report' in submit: report.update_report(submit.get('base64bz2report')) # extract machine data from the report report_data = report.get_report() if 'MachineInfo' in report_data: machine.os_version = report_data['MachineInfo'].get( 'os_vers', 'UNKNOWN') machine.cpu_arch = report_data['MachineInfo'].get( 'arch', 'UNKNOWN') machine.available_disk_space = \ report_data.get('AvailableDiskSpace') or 0 hwinfo = {} if 'SystemProfile' in report_data.get('MachineInfo', []): for profile in report_data['MachineInfo']['SystemProfile']: if profile['_dataType'] == 'SPHardwareDataType': hwinfo = profile._items[0] break if hwinfo: machine.machine_model = hwinfo.get('machine_model') and hwinfo.get('machine_model') or u'unknown' machine.cpu_type = hwinfo.get('cpu_type') and hwinfo.get('cpu_type') or u'unknown' machine.cpu_speed = hwinfo.get('current_processor_speed') and hwinfo.get('current_processor_speed') or u'0' machine.ram = hwinfo.get('physical_memory') and hwinfo.get('physical_memory') or u'0' machine.serial_number = hwinfo.get('serial_number') and hwinfo.get('serial_number')[0:15] or u'unknown' machine.save() report.save() return HttpResponse("Postflight report submmitted for %s.\n" % submit.get('name')) if submission_type == 'preflight': report.runstate = u"in progress" report.activity = report.encode( {"Updating": "preflight"}) machine.save() report.save() return HttpResponse( "Preflight report submmitted for %s.\n" % submit.get('name')) if submission_type == 'report_broken_client': report.runstate = u"broken client" report.report = None report.errors = 1 report.warnings = 0 machine.save() report.save() return HttpResponse( "Broken client report submmitted for %s.\n" % submit.get('name')) return HttpResponse("No report submitted.\n")
def submit(request, submission_type): if request.method != "POST": raise Http404 submit = request.POST serial = submit.get("serial") mac = submit.get("mac") client = None if serial: try: machine = Machine.objects.get(serial_number=serial) except Machine.DoesNotExist: machine = Machine(serial_number=serial) if machine: try: report = MunkiReport.objects.get(machine=machine) except MunkiReport.DoesNotExist: report = MunkiReport(machine=machine) if machine and report: machine.hostname = submit.get("name", "<NO NAME>") machine.remote_ip = request.META["REMOTE_ADDR"] machine.last_munki_update = datetime.now() if "username" in submit: machine.username = submit.get("username") if "location" in submit: machine.location = submit.get("location") report.runtype = submit.get("runtype") report.timestamp = datetime.now() if submit.get("unit"): unit = BusinessUnit.objects.get(hash=submit.get("unit")) machine.businessunit = unit if submission_type == "postflight": report.runstate = u"done" if "base64bz2report" in submit: report.update_report(submit.get("base64bz2report")) # extract machine data from the report report_data = report.get_report() if "MachineInfo" in report_data: machine.os_version = report_data["MachineInfo"].get("os_vers", machine.os_version) machine.cpu_arch = report_data["MachineInfo"].get("arch", machine.cpu_arch) machine.available_disk_space = report_data.get("AvailableDiskSpace") or machine.available_disk_space hwinfo = {} if "SystemProfile" in report_data.get("MachineInfo", []): for profile in report_data["MachineInfo"]["SystemProfile"]: if profile["_dataType"] == "SPHardwareDataType": hwinfo = profile._items[0] break if hwinfo: machine.machine_model = ( hwinfo.get("machine_model") and hwinfo.get("machine_model") or machine.machine_model ) machine.cpu_type = hwinfo.get("cpu_type") and hwinfo.get("cpu_type") or machine.cpu_type machine.cpu_speed = ( hwinfo.get("current_processor_speed") and hwinfo.get("current_processor_speed") or machine.cpu_speed ) machine.ram = hwinfo.get("physical_memory") and hwinfo.get("physical_memory") or machine.ram machine.mac = mac machine.save() report.save() return HttpResponse("Postflight report submmitted for %s.\n" % submit.get("name")) if submission_type == "preflight": report.runstate = u"in progress" report.activity = report.encode({"Updating": "preflight"}) machine.save() report.save() return HttpResponse("Preflight report submmitted for %s.\n" % submit.get("name")) if submission_type == "report_broken_client": report.runstate = u"broken client" # report.report = None report.errors = 1 report.warnings = 0 machine.save() report.save() return HttpResponse("Broken client report submmitted for %s.\n" % submit.get("name")) return HttpResponse("No report submitted.\n")
def submit(request, submission_type): if request.method != 'POST': return HttpResponse("No report submitted.\n") #raise Http404 submit = request.POST serial = submit.get('serial') client = None if serial: try: machine = Machine.objects.get(serial_number=serial) except Machine.DoesNotExist: machine = Machine(serial_number=serial) if machine: try: report = MunkiReport.objects.get(machine=machine) except MunkiReport.DoesNotExist: report = MunkiReport(machine=machine) if machine and report: if 'mac' in submit: mac = submit.get('mac') machine.remote_ip = request.META['REMOTE_ADDR'] if 'name' in submit: machine.hostname = submit.get('name') if 'username' in submit: machine.username = submit.get('username') if 'location' in submit: machine.location = submit.get('location') report.runtype = submit.get('runtype', 'UNKNOWN') report.timestamp = datetime.now() if submit.get('unit'): unit = BusinessUnit.objects.get(hash=submit.get('unit')) machine.businessunit = unit if submission_type == 'reportimagr': if submit.get('status'): machine.imagr_status = submit.get('status') if submit.get('message'): machine.imagr_message = submit.get('message') # delete pending workflow if successful ended if submit.get('status') == 'success': machine.imagr_workflow = "" report.runstate = u"imagr" machine.save() report.save() return HttpResponse( "Imagr report submmitted for %s.\n" % submit.get('serial')) machine.last_munki_update = datetime.now() if submission_type == 'postflight': report.runstate = u"done" if 'base64bz2report' in submit: report.update_report(submit.get('base64bz2report')) # extract machine data from the report report_data = report.get_report() if 'MachineInfo' in report_data: machine.os_version = report_data['MachineInfo'].get( 'os_vers', machine.os_version) machine.cpu_arch = report_data['MachineInfo'].get( 'arch', machine.cpu_arch) machine.available_disk_space = \ report_data.get('AvailableDiskSpace') or machine.available_disk_space hwinfo = {} if 'SystemProfile' in report_data.get('MachineInfo', []): for profile in report_data['MachineInfo']['SystemProfile']: if profile['_dataType'] == 'SPHardwareDataType': hwinfo = profile._items[0] break if hwinfo: machine.machine_model = hwinfo.get('machine_model') and hwinfo.get('machine_model') or machine.machine_model machine.cpu_type = hwinfo.get('cpu_type') and hwinfo.get('cpu_type') or machine.cpu_type machine.cpu_speed = hwinfo.get('current_processor_speed') and hwinfo.get('current_processor_speed') or machine.cpu_speed machine.ram = hwinfo.get('physical_memory') and hwinfo.get('physical_memory') or machine.ram machine.mac = mac machine.save() report.save() return HttpResponse("Postflight report submmitted for %s.\n" % submit.get('name')) if submission_type == 'preflight': report.runstate = u"in progress" report.activity = report.encode( {"Updating": "preflight"}) machine.save() report.save() return HttpResponse( "Preflight report submmitted for %s.\n" % submit.get('name')) if submission_type == 'report_broken_client': report.runstate = u"broken client" #report.report = None report.errors = 1 report.warnings = 0 machine.save() report.save() return HttpResponse( "Broken client report submmitted for %s.\n" % submit.get('name')) return HttpResponse("No report submitted.\n")
def submit(request, submission_type): if request.method != 'POST': raise Http404 submit = request.POST serial = submit.get('serial') mac = submit.get('mac') client = None if serial: try: machine = Machine.objects.get(serial_number=serial) except Machine.DoesNotExist: machine = Machine(serial_number=serial) if machine: try: report = MunkiReport.objects.get(machine=machine) except MunkiReport.DoesNotExist: report = MunkiReport(machine=machine) if machine and report: machine.hostname = submit.get('name', '<NO NAME>') machine.remote_ip = request.META['REMOTE_ADDR'] machine.last_munki_update = datetime.now() if 'username' in submit: machine.username = submit.get('username') if 'location' in submit: machine.location = submit.get('location') report.runtype = submit.get('runtype') report.timestamp = datetime.now() if submit.get('unit'): unit = BusinessUnit.objects.get(hash=submit.get('unit')) machine.businessunit = unit if submission_type == 'postflight': report.runstate = u"done" if 'base64bz2report' in submit: report.update_report(submit.get('base64bz2report')) # extract machine data from the report report_data = report.get_report() if 'MachineInfo' in report_data: machine.os_version = report_data['MachineInfo'].get( 'os_vers', machine.os_version) machine.cpu_arch = report_data['MachineInfo'].get( 'arch', machine.cpu_arch) machine.available_disk_space = \ report_data.get('AvailableDiskSpace') or machine.available_disk_space hwinfo = {} if 'SystemProfile' in report_data.get('MachineInfo', []): for profile in report_data['MachineInfo']['SystemProfile']: if profile['_dataType'] == 'SPHardwareDataType': hwinfo = profile._items[0] break if hwinfo: machine.machine_model = hwinfo.get( 'machine_model') and hwinfo.get( 'machine_model') or machine.machine_model machine.cpu_type = hwinfo.get('cpu_type') and hwinfo.get( 'cpu_type') or machine.cpu_type machine.cpu_speed = hwinfo.get( 'current_processor_speed') and hwinfo.get( 'current_processor_speed') or machine.cpu_speed machine.ram = hwinfo.get('physical_memory') and hwinfo.get( 'physical_memory') or machine.ram machine.mac = mac machine.save() report.save() return HttpResponse("Postflight report submmitted for %s.\n" % submit.get('name')) if submission_type == 'preflight': report.runstate = u"in progress" report.activity = report.encode({"Updating": "preflight"}) machine.save() report.save() return HttpResponse("Preflight report submmitted for %s.\n" % submit.get('name')) if submission_type == 'report_broken_client': report.runstate = u"broken client" #report.report = None report.errors = 1 report.warnings = 0 machine.save() report.save() return HttpResponse("Broken client report submmitted for %s.\n" % submit.get('name')) return HttpResponse("No report submitted.\n")