创建告警规则
curl --request POST \
--url 'https://api.flashcat.cloud/monit/rule/create?app_key=' \
--header 'Content-Type: application/json' \
--data '
{
"folder_id": 100,
"name": "CPU 过高",
"ds_type": "prometheus",
"ds_list": [
"prometheus*"
],
"enabled": true,
"cron_pattern": "* * * * *",
"channel_ids": [
20001
],
"rule_configs": {
"queries": [
{
"name": "A",
"expr": "avg(cpu_usage_idle) < 10"
}
],
"check_threshold": {
"enabled": true,
"critical": "A",
"alerting_check_times": 1,
"recovery_check_times": 1,
"push_recovery_event": true,
"recovery": {
"mode": "invert"
}
}
}
}
'import requests
url = "https://api.flashcat.cloud/monit/rule/create?app_key="
payload = {
"folder_id": 100,
"name": "CPU 过高",
"ds_type": "prometheus",
"ds_list": ["prometheus*"],
"enabled": True,
"cron_pattern": "* * * * *",
"channel_ids": [20001],
"rule_configs": {
"queries": [
{
"name": "A",
"expr": "avg(cpu_usage_idle) < 10"
}
],
"check_threshold": {
"enabled": True,
"critical": "A",
"alerting_check_times": 1,
"recovery_check_times": 1,
"push_recovery_event": True,
"recovery": { "mode": "invert" }
}
}
}
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({
folder_id: 100,
name: 'CPU 过高',
ds_type: 'prometheus',
ds_list: ['prometheus*'],
enabled: true,
cron_pattern: '* * * * *',
channel_ids: [20001],
rule_configs: {
queries: [{name: 'A', expr: 'avg(cpu_usage_idle) < 10'}],
check_threshold: {
enabled: true,
critical: 'A',
alerting_check_times: 1,
recovery_check_times: 1,
push_recovery_event: true,
recovery: {mode: 'invert'}
}
}
})
};
fetch('https://api.flashcat.cloud/monit/rule/create?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/rule/create?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([
'folder_id' => 100,
'name' => 'CPU 过高',
'ds_type' => 'prometheus',
'ds_list' => [
'prometheus*'
],
'enabled' => true,
'cron_pattern' => '* * * * *',
'channel_ids' => [
20001
],
'rule_configs' => [
'queries' => [
[
'name' => 'A',
'expr' => 'avg(cpu_usage_idle) < 10'
]
],
'check_threshold' => [
'enabled' => true,
'critical' => 'A',
'alerting_check_times' => 1,
'recovery_check_times' => 1,
'push_recovery_event' => true,
'recovery' => [
'mode' => 'invert'
]
]
]
]),
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/rule/create?app_key="
payload := strings.NewReader("{\n \"folder_id\": 100,\n \"name\": \"CPU 过高\",\n \"ds_type\": \"prometheus\",\n \"ds_list\": [\n \"prometheus*\"\n ],\n \"enabled\": true,\n \"cron_pattern\": \"* * * * *\",\n \"channel_ids\": [\n 20001\n ],\n \"rule_configs\": {\n \"queries\": [\n {\n \"name\": \"A\",\n \"expr\": \"avg(cpu_usage_idle) < 10\"\n }\n ],\n \"check_threshold\": {\n \"enabled\": true,\n \"critical\": \"A\",\n \"alerting_check_times\": 1,\n \"recovery_check_times\": 1,\n \"push_recovery_event\": true,\n \"recovery\": {\n \"mode\": \"invert\"\n }\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/rule/create?app_key=")
.header("Content-Type", "application/json")
.body("{\n \"folder_id\": 100,\n \"name\": \"CPU 过高\",\n \"ds_type\": \"prometheus\",\n \"ds_list\": [\n \"prometheus*\"\n ],\n \"enabled\": true,\n \"cron_pattern\": \"* * * * *\",\n \"channel_ids\": [\n 20001\n ],\n \"rule_configs\": {\n \"queries\": [\n {\n \"name\": \"A\",\n \"expr\": \"avg(cpu_usage_idle) < 10\"\n }\n ],\n \"check_threshold\": {\n \"enabled\": true,\n \"critical\": \"A\",\n \"alerting_check_times\": 1,\n \"recovery_check_times\": 1,\n \"push_recovery_event\": true,\n \"recovery\": {\n \"mode\": \"invert\"\n }\n }\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.flashcat.cloud/monit/rule/create?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 \"folder_id\": 100,\n \"name\": \"CPU 过高\",\n \"ds_type\": \"prometheus\",\n \"ds_list\": [\n \"prometheus*\"\n ],\n \"enabled\": true,\n \"cron_pattern\": \"* * * * *\",\n \"channel_ids\": [\n 20001\n ],\n \"rule_configs\": {\n \"queries\": [\n {\n \"name\": \"A\",\n \"expr\": \"avg(cpu_usage_idle) < 10\"\n }\n ],\n \"check_threshold\": {\n \"enabled\": true,\n \"critical\": \"A\",\n \"alerting_check_times\": 1,\n \"recovery_check_times\": 1,\n \"push_recovery_event\": true,\n \"recovery\": {\n \"mode\": \"invert\"\n }\n }\n }\n}"
response = http.request(request)
puts response.read_body{
"request_id": "01HK8XQE3Z7JM2NTFQ5YJ8P9R4",
"data": {
"id": 50001,
"folder_id": 100,
"name": "CPU 过高",
"ds_type": "prometheus",
"created_at": 1712000000
}
}{
"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": "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 的已创建规则。
POST
/
monit
/
rule
/
create
创建告警规则
curl --request POST \
--url 'https://api.flashcat.cloud/monit/rule/create?app_key=' \
--header 'Content-Type: application/json' \
--data '
{
"folder_id": 100,
"name": "CPU 过高",
"ds_type": "prometheus",
"ds_list": [
"prometheus*"
],
"enabled": true,
"cron_pattern": "* * * * *",
"channel_ids": [
20001
],
"rule_configs": {
"queries": [
{
"name": "A",
"expr": "avg(cpu_usage_idle) < 10"
}
],
"check_threshold": {
"enabled": true,
"critical": "A",
"alerting_check_times": 1,
"recovery_check_times": 1,
"push_recovery_event": true,
"recovery": {
"mode": "invert"
}
}
}
}
'import requests
url = "https://api.flashcat.cloud/monit/rule/create?app_key="
payload = {
"folder_id": 100,
"name": "CPU 过高",
"ds_type": "prometheus",
"ds_list": ["prometheus*"],
"enabled": True,
"cron_pattern": "* * * * *",
"channel_ids": [20001],
"rule_configs": {
"queries": [
{
"name": "A",
"expr": "avg(cpu_usage_idle) < 10"
}
],
"check_threshold": {
"enabled": True,
"critical": "A",
"alerting_check_times": 1,
"recovery_check_times": 1,
"push_recovery_event": True,
"recovery": { "mode": "invert" }
}
}
}
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({
folder_id: 100,
name: 'CPU 过高',
ds_type: 'prometheus',
ds_list: ['prometheus*'],
enabled: true,
cron_pattern: '* * * * *',
channel_ids: [20001],
rule_configs: {
queries: [{name: 'A', expr: 'avg(cpu_usage_idle) < 10'}],
check_threshold: {
enabled: true,
critical: 'A',
alerting_check_times: 1,
recovery_check_times: 1,
push_recovery_event: true,
recovery: {mode: 'invert'}
}
}
})
};
fetch('https://api.flashcat.cloud/monit/rule/create?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/rule/create?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([
'folder_id' => 100,
'name' => 'CPU 过高',
'ds_type' => 'prometheus',
'ds_list' => [
'prometheus*'
],
'enabled' => true,
'cron_pattern' => '* * * * *',
'channel_ids' => [
20001
],
'rule_configs' => [
'queries' => [
[
'name' => 'A',
'expr' => 'avg(cpu_usage_idle) < 10'
]
],
'check_threshold' => [
'enabled' => true,
'critical' => 'A',
'alerting_check_times' => 1,
'recovery_check_times' => 1,
'push_recovery_event' => true,
'recovery' => [
'mode' => 'invert'
]
]
]
]),
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/rule/create?app_key="
payload := strings.NewReader("{\n \"folder_id\": 100,\n \"name\": \"CPU 过高\",\n \"ds_type\": \"prometheus\",\n \"ds_list\": [\n \"prometheus*\"\n ],\n \"enabled\": true,\n \"cron_pattern\": \"* * * * *\",\n \"channel_ids\": [\n 20001\n ],\n \"rule_configs\": {\n \"queries\": [\n {\n \"name\": \"A\",\n \"expr\": \"avg(cpu_usage_idle) < 10\"\n }\n ],\n \"check_threshold\": {\n \"enabled\": true,\n \"critical\": \"A\",\n \"alerting_check_times\": 1,\n \"recovery_check_times\": 1,\n \"push_recovery_event\": true,\n \"recovery\": {\n \"mode\": \"invert\"\n }\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/rule/create?app_key=")
.header("Content-Type", "application/json")
.body("{\n \"folder_id\": 100,\n \"name\": \"CPU 过高\",\n \"ds_type\": \"prometheus\",\n \"ds_list\": [\n \"prometheus*\"\n ],\n \"enabled\": true,\n \"cron_pattern\": \"* * * * *\",\n \"channel_ids\": [\n 20001\n ],\n \"rule_configs\": {\n \"queries\": [\n {\n \"name\": \"A\",\n \"expr\": \"avg(cpu_usage_idle) < 10\"\n }\n ],\n \"check_threshold\": {\n \"enabled\": true,\n \"critical\": \"A\",\n \"alerting_check_times\": 1,\n \"recovery_check_times\": 1,\n \"push_recovery_event\": true,\n \"recovery\": {\n \"mode\": \"invert\"\n }\n }\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.flashcat.cloud/monit/rule/create?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 \"folder_id\": 100,\n \"name\": \"CPU 过高\",\n \"ds_type\": \"prometheus\",\n \"ds_list\": [\n \"prometheus*\"\n ],\n \"enabled\": true,\n \"cron_pattern\": \"* * * * *\",\n \"channel_ids\": [\n 20001\n ],\n \"rule_configs\": {\n \"queries\": [\n {\n \"name\": \"A\",\n \"expr\": \"avg(cpu_usage_idle) < 10\"\n }\n ],\n \"check_threshold\": {\n \"enabled\": true,\n \"critical\": \"A\",\n \"alerting_check_times\": 1,\n \"recovery_check_times\": 1,\n \"push_recovery_event\": true,\n \"recovery\": {\n \"mode\": \"invert\"\n }\n }\n }\n}"
response = http.request(request)
puts response.read_body{
"request_id": "01HK8XQE3Z7JM2NTFQ5YJ8P9R4",
"data": {
"id": 50001,
"folder_id": 100,
"name": "CPU 过高",
"ds_type": "prometheus",
"created_at": 1712000000
}
}{
"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": "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."
}
}限制说明
| 项目 | 说明 |
|---|---|
| 速率限制 | 每个账户 1,000 次/分钟;50 次/秒 |
| 权限要求 | 告警规则管理(monit) |
使用说明
name、ds_type、cron_pattern和rule_configs.queries为必填项。ds_list(支持通配符)或ds_ids必须有一个非空。cron_pattern使用标准 5 字段 cron 语法。channel_ids可为空,告警将通过全局集成路由。- 每次调用都会记录到账户审计日志,请不要把敏感信息放在请求字段中。
授权
在 Flashduty 控制台 账户 → APP Key 中签发的 app_key。调用任何公开 API 时都必须携带。它等同于所属账户的身份凭证,请妥善保管。
请求体
application/json
完整的告警规则配置。
规则所属文件夹。
规则名称。
自定义标签。
Show child attributes
Show child attributes
数据源类型。
数据源名称模式(支持通配符)。
具体数据源 ID 列表。
规则评估配置。
Show child attributes
Show child attributes
5 字段 cron 调度。不允许以 CRON_TZ= 或 TZ= 开头,时区请填写到 timezone 字段。
告警规则执行时区,决定 cron 调度与生效时间窗口的解释方式。仅接受 IANA 时区名(如 Asia/Shanghai、UTC、Europe/London);不接受 Local、UTC+8、CST 等简写或偏移量。留空时按 Asia/Shanghai 处理。
规则生效的时间窗口。
Show child attributes
Show child attributes
Show child attributes
Show child attributes
可用选项:
text, markdown 告警发送到的协作空间 ID 列表。
通知重复间隔(秒)。
最大重复通知次数。
此页面对您有帮助吗?
⌘I