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.1.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.1-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: detectk_collectors_http-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 f6ddab21a361dbb36268eb40b579e10543c63bfe6caadf9502c3a35ba1d209af
MD5 836af39929cd97e71b3c0df0fbb52437
BLAKE2b-256 fe140aebfbeb1313cf82ffa82f27189eb3f0299d536d8ff18ed5887ae1700738

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for detectk_collectors_http-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 22c243abbec9726e2ae6572a582bb225192e125cd602bde0419916829c7e347f
MD5 89bffe07931ab2570d82e10e4f3791d0
BLAKE2b-256 5d5ad56ed64a534c8c73f004f60ff3df5d711851ee72bc53291197bec04d7c28

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