feat(admin): JSON query API beyond bulk export (P2-04 / 26.14)#17
Merged
Conversation
Adds /api/v1/hosts (filterable + paginated) and /api/v1/hosts/{ip}
alongside the existing /export.json bulk endpoint. Operators piping
inventory into a CMDB / ticketing webhook / monitoring stack no
longer have to download the full snapshot and grep.
GET /api/v1/hosts query params (all optional, AND together):
vendor — exact match
device_type — exact match
hostname — case-insensitive substring
subnet — CIDR membership
port — integer; host must have that TCP port open
limit — page size (default 100, max 1000)
offset — zero-based
Response envelope keeps `total` as the pre-pagination count so
consumers can drive their own page-cursor UI.
GET /api/v1/hosts/{ip} returns {host, ports[]} in one round-trip so
clients don't need a second request for the ports table.
Errors are JSON {"error": "..."} with proper 4xx/5xx codes. 13 new
tests covering every filter dimension, combined filters, pagination
edges (incl. offset past total), invalid input → 400, unknown host
→ 404.
internal/admin/api.go is separated from the HTML-template handlers
in handlers.go so the two concerns can evolve independently.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds `GET /api/v1/hosts` (filterable + paginated) and `GET /api/v1/hosts/{ip}` alongside the existing `/export.json` bulk endpoint. Downstream consumers (CMDB ingest, ticketing webhooks, monitoring) no longer have to pull the whole inventory and grep.
```bash
every linux host on 10.0.0.0/24 with SSH open
curl 'http://localhost:9090/api/v1/hosts?subnet=10.0.0.0/24&device_type=linux-host&port=22'
all printers, page 2
curl 'http://localhost:9090/api/v1/hosts?device_type=printer&limit=50&offset=50'
single host detail with its ports
curl 'http://localhost:9090/api/v1/hosts/10.0.0.42'
```
Filter dimensions (all optional, AND together)
Test plan
🤖 Generated with Claude Code