KosmoKrator

analytics

Grafana Lua API for KosmoKrator Agents

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

7 functions 6 read 1 write API token auth

Lua Namespace

Agents call this integration through app.integrations.grafana.*. Use lua_read_doc("integrations.grafana") 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.

Grafana — Lua API Reference

list_dashboards

Search and list Grafana dashboards.

Parameters

NameTypeRequiredDescription
querystringnoSearch query to filter dashboards by title
typestringnoDashboard type filter (default: "dash-db")
limitintegernoMaximum number of results (default: 100)

Examples

-- List all dashboards
local result = app.integrations.grafana.list_dashboards({})

for _, dash in ipairs(result) do
  print(dash.title .. " (uid: " .. dash.uid .. ")")
end

-- Search for specific dashboards
local result = app.integrations.grafana.list_dashboards({
  query = "infrastructure"
})

get_dashboard

Get a Grafana dashboard by its UID.

Parameters

NameTypeRequiredDescription
uidstringyesThe unique identifier (UID) of the dashboard

Example

local result = app.integrations.grafana.get_dashboard({
  uid = "abc123xyz"
})

print("Dashboard: " .. result.dashboard.title)
print("Panels: " .. #result.dashboard.panels)

create_dashboard

Create or update a Grafana dashboard.

Parameters

NameTypeRequiredDescription
dashboardobjectyesComplete dashboard JSON (must include title)
folderUidstringnoUID of the folder to place the dashboard in
overwritebooleannoOverwrite existing dashboard with same slug (default: false)

Example

local result = app.integrations.grafana.create_dashboard({
  dashboard = {
    title = "My New Dashboard",
    panels = {}
  },
  overwrite = false
})

print("Created dashboard: " .. result.url)
print("UID: " .. result.uid)

list_datasources

List all configured datasources.

Parameters

None.

Example

local result = app.integrations.grafana.list_datasources({})

for _, ds in ipairs(result) do
  print(ds.name .. " (" .. ds.type .. ") — id: " .. ds.id)
end

list_alerts

List Grafana alerts with optional filtering.

Parameters

NameTypeRequiredDescription
dashboardIdintegernoFilter alerts by dashboard ID
panelIdintegernoFilter alerts by panel ID

Example

-- List all alerts
local result = app.integrations.grafana.list_alerts({})

for _, alert in ipairs(result) do
  print(alert.name .. " — state: " .. alert.state)
end

-- Filter by dashboard
local result = app.integrations.grafana.list_alerts({
  dashboardId = 42
})

list_teams

List all Grafana teams with pagination.

Parameters

NameTypeRequiredDescription
pageintegernoPage number (default: 1)
perPageintegernoNumber of teams per page (default: 50)

Example

local result = app.integrations.grafana.list_teams({
  page = 1,
  perPage = 20
})

for _, team in ipairs(result) do
  print(team.name .. " — " .. team.memberCount .. " members")
end

get_current_user

Get the currently authenticated Grafana user. Useful for verifying credentials.

Parameters

None.

Example

local result = app.integrations.grafana.get_current_user({})

print("User: " .. result.name)
print("Login: " .. result.login)
print("Email: " .. result.email)

Multi-Account Usage

If you have multiple Grafana instances configured, use account-specific namespaces:

-- Default account (always works)
app.integrations.grafana.list_dashboards({})

-- Explicit default (portable across setups)
app.integrations.grafana.default.list_dashboards({})

-- Named accounts
app.integrations.grafana.production.list_dashboards({})
app.integrations.grafana.staging.list_dashboards({})

All functions are identical across accounts — only the credentials differ.

Raw agent markdown
# Grafana — Lua API Reference

## list_dashboards

Search and list Grafana dashboards.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `query` | string | no | Search query to filter dashboards by title |
| `type` | string | no | Dashboard type filter (default: `"dash-db"`) |
| `limit` | integer | no | Maximum number of results (default: 100) |

### Examples

```lua
-- List all dashboards
local result = app.integrations.grafana.list_dashboards({})

for _, dash in ipairs(result) do
  print(dash.title .. " (uid: " .. dash.uid .. ")")
end

-- Search for specific dashboards
local result = app.integrations.grafana.list_dashboards({
  query = "infrastructure"
})
```

---

## get_dashboard

Get a Grafana dashboard by its UID.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `uid` | string | yes | The unique identifier (UID) of the dashboard |

### Example

```lua
local result = app.integrations.grafana.get_dashboard({
  uid = "abc123xyz"
})

print("Dashboard: " .. result.dashboard.title)
print("Panels: " .. #result.dashboard.panels)
```

---

## create_dashboard

Create or update a Grafana dashboard.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `dashboard` | object | yes | Complete dashboard JSON (must include `title`) |
| `folderUid` | string | no | UID of the folder to place the dashboard in |
| `overwrite` | boolean | no | Overwrite existing dashboard with same slug (default: false) |

### Example

```lua
local result = app.integrations.grafana.create_dashboard({
  dashboard = {
    title = "My New Dashboard",
    panels = {}
  },
  overwrite = false
})

print("Created dashboard: " .. result.url)
print("UID: " .. result.uid)
```

---

## list_datasources

List all configured datasources.

### Parameters

None.

### Example

```lua
local result = app.integrations.grafana.list_datasources({})

for _, ds in ipairs(result) do
  print(ds.name .. " (" .. ds.type .. ") — id: " .. ds.id)
end
```

---

## list_alerts

List Grafana alerts with optional filtering.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `dashboardId` | integer | no | Filter alerts by dashboard ID |
| `panelId` | integer | no | Filter alerts by panel ID |

### Example

```lua
-- List all alerts
local result = app.integrations.grafana.list_alerts({})

for _, alert in ipairs(result) do
  print(alert.name .. " — state: " .. alert.state)
end

-- Filter by dashboard
local result = app.integrations.grafana.list_alerts({
  dashboardId = 42
})
```

---

## list_teams

List all Grafana teams with pagination.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `page` | integer | no | Page number (default: 1) |
| `perPage` | integer | no | Number of teams per page (default: 50) |

### Example

```lua
local result = app.integrations.grafana.list_teams({
  page = 1,
  perPage = 20
})

for _, team in ipairs(result) do
  print(team.name .. " — " .. team.memberCount .. " members")
end
```

---

## get_current_user

Get the currently authenticated Grafana user. Useful for verifying credentials.

### Parameters

None.

### Example

```lua
local result = app.integrations.grafana.get_current_user({})

print("User: " .. result.name)
print("Login: " .. result.login)
print("Email: " .. result.email)
```

---

## Multi-Account Usage

If you have multiple Grafana instances configured, use account-specific namespaces:

```lua
-- Default account (always works)
app.integrations.grafana.list_dashboards({})

-- Explicit default (portable across setups)
app.integrations.grafana.default.list_dashboards({})

-- Named accounts
app.integrations.grafana.production.list_dashboards({})
app.integrations.grafana.staging.list_dashboards({})
```

All functions are identical across accounts — only the credentials differ.

Metadata-Derived Lua Example

local result = app.integrations.grafana.grafana_list_dashboards({
  query = "example_query",
  type = "example_type",
  limit = 1
})
print(result)

Functions

grafana_list_dashboards

Search and list Grafana dashboards. Returns dashboard UIDs, titles, and folder info. Use query to filter by title.

Operation
Read read
Full name
grafana.grafana_list_dashboards
ParameterTypeRequiredDescription
query string no Search query to filter dashboards by title.
type string no Dashboard type filter. Default: "dash-db" (saved dashboards).
limit integer no Maximum number of results to return (default: 100).

grafana_get_dashboard

Get a Grafana dashboard by its UID. Returns the full dashboard definition including panels, queries, and settings.

Operation
Read read
Full name
grafana.grafana_get_dashboard
ParameterTypeRequiredDescription
uid string yes The unique identifier (UID) of the dashboard.

grafana_create_dashboard

Create or update a Grafana dashboard. Provide the full dashboard JSON with panels, queries, and settings. Set overwrite to true to update an existing dashboard.

Operation
Write write
Full name
grafana.grafana_create_dashboard
ParameterTypeRequiredDescription
dashboard object yes The complete dashboard JSON object. Must include "title" at minimum.
folderUid string no UID of the folder to place the dashboard in.
overwrite boolean no Whether to overwrite an existing dashboard with the same slug (default: false).

grafana_list_datasources

List all configured datasources in Grafana. Returns datasource IDs, names, types (e.g., Prometheus, InfluxDB), and access info.

Operation
Read read
Full name
grafana.grafana_list_datasources
ParameterTypeRequiredDescription
No parameters.

grafana_list_alerts

List Grafana alerts. Optionally filter by dashboard ID or panel ID. Returns alert states, thresholds, and conditions.

Operation
Read read
Full name
grafana.grafana_list_alerts
ParameterTypeRequiredDescription
dashboardId integer no Filter alerts by dashboard ID.
panelId integer no Filter alerts by panel ID.

grafana_list_teams

List all Grafana teams. Returns team IDs, names, emails, and member counts with pagination support.

Operation
Read read
Full name
grafana.grafana_list_teams
ParameterTypeRequiredDescription
page integer no Page number (default: 1).
perPage integer no Number of teams per page (default: 50).

grafana_get_current_user

Get the currently authenticated Grafana user. Useful for verifying credentials and identifying the connected account.

Operation
Read read
Full name
grafana.grafana_get_current_user
ParameterTypeRequiredDescription
No parameters.