DocsAPI ReferenceDiscovery Zones & Environments API

Discovery Zones & Environments API

Manage discovery zones (/api/v1/discovery-zones/) and deployment environments (/api/v1/environments/), including discovery triggers, connection tests and bulk asset assignment.


Two Different Resources

AsPeekIt distinguishes discovery zones (where and how assets are discovered: a Kubernetes cluster, an Azure subscription, a subnet, ...) from deployment environments (the lifecycle stage an asset belongs to: production, staging, test, ...). Discovery zones live under /api/v1/discovery-zones/ and deployment environments under /api/v1/environments/.

  • /api/v1/discovery-zones/ — discovery sources, credentials, schedules and discovery triggers
  • /api/v1/environments/ — deployment environments and bulk assignment of assets to them
  • Reads are available to every authenticated user; all write operations and actions require the manager or admin role
  • List endpoints are paginated (?page=, ?page_size=, maximum page_size 1000)

List Discovery Zones

Retrieve the configured discovery zones. Supports filtering by environment_type, is_active, status and discovery_enabled, full-text search over name/identifier/description (?search=) and ordering by name, created_at, last_discovery or environment_type (?ordering=).

GET /api/v1/discovery-zones/?environment_type=kubernetes&page=1&page_size=50

curl https://idp.example.com/api/v1/discovery-zones/ \
  -H "Authorization: Bearer {access_token}"

# Response
{
  "count": 6,
  "next": null,
  "previous": null,
  "results": [
    {
      "id": 1,
      "name": "Production Kubernetes",
      "environment_type": "kubernetes",
      "environment_type_display": "Kubernetes",
      "identifier": "prod-k8s-cluster",
      "status": "active",
      "is_active": true,
      "discovery_enabled": true,
      "discovery_mode": "local",
      "last_discovery": "2025-06-01T14:03:42Z",
      "last_discovery_status": "completed",
      "asset_count": 352,
      "last_discovery_asset_count": 360
    }
  ]
}

Get Discovery Zone Detail

Retrieve every field of a single zone, including description, connection_config, settings, discovery_interval_minutes, full_discovery_interval_hours and last_discovery_message. Secret values inside connection_config (keys containing password, secret, key or token) are returned as "***MASKED***".

GET /api/v1/discovery-zones/{id}/

curl https://idp.example.com/api/v1/discovery-zones/1/ \
  -H "Authorization: Bearer {access_token}"

Create Discovery Zone

Create a zone (manager or admin). Writable fields: name, environment_type, identifier, description, connection_config, settings, discovery_enabled, discovery_interval_minutes, full_discovery_interval_hours and is_active. Field validation errors are returned as {"field": ["message"]}.

POST /api/v1/discovery-zones/

curl -X POST https://idp.example.com/api/v1/discovery-zones/ \
  -H "Authorization: Bearer {access_token}" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Staging Kubernetes",
    "environment_type": "kubernetes",
    "identifier": "staging-k8s",
    "connection_config": {
      "kubeconfig": "apiVersion: v1\nkind: Config\n...",
      "context": "staging-context"
    },
    "discovery_enabled": true,
    "discovery_interval_minutes": 30
  }'

Update Discovery Zone

Partially update a zone with PATCH (manager or admin). Updatable fields: name, description, connection_config, settings, discovery_enabled, discovery_interval_minutes, full_discovery_interval_hours, is_active and status. environment_type and identifier cannot be changed after creation.

Note: Sending a secret back unchanged as "***MASKED***" keeps the stored value, so a client can round-trip the configuration it received without knowing the secrets. Send a new value only when the secret actually changes.

PATCH /api/v1/discovery-zones/{id}/

curl -X PATCH https://idp.example.com/api/v1/discovery-zones/1/ \
  -H "Authorization: Bearer {access_token}" \
  -H "Content-Type: application/json" \
  -d '{
    "discovery_interval_minutes": 15,
    "connection_config": {
      "host": "vcenter.example.com",
      "username": "readonly@vsphere.local",
      "password": "***MASKED***"
    }
  }'

Delete Discovery Zone

Delete a zone (manager or admin). Returns 204 No Content with an empty body.

Warning: Assets previously discovered by the zone are not deleted by this call.

