Building a correlated daily infrastructure report with ManageLM, InfiniGPT and the Matrix stack

This post documents what was just built on top of the existing Matrix server stack: a scheduled, automated daily report that pulls live data out of ManageLM, cross-references it against Netdata, PatchMon and Pi-hole, and has Claude Sonnet (via OpenRouter) write up the findings as a Matrix message, complete with concrete remediation steps. It is written for whoever next has to maintain this, so it goes into the mechanics rather than staying at the surface.

What ManageLM actually is

ManageLM is a fleet management and automation platform reached in this stack through its Model Context Protocol (MCP) server at https://managelm.safehomelan.com/mcp. The core concept is the agent: a small piece of software registered against a host, which ManageLM can query for data or dispatch operations to. Every tool that acts on a host takes a target, and the server’s own instructions (returned during MCP initialisation) explain the targeting model plainly: if the user names a specific host, pass that hostname; if the user names a capability instead (create an AD user, allow an IP through the web server), pass target: "auto" on the relevant skill tool and ManageLM works out which agent owns that capability. auto only works on skill tools, not on the reporting tools, which need an explicit hostname, group, site, or all.

Querying the server directly confirms it is running version 1.6.5 of the ManageLM MCP implementation against protocol revision 2024-11-05, and it currently exposes fifty-three tools. These fall into a small number of families. There are search and list tools that are pure reads: search_security, search_certificates, search_pki, search_credentials, search_sudo_rules, search_ssh_keys, search_activity, search_monitors, search_backups, search_agents, search_cloud, search_inventory and similar. There are run tools that dispatch a fresh scan against one or more agents, such as run_security_audit, run_inventory_scan, run_access_scan and run_certificate_scan. There is a task subsystem (get_task_status, get_task_history, get_task_changes, answer_task, revert_task) that lets you follow up on anything dispatched asynchronously, including reverting a change via the agent’s local git repository. And then there is a large set of skill tools, one per operational domain: security, packages, services, users, network, storage, system, containers, virtualization, webserver, webapps, proxy, dns, vpn, filesharing, logs, monitoring, files, certificates, developer, base and automation. These are the tools that make real changes on a host, so they were deliberately excluded from the automated report’s toolset (more on that below).

The free tier, and what it actually gives you

Calling get_account_info against the live server returns the account’s plan and usage in one shot, which is the honest way to describe what “free” gets you here rather than guessing from marketing copy. At the time of writing the account is on the free plan with ten agents registered against a limit of ten, meaning the fleet is currently at capacity for this tier. Monitors, certificates, credentials and keystore keys are all reported as unlimited on this plan. The daily request allowance is one thousand, of which the account had used none at the point of the call, and the plan carries no expiry (valid_until: "no expiry"). Agents in this account are organised into three non-default groups: core with two agents, kubernetes with four, and proxmox_client with three, alongside an empty Default group.

Practically, this means the free tier is generous for a household or small fleet: unlimited certificate, credential and monitor tracking, a four-figure daily request budget that a once-a-day automated report barely dents, and no time limit on the plan itself. The binding constraint is the agent count, and once the report started fanning out to four data sources per run it became clear that request budget is not the limiting factor here, wall-clock time and how many tool calls a single LLM turn chooses to make are.

How the ManageLM MCP server is wired in

MCP servers speak JSON-RPC 2.0 over one of a few transports. ManageLM’s own reference client setup uses mcp-remote over HTTP with two custom headers, X-MCP-Id and X-MCP-Secret, and that is what the example configuration shipped in this repository still shows:

{
  "ManageLM": {
    "command": "bash",
    "args": [
      "-lc",
      "npx -y mcp-remote https://managelm.safehomelan.com/mcp --header 'X-MCP-Id: mIm_cid_...' --header 'X-MCP-Secret: ...' --debug"
    ]
  }
}

