Skip to content

Flow routers and SNMP

This contract covers Castles Flow 26.09.0-unified.14-inventory.1. Requests go to the HTTPS origin of your Flow installation and use its current human session. In browser code, use relative URLs with same-origin credentials. Reads need routers.read. Setting changes need routers.write, and browser writes must come from the installation’s configured origin. A missing or expired session gets 401. Insufficient permission or an untrusted origin gets 403.

Every router write also needs an authentication from the last five minutes. An older session returns 403 with reauth_required. Sign in again with the existing password or a previously registered passkey.

The examples below assume you have signed in to that installation. Router ID 42 and address 192.0.2.10 are documentation examples.

GET /api/v1/routers returns router snapshots. The existing status field reports Flow exporter activity (online, offline, or unknown) and is independent of snmp_enabled and snmp_status.

Ignored devices report status as ignored, and disabled ones as disabled. The values online, offline and unknown apply only to active, enabled devices.

snmp_status is always an object. It holds last_attempt_ts, last_success_ts, last_result, last_error, interfaces_discovered, and duration_ms. Timestamps are Unix seconds in UTC, and zero means no attempt or success was recorded. Duration is in milliseconds. An empty result means no poll has completed. A successful last poll does not guarantee the router is reachable right now. The community never appears in the snapshot.

Example request and the complete HTTP 200 response for one router. The response is a bare array, with no pagination and no outer data object.

const response = await fetch('/api/v1/routers', {
credentials: 'same-origin'
});
const contentType = response.headers.get('content-type') || '';
const result = contentType.includes('application/json')
? await response.json()
: { error: await response.text() };
if (!response.ok) throw new Error(result.error || String(response.status));
[
{
"id": 42,
"name": "Example router",
"description": "Documentation example",
"ip": "192.0.2.10",
"tags": [
"example"
],
"flow_sampling": 64,
"enabled": true,
"inventory_state": "active",
"status": "online",
"snmp_enabled": true,
"snmp_status": {
"last_success_ts": 1700000060,
"last_attempt_ts": 1700000060,
"last_result": "success",
"last_error": "",
"interfaces_discovered": 1,
"duration_ms": 25
},
"datagrams_total": 120,
"flow_samples_total": 1200,
"counter_samples_total": 0,
"datagrams_interval": 1,
"flow_samples_interval": 10,
"observed_sampling_rate": 64,
"sub_agent_id": 0,
"uptime_ms": 600000,
"first_seen": 1700000000,
"last_seen": 1700000060,
"estimated_pps": 128,
"estimated_bps": 0
}
]

id, flow_sampling, and the live counters are nonnegative integers. name, description, and ip are strings, tags is an array of strings, and enabled and snmp_enabled are booleans. Live counters are flattened into each snapshot. Fields ending in _total are cumulative counters, and _interval fields cover the current measurement interval. observed_sampling_rate is the exporter’s last sampling factor, sub_agent_id its sub-agent identifier, and uptime_ms its uptime in milliseconds. first_seen and last_seen are Unix seconds in UTC, with zero meaning no observation. estimated_pps is packets per second. estimated_bps is currently zero, so do not treat it as measured bandwidth. snmp_status.last_result is empty, success, timeout, auth_fail, or error. last_error is diagnostic text with the configured community stripped out.

GET /api/v1/routers/42 returns the router definition, SNMP settings included. A configured community shows up as ***. A missing router returns 404.

PUT /api/v1/routers/42/snmp takes a JSON settings object. Send all seven fields, because omitted fields are reset to their defaults:

  • enabled: boolean, default false. Polling also needs global SNMP, an enabled router, and a configured community.
  • version: string "2c". Any other version is rejected on save.
  • community: string. Empty or "***" keeps the stored value, and a new nonempty value replaces it. Responses mask a configured value.
  • query_ip: IP address string, or empty to use the router’s address.
  • query_port: integer from 0 to 65535. 0 selects UDP 161.
  • poll_hc_counters: boolean, default true, selects high-capacity counters.
  • poll_interval_secs: integer from 0 to 4294967295, default 30. The poller enforces a minimum interval of five seconds.

This example turns on polling with a community that is already stored:

const response = await fetch('/api/v1/routers/42/snmp', {
method: 'PUT',
credentials: 'same-origin',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
"enabled": true,
"version": "2c",
"community": "***",
"query_ip": "192.0.2.10",
"query_port": 161,
"poll_hc_counters": true,
"poll_interval_secs": 30
})
});
const contentType = response.headers.get('content-type') || '';
const result = contentType.includes('application/json')
? await response.json()
: { error: await response.text() };
if (!response.ok) throw new Error(result.error || String(response.status));

