发布 0.1.0:通知渠道、告警规则、令牌版本与安全加固
This commit is contained in:
@@ -21,6 +21,7 @@ var notifyTplOrder = []string{
|
||||
"task_fail", "task_recover", "snatch_success", "tenant_dead", "task_stop",
|
||||
"login_lock", "model_deprecated",
|
||||
"log_event_instance", "log_event_identity", "log_event_policy", "log_event_region", "log_event_login",
|
||||
"audit_alert",
|
||||
}
|
||||
|
||||
var notifyTplDefs = map[string]notifyTplDef{
|
||||
@@ -38,9 +39,13 @@ var notifyTplDefs = map[string]notifyTplDef{
|
||||
},
|
||||
"snatch_success": {
|
||||
Label: "抢机成功",
|
||||
Default: "🎉 抢机成功:{{task_name}}\n{{message}}",
|
||||
Vars: []string{"task_name", "message"},
|
||||
Sample: map[string]string{"task_name": "示例抢机任务", "message": "已创建 1/1 台实例"},
|
||||
Default: "🎉 抢机成功:{{task_name}}\n租户:{{tenant}}\n区域:{{region}}\n类型:{{shape}}\n配置:{{spec}}\n镜像:{{image}}\nIP:{{ip}}\n密码:{{root_password}}",
|
||||
Vars: []string{"task_name", "tenant", "region", "shape", "spec", "image", "ip", "root_password", "message"},
|
||||
Sample: map[string]string{
|
||||
"task_name": "示例抢机任务", "tenant": "免费01", "region": "Japan Central (Osaka)",
|
||||
"shape": "VM.Standard.A1.Flex", "spec": "4C/24G", "image": "Canonical-Ubuntu-24.04-aarch64-2025.05.20-0",
|
||||
"ip": "129.150.32.10", "root_password": "Xy3#kP9m-2Qw@7Zn", "message": "created 1: ocid1.instance…",
|
||||
},
|
||||
},
|
||||
"tenant_dead": {
|
||||
Label: "租户失联",
|
||||
@@ -96,6 +101,13 @@ var notifyTplDefs = map[string]notifyTplDef{
|
||||
Vars: []string{"tenant", "event", "resource"},
|
||||
Sample: map[string]string{"tenant": "免费01", "event": "InteractiveLogin", "resource": "demo@example.com"},
|
||||
},
|
||||
"audit_alert": {
|
||||
Label: "审计告警",
|
||||
Default: "🔔 审计告警:{{rule}}\n租户 {{tenant}} · {{event}} {{resource}}\n来源 {{ip}} · 窗口内 {{count}} 次",
|
||||
Vars: []string{"rule", "tenant", "event", "resource", "ip", "count"},
|
||||
Sample: map[string]string{"rule": "非白名单终止实例", "tenant": "免费01",
|
||||
"event": "TerminateInstance", "resource": "web-server-1", "ip": "203.0.113.8", "count": "1"},
|
||||
},
|
||||
}
|
||||
|
||||
var notifyVarPattern = regexp.MustCompile(`\{\{(\w+)\}\}`)
|
||||
@@ -161,3 +173,11 @@ func notifyTplText(custom, kind string) string {
|
||||
}
|
||||
return notifyTplDefs[kind].Default
|
||||
}
|
||||
|
||||
// notifyTplLabel 返回 kind 的显示名,供渠道消息标题(ntfy/bark/邮件主题)使用。
|
||||
func notifyTplLabel(kind string) string {
|
||||
if def, ok := notifyTplDefs[kind]; ok {
|
||||
return def.Label
|
||||
}
|
||||
return "oci-portal 通知"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user