In practice a small bespoke proxy is used instead: runtime/infinigpt/managelm_stdio_proxy.py. It implements the stdio side of MCP itself, reading one JSON-RPC message per line from stdin and writing one response per line to stdout, and forwards every request as an HTTP POST to ManageLM’s endpoint with the two auth headers attached. It captures the mcp-session-id header from the initialize response and attaches it to every subsequent call, and it deliberately skips OAuth discovery, since this is a headless, non-interactive client. This keeps the integration simple and avoids depending on mcp-remote‘s own session and auth-discovery behaviour. The live configuration wires it up like this, reading the endpoint URL and credentials from an env file that never goes into version control:

{
  "ManageLM": {
    "command": "bash",
    "args": [
      "-lc",
      "set -a; . /config/managelm.env; exec python3 /config/managelm_stdio_proxy.py"
    ]
  }
}

Two helper scripts exist for operating this: scripts/enable_managelm_mcp.sh merges the spec above into the bot’s config.json and force-recreates the container, and scripts/validate_managelm_mcp.sh execs into the running container and lists the tools it can see, which is the fastest way to confirm the secret is valid and the proxy is talking to the server correctly.

InfiniGPT, and how it fits together

The Matrix side of this is InfiniGPT (packaged as infinigpt-matrix, and referred to day to day here as IntelliGPT), a modular async Matrix bot built on matrix-nio. It logs into a dedicated bot account, joins a set of rooms, and dispatches incoming messages through a command router (.ai, .model, .persona, and so on). What matters for this report is its tool-calling layer: at startup it reads llm.mcp_servers out of its config, spins up a FastMCPClient per server, lists that server’s tools, and merges all of them into one OpenAI-style tools schema alongside a handful of built-in tools (weather, time, arithmetic, and so on). Every configured MCP server currently contributes to that combined schema: ManageLM, Netdata, Nextcloud, PatchMon, Rancher, ArgoCD, OpenNotebook, Gitea, Pi-hole, Nginx Proxy Manager, Docker, Tailscale and a bespoke RemoteOps server, five hundred and four MCP tools in total plus ten built-ins.

When a chat message triggers a reply, or in this case when the scheduler triggers a report, the bot calls AppContext.respond_with_tools(). This sends the conversation plus the full tools schema to the chosen model’s chat-completions endpoint, and if the model responds with tool calls, the bot executes each one, feeds the JSON result back in as a tool role message, and asks the model to continue. This loop runs for up to eight iterations, which for the enriched report is comfortably enough: a typical run makes twenty to thirty tool calls across two or three iterations before the model is satisfied it has what it needs.

The bot itself is built by installing infinigpt-matrix from its upstream archive and then running a build-time patch script, docker/infinigpt/patch_site_packages.py, against the installed package. This is how every local customisation is layered on, including the scheduler feature described below: the script does targeted, idempotent string replacements against known anchor points in the installed source, so a docker compose build infinigpt always ends up with the same customised bot regardless of what the upstream zip contains that day.

Correlating four MCP servers instead of one

The report was originally ManageLM-only. It has since been extended to also call Netdata, PatchMon and Pi-hole, with ManageLM kept as the backbone that defines the report’s structure and the other three used to corroborate or add context where a host, agent or client overlaps.

Netdata is the metrics and alerting layer. The tools used here are list_raised_alerts for anything currently in a WARNING or CRITICAL state, list_nodes and get_nodes_details for per-node health, and find_anomalous_metrics to surface anything Netdata’s own anomaly-detection models flagged as behaving unusually over the last day. The correlation this enables is straightforward but useful: if ManageLM lists an agent as unhealthy or offline, Netdata can confirm or contradict that from its own telemetry for the same node.

PatchMon is the patch and package-compliance layer. list_hosts and get_host_stats give pending-update counts per host, and list_patch_runs, preview_patch_schedule and get_agent_queue show the state of any patch runs already queued or completed. The correlation of interest is a host that ManageLM’s security audit has already flagged, cross-checked against whether that same host is also sitting on a pile of unapplied updates in PatchMon.