A successful save returns HTTP 200 and the saved settings, with the community masked.

{
"enabled": true,
"version": "2c",
"community": "***",
"query_ip": "192.0.2.10",
"query_port": 161,
"poll_hc_counters": true,
"poll_interval_secs": 30
}

On installations with persistent configuration storage, the save changes only SNMP settings and leaves the rest of the router’s configuration alone. Success is reported after persistence, cache reconciliation, and the agent’s reload check. A save does not test SNMP connectivity.

A 400 means unsupported settings, such as a version other than 2c. Malformed JSON or wrong field types can return 400 or 422. A missing router returns 404. A concurrent runtime mismatch returns 409. An unavailable upstream service or an invalid upstream response returns 502. Storage or runtime reconciliation failure returns 503. After any save error, reload the router before retrying. The persistent write may have gone through even if runtime reconciliation failed, and the API does not claim that such a write was rolled back.

PUT /api/v1/routers/42/interfaces creates or updates one interface entry, identified by ifindex. It needs routers.write and the same authenticated origin described above. Send all four fields. Omitted editable fields fall back to defaults instead of keeping their previous values.

Request field Type and behavior
ifindex Required integer, 0 to 4294967295. Identifies the interface within this router.
name String; defaults to an empty string.
alias String; defaults to an empty string.
classification String: external, internal, backbone, lag, or unknown; defaults to unknown.

These are the editable metadata fields. manual and if_type are response-only, so they cannot be set with this request. A successful edit sets manual to true, which protects the classification from automatic rules. Later SNMP polls can still refresh name, alias, and if_type.

Example request for an existing Ethernet interface:

const response = await fetch('/api/v1/routers/42/interfaces', {
method: 'PUT',
credentials: 'same-origin',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
ifindex: 7,
name: 'Ethernet7',
alias: 'Example uplink',
classification: 'external'
})
});
const contentType = response.headers.get('content-type') || '';
const result = contentType.includes('application/json')
? await response.json()
: { error: await response.text() };
if (!response.ok) {
throw Object.assign(new Error(result.error || String(response.status)), {
status: response.status
});
}

Complete HTTP 200 response, again with no outer data object:

{
"ifindex": 7,
"name": "Ethernet7",
"alias": "Example uplink",
"classification": "external",
"if_type": 6,
"manual": true
}

The response has exactly six fields: integer ifindex; strings name, alias, and classification, meaning the same as in the request; integer if_type from SNMP, 0 to 4294967295; and boolean manual, which is true after this operation. An existing if_type is kept. A newly created entry with no known type gets 0. Here, Ethernet type 6 is kept.

With persistent configuration storage, HTTP 200 comes after the durable write, reconciliation, and a check that the active entry matches the saved edit. Other interfaces, router settings, and SNMP credentials stay as they were. Paired traffic counter availability is checked separately.

DELETE /api/v1/routers/42/interfaces/7 removes the metadata entry for ifindex 7. It needs routers.write, runs the same session and origin checks, and takes no request body. On an existing router, deleting an entry that is already gone still succeeds. A missing router returns 404.

const response = await fetch('/api/v1/routers/42/interfaces/7', {
method: 'DELETE',
credentials: 'same-origin'
});
if (response.status !== 204) {
const contentType = response.headers.get('content-type') || '';
const result = contentType.includes('application/json')
? await response.json()
: { error: await response.text() };
throw Object.assign(new Error(result.error || String(response.status)), {
status: response.status
});
}

Success is HTTP 204 with an empty body. Do not parse it as JSON. With persistent configuration storage, success comes after the durable deletion and a check that the active metadata entry is gone. Historical counter samples stay available. SNMP polling keeps running and can rediscover the interface as an automatically classified entry.

HTTP status Meaning
400 or 422 Invalid path, malformed JSON, missing ifindex, an invalid field type, integer range, or classification.
401 Missing, expired, or revoked session.
403 Insufficient permission or an untrusted browser origin.
404 Router not found.
409 Conflicting or inconsistent interface state; the saved state could not be reconciled with the active entry.
413 The request body exceeds the accepted size limit.
415 The PUT request is missing a JSON content type.
502 A required service could not be reached, or its acknowledgement was invalid or differed from the requested edit.
503 Authentication, persistent storage, or runtime reconciliation is unavailable. The write may already have completed.
500 Internal request-processing failure.

