|
|
||
|---|---|---|
| .. | ||
| src/wfagent_backend | ||
| tests | ||
| README.md | ||
| ZABBIX_SETUP.md | ||
| pyproject.toml | ||
| wfagent_backend.example.yaml | ||
| wfagent_backend_architecture.md | ||
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
src/wfagent_backend/cli.py- CLI entry point and config bootstrapsrc/wfagent_backend/server.py- HTTP server and routingsrc/wfagent_backend/config.py- YAML config parsing and validation
Ingest pipeline
src/wfagent_backend/app.py- request normalization, client metadata, stdout batch loggingsrc/wfagent_backend/contracts.py- canonical ingest and delivery modelssrc/wfagent_backend/mapping.py- event-to-metric matching and metric intent creationsrc/wfagent_backend/queue.py- in-memory queueing, TTL, retry coordinationsrc/wfagent_backend/sender.py-zabbix_senderadapter
What to look at first
app.pyfor request normalization,clientinjection, and batch stdout logging.contracts.pyforDeliveryBatch,DeliveryItem,NormalizedEvent,MetricIntent, andClientInfo.mapping.pyfor dotted-path matching such astarget.kindandtarget.value.server.pyfor HTTP path handling and request timing.
Tests
tests/test_backend.py- ingest contract, stdout logging, and mapping behavior
Architecture
Request flow
HTTP ingest -> request normalization -> queue -> mapper -> sender
The backend is intentionally isolated from the agent project:
- agent code lives in
../agent/src/wfagent - backend code lives in
backend/src/wfagent_backend - the two projects can be installed and deployed independently
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 pointconfig.py- YAML configuration loader and validationserver.py- HTTP server and routingapp.py- ingest normalization and dispatch to the queuequeue.py- in-memory batch queue with retry semanticsmapping.py- event-to-metric mappingsender.py- adapter forzabbix_sendercontracts.py- ingest and delivery data contracts
Configuration
Use wfagent_backend.example.yaml as the starting point.
Main sections
server- HTTP listener settingsagent- agent identity defaults used when the request omits themlogging- structured batch logging to stdoutqueue- in-memory queue sizing and retry policyzabbix- sender command and network settingsmapping- 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
targetobject withkindandvalue data_kindto distinguish payload semantics fromevent_kindpayloadas the raw normalized event payload
Each item includes:
item_idsource_typesource_idevent_kindobserved_at_unix_mspayload
Accepted responses also include a server-observed client object with:
ip_addressremote_portreceived_at_unix_ms
The batch stdout record mirrors this structure:
- top-level
client batch.items[]- no duplicated
target_kind/target_valuealiases - no duplicated
clientinside 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
- Create a virtual environment.
- Install the backend in editable mode.
- Start the server with a config file.
- Point the agent delivery URL at
http://127.0.0.1:8080/api/v1/ingest.
Production deployment
- Bind the backend to a private interface or localhost.
- Place it behind a reverse proxy if you need TLS or authentication.
- Keep
zabbix_senderand network access available on the backend host. - 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