Pi-hole is the DNS and network-activity layer. pihole_info_system gives CPU, memory, disk and temperature for the Pi-hole host itself, pihole_stats_summary and pihole_info_ftl cover the DNS service’s own health, pihole_auth_sessions lists active admin sessions (useful for spotting an unrecognised login to the Pi-hole web interface), and pihole_stats_recent_blocked together with pihole_stats_top_clients (filtered to blocked queries) can surface a client suddenly generating a spike of blocked or suspicious-looking lookups, which is worth flagging alongside a ManageLM audit-log finding for the same host.

All three of these expose tools that change state, not just read it: PatchMon’s trigger_patch, trigger_dry_run and approve_patch_run make real changes to a host’s packages, and Pi-hole has a full set of pihole_action_*, pihole_*_add, pihole_*_delete, pihole_*_update and pihole_config_set tools that alter live DNS behaviour. Because the report’s tools schema is the bot’s entire combined toolset, the model technically has access to all of them. The report’s prompt is therefore explicit that only read-only listing, search, query and get tools may be called while building the report, and that any fix belongs in the remediation section as a suggestion for a human to run, never something the model executes itself.

OpenRouter and Claude Sonnet’s role

InfiniGPT’s LLM client is provider-agnostic: it resolves whichever model string it is given against a small routing table and calls that provider’s chat-completions endpoint directly over HTTPS. The bot’s everyday default model is deepseek/deepseek-v4-flash via OpenRouter, chosen for cost and latency on routine chat. The scheduled report overrides that on a per-report basis and asks for anthropic/claude-sonnet-4.6, again via OpenRouter, because the report has to sit through twenty-plus tool calls, hold the resulting data in context, and produce a long, structured, cross-referenced write-up without losing track of which host a given finding belongs to. That is a different job to answering a one-line chat message, and it is worth spending more on a stronger model for a report that only runs once a day.

The scheduler mechanism

None of the above happened automatically before this piece of work, since InfiniGPT only ever reacted to inbound chat messages. A small scheduler module now runs as a background asyncio task per configured report. It computes the number of seconds until the next occurrence of a given local time in a given IANA timezone using the standard library’s zoneinfo, sleeps, then builds a system and user message pair from a configured prompt and pushes it through the exact same respond_with_tools() loop used for normal chat, before rendering the result to Markdown and sending it into the target room. The configuration for the live report looks like this:

"scheduled_reports": [
  {
    "name": "managelm_daily",
    "enabled": true,
    "room": "#managelm:matrix.safehomelan.com",
    "time": "07:00",
    "timezone": "Europe/London",
    "model": "anthropic/claude-sonnet-4.6",
    "prompt": "..."
  }
]

Because a Matrix room’s configured alias and its internal room ID are different things, and room_send needs the internal ID, the bot now also records the ID returned when it joins each configured channel at startup, so the scheduler can resolve #managelm:matrix.safehomelan.com to the actual !opaque-id:matrix.safehomelan.com it needs to send to. Deploying a change to the prompt or schedule only touches this JSON file, which is bind-mounted into the container, so it just needs a restart:

docker compose restart infinigpt

A code change to the scheduler mechanism itself, on the other hand, needs a rebuild, since it is baked in at image build time by the patch script mentioned earlier:

docker compose build infinigpt
docker compose up -d infinigpt

What the report actually contains

