KosmoKrator

analytics

Prometheus Lua API for KosmoKrator Agents

Agent-facing Lua documentation and function reference for the Prometheus KosmoKrator integration.

7 functions 7 read 0 write API token auth

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.

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

NameTypeRequiredDescription
filterstringnoOptional label selector filter (e.g., "severity=critical")
receiverstringnoFilter 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

NameTypeRequiredDescription
namestringyesThe 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

NameTypeRequiredDescription
typestringnoFilter 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

NameTypeRequiredDescription
namestringyesThe 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

NameTypeRequiredDescription
statestringnoFilter 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

NameTypeRequiredDescription
instancestringyesThe 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.

Metadata-Derived Lua Example

local result = app.integrations.prometheus.prometheus_list_alerts({
  filter = "example_filter",
  receiver = "example_receiver"
})
print(result)

Functions

prometheus_list_alerts

List Prometheus alerts. Optionally filter by alert state or label selectors. Returns alert names, states, labels, and annotations.

Operation
Read read
Full name
prometheus.prometheus_list_alerts
ParameterTypeRequiredDescription
filter string no Optional label selector filter (e.g., "severity=critical").
receiver string no Filter alerts by receiver name.

prometheus_get_alert

Get a Prometheus alert by name. Returns the full alert definition including labels, annotations, and state.

Operation
Read read
Full name
prometheus.prometheus_get_alert
ParameterTypeRequiredDescription
name string yes The name of the alert to retrieve.

prometheus_list_rules

List Prometheus alerting and recording rules. Optionally filter by type. Returns rule groups with their rules and states.

Operation
Read read
Full name
prometheus.prometheus_list_rules
ParameterTypeRequiredDescription
type string no Filter rules by type: "alert" for alerting rules or "recording" for recording rules.

prometheus_get_rule

Get a Prometheus rule group by name. Returns the full rule group definition including all rules within the group.

Operation
Read read
Full name
prometheus.prometheus_get_rule
ParameterTypeRequiredDescription
name string yes The name of the rule group to retrieve.

prometheus_list_targets

List Prometheus scrape targets. Optionally filter by state (active or dropped). Returns target health status, labels, and scrape info.

Operation
Read read
Full name
prometheus.prometheus_list_targets
ParameterTypeRequiredDescription
state string no Filter targets by state: "active" or "dropped".

prometheus_get_target

Get a Prometheus target by its instance address. Returns target health, last scrape info, and discovery labels.

Operation
Read read
Full name
prometheus.prometheus_get_target
ParameterTypeRequiredDescription
instance string yes The target instance address (e.g., "localhost:9090").

prometheus_get_current_user

Get the current authenticated Prometheus user info. Useful for verifying authentication and retrieving user details.

Operation
Read read
Full name
prometheus.prometheus_get_current_user
ParameterTypeRequiredDescription
No parameters.