rb-wf-ag/backend
Ilgiz Kamelyev afd6e85d47 поясняющий файл с описанием последовательности действий в Zabbix для настройки hosts агентов, шаблонов, триггеров, items.. 2026-05-05 12:40:30 +05:00
..
src/wfagent_backend в backend каноническим полем остался только target. В выходной сериализации убраны плоские алиасы target_kind и target_value 2026-05-05 09:31:41 +05:00
tests в backend каноническим полем остался только target. В выходной сериализации убраны плоские алиасы target_kind и target_value 2026-05-05 09:31:41 +05:00
README.md поясняющий файл с описанием последовательности действий в Zabbix для настройки hosts агентов, шаблонов, триггеров, items.. 2026-05-05 12:40:30 +05:00
ZABBIX_SETUP.md поясняющий файл с описанием последовательности действий в Zabbix для настройки hosts агентов, шаблонов, триггеров, items.. 2026-05-05 12:40:30 +05:00
pyproject.toml Проект разделён по каталогам agent и backend. Поддержка legacy messages удалена 2026-05-04 10:31:02 +05:00
wfagent_backend.example.yaml поясняющий файл с описанием последовательности действий в Zabbix для настройки hosts агентов, шаблонов, триггеров, items.. 2026-05-05 12:40:30 +05:00
wfagent_backend_architecture.md в backend каноническим полем остался только target. В выходной сериализации убраны плоские алиасы target_kind и target_value 2026-05-05 09:31:41 +05:00

README.md

Wi-Fi Agents Backend

This project is the delivery backend for wfagent.

It receives webhook deliveries from the agent, normalizes them, queues them for retry, and maps payload fields to downstream metric definitions.

Code Navigation

Main entry points

Ingest pipeline

What to look at first

  • app.py for request normalization, client injection, and batch stdout logging.
  • contracts.py for DeliveryBatch, DeliveryItem, NormalizedEvent, MetricIntent, and ClientInfo.
  • mapping.py for dotted-path matching such as target.kind and target.value.
  • server.py for HTTP path handling and request timing.

Tests

Architecture

Request flow

HTTP ingest -> request normalization -> queue -> mapper -> sender

The backend is intentionally isolated from the agent project:

Responsibilities

  • accept webhook POST requests
  • validate payload structure
  • support canonical items[] payloads
  • preserve queue state until delivery succeeds or TTL expires
  • map selected fields to metric samples
  • send metrics through zabbix_sender

Components

Located in backend/src/wfagent_backend:

  • cli.py - command line entry point
  • config.py - YAML configuration loader and validation
  • server.py - HTTP server and routing
  • app.py - ingest normalization and dispatch to the queue
  • queue.py - in-memory batch queue with retry semantics
  • mapping.py - event-to-metric mapping
  • sender.py - adapter for zabbix_sender
  • contracts.py - ingest and delivery data contracts

Configuration

Use wfagent_backend.example.yaml as the starting point.

Main sections

  • server - HTTP listener settings
  • agent - agent identity defaults used when the request omits them
  • logging - structured batch logging to stdout
  • queue - in-memory queue sizing and retry policy
  • zabbix - sender command and network settings
  • mapping - metric rules and field extraction paths

Ingest API

The backend exposes:

POST /api/v1/ingest
GET  /healthz

Canonical request shape

The webhook contract is a batch envelope with items[]. The client does not send server-side metadata; the backend adds client itself to the response and to internal normalized records. The backend writes one NDJSON record per accepted request batch, even when the batch contains only one item.

The canonical item shape uses:

  • a target object with kind and value
  • data_kind to distinguish payload semantics from event_kind
  • payload as the raw normalized event payload

Each item includes:

  • item_id
  • source_type
  • source_id
  • event_kind
  • observed_at_unix_ms
  • payload

Accepted responses also include a server-observed client object with:

  • ip_address
  • remote_port
  • received_at_unix_ms

The batch stdout record mirrors this structure:

  • top-level client
  • batch.items[]
  • no duplicated target_kind / target_value aliases
  • no duplicated client inside the item payload

Install

From the backend directory:

python -m pip install -e .

Run

wfagent_backend --config wfagent_backend.example.yaml

Optional host and port overrides:

wfagent_backend --config wfagent_backend.example.yaml --host 127.0.0.1 --port 8080

Deployment

Local deployment

  1. Create a virtual environment.
  2. Install the backend in editable mode.
  3. Start the server with a config file.
  4. Point the agent delivery URL at http://127.0.0.1:8080/api/v1/ingest.

Production deployment

  1. Bind the backend to a private interface or localhost.
  2. Place it behind a reverse proxy if you need TLS or authentication.
  3. Keep zabbix_sender and network access available on the backend host.
  4. Increase queue capacity if delivery latency is expected.

Example

The included wfagent_backend.example.yaml shows a minimal setup with:

  • HTTP listener on port 8080
  • ingest path /api/v1/ingest
  • health path /healthz
  • one mapping rule for BSS signal metrics

For a step-by-step Zabbix host/template/item/trigger setup, see ZABBIX_SETUP.md.

Testing

Run the backend tests from the repository root:

pytest backend/tests