diff --git a/model/alerting/alert.go b/model/alerting/alert.go index 161adfcf..39c520fa 100644 --- a/model/alerting/alert.go +++ b/model/alerting/alert.go @@ -3,8 +3,8 @@ package alerting type Alert struct { ClusterID string `json:"cluster_id"` AcknowledgedTime *int64 `json:"acknowledged_time" elastic_mapping:"acknowledged_time:{type:date}"` - ActionExecutionResults []ActionExecutionResult `json:"action_execution_results" elastic_mapping:"action_execution_results"` - AlertHistories []AlertHistory `json:"alert_history" elastic_mapping:"alert_history"` + ActionExecutionResults []ActionExecutionResult `json:"action_execution_results" elastic_mapping:"action_execution_results:{type:object}"` + AlertHistories []AlertHistory `json:"alert_history" elastic_mapping:"alert_history:{type:object}"` EndTime *int64 `json:"end_time" elastic_mapping:"end_time:{type:date}"` ErrorMessage string `json:"error_message" elastic_mapping:"error_message:{type:text}"` Id string `json:"id" elastic_mapping:"id:{type:keyword}"` diff --git a/model/alerting/config.go b/model/alerting/config.go index b72ab769..0f2ccc95 100644 --- a/model/alerting/config.go +++ b/model/alerting/config.go @@ -12,8 +12,8 @@ package alerting type Config struct { ID string `json:"id" index:"id"` Type string `json:"type" elastic_mapping:"type:{type:keyword}"` - Destination Destination `json:"destination,omitempty" elastic_mapping:"destination"` - EmailAccount EmailAccount `json:"email_account,omitempty" elastic_mapping:"email_account"` - EmailGroup EmailGroup `json:"email_group,omitempty" elastic_mapping:"email_group"` - Monitor Monitor `json:"monitor,omitempty" elastic_mapping:"monitor"` + Destination Destination `json:"destination,omitempty" elastic_mapping:"destination:{type:object}"` + EmailAccount EmailAccount `json:"email_account,omitempty" elastic_mapping:"email_account:{type:object}"` + EmailGroup EmailGroup `json:"email_group,omitempty" elastic_mapping:"email_group:{type:object}"` + Monitor Monitor `json:"monitor,omitempty" elastic_mapping:"monitor:{type:object}"` } diff --git a/model/alerting/destination.go b/model/alerting/destination.go index fba4c133..9902fae5 100644 --- a/model/alerting/destination.go +++ b/model/alerting/destination.go @@ -5,14 +5,14 @@ type Destination struct { Name string `json:"name" elastic_mapping:"name:{type:text,fields: {keyword: {type: keyword, ignore_above: 256}}}"` SchemaVersion int `json:"schema_version" elastic_mapping:"schema_version:{type:integer}"` LastUpdateTime int64 `json:"last_update_time" elastic_mapping:"last_update_time:{type:date,format:strict_date_time||epoch_millis}"` - CustomWebhook CustomWebhook `json:"custom_webhook,omitempty" elastic_mapping:"custom_webhook"` - Email EmailDestination `json:"email,omitempty" elastic_mapping:"email"` - Slack Slack `json:"slack,omitempty" elastic_mapping:"slack"` + CustomWebhook CustomWebhook `json:"custom_webhook,omitempty" elastic_mapping:"custom_webhook:{type:object}"` + Email EmailDestination `json:"email,omitempty" elastic_mapping:"email:{type:object}"` + //Slack Slack `json:"slack,omitempty" elastic_mapping:"slack"` } type EmailDestination struct { EmailAccountID string `json:"email_account_id" elastic_mapping:"email_account_id:{type:keyword}"` - Recipients []Recipient `json:"recipients" elastic_mapping:"recipients"` + Recipients []Recipient `json:"recipients" elastic_mapping:"recipients:{type:nested}"` } type Recipient struct { diff --git a/model/alerting/monitor.go b/model/alerting/monitor.go index 9d2f2727..f9fbada8 100644 --- a/model/alerting/monitor.go +++ b/model/alerting/monitor.go @@ -3,17 +3,17 @@ package alerting type Monitor struct { Enabled bool `json:"enabled" elastic_mapping:"enabled: {type:boolean}"` EnabledTime int64 `json:"enabled_time" elastic_mapping:"enabled_time:{type:date,format:strict_date_time||epoch_millis}"` - Inputs []MonitorInput `json:"inputs" elastic_mapping:"inputs"` + Inputs []MonitorInput `json:"inputs" elastic_mapping:"inputs:{type:nested}"` LastUpdateTime int64 `json:"last_update_time" elastic_mapping:"last_update_time:{type:date,format:strict_date_time||epoch_millis}"` Name string `json:"name" elastic_mapping:"name:{type:text,fields: {keyword: {type: keyword, ignore_above: 256}}}"` - Schedule Schedule `json:"schedule" elastic_mapping:"schedule"` + Schedule Schedule `json:"schedule" elastic_mapping:"schedule:{type:object}"` SchemaVersion int `json:"schema_version" elastic_mapping:"schema_version:{type:integer}"` - Triggers []Trigger `json:"triggers" elastic_mapping:"triggers"` + Triggers []Trigger `json:"triggers" elastic_mapping:"triggers:{type:nested}"` Type string `json:"type" elastic_mapping:"type:{type:keyword}` } type MonitorInput struct { - Search MonitorSearch `json:"search" elastic_mapping:"search"` + Search MonitorSearch `json:"search" elastic_mapping:"search:{type:object}"` } type MonitorSearch struct { @@ -33,8 +33,8 @@ type Period struct { type Schedule struct { - Cron *Cron `json:"cron,omitempty" elastic_mapping:"cron"` - Period *Period `json:"period,omitempty" elastic_mapping:"period"` + Cron *Cron `json:"cron,omitempty" elastic_mapping:"cron:{type:object}"` + Period *Period `json:"period,omitempty" elastic_mapping:"period:{type:object}"` } @@ -50,7 +50,7 @@ type Action struct { Name string `json:"name" elastic_mapping:"name:{type:text,fields: {keyword: {type: keyword, ignore_above: 256}}}"` SubjectTemplate map[string]interface{} `json:"subject_template" elastic_mapping:"subject_template:{type:object}"` ThrottleEnabled bool `json:"throttle_enabled" elastic_mapping:"throttle_enabled:{type:boolean}"` - Throttle *Throttle `json:"throttle,omitempty" elastic_mapping:"throttle"` + Throttle *Throttle `json:"throttle,omitempty" elastic_mapping:"throttle:{type:object}"` } type Trigger struct { @@ -58,6 +58,6 @@ type Trigger struct { Severity string `json:"severity" elastic_mapping:"severity:{type:keyword}"` Name string `json:"name" elastic_mapping:"name:{type:text,fields: {keyword: {type: keyword, ignore_above: 256}}}"` Condition map[string]interface{} `json:"condition" elastic_mapping:"condition:{type:object, enabled:false}"` - Actions []Action `json:"actions" elastic_mapping:"actions"` + Actions []Action `json:"actions" elastic_mapping:"actions:{type:nested}"` MinTimeBetweenExecutions int `json:"min_time_between_executions" elastic_mapping:"min_time_between_executions:{type:integer}"` } \ No newline at end of file diff --git a/service/alerting/destination.go b/service/alerting/destination.go index 9adc2ba5..74c8d0b0 100644 --- a/service/alerting/destination.go +++ b/service/alerting/destination.go @@ -78,7 +78,7 @@ func GetDestinations(w http.ResponseWriter, req *http.Request, ps httprouter.Par clearSearch = strings.ReplaceAll(clearSearch, " ", "* *") must = append(must, IfaceMap{ "query_string": IfaceMap{ - "default_field": "destination.name", + //"default_field": "destination.name", "default_operator": "AND", "query": fmt.Sprintf(`*%s*`, clearSearch), }, @@ -183,8 +183,6 @@ func CreateDestination(w http.ResponseWriter, req *http.Request, ps httprouter.P toSaveDest[destination.Type] = destination.Email case "custom_webhook": toSaveDest[destination.Type] = destination.CustomWebhook - case "slack": - toSaveDest[destination.Type] = destination.Slack default: writeError(w, errors.New("type unsupported")) return @@ -250,8 +248,6 @@ func UpdateDestination(w http.ResponseWriter, req *http.Request, ps httprouter.P toSaveDest[destination.Type] = destination.Email case "custom_webhook": toSaveDest[destination.Type] = destination.CustomWebhook - case "slack": - toSaveDest[destination.Type] = destination.Slack default: writeError(w, errors.New("type unsupported")) return diff --git a/service/alerting/monitor.go b/service/alerting/monitor.go index eea3017e..7fddc8c0 100644 --- a/service/alerting/monitor.go +++ b/service/alerting/monitor.go @@ -1,6 +1,7 @@ package alerting import ( + "encoding/json" "errors" "fmt" httprouter "infini.sh/framework/core/api/router" @@ -199,6 +200,8 @@ func GetMonitors(w http.ResponseWriter, req *http.Request, ps httprouter.Params) }, } assignTo(params, sortPageData) + buf, _ := json.Marshal(params) + fmt.Println(string(buf)) config := getDefaultConfig() reqUrl := fmt.Sprintf("%s/%s/_search", config.Endpoint, orm.GetIndexName(alerting.Config{}) ) res, err := doRequest(reqUrl, http.MethodGet, nil, params)