DELETE /api/v1/discovery-zones/{id}/

# 204 No Content

Trigger Discovery

Start a discovery run for an active zone (manager or admin). Optional body {"full_scan": true}. Local zones are queued immediately; relay-managed zones (discovery_mode "relay") get a pending job that the relay picks up on its next poll. Inactive zones answer 400 with {"error": "..."}; a zone that already has a pending or running job answers 409. Every run appears in Job History (Discovery API).

POST /api/v1/discovery-zones/{id}/trigger_discovery/

# Response (local)
{ "status": "queued", "environment": "Production Kubernetes", "job_id": "…", "task_id": "…" }

# Response (relay)
{ "status": "pending_relay", "environment": "DC1 Network", "job_id": "…", "message": "Discovery queued — the relay will pick it up on next contact." }

Test Connection

Validate the stored connection configuration without running a discovery (manager or admin). The response always contains success and a sanitized message; a missing collector for the zone type answers 400.

POST /api/v1/discovery-zones/{id}/test_connection/

# Response
{ "success": true, "environment": "Production Kubernetes", "message": "Connection successful" }

Zone Types, Statistics and Assets

Helper endpoints for building UIs and dashboards.

  • Zone types: azure, gcp, aws, vsphere, kubernetes, network, snmp, agent, digitalocean, prometheus, zabbix, tempo
# Available zone types: [{"value": "kubernetes", "label": "Kubernetes"}, ...]
GET /api/v1/discovery-zones/types/

# Statistics (accepts the same filters as the list)
GET /api/v1/discovery-zones/stats/
# { "total": 6, "by_type": [{"environment_type": "kubernetes", "count": 2}], "by_status": [{"status": "active", "count": 5}] }

# Up to 100 active assets seen by one zone (also assets merged into another zone's asset), sorted by name
GET /api/v1/discovery-zones/{id}/assets/

Connection Configuration by Type

The connection_config object varies by zone type. Typical fields:

  • kubernetes: kubeconfig (YAML string), context (optional)
  • azure: tenant_id, client_id, client_secret, subscription_id
  • gcp: project_id, credentials_json (service account key as JSON string)
  • vsphere: host (vCenter hostname), username, password, port (default 443)
  • network: targets (CIDR list or newline/comma separated string), ports, scan_type
  • snmp: targets, community (v2c) or username/auth_protocol/auth_password (v3), version, port (default 161)
  • agent: no connection_config (agents push data to the platform)
  • prometheus: url, auth_type (none, basic, bearer), username/password or bearer_token
  • zabbix: url, auth_type (password or token), username/password or api_token
  • tempo: url, auth_type, optional grafana_url, grafana_api_key, grafana_datasource_uid

Warning: connection_config holds credentials. Use read-only service accounts; secrets are never returned in clear text by the API.

Deployment Environments

Deployment environments classify assets by lifecycle stage. Fields: id, name (unique), slug (read-only, derived from name), kind (production, staging, test, demo, development, custom), description, color (e.g. #22c55e), is_active, asset_count (active assets, read-only), created_at, updated_at. Standard CRUD is available; create/update/delete require manager or admin.

GET    /api/v1/environments/
POST   /api/v1/environments/
GET    /api/v1/environments/{id}/
PATCH  /api/v1/environments/{id}/
DELETE /api/v1/environments/{id}/   # 204 No Content

curl -X POST https://idp.example.com/api/v1/environments/ \
  -H "Authorization: Bearer {access_token}" \
  -H "Content-Type: application/json" \
  -d '{ "name": "Production", "kind": "production", "color": "#ef4444" }'

Assign Assets to an Environment

Bulk-assign assets to a deployment environment (manager or admin). asset_ids is required (max 5000, unknown ids are rejected). With cascade (default true) the children of each asset (via parent) are assigned too.

POST /api/v1/environments/{id}/assign/
{ "asset_ids": [12, 13, 14], "cascade": true }

# Response
{ "environment": 3, "requested": 3, "updated": 17, "cascade": true }

Unassign Assets

Clear the deployment environment of a set of assets (manager or admin). Accepts the same payload as assign.

POST /api/v1/environments/unassign/
{ "asset_ids": [12, 13], "cascade": false }

# Response
{ "updated": 2 }