analytics
Prometheus Lua API for KosmoKrator Agents
Agent-facing Lua documentation and function reference for the Prometheus KosmoKrator integration.Lua Namespace
Agents call this integration through app.integrations.prometheus.*.
Use lua_read_doc("integrations.prometheus") inside KosmoKrator to discover the same reference at runtime.
Call Lua from the Headless CLI
Use kosmo integrations:lua when a shell script, CI job, cron job, or another coding CLI should run a deterministic
Prometheus workflow without starting an interactive agent session.
kosmo integrations:lua --eval 'dump(app.integrations.prometheus.list_alerts({filter = "example_filter", receiver = "example_receiver"}))' --json kosmo integrations:lua --eval 'print(docs.read("prometheus"))' --json
kosmo integrations:lua --eval 'print(docs.read("prometheus.list_alerts"))' --json Workflow file
Put repeatable logic in a Lua file, then execute it with JSON output for the calling process.
local prometheus = app.integrations.prometheus
local result = prometheus.list_alerts({filter = "example_filter", receiver = "example_receiver"})
dump(result) kosmo integrations:lua workflow.lua --json
kosmo integrations:lua workflow.lua --force --json integrations:lua exposes app.integrations.prometheus, app.mcp.*, docs.*, json.*, and regex.*. Use app.integrations.prometheus.default.* or app.integrations.prometheus.work.* when you configured named credential accounts.
MCP-only Lua
If the script only needs configured MCP servers and does not need Prometheus, use the narrower mcp:lua command.
# Use mcp:lua for MCP-only scripts; use integrations:lua for this integration namespace.
kosmo mcp:lua --eval 'dump(mcp.servers())' --json Agent-Facing Lua Docs
This is the rendered version of the full Lua documentation exposed to agents when they inspect the integration namespace.
Prometheus — Lua API Reference
list_alerts
List Prometheus alerts with optional filtering.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
filter | string | no | Optional label selector filter (e.g., "severity=critical") |
receiver | string | no | Filter alerts by receiver name |
Examples
-- List all alerts
local result = app.integrations.prometheus.list_alerts({})
for _, alert in ipairs(result.alerts or {}) do
print(alert.name .. " — state: " .. alert.state)
end
-- Filter by label
local result = app.integrations.prometheus.list_alerts({
filter = "severity=critical"
})
get_alert
Get a Prometheus alert by name.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
name | string | yes | The name of the alert to retrieve |
Example
local result = app.integrations.prometheus.get_alert({
name = "HighMemoryUsage"
})
print("Alert: " .. result.name)
print("State: " .. result.state)
print("Expression: " .. result.query)
list_rules
List Prometheus alerting and recording rules.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
type | string | no | Filter rules by type: "alert" or "recording" |
Examples
-- List all rules
local result = app.integrations.prometheus.list_rules({})
for _, group in ipairs(result.groups or {}) do
print("Group: " .. group.name)
for _, rule in ipairs(group.rules or {}) do
print(" Rule: " .. rule.name)
end
end
-- Filter to alerting rules only
local result = app.integrations.prometheus.list_rules({
type = "alert"
})
get_rule
Get a Prometheus rule group by name.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
name | string | yes | The name of the rule group to retrieve |
Example
local result = app.integrations.prometheus.get_rule({
name = "system-alerts"
})
print("Rule Group: " .. result.name)
for _, rule in ipairs(result.rules or {}) do
print(" Rule: " .. rule.name .. " — type: " .. rule.type)
end
list_targets
List Prometheus scrape targets.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
state | string | no | Filter targets by state: "active" or "dropped" |
Examples
-- List all targets
local result = app.integrations.prometheus.list_targets({})
for _, target in ipairs(result.activeTargets or {}) do
print(target.discoveredLabels.__address__ .. " — health: " .. target.health)
end
-- Filter to active targets only
local result = app.integrations.prometheus.list_targets({
state = "active"
})
get_target
Get a Prometheus target by its instance address.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
instance | string | yes | The target instance address (e.g., "localhost:9090") |
Example
local result = app.integrations.prometheus.get_target({
instance = "localhost:9090"
})
print("Health: " .. result.health)
print("Last Scrape: " .. result.lastScrape)
print("Scrape Duration: " .. result.scrapeDuration)
get_current_user
Get the current authenticated Prometheus user info. Useful for verifying authentication.
Parameters
None.
Example
local result = app.integrations.prometheus.get_current_user({})
print("User: " .. (result.name or result.email))
print("ID: " .. result.id)
Multi-Account Usage
If you have multiple Prometheus instances configured, use account-specific namespaces:
-- Default account (always works)
app.integrations.prometheus.list_alerts({})
-- Explicit default (portable across setups)
app.integrations.prometheus.default.list_alerts({})
-- Named accounts
app.integrations.prometheus.production.list_alerts({})
app.integrations.prometheus.staging.list_alerts({})
All functions are identical across accounts — only the credentials differ.
Raw agent markdown
# Prometheus — Lua API Reference
## list_alerts
List Prometheus alerts with optional filtering.
### Parameters
| Name | Type | Required | Description |
|------|------|----------|-------------|
| `filter` | string | no | Optional label selector filter (e.g., `"severity=critical"`) |
| `receiver` | string | no | Filter alerts by receiver name |
### Examples
```lua
-- List all alerts
local result = app.integrations.prometheus.list_alerts({})
for _, alert in ipairs(result.alerts or {}) do
print(alert.name .. " — state: " .. alert.state)
end
-- Filter by label
local result = app.integrations.prometheus.list_alerts({
filter = "severity=critical"
})
```
---
## get_alert
Get a Prometheus alert by name.
### Parameters
| Name | Type | Required | Description |
|------|------|----------|-------------|
| `name` | string | yes | The name of the alert to retrieve |
### Example
```lua
local result = app.integrations.prometheus.get_alert({
name = "HighMemoryUsage"
})
print("Alert: " .. result.name)
print("State: " .. result.state)
print("Expression: " .. result.query)
```
---
## list_rules
List Prometheus alerting and recording rules.
### Parameters
| Name | Type | Required | Description |
|------|------|----------|-------------|
| `type` | string | no | Filter rules by type: `"alert"` or `"recording"` |
### Examples
```lua
-- List all rules
local result = app.integrations.prometheus.list_rules({})
for _, group in ipairs(result.groups or {}) do
print("Group: " .. group.name)
for _, rule in ipairs(group.rules or {}) do
print(" Rule: " .. rule.name)
end
end
-- Filter to alerting rules only
local result = app.integrations.prometheus.list_rules({
type = "alert"
})
```
---
## get_rule
Get a Prometheus rule group by name.
### Parameters
| Name | Type | Required | Description |
|------|------|----------|-------------|
| `name` | string | yes | The name of the rule group to retrieve |
### Example
```lua
local result = app.integrations.prometheus.get_rule({
name = "system-alerts"
})
print("Rule Group: " .. result.name)
for _, rule in ipairs(result.rules or {}) do
print(" Rule: " .. rule.name .. " — type: " .. rule.type)
end
```
---
## list_targets
List Prometheus scrape targets.
### Parameters
| Name | Type | Required | Description |
|------|------|----------|-------------|
| `state` | string | no | Filter targets by state: `"active"` or `"dropped"` |
### Examples
```lua
-- List all targets
local result = app.integrations.prometheus.list_targets({})
for _, target in ipairs(result.activeTargets or {}) do
print(target.discoveredLabels.__address__ .. " — health: " .. target.health)
end
-- Filter to active targets only
local result = app.integrations.prometheus.list_targets({
state = "active"
})
```
---
## get_target
Get a Prometheus target by its instance address.
### Parameters
| Name | Type | Required | Description |
|------|------|----------|-------------|
| `instance` | string | yes | The target instance address (e.g., `"localhost:9090"`) |
### Example
```lua
local result = app.integrations.prometheus.get_target({
instance = "localhost:9090"
})
print("Health: " .. result.health)
print("Last Scrape: " .. result.lastScrape)
print("Scrape Duration: " .. result.scrapeDuration)
```
---
## get_current_user
Get the current authenticated Prometheus user info. Useful for verifying authentication.
### Parameters
None.
### Example
```lua
local result = app.integrations.prometheus.get_current_user({})
print("User: " .. (result.name or result.email))
print("ID: " .. result.id)
```
---
## Multi-Account Usage
If you have multiple Prometheus instances configured, use account-specific namespaces:
```lua
-- Default account (always works)
app.integrations.prometheus.list_alerts({})
-- Explicit default (portable across setups)
app.integrations.prometheus.default.list_alerts({})
-- Named accounts
app.integrations.prometheus.production.list_alerts({})
app.integrations.prometheus.staging.list_alerts({})
```
All functions are identical across accounts — only the credentials differ. local result = app.integrations.prometheus.list_alerts({filter = "example_filter", receiver = "example_receiver"})
print(result) Functions
list_alerts Read
List Prometheus alerts. Optionally filter by alert state or label selectors. Returns alert names, states, labels, and annotations.
- Lua path
app.integrations.prometheus.list_alerts- Full name
prometheus.prometheus_list_alerts
| Parameter | Type | Required | Description |
|---|---|---|---|
filter | string | no | Optional label selector filter (e.g., "severity=critical"). |
receiver | string | no | Filter alerts by receiver name. |
get_alert Read
Get a Prometheus alert by name. Returns the full alert definition including labels, annotations, and state.
- Lua path
app.integrations.prometheus.get_alert- Full name
prometheus.prometheus_get_alert
| Parameter | Type | Required | Description |
|---|---|---|---|
name | string | yes | The name of the alert to retrieve. |
list_rules Read
List Prometheus alerting and recording rules. Optionally filter by type. Returns rule groups with their rules and states.
- Lua path
app.integrations.prometheus.list_rules- Full name
prometheus.prometheus_list_rules
| Parameter | Type | Required | Description |
|---|---|---|---|
type | string | no | Filter rules by type: "alert" for alerting rules or "recording" for recording rules. |
get_rule Read
Get a Prometheus rule group by name. Returns the full rule group definition including all rules within the group.
- Lua path
app.integrations.prometheus.get_rule- Full name
prometheus.prometheus_get_rule
| Parameter | Type | Required | Description |
|---|---|---|---|
name | string | yes | The name of the rule group to retrieve. |
list_targets Read
List Prometheus scrape targets. Optionally filter by state (active or dropped). Returns target health status, labels, and scrape info.
- Lua path
app.integrations.prometheus.list_targets- Full name
prometheus.prometheus_list_targets
| Parameter | Type | Required | Description |
|---|---|---|---|
state | string | no | Filter targets by state: "active" or "dropped". |
get_target Read
Get a Prometheus target by its instance address. Returns target health, last scrape info, and discovery labels.
- Lua path
app.integrations.prometheus.get_target- Full name
prometheus.prometheus_get_target
| Parameter | Type | Required | Description |
|---|---|---|---|
instance | string | yes | The target instance address (e.g., "localhost:9090"). |
get_current_user Read
Get the current authenticated Prometheus user info. Useful for verifying authentication and retrieving user details.
- Lua path
app.integrations.prometheus.get_current_user- Full name
prometheus.prometheus_get_current_user
| Parameter | Type | Required | Description |
|---|---|---|---|
| No parameters. | |||