Schnittstellenmonitoring
IM4HC Monitoring
Wenn Nachrichten warten, sichtbar werden lassen.
IM4HC Monitoring beobachtet Nachrichtenwarteschlangen der Integrationsplattform. Es erkennt überalterte HL7-Nachrichten und unterstützt die Zuordnung von Vorfällen zu betroffenen Schnittstellen.

Context
At a glance.
Erkennung
Warteschlangen finden und das Alter der Nachrichten prüfen.
Einordnung
Auffälligkeiten nach Schwere, Verlauf und Schnittstelle zusammenführen.
Verfolgung
Vorfälle vom ersten Hinweis bis zur Auflösung begleiten.
How it works
Follow the workflow.
HL7-Warteschlangen
Nachrichtenbestand
Prüfung
Alter & Verlauf
Vorfall
Schnittstelle zuordnen
Monitoring
Hinweis & Auflösung
Conceptual diagram · not live data
Explore the details
The original article.
The original service-desk article is preserved below. The editorial context above explains the service; statements in the source reflect its publication date.
Read original article Content & documentation
im4hc Monitor – Comprehensive Technical Documentation
Document ID: DOC-IM4HC-001
Version: 1.1.0
Last Updated: February 2026
Maintained by: DigitalON Technology Services
Support Portal: support.digitalon.co.za
Table of Contents
- Executive Summary
- System Architecture
- Component Documentation
- Data Flow & Workflows
- Installation & Deployment
- Configuration Reference (Abschnitt in der Quelle nicht enthalten)
- Operational Runbook (Abschnitt in der Quelle nicht enthalten)
- Troubleshooting Playbook (Abschnitt in der Quelle nicht enthalten)
- Alert Reference (Abschnitt in der Quelle nicht enthalten)
- API & Integration Reference (Abschnitt in der Quelle nicht enthalten)
- Appendix (Abschnitt in der Quelle nicht enthalten)
1. Executive Summary
1.1 Purpose
The im4hc Monitor is a production-grade Python monitoring solution designed to detect and alert on stale HL7 messages in the im4hc healthcare integration platform. It provides near real-time visibility into message queue health across 148+ queue tables and 59+ healthcare providers, and integrates directly into CheckMK for service monitoring.
1.2 Key Capabilities
| Feature | Description |
|---|---|
| Auto-Discovery | Dynamically discovers queue tables from the MySQL schema (no hardcoded list). |
| Dual-Channel Alerting | Telegram + Matrix (bridged to WhatsApp) notifications. |
| Severity Classification | CRITICAL/HIGH/MEDIUM based on message age, count, and recurrence. |
| Incident Reference IDs | Unique INC-YYYYMMDD-NNN IDs for tracking and support conversations. |
| Alert Deduplication | One alert per incident + one recovery notification when cleared. |
| Historical Context | Provider incident history, MTTR, and “clean streak” tracking. |
| Compact Mobile Format | Optimized message format for WhatsApp/Matrix readability. |
| Incident Lifecycle | Tracks incident states: new → ongoing → resolved. |
| CheckMK Integration | Native CheckMK local-check output format (0/1/2/3 status codes). |
| Rate Limiting | Independent cooldown timers per notification channel. |
| Discovery History | Tracks queue table additions/removals over time (snapshots). |
| Provider Metadata | Escalation hints and troubleshooting guidance per provider. |
1.3 Current Deployment Status
| Attribute | Value |
|---|---|
| Active Hosts | hel1dc6p (Tailscale), ncdcncogrd03 (10.8.9.235) |
| MySQL Endpoint | 10.8.7.225:3306 |
| Tables Monitored | 148 (100 inbound, 48 outbound) |
| Providers | 59 healthcare integrations |
| Check Intervals | queue-scan: 900s, matrix: 1800s |
| Default Stale Threshold | 880 seconds (~14m 40s) |
1.4 Business Impact
- Early Detection: identifies stuck messages before they impact clinical operations and patient workflows.
- Reduced MTTR: alerts include historical context and provider hints to accelerate investigation.
- No Alert Fatigue: deduplication prevents repeated alerts for the same incident.
- Provider Visibility: problems are grouped by provider and classified by severity.
- Mobile-Friendly: compact format is readable in WhatsApp/Matrix.
- Audit Trail: discovery snapshots + incident lifecycle improve traceability.
2. System Architecture
2.1 High-Level Architecture
At a glance:
- CheckMK agent runs local checks (every 900s and 1800s).
- Checks run the
im4hc_monitorPython package to discover queues and detect stale messages. - Incidents are tracked persistently in a JSON state file.
- Alerts are sent via Telegram and Matrix (bridged to WhatsApp).
- Dashboards are accessible via CheckMK UI and Grafana.
Key runtime components:
- Monitoring Host: ncdcncogrd03 (CheckMK agent + Python package)
- Database: MySQL @ 10.8.7.225:3306 (schema:
im4hc) - Notifications: Telegram bot, Matrix homeserver + WhatsApp bridge
- Dashboards: CheckMK service status + Grafana deep link
2.2 Package Module Structure
| Area | Modules | Purpose |
|---|---|---|
| Core | main.py, config.py, db.py | CLI orchestration, config loading, MySQL connectivity. |
| Checks | checks/queue_scan.py, checks/matrix_check.py | 900s queue scan + 1800s lifecycle check. |
| Discovery | discovery.py | Auto-discover queue tables + scan for stale messages. |
| State | state.py | Incident tracking, history, MTTR, deduplication state. |
| Notifications | notify.py, matrix_notify.py, provider_metadata.py | Severity classification, formatting, dispatch to channels. |
| CheckMK Output | checkmk_output.py | Local-check format output for CheckMK. |
| Validation | preflight.py | 6-point preflight validation before checks run. |
2.3 Component Responsibilities
| Module | Responsibility |
|---|---|
main.py | CLI entry point, argument parsing, check orchestration. |
config.py | INI config loading, token file reading, feature flags. |
db.py | MySQL connection with dual-driver fallback. |
discovery.py | Queue table discovery via information_schema. |
state.py | Persistent incident state, history, MTTR, deduplication. |
notify.py | Severity, grouping, formatting, channel dispatch, context. |
matrix_notify.py | Matrix API client (stdlib-only compatible). |
provider_metadata.py | Provider hints and escalation metadata. |
preflight.py | Validates config/state/db/notification channels. |
checkmk_output.py | Generates CheckMK local check output lines. |
3. Component Documentation
3.1 Discovery Engine
The discovery engine automatically identifies HL7 queue tables without hardcoding table names. Queue tables are detected using regex patterns and explicit exclusions.
3.1.1 Table Detection Patterns
# Queue Table Detection Patterns (from discovery.py)
QUEUE_TABLE_PATTERNS = [
"^out_\\w+", # out_hims_orm, out_lancet_orm_12900
"^in_\\w+", # in_ampath_orm, in_sanbs_oru
"^\\w+_orm_in$", # beningfield_orm_in, labos_orm_in
"^\\w+_oru_in$", # labos_oru_in, chiro_oru_in
"^\\w+_mdm_in$", # skylims_mdm_in, valabjee_mdm_in
]
EXCLUDE_TABLES = {"queuedetail", "orm_queue_ack"}
DEFAULT_EXCLUDE_SUFFIXES = ("_keytable", "_stat") 3.1.2 Provider Extraction Logic
Providers are extracted from queue table names to allow grouping and history tracking:
Examples:
out_hims_orm -> hims
out_lancet_orm_12900 -> lancet
in_ampath_orm -> ampath
in_sanbs_oru -> sanbs
beningfield_orm_in -> beningfield
skylims_mdm_in -> skylims 3.2 State Management
The state module provides persistent tracking of active incidents, alert cooldowns, discovery history, and provider MTTR. State is stored in a JSON file (default: /var/tmp/im4hc_monitor_state.json).
3.2.1 State File Structure
{
"active_incidents": {
"out_hims_orm": {
"first_detected": 1738742400.0,
"last_seen": 1738743300.0,
"message_count": 15,
"peak_count": 25,
"oldest_message": "2026-02-05 08:45:00",
"incident_id": "INC-20260205-001",
"provider": "hims",
"alert_sent": true,
"alert_sent_at": 1738742500.0
}
},
"alerts": {
"queue_scan": {"last_sent": 1738743000.0, "message_hash": "abc123"},
"matrix_alert": {"last_sent": 1738742400.0}
},
"incident_counter": {"date": "20260205", "count": 3},
"incident_history": { "... per provider ...": {} },
"discovered_tables": { "... per table ...": {} },
"discovery_snapshots": [ "... history ..." ]
} 3.2.2 State Sections
| Section | Purpose |
|---|---|
active_incidents | Open incidents with per-table tracking and alert_sent flags. |
alerts | Per-channel cooldown and (optional) message hash dedup state. |
incident_counter | Daily counter to generate INC-YYYYMMDD-NNN IDs. |
incident_history | Per-provider incident archive + MTTR stats. |
discovered_tables | Registry of discovered queue tables (direction/provider/status). |
discovery_snapshots | Timestamped snapshots for tracking additions/removals. |
3.3 Notification System
3.3.1 Dual-Channel Design
- Both Telegram and Matrix are supported.
- Each channel has an independent cooldown to prevent flooding.
- Each channel has an alert time window (default 04:00–23:00 local time).
- Matrix messages are formatted compactly and may appear in WhatsApp via a bridge.
3.3.2 Severity Classification
| Severity | Condition | Icon |
|---|---|---|
| CRITICAL | Age > 4h OR Count > 50 OR 3+ incidents in 24h | ???? |
| HIGH | Age > 2h OR Count > 20 | ???? |
| MEDIUM | Default for other stale-queue issues | ???? |
Legend:
>>>/>= outbound queue (to provider)<<<<[NEW][INCREASING][STABLE][DECREASING]= partial recoveryINC-YYYYMMDD-NNN= incident reference ID
3.4 Preflight Validation
Before monitoring checks run (especially in automated service contexts), the system supports a 6-point preflight. This prevents false alerts caused by missing config, broken DB connectivity, or invalid tokens.
Preflight checks:
[config] Required configuration fields are present
[state_file] State file path exists / is writable
[mysql] MySQL connectivity and schema access
[discovery] Queue discovery returns tables
[telegram] Telegram token validated via getMe
[matrix] Matrix token validated via whoami Example preflight output:
=== im4hc_monitor Preflight Report ===
[PASS] config: All required fields present
[PASS] state_file: Writable: /var/tmp/im4hc_monitor_state.json
[PASS] mysql: Connected and schema accessible
[PASS] discovery: Found 148 queue tables
[PASS] telegram: Token valid (getMe OK)
[PASS] matrix: Connected as @digitalon:alldigital-on.com
Result: 6/6 checks passed 4. Data Flow & Workflows
4.1 Queue Scan Check Flow (900s)
Goal: detect stale messages across all queue tables and trigger alerts with deduplication.
- Load config + state.
- Discover queue tables.
- Record discovery snapshot history.
- Scan tables for stale messages older than
queue_age_seconds(default 880s). - If no problems: output OK to CheckMK.
- If problems: classify WARN/CRIT based on affected-table count and format alert.
- Send alerts (Telegram + Matrix) if time window + cooldown allow.
- Save updated state and exit.
4.2 Matrix Check Flow (1800s) with Incident Lifecycle
Goal: manage incident lifecycle state and send recovery notifications when queues clear.
- Load config + state.
- Discover and scan tables.
- Compare current problems vs active incidents in state.
- Resolved incidents: close and send recovery notifications.
- Still-active incidents: update age, counts, trends, and keep open.
- New incidents: create incident IDs and mark NEW vs ONGOING based on age.
- Output CheckMK status and save state.
4.3 Incident Lifecycle State Machine
- Detected → queue has stale messages
- New → age < 5 minutes (CheckMK CRIT: “NEW integration problem”)
- Ongoing → age ≥ 5 minutes (CheckMK WARN: “Ongoing integration issue”)
- Resolved → queue clears; recovery is sent once
5. Installation & Deployment
5.1 Prerequisites
| Requirement | Version | Notes |
|---|---|---|
| Python | 3.8+ | Core functionality is standard-library friendly. |
| mysql-connector-python | 8.0+ | Primary MySQL driver. |
| pymysql | 1.0+ | Optional fallback driver. |
| requests | 2.25+ | Used for Telegram (urllib fallback may exist). |
| CheckMK Agent | 2.x | Runs local checks at defined intervals. |
6.2 Configuration Sections Explained
| Section | Key | Meaning |
|---|---|---|
| [mysql] | host/port/user/password/database | MySQL connectivity for schema scan + queue analysis. |
| [discovery] | schema/exclude_suffixes/max_snapshots | Controls which tables are discovered and history retention. |
| [thresholds] | queue_age_seconds + severity thresholds | Controls stale detection sensitivity and severity classification. |
| [checkmk] | service_queue_scan/service_matrix | Service names shown in CheckMK. |
| [telegram] | token file, chat_ids, cooldown, hours | Telegram alerting configuration. |
| [matrix] | homeserver/room/token/cooldown/hours | Matrix alerting configuration (may bridge to WhatsApp). |
| [formatting] | include_* | Controls whether to include direction, trend, history, hints, etc. |
| [providers] | metadata_file/default_hint | Provider metadata and escalation hints. |
| [state] | state_file/history retention | Incident tracking persistence settings. |
Security note: Do not publish token values, internal IPs, or credentials in a public-facing portal. Keep this article internal or redact sensitive values.