Skip to main content

HTTP/REST API collector for DetectK

Project description

DetectK HTTP Collector

HTTP/REST API collector for DetectK with support for various response formats and authentication methods.

Installation

pip install detectk-collectors-http

Features

  • Response Formats: JSON, plain text, CSV
  • Authentication: API key, Bearer token, Basic Auth, custom headers
  • Flexible Value Extraction: JSONPath, regex, direct value
  • Error Handling: Retry logic, timeout configuration
  • HTTP Methods: GET, POST
  • SSL Verification: Configurable

Usage

JSON API (JSONPath extraction)

name: "prometheus_metric"
description: "Collect metric from Prometheus API"

collector:
  type: "http"
  params:
    url: "http://prometheus:9090/api/v1/query"
    method: "GET"
    params:
      query: "up{job='api'}"
    response_format: "json"
    value_path: "data.result[0].value[1]"  # JSONPath
    timeout: 10

detector:
  type: "threshold"
  params:
    threshold: 0.5
    operator: "less_than"

Plain Text Response

collector:
  type: "http"
  params:
    url: "http://api.example.com/metrics/count"
    response_format: "text"
    # Response is direct numeric value

With Authentication

collector:
  type: "http"
  params:
    url: "https://api.example.com/metrics"
    headers:
      Authorization: "Bearer ${API_TOKEN}"
    response_format: "json"
    value_path: "metrics.active_users"

POST Request

collector:
  type: "http"
  params:
    url: "https://api.example.com/query"
    method: "POST"
    json:
      query: "SELECT COUNT(*) FROM events"
      time_range: "1h"
    headers:
      X-API-Key: "${API_KEY}"
    response_format: "json"
    value_path: "result.count"

Configuration

Required Parameters

  • url: API endpoint URL
  • response_format: Response format ("json", "text", "csv")
  • value_path: Path to extract value (for JSON/CSV)

Optional Parameters

  • method: HTTP method (default: "GET")
  • headers: Custom HTTP headers
  • params: Query parameters (GET)
  • json: JSON body (POST)
  • data: Form data (POST)
  • timeout: Request timeout in seconds (default: 30)
  • verify_ssl: Verify SSL certificates (default: True)
  • retry_count: Number of retries (default: 3)
  • retry_delay: Delay between retries in seconds (default: 1)

Authentication Examples

API Key (Header):

headers:
  X-API-Key: "${API_KEY}"

Bearer Token:

headers:
  Authorization: "Bearer ${TOKEN}"

Basic Auth:

headers:
  Authorization: "Basic ${BASE64_CREDENTIALS}"

JSONPath Syntax

Use dot notation and array indexing:

  • data.value - Simple path
  • data.result[0].value - Array indexing
  • metrics.active_users - Nested objects

Examples

See examples/http/ directory for complete configurations:

  • Prometheus query
  • Grafana API
  • Custom REST API
  • Health check endpoint

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

detectk_collectors_http-0.1.0.tar.gz (8.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

detectk_collectors_http-0.1.0-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file detectk_collectors_http-0.1.0.tar.gz.

File metadata

  • Download URL: detectk_collectors_http-0.1.0.tar.gz
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for detectk_collectors_http-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f8b61593dfecb3d4d452af442e9f5a3626000b120c325b0b1456974ffcf77e43
MD5 ae6add84e98f9ee34cff8afa5e869baa
BLAKE2b-256 d26d05be627b2f4850ed21ca7bc4fb79782b85778f25bebad835788f6aa797e7

See more details on using hashes here.

File details

Details for the file detectk_collectors_http-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for detectk_collectors_http-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 499a83fe33675ee4f93380a0310a9b31a2d43f0e0f7de833911a9eb408b0a031
MD5 50b2fff106d07f3968b5cb90796b7788
BLAKE2b-256 6b281fa06682ee501ae7441870a88d1e671a9e6588afa1340871af7ecfdd5b6f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page