def create_audit_entry(self, request, transaction_id=None, **kwargs): entry = AuditLogEntry( actor=request.user if request.user.is_authenticated() else None, # TODO(jtcunning): assert that REMOTE_ADDR is a real IP. ip_address=request.META['REMOTE_ADDR'], **kwargs ) # Only create a real AuditLogEntry record if we are passing an event type # otherwise, we want to still log to our actual logging if entry.event is not None: entry.save() extra = { 'ip_address': entry.ip_address, 'organization_id': entry.organization_id, 'object_id': entry.target_object, 'entry_id': entry.id, 'actor_label': entry.actor_label } if transaction_id is not None: extra['transaction_id'] = transaction_id audit_logger.info(entry.get_event_display(), extra=extra) return entry
def create_audit_entry(self, request, transaction_id=None, **kwargs): entry = AuditLogEntry( actor=request.user if request.user.is_authenticated() else None, # TODO(jtcunning): assert that REMOTE_ADDR is a real IP. ip_address=request.META['REMOTE_ADDR'], **kwargs) # Only create a real AuditLogEntry record if we are passing an event type # otherwise, we want to still log to our actual logging if entry.event is not None: entry.save() extra = { 'ip_address': entry.ip_address, 'organization_id': entry.organization_id, 'object_id': entry.target_object, 'entry_id': entry.id, 'actor_label': entry.actor_label } if transaction_id is not None: extra['transaction_id'] = transaction_id audit_logger.info(entry.get_event_display(), extra=extra) return entry
def create_audit_entry(self, request, transaction_id=None, **kwargs): user = request.user if request.user.is_authenticated() else None api_key = request.auth if isinstance(request.auth, ApiKey) else None entry = AuditLogEntry(actor=user, actor_key=api_key, ip_address=request.META['REMOTE_ADDR'], **kwargs) # Only create a real AuditLogEntry record if we are passing an event type # otherwise, we want to still log to our actual logging if entry.event is not None: entry.save() extra = { 'ip_address': entry.ip_address, 'organization_id': entry.organization_id, 'object_id': entry.target_object, 'entry_id': entry.id, 'actor_label': entry.actor_label } if entry.actor_id: extra['actor_id'] = entry.actor_id if entry.actor_key_id: extra['actor_key_id'] = entry.actor_key_id if transaction_id is not None: extra['transaction_id'] = transaction_id audit_logger.info(entry.get_event_display(), extra=extra) return entry
def create_audit_entry(self, request, transaction_id=None, **kwargs): user = request.user if request.user.is_authenticated() else None api_key = request.auth if isinstance(request.auth, ApiKey) else None entry = AuditLogEntry( actor=user, actor_key=api_key, ip_address=request.META['REMOTE_ADDR'], **kwargs ) # Only create a real AuditLogEntry record if we are passing an event type # otherwise, we want to still log to our actual logging if entry.event is not None: entry.save() extra = { 'ip_address': entry.ip_address, 'organization_id': entry.organization_id, 'object_id': entry.target_object, 'entry_id': entry.id, 'actor_label': entry.actor_label } if entry.actor_id: extra['actor_id'] = entry.actor_id if entry.actor_key_id: extra['actor_key_id'] = entry.actor_key_id if transaction_id is not None: extra['transaction_id'] = transaction_id audit_logger.info(entry.get_event_display(), extra=extra) return entry
def create_audit_entry(request, transaction_id=None, logger=None, **kwargs): from sentry.models import ApiKey # Django 1.9 setup issue from sentry.models import AuditLogEntry # Django 1.9 setup issue from sentry.models import AuditLogEntryEvent # Django 1.9 setup issue user = request.user if request.user.is_authenticated() else None api_key = request.auth if hasattr(request, 'auth') \ and isinstance(request.auth, ApiKey) else None entry = AuditLogEntry(actor=user, actor_key=api_key, ip_address=request.META['REMOTE_ADDR'], **kwargs) # Only create a real AuditLogEntry record if we are passing an event type # otherwise, we want to still log to our actual logging if entry.event is not None: entry.save() if entry.event == AuditLogEntryEvent.ORG_REMOVE: create_org_delete_log(entry) elif entry.event == AuditLogEntryEvent.PROJECT_REMOVE: create_project_delete_log(entry) elif entry.event == AuditLogEntryEvent.TEAM_REMOVE: create_team_delete_log(entry) extra = { 'ip_address': entry.ip_address, 'organization_id': entry.organization_id, 'object_id': entry.target_object, 'entry_id': entry.id, 'actor_label': entry.actor_label } if entry.actor_id: extra['actor_id'] = entry.actor_id if entry.actor_key_id: extra['actor_key_id'] = entry.actor_key_id if transaction_id is not None: extra['transaction_id'] = transaction_id if logger: logger.info(entry.get_event_display(), extra=extra) return entry
def create_audit_entry(request, transaction_id=None, logger=None, **kwargs): user = kwargs.pop("actor", request.user if request.user.is_authenticated else None) api_key = (request.auth if hasattr(request, "auth") and isinstance(request.auth, ApiKey) else None) entry = AuditLogEntry(actor=user, actor_key=api_key, ip_address=request.META["REMOTE_ADDR"], **kwargs) # Only create a real AuditLogEntry record if we are passing an event type # otherwise, we want to still log to our actual logging if entry.event is not None: entry.save() if entry.event == AuditLogEntryEvent.ORG_REMOVE: create_org_delete_log(entry) elif entry.event == AuditLogEntryEvent.PROJECT_REMOVE: create_project_delete_log(entry) elif entry.event == AuditLogEntryEvent.TEAM_REMOVE: create_team_delete_log(entry) extra = { "ip_address": entry.ip_address, "organization_id": entry.organization_id, "object_id": entry.target_object, "entry_id": entry.id, "actor_label": entry.actor_label, } if entry.actor_id: extra["actor_id"] = entry.actor_id if entry.actor_key_id: extra["actor_key_id"] = entry.actor_key_id if transaction_id is not None: extra["transaction_id"] = transaction_id if logger: logger.info(entry.get_event_display(), extra=extra) return entry
def create_audit_entry_from_user(user, api_key=None, ip_address=None, transaction_id=None, logger=None, **kwargs): entry = AuditLogEntry(actor=user, actor_key=api_key, ip_address=ip_address, **kwargs) # Only create a real AuditLogEntry record if we are passing an event type # otherwise, we want to still log to our actual logging if entry.event is not None: entry.save() if entry.event == AuditLogEntryEvent.ORG_REMOVE: create_org_delete_log(entry) elif entry.event == AuditLogEntryEvent.PROJECT_REMOVE: create_project_delete_log(entry) elif entry.event == AuditLogEntryEvent.TEAM_REMOVE: create_team_delete_log(entry) extra = { "ip_address": entry.ip_address, "organization_id": entry.organization_id, "object_id": entry.target_object, "entry_id": entry.id, "actor_label": entry.actor_label, } if entry.actor_id: extra["actor_id"] = entry.actor_id if entry.actor_key_id: extra["actor_key_id"] = entry.actor_key_id if transaction_id is not None: extra["transaction_id"] = transaction_id if logger: logger.info(entry.get_event_display(), extra=extra) return entry