Skip to content

Check JSON reports with Nagios or Icinga

check-mail-report.py checks a fresh direct validator probe. Each run sends a synthetic message to check, reads the report link from the confirmed SMTP DATA response and fetches the public report using HTTPS GET. New nonces in Message-ID and body prevent reuse of deduplicated reports. This checks SMTP, storage and HTTP on this route. It does not verify the regular outgoing server and signing chain.

For regular checks through your own outgoing Postfix, use check_mail_report from the nagios-plugins-custom repository. This extended check differs from the included deploy/check-mail-report.py. Installation, release bundles and fixed sudo/Icinga rules are documented in the plugin guide.

Keep the existing statistics/readiness check separate. A deliberately suspicious message does not automatically mean a broken validator. Without extra expectations, the plugin requires complete core findings, but no SPF/DKIM pass or particular score.

Public JSON contract

GET /api/v1/reports/{token} returns HTTP 200 with application/json. The HTML link is /r/{token}; the plugin requires the current 32-character Base64url token without query or fragment. JSON is not part of SMTP responses or reply messages. The token is an access reference and must not appear in argv.

Supported schema_version is 1. validator_version identifies the generating software, not the schema. created_at and expires_at are UTC timestamps. status is ohne_festgestellte_probleme, auffaellig or unvollstaendig. Checks provide stable name, code, result and level; localized detail is not parsed. Optional modules describe activation, not successful findings. Score thresholds require complete rating version 1, scope message_and_last_hop, score 0–100, grade S–F and empty missing. Extra fields and unconfigured optional findings are tolerated.

Synthetic public example; its fixed timestamps do not prove current operation:

{
  "schema_version": 1,
  "validator_version": "1.1.0",
  "created_at": "2026-10-08T12:00:00Z",
  "expires_at": "2026-10-08T13:00:00Z",
  "status": "ohne_festgestellte_probleme",
  "checks": [
    {"name": "SPF", "code": "spf_pass", "result": "pass", "level": "ok"},
    {"name": "DKIM", "code": "unsigned", "result": "none", "level": "hinweis"},
    {"name": "DMARC", "code": "aligned", "result": "pass", "level": "ok"}
  ],
  "modules": [{"name": "wkd", "state": "disabled"}]
}

Missing, invalid and expired references all return 404 with {"error":"Not Found"}. Storage errors return 503 with {"error":"Service Unavailable"}. Proxy error formats may differ. The API sends Cache-Control: no-store and excludes private details, unlock codes and access tokens from JSON. The permanent example has permanent_example: true and is rejected by the plugin.

Installation and protected configuration

The plugin requires Linux and Python 3.11 or newer with its standard library. The monitoring user needs access to configured SMTP/HTTPS targets, but no database or private diagnostic access. These instructions are an installation template; development acceptance installs nothing into existing monitoring. The JSON file must belong to the actual service user, have mode 0600 and be a regular file, not a symlink.

install -o root -g root -m 0755 deploy/check-mail-report.py /usr/lib/nagios/plugins/check-mail-report.py
install -d -o root -g nagios -m 0750 /etc/nagios/mail-report
install -o nagios -g nagios -m 0600 /dev/null /etc/nagios/mail-report/probe.json

Choose your test identity, TLS profile, destination and volume, then replace these synthetic values. Only the check recipient is allowed; no automatic reply or intentional bounce is requested.

{
  "origin": "https://validator.example.test",
  "smtp_host": "validator.example.test",
  "smtp_port": 25,
  "smtp_tls": "starttls",
  "sender": "monitor@example.test",
  "recipient": "check@validator.example.test",
  "helo": "monitor.example.test",
  "expect": []
}

smtp_tls supports starttls and implicit, with certificate and hostname verification. Optional absolute ca_file applies to both transports. Optional smtp_user/smtp_password are loaded only from the protected file and require TLS. Local tests may use loopback_plain and allow_loopback_http: true; both require numeric loopback addresses. There is no TLS fallback, redirect or environment proxy. The fixed origin also restricts links received over SMTP.

sudo -u nagios /usr/bin/python3 /usr/lib/nagios/plugins/check-mail-report.py --config /etc/nagios/mail-report/probe.json --timeout 30 --max-age 300

Whole-run deadline: 30 seconds, configurable from 0.1 to 300, including file access, DNS, connection and reading. GET receives at most ten seconds and never more than the remaining whole-run budget. Limits: 1 MiB HTTP body, JSON depth 16, 16384 JSON nodes, 512 checks, 16 KiB SMTP reply and 16 KiB configuration. A short-lived child performs the check; its parent terminates and reaps only that tracked process on deadline or SIGTERM/SIGINT and reports CRITICAL. No retries. Default maximum age: 300 seconds; expiry, future timestamps and creation before the current SMTP run are checked with five seconds of clock tolerance. Synchronize host clocks.

For reuse, select --mode report and put the full HTML link in report_url in the same protected file. This mode sends no mail, but still requires a fresh, unexpired report.

Check regular Postfix delivery

In postfix mode, check_mail_report submits a new test message to your own Postfix, reads its queue ID and waits for the corresponding outgoing postfix/smtp delivery. It extracts the report link from that delivery's final status=sent (250 ...) response. This checks the actual sending route, its milter/DKIM signing and Internet TLS transport. Signing must already be configured; the plugin does not set it up.

