Run PromQL queries, inspect alert state, and troubleshoot OAuth2 or OIDC client-credentials access to Prometheus-compatible APIs.
94
94%
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Passed
No known issues
Use this file for exact CLI syntax, expected payloads, and error handling.
These conventions apply to all bundled scripts:
--help is available and preferred over guessing flags.{"error": "...", "error_code": "..."}scripts/prom_query.pyTop-level help:
python3 scripts/prom_query.py -hconfigpython3 scripts/prom_query.py configReturns configuration validation and redacted values.
Success example:
{
"cache": {...},
"errors": [],
"optional_env": {...},
"required_env": {...},
"resolved_config": {...},
"valid": true
}Typical validation failure (valid: false) includes all issues in errors and exits non-zero.
querypython3 scripts/prom_query.py query --expr 'up'Output:
{
"auth_source": "cache|token_endpoint",
"query": "up",
"response": {"status": "success", "data": {...}}
}alertspython3 scripts/prom_query.py alerts --state pendingBehavior: emits the same structure as query and adds state.
Generated expression is ALERTS{alertstate="<state>"}.
tokenpython3 scripts/prom_query.py token
python3 scripts/prom_query.py token --refreshReturns metadata for cached/fresh token source.
{
"cache_path": ".../token-cache.json",
"expires_at": 1234567890,
"expires_in_seconds": 3600,
"scope": "read",
"source": "cache",
"token_type": "Bearer"
}scripts/check_config.pyValidate local config and emit the same validation payload shape as
prom_query.py config.
python3 scripts/check_config.pyOn invalid timeout format it returns:
{
"error": "PROM_QUERY_TIMEOUT must be a number",
"error_code": "INVALID_TIMEOUT"
}scripts/smoke_test.shRun local unit tests plus a live end-to-end smoke pass against the configured Prometheus and token endpoints.
./scripts/smoke_test.shRequired environment variables are the same as prom_query.py:
PROM_QUERY_PROMETHEUS_URLPROM_QUERY_TOKEN_URLPROM_QUERY_CLIENT_IDPROM_QUERY_CLIENT_SECRETThe script runs, in order:
python3 -m unittest -v tests/test_prom_query.pypython3 scripts/check_config.pypython3 scripts/prom_query.py configpython3 scripts/prom_query.py token --refreshpython3 scripts/prom_query.py tokenpython3 scripts/prom_query.py query --expr 'up'python3 scripts/prom_query.py alerts --state firingpython3 scripts/prom_query.py alerts --state pendingpython3 scripts/prom_query.py alerts --state inactiveINVALID_TIMEOUTINVALID_CONFIGTOKEN_REQUEST_FAILEDPROMETHEUS_REQUEST_FAILEDTOKEN_RESPONSE_INVALIDINVALID_JSON_RESPONSEINVALID_COMMANDSCRIPT_ERRORscript errors are in the form { "error": "...", "error_code": "..." }.