class GrafanaBundle:
r"""无额外依赖的 Grafana / Alertmanager 告警载荷归一化工具 bundle。"""
def register(self, registry: ToolRegistry, context: BundleContext) -> None:
registry.add(
Tool(
name="normalize_grafana_alerts",
description="把 Grafana 或 Alertmanager 告警 webhook 载荷归一化为紧凑告警事实。",
input_schema={
"type": "object",
"properties": {"payload": {"type": "object", "description": "Grafana/Alertmanager webhook JSON。"}},
"required": ["payload"],
"additionalProperties": False,
},
handler=lambda payload: normalize_grafana_alerts(payload),
)
)
registry.add(
Tool(
name="search_grafana_dashboards",
description="搜索 Grafana dashboard,用于先定位集群状态或服务状态面板。",
input_schema={
"type": "object",
"properties": {
"query": {"type": "string", "description": "Dashboard 标题关键词。"},
"limit": {"type": "integer", "description": "最多返回多少个 dashboard,默认 10。"},
},
"additionalProperties": False,
},
handler=lambda query=None, limit=10: _search_dashboards(context, query=query, limit=limit),
)
)
registry.add(
Tool(
name="get_grafana_dashboard",
description="读取 Grafana dashboard 的标题、panel 与 Prometheus 查询摘要。",
input_schema={
"type": "object",
"properties": {"uid": {"type": "string", "description": "Grafana dashboard uid。"}},
"required": ["uid"],
"additionalProperties": False,
},
handler=lambda uid: _get_dashboard(context, uid=uid),
)
)
registry.add(
Tool(
name="query_grafana_prometheus",
description="通过 Grafana 的 Prometheus datasource 执行只读 instant query。",
input_schema={
"type": "object",
"properties": {
"query": {"type": "string", "description": "PromQL instant query。"},
"datasource_uid": {"type": "string", "description": "可选 Grafana datasource uid。"},
"max_results": {"type": "integer", "description": "最多返回多少条时间序列,默认 20。"},
},
"required": ["query"],
"additionalProperties": False,
},
handler=lambda query, datasource_uid=None, max_results=20: _query_prometheus(
context, query=query, datasource_uid=datasource_uid, max_results=max_results
),
)
)