Malachi. AuditLog
(malachi v0.8.13)
View Source
Structured audit system with ETS storage and secondary indexes.
Tracks security events including authentication, lockouts, sessions, and administrative activities. Maintains 30-day history with automatic cleanup.
Event Types
:auth_success- Successful authentication:auth_failure- Failed authentication:auth_lockout- Account locked due to excessive attempts:session_created- New session created:session_revoked- Session manually revoked:session_expired- Session expired by timeout:session_hijack_attempt- Hijacking attempt detected:account_unlocked- Account unlocked by admin:config_validation_failed- Configuration validation failed:dashboard_access- Dashboard HTTP endpoint accessed:dashboard_login_success- Successful dashboard login:dashboard_auth_failure- Failed dashboard authentication
Event Structure
Each event is stored as:
{event_id, timestamp, event_type, username, ip, action, status, metadata}
Summary
Functions
Returns a specification to start this module under a supervisor.
Flush buffered events to disk immediately. Useful for testing or ensuring events are written before shutdown.
Returns all events (limited to most recent).
Returns events of a specific type.
Returns events for a specific user.
Returns event statistics.
Records an audit event.
Starts the audit log, which buffers security events and periodically flushes them to ETS and, if configured, a file or stdout.
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
Flush buffered events to disk immediately. Useful for testing or ensuring events are written before shutdown.
Returns all events (limited to most recent).
Parameters
limit- Maximum number of events to return (default: 1000)
Returns events of a specific type.
Parameters
event_type- Event type to filterlimit- Maximum number of events to return (default: 1000)
Returns events for a specific user.
Parameters
username- Usernamelimit- Maximum number of events to return (default: 1000)
Returns event statistics.
Records an audit event.
Parameters
event_type- Atom representing the event typecontext- Map withusernameandip(optional)action- String describing the action (e.g., "authenticate", "unlock_account")status-:successor:failuremetadata- Map with event-specific additional data
Examples
iex> AuditLog.log_event(:auth_success, %{username: "admin", ip: {192, 168, 1, 1}},
...> "authenticate", :success, %{})
:ok
iex> AuditLog.log_event(:auth_lockout, %{username: "user", ip: {10, 0, 0, 1}},
...> "account_locked", :automatic, %{attempt_count: 5, lockout_duration_ms: 300_000})
:ok
Starts the audit log, which buffers security events and periodically flushes them to ETS and, if configured, a file or stdout.