The report has five fixed sections, in this order. It opens with an “At a glance” summary of the most urgent items across all four sources. Section one is Compliance, covering ManageLM’s security audit findings, certificate and PKI state, credentials, sudo rules and SSH keys, enriched with PatchMon’s per-host pending-update counts and Pi-hole’s active admin sessions. Section two is Monitoring, covering ManageLM’s monitor and backup status, enriched with Netdata’s active alerts and node health and Pi-hole’s own system health. Section three is Audit Logs, covering ManageLM’s activity search for failed logins, elevated commands and file changes over the last twenty-four hours, enriched with Pi-hole’s session and blocked-query data for the same window. Section four is anything else of interest: offline or unhealthy agents and recent task history from ManageLM, stuck or failed patch runs from PatchMon, and any standout anomaly from Netdata. Section five, always last, is Remediation Suggestions: one concrete fix per finding raised earlier, expressed either as an exact shell command, as the specific ManageLM skill and operation that would resolve it, or as the specific read-only-safe tool call that would help diagnose it further, always tied to the exact host, user or certificate named earlier in the report rather than generic advice.

An anonymised example

The following is illustrative, built from the same structure the live report produces, with all identifying detail replaced.

At a glance: one certificate expires within seven days on app-01, and PatchMon
shows the same host is thirty-four packages behind on security updates.
Netdata confirms app-01 has been running above ninety per cent memory for the
last six hours.

1. Compliance
- TLS certificate for app-01.internal expires in 6 days (search_certificates).
  PatchMon: app-01 has 34 pending updates, 12 marked security (list_hosts,
  get_host_stats) - the same host is behind on patching as well as certs.
- No unresolved sudo-rule or SSH-key findings.

2. Monitoring
- Backup job "nightly-db" on db-02 failed last night (search_backups).
  Netdata confirms db-02 raised a CRITICAL disk-space alert four hours before
  the backup window (list_raised_alerts).
- Pi-hole (pihole-01) system health nominal: 18% CPU, 41% memory.

3. Audit Logs
- Three failed SSH logins for user svc-deploy on app-01 in the last 24h
  (search_activity). Pi-hole shows no unusual blocked-query spike from
  app-01's IP in the same window, which suggests this is not DNS-based
  scanning traffic.

4. Anything else of interest
- Agent edge-fw has not checked in for 9 hours (search_agents).
  get_agent_queue on PatchMon shows a patch run for edge-fw stuck in
  "queued" for the same period, consistent with the agent being offline
  rather than the job itself failing.

5. Remediation Suggestions
- app-01 certificate: run `certbot renew --cert-name app-01.internal`, or
  ManageLM certificates -> renew on app-01.
- app-01 patch backlog: ManageLM packages -> update on app-01, or PatchMon ->
  trigger_patch (dry run first) on app-01.
- db-02 backup failure: check disk space before re-running the backup job;
  ManageLM storage -> overview on db-02 to confirm space has been freed.
- edge-fw offline: check power/network for edge-fw directly; once it is back,
  re-queue the stuck PatchMon run rather than waiting for the next cycle.

Summary

ManageLM’s free tier, ten agents, unlimited monitors, certificates and credentials, a thousand requests a day and no expiry, is more than sufficient to run a single daily correlated report against a small fleet. Its MCP server is reached here through a small bespoke stdio proxy rather than the stock mcp-remote path, which keeps the auth and session handling simple and headless. InfiniGPT already had everything needed to consume that server, since MCP tool calling was a first-class feature, so the actual new work was a scheduler: a background task per configured report that fires at a set local time, runs the bot’s existing tool-calling loop with a purpose-built prompt, and posts the result into Matrix. Extending that prompt to also pull from Netdata, PatchMon and Pi-hole turned a single-source status dump into something closer to a real correlated incident report, at the cost of a longer run (around four minutes rather than two) and a firm rule that the automated run may only read data, never act on it. Claude Sonnet via OpenRouter does the actual synthesis, chosen specifically because holding twenty-plus tool results in context and writing a coherent, cross-referenced report is a heavier task than the bot’s everyday chat model needs to handle. The whole thing is configuration and a small amount of Python: one JSON block for the schedule and prompt, one module for the timing logic, and a handful of patch functions wiring it into the bot’s existing startup and shutdown path.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *