def METHOD_NAME(msn, user_agent, ip, data):
    for report in data:
        events = report.pop('events')
        event_uuid = uuid.uuid4()
        for event_index, (created_at, payload) in enumerate(events):
            # event type
            try:
                failed = int(payload["status"]) != 0
            except (KeyError, ValueError):
                failed = True
            payload_type = payload.get("type")
            if payload_type == "install":
                if failed:
                    event_cls = MunkiInstallFailedEvent
                else:
                    event_cls = MunkiInstallEvent
            elif payload_type == "removal":
                if failed:
                    event_cls = MunkiRemovalFailedEvent
                else:
                    event_cls = MunkiRemovalEvent
            elif payload_type == "warning":
                event_cls = MunkiWarningEvent
            elif payload_type == "error":
                event_cls = MunkiErrorEvent
            elif payload_type == "start":
                event_cls = MunkiStartEvent
            else:
                logger.error("Unknown munki event payload type %s", payload_type)
                continue
            # build event
            metadata = EventMetadata(
                uuid=event_uuid,
                index=event_index,
                machine_serial_number=msn,
                request=EventRequest(user_agent, ip),
                created_at=parser.parse(created_at),
                incident_updates=payload.pop("incident_updates", []),
            )
            payload.update(report)
            event = event_cls(metadata, payload)
            event.post()