API接口说明
本章节介绍智能运维模块提供的RESTful API接口。
API: /v1/api/app/intelligent-interaction
功能描述:通过交互的方式使用运维工具。
请求方式:POST
参数及其解释:如下表所示:
表 1 接口参数说明
交互类型,可选范围为['tool_interaction', 'fault_diagnostic']。
| |||
返回结果类型:流式event
测试接口样例1:
curl -X 'POST' 'https://x.x.x.x:x/v1/api/app/intelligent-interaction' -H 'accept: application/json' -H 'Content-Type: application/json' -d '{
"query":"数据库test_db中有条sql语句select* from t1 where id = 10000;请帮我进行一下索引推荐",
"mode":"tool_interaction",
"user_id":"user123",
"session_id":"session123",
"history_len":1
}' --cacert /path/xxx.crt --key /path/xxx.key --cert /path/xxx.crt --pass "***"
参考返回结果格式:
data:{"data":[{"content":"工具匹配中...","type":"progress"}],"success":true}\n\n
data:{"data":[{"content":"提取参数中...","type":"progress"}],"success":true}\n\n
data:{"data":[{"content":"工具调用中...","type":"progress"}],"success":true}\n\n
data:{"data":[{"color":"black","content":"推荐的索引如下表所示:","type":"str"},{"content":{"headers":["索引描述","预计占用","预计提升"],"rows":[["CREATEINDEX idx_t1_id ON public.t1(id);","2.49MB","99.91%"]]},"type":"table"}],"success":true}\n\n
data:{"data":[{"content":"DONE","type":"progress"}],"success":true}\n\n
测试接口样例2(query参数值可通过工具交互的告警查询结果获取):
curl -X 'POST' 'https://x.x.x.x:x/v1/api/app/intelligent-interaction' -H 'accept: application/json' -H 'Content-Type: application/json' -d '{
"query":"{\"history_alarm_id\": \"c_190471\", \"metric_name\": \"gaussdb_cluster_state\", \"instance\": \"10.90.56.xx\", \"alarm_type\": \"ALARM\", \"alarm_level\": 20, \"start_time\": \"2024-09-05 15:28:56\", \"alarm_content\": \"10.90.56.xx(dn ): {\\\"ping\\\": 0, \\\"dn_status\\\": 1, \\\"bind_ip_failed\\\": 0, \\\"dn_ping_standby\\\": 0, \\\"ffic_updated\\\": 0, \\\"cms_phonydead_restart\\\": 0, \\\"cms_restart_pending\\\": 0, \\\"dn_read_only\\\": 0, \\\"dn_manual_stop\\\": 0, \\\"dn_disk_damage\\\": 0, \\\"dn_nic_down\\\": 0, \\\"dn_port_conflict\\\": 0, \\\"dn_writable\\\": 0} Unknown\", \"source\": \"dbmind\", \"status\": 0}",
"mode":"fault_diagnostic",
"model_name":"pangu",
"user_id":"user123",
"session_id":"session123"
}' --cacert /path/xxx.crt --key /path/xxx.key --cert /path/xxx.crt --pass "***"
参考返回结果格式:
data:{"data":[{"content":"查询故障树...","type":"progress"}],"success":true}
data:{"data":[{"content":"异常告警信息识别中...","type":"progress"}],"success":true}
data:{"data":[{"content":"参数识别中...","type":"progress"}],"success":true}
data:{"data":[{"color":"black","content":"'cluster_feature'","type":"str"}],"success":true}
data:{"data":[{"content":"DONE","type":"progress"}], "success": true}
异常情况:
data:{"data":[{"content":"工具执行异常","type":"str"}],"success":true}\n\n
data:{"data":[{"content":"大模型服务异常","type":"str"}],"success":true}\n\n
data:{"data":[{"content":"运维知识库异常","type":"str"}],"success":true}\n\n
API: /v1/api/llms
功能描述:获取所有可用的大语言模型列表。
请求方式:GET
参数及其解释:无
测试接口样例:
curl -X 'GET' 'https://x.x.x.x:x/v1/api/llms' -H 'accept: application/json' -H 'Content-Type: application/json' --cacert /path/xxx.crt --key /path/xxx.key --cert /path/xxx.crt --pass "***"
参考返回结果格式:
获取成功1:
{"data":{"local":[],"online":["pangu_cloud_sigma_unify_plugin_38b","Llama3-8B-Chinese-Chat"]},"success":true}
获取成功2:
{"data":true,"success":true}
API: /v1/api/llms
功能描述:切换大模型。
请求方式:PUT
参数及其解释:如下表所示:
表 2 接口参数说明
测试接口样例:
curl -X 'PUT' 'https://x.x.x.x:x/v1/api/llms?name=pangu&user_id=xxx&session_id=xxx' -H 'accept: application/json' -H 'Content-Type: application/json' --cacert /path/xxx.crt --key /path/xxx.key --cert /path/xxx.crt --pass "***"
参考返回结果格式:
切换成功:
{"data":true,"success":true}
切换失败1(模型切换失败的详细原因记录在日志中):
{"data":false,"success":true}
切换失败2:
{"msg":"Internal server error.","success":false}
API: /v1/api/clusters
功能描述:获取DBMind纳管的所有数据库集群信息。
请求方式:GET
参数及其解释:无
测试接口样例:
curl -X 'GET' 'https://x.x.x.x:x/v1/api/clusters' -H 'accept: application/json' -H 'Content-Type: application/json' --cacert /path/xxx.crt --key /path/xxx.key --cert /path/xxx.crt --pass "***"
参考返回结果格式:
获取成功1:
{"data":{"x.x.x.x:x":{"cluster_name":"cluster1","intances":["x.x.x.x:x","x.x.x.x:x"],"managed":true},"x.x.x.x:x":{"cluster_name":"cluster2","intances":["x.x.x.x:x","x.x.x.x:x"],"managed":false}},"success":true}
获取成功2:
{"data":{},"success":true}
获取失败:
{"msg":"Internal server error.","success":false}
API: /v1/api/clusters
功能描述:切换当前监控的数据库集群
请求方式:PUT
参数及其解释:如下表所示:
表 3 接口参数说明
测试接口样例:
curl -X 'PUT' 'https://x.x.x.x:x/v1/api/clusters?instance=x.x.x.x:x&user_id=xxx&session_id=xxx' -H 'accept: application/json' -H 'Content-Type: application/json' --cacert /path/xxx.crt --key /path/xxx.key --cert /path/xxx.crt --pass "***"
参考返回结果格式:
切换成功:
{"data":true,"success":true}
切换失败1:
{"data":false,"success":true}
切换失败2:
{"msg":"Internal server error.","success":false}
API: /v1/api/clusters/register
功能描述:注册dbmind纳管范围的数据库集群。
请求方式:POST
参数及其解释:如下表所示:
表 4 接口参数说明
测试接口样例:
curl -X 'POST' 'https://x.x.x.x:x/v1/api/clusters/register' -H 'accept: application/json' -H 'Content-Type: application/json' -d '{ "cluster_name": "cluster1", "host": "db_host_ip", "port": "5432", "username": "db_user", "password": "db_password"}' --cacert /path/xxx.crt --key /path/xxx.key --cert /path/xxx.crt --pass "***"
参考返回结果格式
注册成功:
{"data":{"msg":"注册成功","status":0},"success":true}
注册集群的账号密码错误:
{"data":{"msg":"无法连接到此集群","status":503},"success":true}
注册集群不在dbmind纳管范围:
{"data":{"msg":"dbmind没有纳管此集群,无法注册","status":1001},"success":true}
注册集群的名字重复:
{"data":{"msg":"该集群名已被占用","status":1002},"success":true}
说明: 注册成功后,集群信息存储在集群管理表,表接口参考附录中表6。
意见反馈