KosmoKrator

monitoring

Datadog Lua API for KosmoKrator Agents

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

10 functions 6 read 4 write API key auth

Lua Namespace

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

Datadog — Lua API Reference

list_monitors

List Datadog monitors with optional filtering.

Parameters

NameTypeRequiredDescription
namestringnoFilter monitors by name (substring match)
tagsstringnoComma-separated tags (e.g., "env:production,service:api")
pageintegernoPage number for pagination (default: 0)
page_sizeintegernoResults per page (default: 30)

Example

local result = app.integrations.datadog.list_monitors({
  tags = "env:production"
})

for _, monitor in ipairs(result) do
  print(monitor.id .. ": " .. monitor.name .. " [" .. monitor.overall_state .. "]")
end

get_monitor

Get full details of a specific monitor.

Parameters

NameTypeRequiredDescription
monitor_idintegeryesThe monitor ID

Example

local result = app.integrations.datadog.get_monitor({
  monitor_id = 12345
})

print("Name: " .. result.name)
print("Query: " .. result.query)
print("State: " .. result.overall_state)

create_monitor

Create a new Datadog monitor.

Parameters

NameTypeRequiredDescription
typestringyesMonitor type: "metric alert", "service check", "event alert", "query alert", "composite", "log alert", "rum alert"
querystringyesMonitor query (e.g., "avg(last_5m):avg:system.cpu.user{host:my-host} > 90")
namestringnoDisplay name
messagestringnoNotification message (supports @mention syntax)
priorityintegernoPriority level (1-5, where 1 is highest)
optionsobjectnoJSON-encoded options: thresholds, notify_no_data, no_data_timeframe, etc.
tagsarraynoTags (e.g., {"env:production", "service:api"})

Monitor Options (JSON)

Common options for metric alert thresholds:

{
  "thresholds": {
    "critical": 90,
    "warning": 80,
    "critical_recovery": 85,
    "warning_recovery": 75
  },
  "notify_no_data": true,
  "no_data_timeframe": 10,
  "renotify_interval": 60
}

Example

local result = app.integrations.datadog.create_monitor({
  type = "metric alert",
  query = "avg(last_5m):avg:system.cpu.user{env:production} > 90",
  name = "High CPU on Production",
  message = "CPU is above 90% on {{host.name}} @slack-alerts",
  priority = 2,
  options = '{"thresholds":{"critical":90,"warning":80},"notify_no_data":true}',
  tags = {"env:production", "team:infra"}
})

print("Created monitor ID: " .. result.id)

update_monitor

Update an existing monitor.

Parameters

NameTypeRequiredDescription
monitor_idintegeryesThe monitor ID
typestringnoUpdated monitor type
querystringnoUpdated query
namestringnoUpdated name
messagestringnoUpdated message
priorityintegernoUpdated priority
optionsobjectnoUpdated options (JSON)
tagsarraynoUpdated tags

Example

local result = app.integrations.datadog.update_monitor({
  monitor_id = 12345,
  query = "avg(last_5m):avg:system.cpu.user{env:production} > 95",
  message = "CPU critical! @pagerduty-production"
})

print("Updated monitor: " .. result.name)

delete_monitor

Delete a monitor permanently.

Parameters

NameTypeRequiredDescription
monitor_idintegeryesThe monitor ID to delete

Example

local result = app.integrations.datadog.delete_monitor({
  monitor_id = 12345
})

print(result)  -- "Monitor 12345 has been deleted."

query_metrics

Query Datadog metrics for a given time range.

Parameters

NameTypeRequiredDescription
fromintegeryesStart time as Unix timestamp (seconds)
tointegeryesEnd time as Unix timestamp (seconds)
querystringyesDatadog metric query string

Query Syntax

aggregation:metric.name{filter} by {grouping}
  • Aggregation: avg, max, min, sum, count
  • Filter: tag-based (e.g., {env:production,service:api})
  • Grouping: by {host}, by {region}, etc.

Example

