def staging(request, serial): if request.method == 'POST': submit = request.POST workflow = submit.get('workflow') runtype = submit.get('type') if serial: try: machine = Machine.objects.get(serial_number=serial) except Machine.DoesNotExist: machine = Machine(serial_number=serial) else: raise Http404 if runtype == "save": if workflow == "no workflow": machine.imagr_workflow = "" machine.imagr_status = "" machine.imagr_message = "" else: machine.imagr_workflow = workflow machine.save() return HttpResponse("OK!") elif runtype == "load": imagr_status = machine.imagr_status imagr_message = machine.imagr_message c = RequestContext(request,{'imagr_status': imagr_status, 'imagr_message': imagr_message }) c.update(csrf(request)) return render_to_response('reports/staging_status.html', c) else: machine = None if serial: try: machine = Machine.objects.get(serial_number=serial) except Machine.DoesNotExist: raise Http404 else: raise Http404 imagr_workflow = machine.imagr_workflow #imagr_target = machine.imagr_target error = None workflows = {} imagr_config_plist = "" if IMAGR_CONFIG_URL: try: config = urllib.urlopen(IMAGR_CONFIG_URL) imagr_config_plist = config.read() imagr_config_plist = plistlib.readPlistFromString(imagr_config_plist) except: error = "Can't reach server!" else: error = "Imagr URL not defined!" c = RequestContext(request,{'imagr_workflow': imagr_workflow, #'imagr_target': imagr_target, 'workflows': workflows, 'error': error, 'imagr_config_plist': imagr_config_plist, 'machine_serial': serial, 'page': 'reports'}) c.update(csrf(request)) return render_to_response('reports/staging.html', c)
def staging(request, serial): if request.method == 'POST': submit = request.POST workflow = submit.get('workflow') runtype = submit.get('type') if serial: try: machine = Machine.objects.get(serial_number=serial) except Machine.DoesNotExist: machine = Machine(serial_number=serial) else: raise Http404 if runtype == "save": if workflow == "no workflow": machine.imagr_workflow = "" machine.imagr_status = "" machine.imagr_message = "" else: machine.imagr_workflow = workflow machine.save() return HttpResponse("OK!") elif runtype == "load": imagr_status = machine.imagr_status imagr_message = machine.imagr_message c = RequestContext(request, { 'imagr_status': imagr_status, 'imagr_message': imagr_message }) c.update(csrf(request)) return render_to_response('reports/staging_status.html', c) else: machine = None if serial: try: machine = Machine.objects.get(serial_number=serial) except Machine.DoesNotExist: raise Http404 else: raise Http404 imagr_workflow = machine.imagr_workflow #imagr_target = machine.imagr_target error = None workflows = {} imagr_config_plist = "" if IMAGR_CONFIG_URL: try: config = urllib.urlopen(IMAGR_CONFIG_URL) imagr_config_plist = config.read() imagr_config_plist = plistlib.readPlistFromString( imagr_config_plist) except: error = "Can't reach server!" else: error = "Imagr URL not defined!" c = RequestContext( request, { 'imagr_workflow': imagr_workflow, #'imagr_target': imagr_target, 'workflows': workflows, 'error': error, 'imagr_config_plist': imagr_config_plist, 'machine_serial': serial, 'page': 'reports' }) c.update(csrf(request)) return render_to_response('reports/staging.html', c)
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': 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")