更新数据源
curl --request POST \
--url 'https://api.flashcat.cloud/monit/datasource/update?app_key=' \
--header 'Content-Type: application/json' \
--data '
{
"id": 10,
"type_ident": "prometheus",
"name": "Prometheus Prod v2",
"note": "Updated",
"address": "http://prometheus-v2.example.com:9090",
"edge_cluster_name": "default",
"payload": {
"prometheus": {
"basic_auth_enabled": false
}
}
}
'import requests
url = "https://api.flashcat.cloud/monit/datasource/update?app_key="
payload = {
"id": 10,
"type_ident": "prometheus",
"name": "Prometheus Prod v2",
"note": "Updated",
"address": "http://prometheus-v2.example.com:9090",
"edge_cluster_name": "default",
"payload": { "prometheus": { "basic_auth_enabled": False } }
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
id: 10,
type_ident: 'prometheus',
name: 'Prometheus Prod v2',
note: 'Updated',
address: 'http://prometheus-v2.example.com:9090',
edge_cluster_name: 'default',
payload: {prometheus: {basic_auth_enabled: false}}
})
};
fetch('https://api.flashcat.cloud/monit/datasource/update?app_key=', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.flashcat.cloud/monit/datasource/update?app_key=",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'id' => 10,
'type_ident' => 'prometheus',
'name' => 'Prometheus Prod v2',
'note' => 'Updated',
'address' => 'http://prometheus-v2.example.com:9090',
'edge_cluster_name' => 'default',
'payload' => [
'prometheus' => [
'basic_auth_enabled' => false
]
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.flashcat.cloud/monit/datasource/update?app_key="
payload := strings.NewReader("{\n \"id\": 10,\n \"type_ident\": \"prometheus\",\n \"name\": \"Prometheus Prod v2\",\n \"note\": \"Updated\",\n \"address\": \"http://prometheus-v2.example.com:9090\",\n \"edge_cluster_name\": \"default\",\n \"payload\": {\n \"prometheus\": {\n \"basic_auth_enabled\": false\n }\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.flashcat.cloud/monit/datasource/update?app_key=")
.header("Content-Type", "application/json")
.body("{\n \"id\": 10,\n \"type_ident\": \"prometheus\",\n \"name\": \"Prometheus Prod v2\",\n \"note\": \"Updated\",\n \"address\": \"http://prometheus-v2.example.com:9090\",\n \"edge_cluster_name\": \"default\",\n \"payload\": {\n \"prometheus\": {\n \"basic_auth_enabled\": false\n }\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.flashcat.cloud/monit/datasource/update?app_key=")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"id\": 10,\n \"type_ident\": \"prometheus\",\n \"name\": \"Prometheus Prod v2\",\n \"note\": \"Updated\",\n \"address\": \"http://prometheus-v2.example.com:9090\",\n \"edge_cluster_name\": \"default\",\n \"payload\": {\n \"prometheus\": {\n \"basic_auth_enabled\": false\n }\n }\n}"
response = http.request(request)
puts response.read_body{
"request_id": "01HK8XQE3Z7JM2NTFQ5YJ8P9R4",
"data": {
"id": 10,
"account_id": 10023,
"type_ident": "prometheus",
"name": "Prometheus Prod v2",
"enabled": true,
"note": "Updated",
"address": "http://prometheus-v2.example.com:9090",
"payload": {
"prometheus": {
"basic_auth_enabled": false,
"basic_auth_username": "",
"basic_auth_password": "",
"tls_skip_verify": false
}
},
"edge_cluster_name": "default",
"updated_at": 1712100000,
"alerting_enabled": true,
"manage_team_id": null,
"readonly_team_ids": null,
"creator_id": 20001
}
}{
"request_id": "01HK8XQE3Z7JM2NTFQ5YJ8P9R4",
"error": {
"code": "InvalidParameter",
"message": "The specified parameter is not valid."
}
}{
"request_id": "01HK8XQE3Z7JM2NTFQ5YJ8P9R4",
"error": {
"code": "Unauthorized",
"message": "You are unauthorized."
}
}{
"request_id": "01HK8XQE3Z7JM2NTFQ5YJ8P9R4",
"error": {
"code": "AccessDenied",
"message": "Access Denied."
}
}{
"request_id": "01HK8XQE3Z7JM2NTFQ5YJ8P9R4",
"error": {
"code": "RequestTooFrequently",
"message": "Request too frequently."
}
}{
"request_id": "01HK8XQE3Z7JM2NTFQ5YJ8P9R4",
"error": {
"code": "InternalError",
"message": "We encountered an internal error, and it has been reported. Please try again later."
}
}告警数据源
更新数据源
按 ID 更新数据源,整体替换其名称、备注、地址、payload 和 edge 集群。
POST
/
monit
/
datasource
/
update
更新数据源
curl --request POST \
--url 'https://api.flashcat.cloud/monit/datasource/update?app_key=' \
--header 'Content-Type: application/json' \
--data '
{
"id": 10,
"type_ident": "prometheus",
"name": "Prometheus Prod v2",
"note": "Updated",
"address": "http://prometheus-v2.example.com:9090",
"edge_cluster_name": "default",
"payload": {
"prometheus": {
"basic_auth_enabled": false
}
}
}
'import requests
url = "https://api.flashcat.cloud/monit/datasource/update?app_key="
payload = {
"id": 10,
"type_ident": "prometheus",
"name": "Prometheus Prod v2",
"note": "Updated",
"address": "http://prometheus-v2.example.com:9090",
"edge_cluster_name": "default",
"payload": { "prometheus": { "basic_auth_enabled": False } }
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
id: 10,
type_ident: 'prometheus',
name: 'Prometheus Prod v2',
note: 'Updated',
address: 'http://prometheus-v2.example.com:9090',
edge_cluster_name: 'default',
payload: {prometheus: {basic_auth_enabled: false}}
})
};
fetch('https://api.flashcat.cloud/monit/datasource/update?app_key=', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.flashcat.cloud/monit/datasource/update?app_key=",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'id' => 10,
'type_ident' => 'prometheus',
'name' => 'Prometheus Prod v2',
'note' => 'Updated',
'address' => 'http://prometheus-v2.example.com:9090',
'edge_cluster_name' => 'default',
'payload' => [
'prometheus' => [
'basic_auth_enabled' => false
]
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.flashcat.cloud/monit/datasource/update?app_key="
payload := strings.NewReader("{\n \"id\": 10,\n \"type_ident\": \"prometheus\",\n \"name\": \"Prometheus Prod v2\",\n \"note\": \"Updated\",\n \"address\": \"http://prometheus-v2.example.com:9090\",\n \"edge_cluster_name\": \"default\",\n \"payload\": {\n \"prometheus\": {\n \"basic_auth_enabled\": false\n }\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.flashcat.cloud/monit/datasource/update?app_key=")
.header("Content-Type", "application/json")
.body("{\n \"id\": 10,\n \"type_ident\": \"prometheus\",\n \"name\": \"Prometheus Prod v2\",\n \"note\": \"Updated\",\n \"address\": \"http://prometheus-v2.example.com:9090\",\n \"edge_cluster_name\": \"default\",\n \"payload\": {\n \"prometheus\": {\n \"basic_auth_enabled\": false\n }\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.flashcat.cloud/monit/datasource/update?app_key=")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"id\": 10,\n \"type_ident\": \"prometheus\",\n \"name\": \"Prometheus Prod v2\",\n \"note\": \"Updated\",\n \"address\": \"http://prometheus-v2.example.com:9090\",\n \"edge_cluster_name\": \"default\",\n \"payload\": {\n \"prometheus\": {\n \"basic_auth_enabled\": false\n }\n }\n}"
response = http.request(request)
puts response.read_body{
"request_id": "01HK8XQE3Z7JM2NTFQ5YJ8P9R4",
"data": {
"id": 10,
"account_id": 10023,
"type_ident": "prometheus",
"name": "Prometheus Prod v2",
"enabled": true,
"note": "Updated",
"address": "http://prometheus-v2.example.com:9090",
"payload": {
"prometheus": {
"basic_auth_enabled": false,
"basic_auth_username": "",
"basic_auth_password": "",
"tls_skip_verify": false
}
},
"edge_cluster_name": "default",
"updated_at": 1712100000,
"alerting_enabled": true,
"manage_team_id": null,
"readonly_team_ids": null,
"creator_id": 20001
}
}{
"request_id": "01HK8XQE3Z7JM2NTFQ5YJ8P9R4",
"error": {
"code": "InvalidParameter",
"message": "The specified parameter is not valid."
}
}{
"request_id": "01HK8XQE3Z7JM2NTFQ5YJ8P9R4",
"error": {
"code": "Unauthorized",
"message": "You are unauthorized."
}
}{
"request_id": "01HK8XQE3Z7JM2NTFQ5YJ8P9R4",
"error": {
"code": "AccessDenied",
"message": "Access Denied."
}
}{
"request_id": "01HK8XQE3Z7JM2NTFQ5YJ8P9R4",
"error": {
"code": "RequestTooFrequently",
"message": "Request too frequently."
}
}{
"request_id": "01HK8XQE3Z7JM2NTFQ5YJ8P9R4",
"error": {
"code": "InternalError",
"message": "We encountered an internal error, and it has been reported. Please try again later."
}
}限制说明
| 项目 | 说明 |
|---|---|
| 速率限制 | 每个账户 300 次/分钟;20 次/秒 |
| 权限要求 | 数据源管理(monit) |
使用说明
- 这是整体替换而非局部更新:每次调用都要发送
type_ident、name、edge_cluster_name、payload,以及address(cloud部署的 Elasticsearch 除外)。note、address、payload会覆盖已保存的值,因此省略note会将其清空。 - 省略
enabled、alerting_enabled、manage_team_id、readonly_team_ids时保持原值。enabled或alerting_enabled传null会被拒绝;两个团队字段传null表示清除。 - 密钥:诊断类型省略密码(以及 Kafka 的
tls_key)表示保留已保存的值,传空字符串表示清除;tencent_cls省略或传空的secret_key表示保留已保存的密钥;其他类型需要重新发送凭据。 - 将
enabled或alerting_enabled设为false,或修改type_ident、edge_cluster_name,会关闭使用该数据源的规则上的未恢复告警;重命名时,会关闭ds_list名称模式不再匹配新名称的规则上的未恢复告警。 - 只要仍有已启用的告警规则选中该数据源,关闭
alerting_enabled会返回 HTTP 409UndonedOrderExist。 - 只有账户所有者、管理员、创建者和负责团队成员可以更新数据源(未设置负责团队时,拥有该权限的调用方均可);其他人返回
AccessDenied。ID 不存在或属于其他账户时返回ResourceNotFound。 - 每次调用都会记录到账户审计日志。
授权
请求体
application/json
创建或更新数据源的请求体。id 仅更新时必填,创建时忽略。更新会用请求中的值整体替换 type_ident、name、note、address、payload 和 edge_cluster_name,因此必须全部重新发送;仅 enabled、alerting_enabled、manage_team_id、readonly_team_ids 在省略时保持原值。除 deployment=cloud 的 Elasticsearch 外,address 对所有类型必填。
数据源类型。
告警类(可用于告警规则评估):
prometheus:兼容 Prometheus 的指标数据源。loki:Grafana Loki 日志。mysql:MySQL。oracle:Oracle 数据库。postgres:PostgreSQL。clickhouse:ClickHouse。elasticsearch:Elasticsearch。sls:阿里云日志服务(SLS)。tencent_cls:腾讯云日志服务(CLS)。victorialogs:VictoriaLogs。
仅诊断类(不能用于告警评估,alerting_enabled 恒为 false):
redis_node:单个 Redis 节点。redis_sentinel:Redis Sentinel。mongodb_mongod:MongoDB mongod 实例。mongodb_mongos:MongoDB mongos 路由。kafka:Kafka 集群。
存放类型专属配置的 payload 键与类型同名。
可用选项:
prometheus, loki, mysql, oracle, postgres, clickhouse, elasticsearch, sls, tencent_cls, victorialogs, redis_node, redis_sentinel, mongodb_mongod, mongodb_mongos, kafka 连接地址;除 deployment: cloud 的 elasticsearch 外,所有类型都必填。规范化后最长 4096 个字符。各类型格式:
prometheus、loki、victorialogs:HTTP URL;不以http开头时自动补http://。mysql、oracle、postgres:host:port。clickhouse:一个或多个以逗号分隔的host:port,重复地址会被拒绝。self-managed的elasticsearch:一个或多个以逗号分隔的 HTTP(S) URL(缺省协议为http://),各 URL 的查询参数必须一致,重复地址会被拒绝;cloud部署无需填写。sls:不带http://或https://前缀的 endpoint。tencent_cls:只能是cls.tencentcloudapi.com或cls.internal.tencentcloudapi.com(要求 Monitors edge >= v0.66.0)。redis_node、redis_sentinel、mongodb_mongod、mongodb_mongos:单个host:port(IPv6 须加方括号),不能含 URI、用户信息或查询串。kafka:1-32 个互不重复、以逗号分隔的host:port引导地址(payload 中没有 broker 列表)。
Maximum string length:
4096此页面对您有帮助吗?