Application write errors are a JSON object with one string field, error. Authentication and request-validation failures can come back as plain text, and the examples handle both. Do not use the diagnostic text as a stable machine-readable error code.

Example HTTP 409 response:

{
"error": "Interface settings changed during reconciliation; reload interfaces before retrying"
}

After a 409, 502, 503, or a connection failure, preserve the intended edit and read the current router definition before deciding whether to retry. A failed acknowledgement does not mean the change was rolled back. Check the saved metadata by reading interfaces from GET /api/v1/routers/42. The counter endpoint also lists observed interfaces, so its rows alone cannot confirm that metadata was deleted.

const response = await fetch('/api/v1/routers/42', {
credentials: 'same-origin'
});
const contentType = response.headers.get('content-type') || '';
const result = contentType.includes('application/json')
? await response.json()
: { error: await response.text() };
if (!response.ok) throw new Error(result.error || String(response.status));
const currentInterface = result.interfaces.find(row => row.ifindex === 7) ?? null;

Compare currentInterface with the intended metadata or deletion. If the read fails or the state is unexpected, resolve that condition before another write. The example deliberately does not retry on its own and does not resend a complete router definition.

GET /api/v1/routers/42/interfaces?lookback_seconds=300 returns interface inventory, counter rates and, when available, a Flow comparison. lookback_seconds is an optional integer from 60 to 1800, inclusive. Without it, the lookback is ten polling intervals, with the polling interval taken as at least 30 seconds and the result clamped to 300–1800 seconds. The query ends at the server’s current UTC second. The frontend offers 5, 15 and 30 minutes.

counter_source is snmp when SNMP is enabled for this router, and sflow otherwise. If SNMP fails, no other counter source takes its place. The result is the union of configured interfaces and interfaces with counter samples in the requested lookback. An empty array means neither set has an interface. A configured interface with no counters still gets a row, with unavailable rates.

Flow is matched on this router’s exporter IPv4 address, interface index and direction. Each row uses its own first and last counter timestamps. Counter rates are the cumulative difference divided by that elapsed time. Flow sums include timestamps in [window_start, window_end) and use exactly the same divisor. Sampling weight is applied once, and integer rates are rounded down. The top-level window_start and window_end give the envelope of the row intervals, not a shared measurement interval. Both are zero when no interval spans distinct timestamps.

This endpoint compares stored IPv4 Flow samples with IF-MIB counters for the whole port, and the two can cover different traffic even when the time bounds line up. The key is exporter IPv4 plus ifIndex. Separate logical observation domains that share that key are not told apart here. Confirm that this key identifies the intended interface before interpreting a ratio. A ratio other than one is not, by itself, a reason to change sampling settings.

const response = await fetch('/api/v1/routers/42/interfaces?lookback_seconds=300', {
credentials: 'same-origin'
});
const contentType = response.headers.get('content-type') || '';
const result = contentType.includes('application/json')
? await response.json()
: { error: await response.text() };
if (!response.ok) throw new Error(result.error || String(response.status));

Complete HTTP 200 collector response for one interface, with a 30-second measured interval inside the requested 5-minute lookback:

{
"router_id": 42,
"agent_ip": "192.0.2.10",
"counter_source": "snmp",
"lookback_seconds": 300,
"collection_mode": "collector",
"flow_comparison_available": true,
"flow_comparison_reason": null,
"window_start": 1700000030,
"window_end": 1700000060,
"interfaces": [
{
"ifindex": 7,
"name": "Ethernet7",
"alias": "Example uplink",
"classification": "external",
"manual": true,
"if_speed": 1000000000,
"if_status": 3,
"in_bps_snmp": 8000,
"out_bps_snmp": 16000,
"in_pps_snmp": 20,
"out_pps_snmp": 30,
"in_bps_counter": 8000,
"out_bps_counter": 16000,
"in_pps_counter": 20,
"out_pps_counter": 30,
"in_bps_flow": 4000,
"out_bps_flow": 8000,
"in_pps_flow": 10,
"out_pps_flow": 15,
"total_bps_counter": 24000,
"total_pps_counter": 50,
"total_bps_flow": 12000,
"total_pps_flow": 25,
"in_ratio": 0.5,
"out_ratio": 0.5,
"in_flow_samples": 1,
"out_flow_samples": 1,
"in_comparison_reason": null,
"out_comparison_reason": null,
"counter_source": "snmp",
"counter_status": "ok",
"counter_reset": false,
"counter_samples": 2,
"window_start": 1700000030,
"window_end": 1700000060,
"window_seconds": 30,
"last_seen": 1700000060
}
]
}

