As our technical team works on Moodle, we find ourselves tackling issues that may be of interest to other developers. As a part of the Moodle community and advocators of openness, we decided to share our own experiences from Moodle Dev, among other things of course! If you haven’t read our previous post, take a look at “The Antivirus MIME Blocker”
What is Moodle event monitoring?
Sometimes we need updates on the basis of some actions in an email. Such actions are related to who has logged in to the site, what manipulation is going on, on the site such as adding/deleting/viewing any activity, submission of assignment etc. Moodle provides action based notification system ‘Event monitoring’ to keep user updated for any action happens in the LMS.
Event monitoring allows admins and teachers to receive notifications when certain events happen in Moodle such as user logged in, user created, quiz creation & quiz submission etc. Any role that has tool/monitor:subscribe can subscribe to the event. By default, this is only for admin, manager and teachers.
Before version 2.7, Moodle used simple logging API to log any action in the database, these actions were then displayed on log report and live log reports. We can’t receive any notification of action performed through logging API. In Moodle 2.8, Moodle introduced ‘Event monitoring system’ that is used to add all logs into a database as well as we to receive email notifications.
Categorisation of event monitoring
We can categorise Moodle events into two parts:
- Existing events in core
- Custom events by event API
1. Existing events in core
The Moodle event system contains multiple built-in actions for notifications such as “view module”, “role assign”, “user created” etc. We can see the list of available events from Moodle documentation: https://docs.moodle.org/dev/Event_2#Existing_events
Create event monitoring rule for existing events
Enable event monitoring
An administrator can enable it from Site administration > Reports > Event monitoring rules.
The first step is to create the rule to be monitored. Then, a user such as an admin and teacher, can subscribe to created event.
A teacher can create a rule from Course administration > Reports > Event monitoring rules
The administrator can, additionally, create a rule from Site administration > Reports > Event monitoring rules
- Click on ‘Add new rule’
- Add necessary information such ad Rule name, Area to monitor such as ‘core’ & event name such as ‘User has logged in’
- Click on ‘Save changes’ button
- Now go to ‘Event monitoring page’
- Select a course ‘Site’
- Click on plus + sign for subscribe
By default, students get notifications that are shown in User menu > Preferences > Notification(configuration needed by the administrator), there are a lot of events created for monitoring in which a student can also subscribe to events that will be created by administrator or teachers. The administrator will allow access to students so that they can subscribe to the event. Below are the steps that have to be followed in order to allow students to get notification of any event.
- Go to Site administration > Users > Define roles and click edit icon for student role.
- Allow ‘tool/monitor:subscribe’ capability to student role.
- Now student can subscribe created event via the user menu Preferences > Event monitoring.
2. Custom Events by event API
Moodle provides event API which can be added in plugin, so we can create custom events within a plugin and once the event is triggered, a notification will be generated. Below is the overview of how can we implement event API to our plugin.
Moodle provides detailed documentation that describes how to implement event API into your plugin: https://docs.moodle.org/dev/Events_API
Below you may find some screenshots that depict the actions explained throughout this post.
View event list
Enable Event Monitoring