Search by

drupal / mutamad_logging

Drupal-Infrastructure

Security event logging for Mutamad: every log entry sent to syslog as structured JSON for a SIEM, a larger database log, revision comparison, and scheduled tasks that run on time with a log of every run. Aligned to NCA ECC-2:2024 12-2.

Package info

git.drupalcode.org/project/mutamad_logging.git

Homepage

Issues

Type:drupal-recipe

pkg:composer/drupal/mutamad_logging

Statistics

Installs: 61

Dependents: 1

Suggesters: 0

1.0.x-dev 2026-11-12 17:39 UTC

This package is not auto-updated.

Last update: 2026-11-16 06:04:21 UTC


README

Mutamad Logging — السجلات

Mutamad Logging

Security event logging for Mutamad: every log entry sent to syslog as structured JSON for a SIEM, a larger database log, revision comparison, and scheduled tasks that run on time with a log of every run. Aligned to NCA ECC-2:2024 12-2.

Built and maintained by iSpectra.

What it sets up

ControlWhatNCA ECC
SIEM feedEvery log entry to syslog as one JSON object — message, level, channel, time, user, IP address, URL, referrer — on facility LOCAL0, identified as mutamad, info and above (Monolog)12-2-1
Database logStill receives every entry, and keeps the last 100,000 instead of core's 1,00012-2-3
Revision comparisonDiff: what changed between two revisions of a page, field by field12-2
Scheduled tasksUltimate Cron: each cron task a job of its own, every 15 minutes at its own minute, with 30 days of runs logged; core's Automated Cron set to Never; the status report warns after 1 hour without cron (see below)12-2

A syslog line looks like this:

<133>Sep 29 12:05:22 mutamad[26098]: {"message":"Login attempt failed from 172.18.0.5.","context":{},"level":250,"level_name":"NOTICE","channel":"user","datetime":"2026-09-29T12:05:22.762663+03:00","extra":{"referer":"","ip":"172.18.0.5","request_uri":"https://example.gov.sa/user/login","uid":0,"user":""}}

<133> is facility LOCAL0 at level notice, so the host's syslog daemon can route Mutamad's entries to the SIEM on their own. A newline inside a message is escaped, so one entry is always one line.

Where log entries go — configured outside this recipe

Monolog replaces Drupal's own loggers and is configured only in a services file, not in configuration, so a recipe cannot set it. With Monolog's defaults nothing reaches the database log and everything goes to syslog as plain text.

The Mutamad project template sets it in services.mutamad.yml. A site built another way adds this to one of its own services files, loaded through $settings['container_yamls']:

parameters:
  monolog.channel_handlers:
    default:
      handlers:
        - name: 'drupal.dblog'
        - name: 'mutamad_syslog'
          formatter: 'mutamad_json'

services:
  monolog.handler.mutamad_syslog:
    class: Monolog\Handler\SyslogHandler
    arguments: ['mutamad', 'local0', 'info']
  monolog.formatter.mutamad_json:
    class: Monolog\Formatter\JsonFormatter
    arguments: [1, false]

The second argument of the formatter, false, matters: PHP's syslog() splits a message at each newline, and Monolog's JSON formatter otherwise ends every entry with one, which adds an empty syslog line after each entry.

The host must run a syslog daemon (rsyslog, syslog-ng) that forwards LOCAL0 to the SIEM. Without a /dev/log socket the entries sent to syslog are lost; mutamad-verify says so. Many containers, DDEV's included, have none.

Core's syslog module is not installed: with Monolog in place it would never be called.

Who reads the log, and who can clear it

Drupal core puts reading the database log and clearing it behind one permission, View site reports, and clearing it records nothing — the table is simply emptied. So:

  • On a Mutamad site only site_admin holds it (Mutamad Roles). The copy already sent to the SIEM is not affected by a clear, and is the one that counts.
  • Content roles cannot see the log.

This recipe grants nothing and creates no roles, so it applies to any Drupal site.

The admin audit trail — who changed roles, permissions, menus, content — stays in Mutamad Admin.

Exporting the log for an audit