Requirements and limits:

  • Linux; Python >=3.11 for the source script, while release bundles include Python 3.12.
  • Numeric loopback SMTP without authentication, using smtp_tls: loopback_plain. Postfix must locally accept your sender and the check recipient. Plaintext applies only to loopback; Postfix controls Internet TLS.
  • Access to /var/log/mail.log in the supported postfix/smtp format. Journal-only logging, other log paths and different formats are currently unsupported. SMTP and logs must belong to the same Postfix instance, including in containers. With Icinga, run the check on the sending host/agent.
  • SMTP delivery to RateMyMail and HTTPS access to its public API. The final delivery response must contain exactly one report link on the configured origin. An external smarthost often confirms only acceptance into its own queue without returning that link; such a route is not automatically compatible with the current Postfix mode.

Put the following content in the custom plugin's protected JSON file; adapt the example domain, sender identity and local port:

{
  "origin": "https://validator.example.test",
  "assess_all": true,
  "smtp_host": "127.0.0.1",
  "smtp_port": 25,
  "smtp_tls": "loopback_plain",
  "sender": "monitor@example.test",
  "recipient": "check@validator.example.test",
  "helo": "monitor.example.test",
  "expect": [
    {"name": "SPF", "codes": ["spf_pass"], "result": "pass"},
    {"name": "DKIM", "codes": ["signature_valid"], "result": "pass", "match": "any"},
    {"name": "DMARC", "codes": ["aligned"], "result": "pass"}
  ]
}

The configuration must be a regular nonsymlink file with mode 0600, owned by the executing user or root. Grant only necessary log read access or use the fixed sudo rule from the plugin guide; Nagios must not be able to write the plugin, bundle or symlink. After that installation, using its configured path:

sudo -u nagios sudo -n /opt/nagios-plugins-lukas/check_mail_report --mode postfix --config /etc/nagios/mail-report/postfix.json --timeout 60 --max-age 300

With assess_all: true, every public finding is assessed: problem produces CRITICAL, unbekannt UNKNOWN and hinweis WARNING; ok and nicht_anwendbar do not alert. Confirmed problems take precedence over optional unknown findings. SPF/DKIM/DMARC expectations additionally enforce the intended sender profile. The public API requires no account/API key; a valid report link grants access and remains confidential.

Start with a five-minute interval and one check attempt. A timeout does not remove an already accepted message from the Postfix queue; it may still be delivered later. The next run nevertheless uses a new test message and never an old report. This checks the sending route, not IMAP or every receiving function. The following direct probe examples remain separate.

Expectations and exit codes

Below “Problems, notices and incomplete checks”, the report page shows a copyable ignore_checks configuration for the custom Nagios plugin. It selects the listed problem, advisory and unknown findings using the original JSON names and codes instead of translated display labels. Presentation-only rows without a recorded finding are selected by name. Merge the entry into the protected plugin configuration; ignore: false disables an exception again. The report and score remain unchanged. The page does not activate exceptions automatically.

Optional expectations use check names and codes. Default match: all requires every matching check; any can accept a successful signature among several DKIM signatures. result and level add constraints. An absent required check is UNKNOWN, a confirmed mismatch defaults to CRITICAL; severity: warning lowers that mismatch to WARNING.

{
  "name": "DKIM",
  "codes": ["signature_valid"],
  "result": "pass",
  "level": "ok",
  "match": "any",
  "severity": "critical"
}

Place this entry in expect. An unsigned direct probe will not satisfy it. Leave expect empty for the baseline profile. A regular signed sender profile and its report-link return path are covered by the custom plugin's Postfix mode above; the direct probe does not use that sending route.

Exit code Meaning
0 OK Fresh valid report meets configured expectations
1 WARNING Warning threshold or explicitly tolerated mismatch
2 CRITICAL Critical expectation fails or SMTP/DNS/TLS/HTTP is unavailable
3 UNKNOWN Misconfiguration, missing/stale reference, incomplete or unknown evidence

Unreadable reports produce no message verdict. Missing required evidence takes precedence over message mismatches; with fully evaluable evidence, CRITICAL precedes WARNING. Output and perfdata exclude free mail text, domains, tokens and credentials.

Score thresholds are opt-in, for example --warning 90: --critical 70:. Nagios ranges include endpoints: 90: alerts below 90, 10 outside 0–10, ~:10 above 10 and @10:20 within 10–20. The first line uses English and bounded metrics after |; the exit code determines status. Monitoring plugin guidelines.

OK - fresh report meets expectations | report_age=0.100s;;;0; checks_ok=0.000;;;0; checks_failed=0.000;;;0; http_time=0.012s;;;0;

Monitoring definitions

Nagios command; the configuration path contains no report token:

define command {
    command_name check_mail_report_probe
    command_line /usr/bin/python3 /usr/lib/nagios/plugins/check-mail-report.py --config /etc/nagios/mail-report/probe.json --timeout 30 --max-age 300
}

Icinga command; adjust file ownership if using a different service user:

object CheckCommand "mail-report-probe" {
  command = [ "/usr/bin/python3", "/usr/lib/nagios/plugins/check-mail-report.py" ]
  arguments = {
    "--config" = "$mail_report_config$"
    "--timeout" = "30"
    "--max-age" = "300"
  }
  vars.mail_report_config = "/etc/nagios/mail-report/probe.json"
}

Start with a five-minute interval and adjust to mail volume, report TTL and limits. Each run creates one mail and one stored report; shorter intervals need an explicit capacity decision. Preserve the existing statistics check and other monitoring configuration.