local result = app.integrations.datadog.query_metrics({
  from = os.time() - 3600,  -- 1 hour ago
  to = os.time(),            -- now
  query = "avg:system.cpu.user{env:production} by {host}"
})

if result.series then
  for _, series in ipairs(result.series) do
    print("Host: " .. (series.scope or "unknown"))
    print("  Points: " .. #series.pointlist)
  end
end

list_dashboards

List all Datadog dashboards.

Parameters

None.

Example

local result = app.integrations.datadog.list_dashboards({})

for _, dashboard in ipairs(result.dashboards or {}) do
  print(dashboard.id .. ": " .. dashboard.title)
end

get_dashboard

Get full details of a specific dashboard.

Parameters

NameTypeRequiredDescription
dashboard_idstringyesThe dashboard ID

Example

local result = app.integrations.datadog.get_dashboard({
  dashboard_id = "abc-123-def"
})

print("Title: " .. result.title)
print("Widgets: " .. #(result.widgets or {}))

for _, widget in ipairs(result.widgets or {}) do
  print("  - " .. (widget.definition.title or "Untitled"))
end

post_event

Post an event to the Datadog event stream.

Parameters

NameTypeRequiredDescription
titlestringyesEvent title
textstringyesEvent body (supports Markdown)
prioritystringno"normal" or "low" (default: "normal")
tagsarraynoTags (e.g., {"env:production"})
alert_typestringno"info", "warning", "error", or "success" (default: "info")
date_happenedintegernoUnix timestamp (default: now)
source_type_namestringnoSource type (e.g., "my_app")
hoststringnoAssociated host name
aggregation_keystringnoKey to group related events

Example

local result = app.integrations.datadog.post_event({
  title = "Deployment completed",
  text = "Version 2.1.0 deployed to production successfully.",
  priority = "normal",
  tags = {"env:production", "source:deploy"},
  alert_type = "success"
})

print("Event URL: " .. (result.url or "created"))

get_current_user

Get the currently authenticated Datadog user.

Parameters

None.

Example

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

print("User: " .. (result.handle or "unknown"))
print("Name: " .. (result.name or "unknown"))
print("Email: " .. (result.email or "unknown"))

Multi-Account Usage

If you have multiple Datadog accounts configured, use account-specific namespaces:

-- Default account (always works)
app.integrations.datadog.list_monitors({})

-- Explicit default (portable across setups)
app.integrations.datadog.default.list_monitors({})

-- Named accounts
app.integrations.datadog.production.list_monitors({})
app.integrations.datadog.staging.list_monitors({})

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


Common Patterns

Check for alerting monitors

local monitors = app.integrations.datadog.list_monitors({
  tags = "env:production"
})

local alerting = {}
for _, m in ipairs(monitors) do
  if m.overall_state == "Alert" then
    table.insert(alerting, m)
  end
end

if #alerting > 0 then
  print(#alerting .. " monitors are alerting!")
  for _, m in ipairs(alerting) do
    print("  - " .. m.name)
  end
else
  print("All monitors OK")
end

Query CPU and post event if high

local result = app.integrations.datadog.query_metrics({
  from = os.time() - 300,
  to = os.time(),
  query = "avg:system.cpu.user{env:production}"
})

if result.series and #result.series > 0 then
  local last_point = result.series[1].pointlist[#result.series[1].pointlist]
  if last_point and last_point[2] > 80 then
    app.integrations.datadog.post_event({
      title = "High CPU Alert",
      text = "CPU is at " .. last_point[2] .. "%",
      alert_type = "warning",
      tags = {"env:production", "severity:high"}
    })
  end
end
Raw agent markdown
# Datadog — Lua API Reference

## list_monitors

List Datadog monitors with optional filtering.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `name` | string | no | Filter monitors by name (substring match) |
| `tags` | string | no | Comma-separated tags (e.g., `"env:production,service:api"`) |
| `page` | integer | no | Page number for pagination (default: 0) |
| `page_size` | integer | no | Results per page (default: 30) |

### Example

```lua
local result = app.integrations.datadog.list_monitors({
  tags = "env:production"
})

for _, monitor in ipairs(result) do
  print(monitor.id .. ": " .. monitor.name .. " [" .. monitor.overall_state .. "]")
end
```

---

## get_monitor

Get full details of a specific monitor.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `monitor_id` | integer | yes | The monitor ID |

### Example

```lua
local result = app.integrations.datadog.get_monitor({
  monitor_id = 12345
})

print("Name: " .. result.name)
print("Query: " .. result.query)
print("State: " .. result.overall_state)
```

---

## create_monitor

Create a new Datadog monitor.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `type` | string | yes | Monitor type: `"metric alert"`, `"service check"`, `"event alert"`, `"query alert"`, `"composite"`, `"log alert"`, `"rum alert"` |
| `query` | string | yes | Monitor query (e.g., `"avg(last_5m):avg:system.cpu.user{host:my-host} > 90"`) |
| `name` | string | no | Display name |
| `message` | string | no | Notification message (supports `@mention` syntax) |
| `priority` | integer | no | Priority level (1-5, where 1 is highest) |
| `options` | object | no | JSON-encoded options: thresholds, notify_no_data, no_data_timeframe, etc. |
| `tags` | array | no | Tags (e.g., `{"env:production", "service:api"}`) |

### Monitor Options (JSON)

Common options for metric alert thresholds:

```json
{
  "thresholds": {
    "critical": 90,
    "warning": 80,
    "critical_recovery": 85,
    "warning_recovery": 75
  },
  "notify_no_data": true,
  "no_data_timeframe": 10,
  "renotify_interval": 60
}
```

### Example

```lua
local result = app.integrations.datadog.create_monitor({
  type = "metric alert",
  query = "avg(last_5m):avg:system.cpu.user{env:production} > 90",
  name = "High CPU on Production",
  message = "CPU is above 90% on {{host.name}} @slack-alerts",
  priority = 2,
  options = '{"thresholds":{"critical":90,"warning":80},"notify_no_data":true}',
  tags = {"env:production", "team:infra"}
})

print("Created monitor ID: " .. result.id)
```

---

## update_monitor

Update an existing monitor.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `monitor_id` | integer | yes | The monitor ID |
| `type` | string | no | Updated monitor type |
| `query` | string | no | Updated query |
| `name` | string | no | Updated name |
| `message` | string | no | Updated message |
| `priority` | integer | no | Updated priority |
| `options` | object | no | Updated options (JSON) |
| `tags` | array | no | Updated tags |

### Example

```lua
local result = app.integrations.datadog.update_monitor({
  monitor_id = 12345,
  query = "avg(last_5m):avg:system.cpu.user{env:production} > 95",
  message = "CPU critical! @pagerduty-production"
})

print("Updated monitor: " .. result.name)
```

---

## delete_monitor

Delete a monitor permanently.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `monitor_id` | integer | yes | The monitor ID to delete |

### Example

```lua
local result = app.integrations.datadog.delete_monitor({
  monitor_id = 12345
})

print(result)  -- "Monitor 12345 has been deleted."
```

---

## query_metrics

Query Datadog metrics for a given time range.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `from` | integer | yes | Start time as Unix timestamp (seconds) |
| `to` | integer | yes | End time as Unix timestamp (seconds) |
| `query` | string | yes | Datadog metric query string |

### Query Syntax

```
aggregation:metric.name{filter} by {grouping}
```

- **Aggregation**: `avg`, `max`, `min`, `sum`, `count`
- **Filter**: tag-based (e.g., `{env:production,service:api}`)
- **Grouping**: `by {host}`, `by {region}`, etc.

### Example

```lua
local result = app.integrations.datadog.query_metrics({
  from = os.time() - 3600,  -- 1 hour ago
  to = os.time(),            -- now
  query = "avg:system.cpu.user{env:production} by {host}"
})

if result.series then
  for _, series in ipairs(result.series) do
    print("Host: " .. (series.scope or "unknown"))
    print("  Points: " .. #series.pointlist)
  end
end
```

---

## list_dashboards

List all Datadog dashboards.

### Parameters

None.

### Example

```lua
local result = app.integrations.datadog.list_dashboards({})

for _, dashboard in ipairs(result.dashboards or {}) do
  print(dashboard.id .. ": " .. dashboard.title)
end
```

---

## get_dashboard

Get full details of a specific dashboard.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `dashboard_id` | string | yes | The dashboard ID |

### Example

```lua
local result = app.integrations.datadog.get_dashboard({
  dashboard_id = "abc-123-def"
})

print("Title: " .. result.title)
print("Widgets: " .. #(result.widgets or {}))

for _, widget in ipairs(result.widgets or {}) do
  print("  - " .. (widget.definition.title or "Untitled"))
end
```

---

## post_event

Post an event to the Datadog event stream.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `title` | string | yes | Event title |
| `text` | string | yes | Event body (supports Markdown) |
| `priority` | string | no | `"normal"` or `"low"` (default: `"normal"`) |
| `tags` | array | no | Tags (e.g., `{"env:production"}`) |
| `alert_type` | string | no | `"info"`, `"warning"`, `"error"`, or `"success"` (default: `"info"`) |
| `date_happened` | integer | no | Unix timestamp (default: now) |
| `source_type_name` | string | no | Source type (e.g., `"my_app"`) |
| `host` | string | no | Associated host name |
| `aggregation_key` | string | no | Key to group related events |

### Example

```lua
local result = app.integrations.datadog.post_event({
  title = "Deployment completed",
  text = "Version 2.1.0 deployed to production successfully.",
  priority = "normal",
  tags = {"env:production", "source:deploy"},
  alert_type = "success"
})

print("Event URL: " .. (result.url or "created"))
```

---

## get_current_user

Get the currently authenticated Datadog user.

### Parameters

None.

### Example

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

print("User: " .. (result.handle or "unknown"))
print("Name: " .. (result.name or "unknown"))
print("Email: " .. (result.email or "unknown"))
```

---

## Multi-Account Usage

If you have multiple Datadog accounts configured, use account-specific namespaces:

```lua
-- Default account (always works)
app.integrations.datadog.list_monitors({})

-- Explicit default (portable across setups)
app.integrations.datadog.default.list_monitors({})

-- Named accounts
app.integrations.datadog.production.list_monitors({})
app.integrations.datadog.staging.list_monitors({})
```

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

---

## Common Patterns

### Check for alerting monitors

```lua
local monitors = app.integrations.datadog.list_monitors({
  tags = "env:production"
})

local alerting = {}
for _, m in ipairs(monitors) do
  if m.overall_state == "Alert" then
    table.insert(alerting, m)
  end
end

if #alerting > 0 then
  print(#alerting .. " monitors are alerting!")
  for _, m in ipairs(alerting) do
    print("  - " .. m.name)
  end
else
  print("All monitors OK")
end
```

### Query CPU and post event if high

```lua
local result = app.integrations.datadog.query_metrics({
  from = os.time() - 300,
  to = os.time(),
  query = "avg:system.cpu.user{env:production}"
})

if result.series and #result.series > 0 then
  local last_point = result.series[1].pointlist[#result.series[1].pointlist]
  if last_point and last_point[2] > 80 then
    app.integrations.datadog.post_event({
      title = "High CPU Alert",
      text = "CPU is at " .. last_point[2] .. "%",
      alert_type = "warning",
      tags = {"env:production", "severity:high"}
    })
  end
end
```

Metadata-Derived Lua Example

local result = app.integrations.datadog.datadog_list_monitors({
  name = "example_name",
  tags = "example_tags",
  page = 1,
  page_size = 1
})
print(result)

Functions

datadog_list_monitors

List Datadog monitors. Optionally filter by name or tags. Returns monitor IDs, names, types, states, and query definitions.

Operation
Read read
Full name
datadog.datadog_list_monitors
ParameterTypeRequiredDescription
name string no Filter monitors by name (substring match).
tags string no Comma-separated list of tags to filter by (e.g., "env:production,service:api").
page integer no Page number for pagination (default: 0).
page_size integer no Number of monitors per page (default: 30).

datadog_get_monitor

Get full details of a specific Datadog monitor by ID. Returns the monitor query, thresholds, message, and current state.

Operation
Read read
Full name
datadog.datadog_get_monitor
ParameterTypeRequiredDescription
monitor_id integer yes The ID of the monitor to retrieve.

datadog_create_monitor

Create a new Datadog monitor. Specify the monitor type, query, name, and optional message and thresholds. Common types: "metric alert", "service check", "event alert".

Operation
Write write
Full name
datadog.datadog_create_monitor
ParameterTypeRequiredDescription
type string yes Monitor type: "metric alert", "service check", "event alert", "query alert", "composite", "log alert", "rum alert", etc.
query string yes The monitor query (e.g., "avg(last_5m):avg:system.cpu.user{host:my-host} > 90").
name string no Display name for the monitor.
message string no Notification message. Supports @mention syntax (e.g., "@slack-my-channel").
priority integer no Monitor priority level (1-5, where 1 is highest).
options object no JSON-encoded monitor options: thresholds, notify_no_data, no_data_timeframe, renotify_interval, escalation_message, etc.
tags array no List of tags to assign to the monitor (e.g., ["env:production", "service:api"]).

datadog_update_monitor

Update an existing Datadog monitor. Provide the monitor ID and the fields to update (name, query, message, options, tags, etc.).

Operation
Write write
Full name
datadog.datadog_update_monitor
ParameterTypeRequiredDescription
monitor_id integer yes The ID of the monitor to update.
type string no Updated monitor type.
query string no Updated monitor query.
name string no Updated display name.
message string no Updated notification message.
priority integer no Updated priority level (1-5).
options object no JSON-encoded monitor options (thresholds, notify_no_data, etc.).
tags array no Updated list of tags.

datadog_delete_monitor

Delete a Datadog monitor by ID. This action is permanent and cannot be undone.

Operation
Write write
Full name
datadog.datadog_delete_monitor
ParameterTypeRequiredDescription
monitor_id integer yes The ID of the monitor to delete.

datadog_query_metrics

Query Datadog metrics between two timestamps. Use Datadog query syntax (e.g., "avg:system.cpu.user{env:production} by {host}"). Returns time series data points.

Operation
Read read
Full name
datadog.datadog_query_metrics
ParameterTypeRequiredDescription
from integer yes Start time as Unix timestamp in seconds (e.g., 1710000000). Use current time minus seconds for relative ranges.
to integer yes End time as Unix timestamp in seconds. Use current time for "now".
query string yes Datadog metric query string (e.g., "avg:system.cpu.user{env:production} by {host}").

datadog_list_dashboards

List all Datadog dashboards. Returns dashboard IDs, titles, descriptions, and modification dates.

Operation
Read read
Full name
datadog.datadog_list_dashboards
ParameterTypeRequiredDescription
No parameters.

datadog_get_dashboard

Get full details of a specific Datadog dashboard by ID. Returns the dashboard layout, widgets, and template variables.

Operation
Read read
Full name
datadog.datadog_get_dashboard
ParameterTypeRequiredDescription
dashboard_id string yes The ID of the dashboard to retrieve.

datadog_post_event

Post an event to the Datadog event stream. Specify title, text, priority, tags, and alert type. Events appear in the event timeline.

Operation
Write write
Full name
datadog.datadog_post_event
ParameterTypeRequiredDescription
title string yes Event title.
text string yes Event body text. Supports Markdown.
priority string no Event priority: "normal" or "low". Defaults to "normal".
tags array no List of tags for the event (e.g., ["env:production", "service:api"]).
alert_type string no Alert type: "info", "warning", "error", or "success". Defaults to "info".
date_happened integer no Unix timestamp for when the event occurred. Defaults to now.
source_type_name string no Source type name (e.g., "my_app").
host string no Host name to associate with the event.
aggregation_key string no Key to group related events together.

datadog_get_current_user

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

Operation
Read read
Full name
datadog.datadog_get_current_user
ParameterTypeRequiredDescription
No parameters.