Response fields:

  • router_id is an integer and agent_ip an IPv4 string. lookback_seconds is the lookback the query actually used. collection_mode is collector or mirror. flow_comparison_available says whether this collection mode supports exporter interface comparison at all; it does not promise valid samples for every row. flow_comparison_reason is null in collector mode and mirror_port_mapping_unavailable in mirror mode.
  • Each row has integer ifindex, strings name and alias, boolean manual, and classification: external, internal, backbone, lag or unknown. if_speed is in bits per second. if_status is an integer mask, with administrative up in bit 0 and operational up in bit 1. Both are null when there are no counter observations.
  • Row window_start, window_end and last_seen are UTC Unix seconds, or null without observations. window_seconds is the positive difference between the row bounds, or null when there is no distinct pair. counter_samples counts stored observations, identical duplicate timestamps included. Contradictory values at one timestamp invalidate the interval.
  • counter_status is ok, missing, insufficient_samples, counter_reset or invalid_samples. A rate needs at least two distinct timestamps, no observed counter decrease, and no conflicting same-time observations. counter_reset is true only for the reset status. The detector catches decreases between recorded observations. It cannot see a reset and recovery that both happened between polls.
  • Fields ending in _bps_counter, _bps_snmp or _bps_flow are nonnegative integer bits per second, or null. The matching _pps_ fields are packets per second, or null. The legacy _snmp names repeat the selected counter source, even when that source is sflow. Invalid or missing counters give null counter rates. No Flow samples, or an unknown sampling weight, give null Flow rates. A measured zero stays numeric zero.
  • total_bps_counter, total_pps_counter, total_bps_flow and total_pps_flow add the In and Out values only when both are available. If a direction is missing, its Total is null. These totals are per interface, so do not add up LAG aggregates and their members as if they were independent traffic.
  • in_flow_samples and out_flow_samples count Flow records in that row’s interval and direction. In mirror mode, zero means no per-port Flow query ran. in_ratio and out_ratio are Flow bps divided by counter bps, or null when comparison is unavailable or the counter rate is zero. A null ratio must not be displayed as zero.

in_comparison_reason and out_comparison_reason are null when the ratio is available. Otherwise they take one of these values:

  • mirror_port_mapping_unavailable: ordinary mirror copies lack verified original port and direction mapping.
  • counter_missing: no counter observations in the lookback.
  • counter_insufficient_samples: no pair of distinct counter timestamps.
  • counter_reset: a cumulative counter decreased within the recorded interval.
  • counter_invalid_samples: conflicting counter observations share a timestamp.
  • no_flow_samples: no Flow records for this interface, direction and interval.
  • sampling_unknown: at least one matching Flow record has an unknown or invalid sampling weight.
  • zero_counter_rate: the measured counter rate is zero, so the ratio is undefined. Valid Flow and counter rates are still available.

Ordinary SPAN does not preserve the original switch port or direction. That is why, in mirror mode, the backend runs no per-port Flow query and returns null Flow rates and ratios. SNMP In, Out and Total are still independent switch-counter measurements. An RX-only mirror establishes neither mirrored Out nor a complete bidirectional Flow Total. Changing a sampling multiplier cannot recover missing direction or port information.

Complete HTTP 200 mirror response for a configured interface with no counter observations:

{
"router_id": 42,
"agent_ip": "192.0.2.10",
"counter_source": "snmp",
"lookback_seconds": 300,
"collection_mode": "mirror",
"flow_comparison_available": false,
"flow_comparison_reason": "mirror_port_mapping_unavailable",
"window_start": 0,
"window_end": 0,
"interfaces": [
{
"ifindex": 7,
"name": "Ethernet7",
"alias": "Example uplink",
"classification": "external",
"manual": true,
"if_speed": null,
"if_status": null,
"in_bps_snmp": null,
"out_bps_snmp": null,
"in_pps_snmp": null,
"out_pps_snmp": null,
"in_bps_counter": null,
"out_bps_counter": null,
"in_pps_counter": null,
"out_pps_counter": null,
"in_bps_flow": null,
"out_bps_flow": null,
"in_pps_flow": null,
"out_pps_flow": null,
"total_bps_counter": null,
"total_pps_counter": null,
"total_bps_flow": null,
"total_pps_flow": null,
"in_ratio": null,
"out_ratio": null,
"in_flow_samples": 0,
"out_flow_samples": 0,
"in_comparison_reason": "mirror_port_mapping_unavailable",
"out_comparison_reason": "mirror_port_mapping_unavailable",
"counter_source": "snmp",
"counter_status": "missing",
"counter_reset": false,
"counter_samples": 0,
"window_start": null,
"window_end": null,
"window_seconds": null,
"last_seen": null
}
]
}