Export from the SIEM: it holds every entry, for as long as the retention policy says, and nobody on the site can clear it. For the database log alone — on a site whose SIEM is not connected yet, for instance — Drush writes the same columns as Recent log messages, plus the IP address and page:

drush watchdog:show --count=100000 --extended --format=csv > log.csv

The file holds visitors' IP addresses, which are personal data: keep it out of the web root and delete it once the audit is done.

Scheduled tasks (cron)

Cron is where a Mutamad site checks for security updates (NCA ECC 2-10-3), expires passwords (ECC 2-2-3), trims the database log (ECC 12-2-3), sends newsletters and updates the search index. When cron stops, nothing fails visibly: the site keeps working, and those controls stop.

WhatSetting
Each task its own jobUltimate Cron: every module's cron task is a job, run every 15 minutes, each at its own minute so they do not all start together; a task that fails does not stop the others
A log of every runEach job keeps 30 days of runs — start, duration, messages — instead of its last 1,000. Errors also reach the database log and the SIEM
Automated Cron offCore's Automated Cron set to Never: it ran cron at the end of a visitor's request, every three hours, so a quiet site ran its tasks late
A warning when cron stopsThe status report warns after 1 hour without cron and shows an error after 1 day (core: 2 days and 2 weeks)

A recipe cannot uninstall a module, and core's standard recipe installs Automated Cron, so it is set to Never, not removed. This recipe installs it too, so the setting is the same on any site.

The server must run cron

With Automated Cron off, nothing runs cron until the server does. Run drush cron every minute; Ultimate Cron decides which tasks are due. On a host, add a crontab line for the user that owns the site:

* * * * * cd /var/www/example.gov.sa && vendor/bin/drush cron --quiet

A host that cannot run a task every minute can run it every 5 minutes; a task then runs within 5 minutes of its time. The Mutamad project template does it in DDEV (.ddev/config.cron.yaml): ddev start starts it, and it pauses while Drupal is installed or a recipe is applied.

New tasks need a cache rebuild

Ultimate Cron runs only the tasks it has a job for. It creates jobs when a module is installed from Extend or Drush, and when caches are rebuilt — but not when a recipe installs the module: recipes install in syncing mode, which Ultimate Cron skips. A task without a job never runs, and cron still reports success.

  • A new Mutamad site is fine: the Mutamad profile creates the jobs at the end of installation.
  • After applying this recipe, or any recipe later, rebuild caches: drush cache:rebuild.
  • mutamad-verify checks that every task has an active job.

Who manages the jobs

Only the administrator. Administer Ultimate Cron lists the jobs, shows their logs, pauses them and changes their schedules, and pausing the password-expiry or update-check job would switch a control off. In Ultimate Cron 2.0.0-beta2, View cron jobs opens nothing on its own: the job list and the logs need Administer Ultimate Cron. A site administrator with View site reports sees on the status report when cron last ran and whether any job is behind schedule.

From the server:

drush cron:list               # every job, its schedule and last run
drush cron:logs system_cron   # one job's recent runs
drush cron:run update_cron    # run one job now

Ultimate Cron is a beta

Ultimate Cron 2.x has no stable release yet. Drupal's security team covers stable releases only, so a vulnerability in it may be fixed without a security advisory. Watch its release notes, and update it with the site.

Requirements

Drupal core 11.4. Composer brings Monolog, Diff and Ultimate Cron. A site's root composer.json must allow Ultimate Cron's beta, as Mutamad's project template does:

composer require drupal/ultimate_cron:^2.0@beta drupal/mutamad_logging

Apply it to an existing site

drush recipe ../recipes/mutamad_logging
drush cache:rebuild

Then add the Monolog block above to a services file if the site does not use Mutamad's project template, and rebuild caches again. Check that a new log entry appears in Recent log messages — if it does not, Monolog is running with its defaults. Add the crontab line, and an hour later check Reports › Status report: Cron maintenance tasks should say cron ran a few minutes ago, and Ultimate Cron "Cron is running properly."

On an existing site the recipe cannot take View site reports away from a role that already has it. Check that no content role holds it.

Maintainers

iSpectra

Built and maintained by iSpectra (on drupal.org).