change field elastic mapping from nested to object
This commit is contained in:
parent
9425f506bf
commit
7ea9100e57
|
@ -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}"`
|
||||
|
|
|
@ -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}"`
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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}"`
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue