Moodle security events in your SIEM, as JSON lines
Our free logstore_siem plugin writes Moodle sign-ins, failed sign-ins, role changes, new site admins and setting changes as JSON lines to a file or syslog.
Short answer: Moodle records every sign-in, role change and setting change, but only in its own database table, where a security team’s SIEM cannot see it without custom queries. Our free plugin, logstore_siem, writes those events as one JSON line each, to a file or to the system log (syslog). Filebeat, Fluent Bit, the Splunk forwarder or rsyslog can then send them on like any other log.
This is the thirty-third plugin in our series: one plugin for each Moodle plugin type, each one teaching DevLMS Studio, our AI plugin builder, how that type works. It answers MDL-85305, an open request on Moodle’s tracker (1 vote, 3 watchers when we checked). The request notes that the old SIEM plugins stopped being maintained years ago. The Splunk and Graylog log stores we found stop at Moodle 3.1.
What it does
- Always written: sign-ins and sign-outs, failed sign-ins, “log in as”, accounts created, changed and deleted, password changes, roles given and taken away, permission changes, every setting change Moodle logs, new web service tokens, course deletions and the multi-factor sign-in events.
- If you want more: every change (anything created, updated or deleted), or every event including page views.
- Who did what to whom: each line has the username of the person who did it, the person it was done to, and the real user behind a “log in as”.
- New site administrators by name. Moodle logs a change of site administrators as two lists of numbers, such as “2” becoming “2, 57”. The plugin works out who was added and who was removed and writes their usernames, which the tracker request asked for.
- Secrets stay out. Moodle already hides password settings. The plugin also hides any setting named like a key, secret or token, and drops passwords and tokens from event details.
- Nothing breaks if the log does. A full disk or a missing folder never stops the page that caused the event. The failure goes to the server’s error log, and a test page linked from the settings sends one line and shows where it went or why it could not.
The lines are plain JSON with their own field names. They are not in Elastic Common Schema or any other SIEM’s format, so you map the fields once in your collector. We have not tested it with a particular SIEM. It supports Moodle 4.5 LTS to 5.3, is off until an admin turns it on, and the code is on GitHub.
How a Moodle log store works
From Moodle 5.3’s logging code (the same in 4.5):
- Every event Moodle triggers goes to each log store an admin has turned on. A store says which events it wants, collects them during the page, and writes them when the page finishes, so a store can be slow without making anyone wait mid-click.
- Stores only receive events once the database work for that page is saved. Tests have to allow for that, or nothing ever arrives.
- A failed sign-in records the username exactly as it was typed, and anyone can type anything there. So the file path can only be set in config.php, not in a web form, and the JSON is written with
<,>and&escaped. Typed text cannot become a new line, markup or code. - Moodle’s event records hold ids. The plugin looks up usernames and role names when it writes, because a SIEM alert that says “user 57” helps nobody at 3 a.m.
Unit tests trigger real events, such as a role assignment, a failed sign-in with code in the username, a new site administrator and a changed API key setting, then read the file back. Browser tests sign in with a wrong password, enrol a student and add a site administrator through Moodle’s own pages, then check each line field by field.
Need a plugin like this for your own Moodle?
Describe it in DevLMS Studio and watch it built and tested in a real Moodle, or ask our team for a fixed price.
Open DevLMS Studio