The combined counter and Flow request has a ten-second server budget. A timeout returns 504 with a JSON error. A query or result failure returns 502, unconfigured statistics storage returns 503, and a missing router returns 404. An invalid lookback_seconds returns 400: a value outside 60–1800, a malformed integer, or a duplicate. Query extraction errors can have a text body, so do not assume every error is JSON. Authentication and permissions are unchanged.

Complete HTTP 400 response for an out-of-range integer:

{
"error": "lookback_seconds must be an integer from 60 to 1800"
}

Complete HTTP 504 response:

{
"error": "Interface statistics request timed out; retry when ClickHouse is available"
}

The application version endpoint keeps its own build metadata and caps the optional storage-version lookup at two seconds.

POST /api/v1/routers/actions changes 1 to 128 selected devices atomically in persistent storage. It needs routers.write and a session authenticated within the last five minutes, which an ordinary password login or an optional registered passkey can provide. Each target must include its current positive integer id and exporter ip. IDs and IP addresses must all be distinct. Unknown fields and actions are rejected. The endpoint requires the persistent configuration service.

Router definitions and list snapshots include inventory_state, which is active or ignored for records visible through the API. The list does include ignored devices. The web interface hides them by default and offers an Ignored filter. Deleted devices return 404 on the ordinary detail endpoint and drop out of the list. A minimal internal address record stays behind to prevent automatic rediscovery.

  • enable: sets enabled=true and inventory_state=active.
  • disable: sets enabled=false and keeps inventory_state. An active device stays in the main list, and an ignored device stays ignored.
  • ignore: sets inventory_state=ignored, keeping the settings and the previous enabled value.
  • restore: sets inventory_state=active and keeps the previous enabled value, so a device that was disabled stays disabled.
  • delete: removes the device configuration and suppresses automatic rediscovery for that address. Adding the address again explicitly creates a new configuration.

In collector mode, disabled, ignored and deleted exporter addresses stop feeding new sFlow, NetFlow v9 and IPFIX records into storage and live detection. sFlow uses the embedded agent address. NetFlow and IPFIX use the UDP source address. Scheduled SNMP polling stops too. Records that were already accepted, and historical data, stay where they are, so historical time windows can still contain that device’s traffic. In mirror mode, a router inventory entry does not identify the original SPAN source, so this action does not remove that switch’s copies from the shared mirror capture.

const response = await fetch('/api/v1/routers/actions', {
method: 'POST',
credentials: 'same-origin',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
action: 'ignore',
targets: [{ id: 42, ip: '192.0.2.10' }]
})
});
const contentType = response.headers.get('content-type') || '';
const result = contentType.includes('application/json')
? await response.json()
: { error: await response.text() };
if (!response.ok) throw new Error(result.error || String(response.status));

A successful call returns HTTP 200, and only after every selected device has been saved, published and verified in runtime.

{
"action": "ignore",
"devices": [
{
"id": 42,
"ip": "192.0.2.10",
"enabled": true,
"inventory_state": "ignored"
}
]
}

Empty selections, more than 128 targets, and duplicate identities return 400. Invalid JSON types or unknown enum values may return 400 or 422. A missing device or a changed id/IP pair returns 409, and none of the batch is applied. Missing authentication returns 401. Insufficient permissions, an untrusted browser origin, or an expired recent-authentication window return 403. Storage or runtime publication errors return 503, and upstream transport failures may return 502 or 504. A request that failed or timed out may still have committed the change, so reload the device list before retrying. Operations are audited without credentials. The existing single-device DELETE requests use the same deletion semantics.

A manual POST /api/v1/routers/42/snmp/test also returns 409 while the device is ignored or disabled. Restore it and enable collection before running a test.

A 409 can also come back after persistence, if runtime verification finds a mismatch. Read the list again. A 409 on its own does not prove the change was rolled back.