2025-11-18 16:46:47 +08:00
|
|
|
// Package event define real time data evnet operation functions
|
|
|
|
|
package event
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
|
|
|
|
|
"modelRT/logger"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type actionHandler func(ctx context.Context, content string) error
|
|
|
|
|
|
|
|
|
|
// actionDispatchMap define variable to store all action handler into map
|
|
|
|
|
var actionDispatchMap = map[string]actionHandler{
|
|
|
|
|
"info": handleInfoAction,
|
|
|
|
|
"warning": handleWarningAction,
|
|
|
|
|
"error": handleErrorAction,
|
|
|
|
|
"critical": handleCriticalAction,
|
|
|
|
|
"exception": handleExceptionAction,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TriggerEventAction define func to trigger event by action in compute config
|
|
|
|
|
func TriggerEventAction(ctx context.Context, command string, content string) {
|
|
|
|
|
handler, exists := actionDispatchMap[command]
|
|
|
|
|
if !exists {
|
|
|
|
|
logger.Error(ctx, "unknown action command", "command", command)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
err := handler(ctx, content)
|
|
|
|
|
if err != nil {
|
|
|
|
|
logger.Error(ctx, "action handler failed", "command", command, "content", content, "error", err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
logger.Info(ctx, "action handler success", "command", command, "content", content)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func handleInfoAction(ctx context.Context, content string) error {
|
|
|
|
|
// 实际执行发送警告、记录日志等操作
|
|
|
|
|
actionParams := content
|
|
|
|
|
// ... logic to send info level event using actionParams ...
|
|
|
|
|
logger.Warn(ctx, "trigger info event", "message", actionParams)
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func handleWarningAction(ctx context.Context, content string) error {
|
|
|
|
|
// 实际执行发送警告、记录日志等操作
|
|
|
|
|
actionParams := content
|
|
|
|
|
// ... logic to send warning level event using actionParams ...
|
2025-12-01 17:22:29 +08:00
|
|
|
logger.Warn(ctx, "trigger warning event", "message", actionParams)
|
2025-11-18 16:46:47 +08:00
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func handleErrorAction(ctx context.Context, content string) error {
|
|
|
|
|
// 实际执行发送警告、记录日志等操作
|
|
|
|
|
actionParams := content
|
|
|
|
|
// ... logic to send error level event using actionParams ...
|
|
|
|
|
logger.Warn(ctx, "trigger error event", "message", actionParams)
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func handleCriticalAction(ctx context.Context, content string) error {
|
|
|
|
|
// 实际执行发送警告、记录日志等操作
|
|
|
|
|
actionParams := content
|
|
|
|
|
// ... logic to send critical level event using actionParams ...
|
|
|
|
|
logger.Warn(ctx, "trigger critical event", "message", actionParams)
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func handleExceptionAction(ctx context.Context, content string) error {
|
|
|
|
|
// 实际执行发送警告、记录日志等操作
|
|
|
|
|
actionParams := content
|
|
|
|
|
// ... logic to send except level event using actionParams ...
|
|
|
|
|
logger.Warn(ctx, "trigger except event", "message", actionParams)
|
|
|
|
|
return nil
|
|
|
|
|
}
|