openclaw-grafana-lens
Version:
OpenClaw plugin that gives AI agents full Grafana access — 18 composable tools for PromQL/LogQL/TraceQL queries, dashboard creation, alerting, SRE investigation, security monitoring, data collection pipeline management via Grafana Alloy (29 recipes), and
105 lines (104 loc) • 3.36 kB
TypeScript
/**
* grafana_create_alert tool
*
* Creates Grafana-native alert rules via the Unified Alerting provisioning API.
* The agent composes PromQL conditions — Grafana's alerting engine evaluates
* them on schedule and notifies via configured contact points.
*
* Auto-creates a "Grafana Lens Alerts" folder if no folderUid is specified.
*
* Before creating the rule, the expression is dry-run against the datasource
* to validate it. The result is included as `metricValidation` in the response.
* The alert is always created regardless — the metric may not have data yet.
*/
import { GrafanaClientRegistry } from "../grafana-client-registry.js";
/** Metric validation result from dry-running the expression before alert creation. */
export type MetricValidation = {
valid: boolean;
error?: string;
sampleValue?: number;
};
/** Valid evaluation modes for alert expressions. */
export type EvaluationMode = "instant" | "rate" | "increase";
/**
* Wrap a PromQL expression based on the evaluation mode.
*
* - `instant`: returns expression as-is (raw value comparison)
* - `rate`: wraps in `rate(expr[window])` — per-second rate of a counter
* - `increase`: wraps in `increase(expr[window])` — total increase over window
*/
export declare function wrapExpression(expr: string, evaluation: EvaluationMode, window: string): string;
export declare function createAlertToolFactory(registry: GrafanaClientRegistry): (_ctx: unknown) => {
name: string;
label: string;
description: string;
parameters: {
type: "object";
properties: {
title: {
type: string;
description: string;
};
datasourceUid: {
type: string;
description: string;
};
expr: {
type: string;
description: string;
};
threshold: {
type: string;
description: string;
};
evaluation: {
type: string;
enum: string[];
description: string;
};
evaluationWindow: {
type: string;
description: string;
};
condition: {
type: string;
enum: string[];
description: string;
};
for: {
type: string;
description: string;
};
folderUid: {
type: string;
description: string;
};
labels: {
type: string;
description: string;
};
annotations: {
type: string;
description: string;
};
noDataState: {
type: string;
enum: string[];
description: string;
};
execErrState: {
type: string;
enum: string[];
description: string;
};
};
required: string[];
};
execute(_toolCallId: string, params: Record<string, unknown>): Promise<{
content: Array<{
type: "text";
text: string;
}>;
details: unknown;
}>;
};