diff --git a/model/alerting/alert.go b/model/alerting/alert.go index 1fb44d22..6e21f572 100644 --- a/model/alerting/alert.go +++ b/model/alerting/alert.go @@ -17,9 +17,9 @@ type Alert struct { ResourceID string `json:"resource_id" elastic_mapping:"resource_id: { type: keyword }"` ResourceName string `json:"resource_name" elastic_mapping:"resource_name: { type: keyword }"` Expression string `json:"expression" elastic_mapping:"expression: { type: keyword, copy_to:search_text }"` - Objects []string `json:"objects" elastic_mapping:"objects: { type:keyword,copy_to:search_text }"` - Severity string `json:"severity" elastic_mapping:"severity: { type: keyword }"` - Title string `json:"title" elastic_mapping:"title: { type: keyword }"` + Objects []string `json:"objects" elastic_mapping:"objects: { type:keyword,copy_to:search_text }"` + Priority string `json:"priority" elastic_mapping:"priority: { type: keyword }"` + Title string `json:"title" elastic_mapping:"title: { type: keyword }"` Message string `json:"message" elastic_mapping:"context: { type: keyword, copy_to:search_text }"` AcknowledgedTime interface{} `json:"acknowledged_time,omitempty"` ActionExecutionResults []ActionExecutionResult `json:"action_execution_results"` @@ -68,8 +68,8 @@ type AlertMessage struct { IgnoredTime time.Time `json:"ignored_time,omitempty" elastic_mapping:"ignored_time: { type: date }"` IgnoredReason string `json:"ignored_reason,omitempty" elastic_mapping:"ignored_reason: { type: keyword,copy_to:search_text }"` IgnoredUser string `json:"ignored_user,omitempty" elastic_mapping:"ignored_user: { type: keyword,copy_to:search_text }"` - Severity string `json:"severity" elastic_mapping:"severity: { type: keyword }"` - SearchText string `json:"-" elastic_mapping:"search_text:{type:text,index_prefixes:{},index_phrases:true, analyzer:suggest_text_search }"` + Priority string `json:"priority" elastic_mapping:"priority: { type: keyword }"` + SearchText string `json:"-" elastic_mapping:"search_text:{type:text,index_prefixes:{},index_phrases:true, analyzer:suggest_text_search }"` } /* diff --git a/plugin/api/alerting/alert.go b/plugin/api/alerting/alert.go index 475dc4b7..e62579f9 100644 --- a/plugin/api/alerting/alert.go +++ b/plugin/api/alerting/alert.go @@ -51,9 +51,9 @@ func (h *AlertAPI) searchAlert(w http.ResponseWriter, req *http.Request, ps http queryDSL = `{"sort":[%s],"query":{"bool":{"must":[%s]}}, "size": %d, "from": %d}` strSize = h.GetParameterOrDefault(req, "size", "20") strFrom = h.GetParameterOrDefault(req, "from", "0") - state = h.GetParameterOrDefault(req, "state", "") - severity = h.GetParameterOrDefault(req, "severity", "") - sort = h.GetParameterOrDefault(req, "sort", "") + state = h.GetParameterOrDefault(req, "state", "") + priority = h.GetParameterOrDefault(req, "priority", "") + sort = h.GetParameterOrDefault(req, "sort", "") ruleID = h.GetParameterOrDefault(req, "rule_id", "") min = h.GetParameterOrDefault(req, "min", "") max = h.GetParameterOrDefault(req, "max", "") @@ -80,9 +80,9 @@ func (h *AlertAPI) searchAlert(w http.ResponseWriter, req *http.Request, ps http mustBuilder.WriteString(",") mustBuilder.WriteString(fmt.Sprintf(`{"term":{"state":{"value":"%s"}}}`, state)) } - if severity != "" { + if priority != "" { mustBuilder.WriteString(",") - mustBuilder.WriteString(fmt.Sprintf(`{"term":{"severity":{"value":"%s"}}}`, severity)) + mustBuilder.WriteString(fmt.Sprintf(`{"term":{"priority":{"value":"%s"}}}`, priority)) } size, _ := strconv.Atoi(strSize) if size <= 0 { @@ -130,7 +130,7 @@ func (h *AlertAPI) getAlertStats(w http.ResponseWriter, req *http.Request, ps ht "aggs": util.MapStr{ "terms_by_state": util.MapStr{ "terms": util.MapStr{ - "field": "severity", + "field": "priority", "size": 5, }, }, @@ -144,22 +144,22 @@ func (h *AlertAPI) getAlertStats(w http.ResponseWriter, req *http.Request, ps ht }, http.StatusInternalServerError) return } - severityAlerts := map[string]interface{}{} + priorityAlerts := map[string]interface{}{} if termsAgg, ok := searchRes.Aggregations["terms_by_state"]; ok { for _, bk := range termsAgg.Buckets { - if severity, ok := bk["key"].(string); ok { - severityAlerts[severity] = bk["doc_count"] + if priority, ok := bk["key"].(string); ok { + priorityAlerts[priority] = bk["doc_count"] } } } - for severity, _ := range alerting.PriorityWeights { - if _, ok := severityAlerts[severity]; !ok { - severityAlerts[severity] = 0 + for priority, _ := range alerting.PriorityWeights { + if _, ok := priorityAlerts[priority]; !ok { + priorityAlerts[priority] = 0 } } h.WriteJSON(w, util.MapStr{ "alert": util.MapStr{ - "current": severityAlerts, + "current": priorityAlerts, }, }, http.StatusOK) } \ No newline at end of file diff --git a/plugin/api/alerting/message.go b/plugin/api/alerting/message.go index c3071f87..7d9fca14 100644 --- a/plugin/api/alerting/message.go +++ b/plugin/api/alerting/message.go @@ -302,7 +302,7 @@ func (h *AlertAPI) getAlertMessage(w http.ResponseWriter, req *http.Request, ps "rule_enabled": rule.Enabled, "title": message.Title, "message": message.Message, - "severity": message.Severity, + "severity": message.Priority, "created": message.Created, "updated": message.Updated, "resource_name": rule.Resource.Name, diff --git a/service/alerting/constants.go b/service/alerting/constants.go index c546ca8c..5e811c8e 100644 --- a/service/alerting/constants.go +++ b/service/alerting/constants.go @@ -20,9 +20,9 @@ const ( ParamResults = "results" // ParamMessage = "message" //检查消息 自定义(模版渲染) ParamTitle = "title" - ParamThreshold = "threshold" //检查预设值 []string + ParamThreshold = "threshold" //检查预设值 []string ParamResultValue = "result_value" //检查结果 {group_tags:["cluster-xxx", "node-xxx"], check_values:[]} - Severity = "severity" //告警等级 + Priority = "priority" //告警等级 ParamTimestamp = "timestamp" //事件产生时间戳 ParamGroupValues = "group_values" ParamIssueTimestamp = "issue_timestamp" diff --git a/service/alerting/elasticsearch/engine.go b/service/alerting/elasticsearch/engine.go index dd798209..2c09c3de 100644 --- a/service/alerting/elasticsearch/engine.go +++ b/service/alerting/elasticsearch/engine.go @@ -500,7 +500,7 @@ func (engine *Engine) GetTargetMetricData(rule *alerting.Rule, isFilterNaN bool, } //CheckCondition check whether rule conditions triggered or not //if triggered returns an ConditionResult -//sort conditions by severity desc before check , and then if condition is true, then continue check another group +//sort conditions by priority desc before check , and then if condition is true, then continue check another group func (engine *Engine) CheckCondition(rule *alerting.Rule)(*alerting.ConditionResult, error){ var resultItems []alerting.ConditionResultItem targetMetricData, queryResult, err := engine.GetTargetMetricData(rule, true, nil) @@ -651,7 +651,7 @@ func (engine *Engine) Do(rule *alerting.Rule) error { conditionResults := checkResults.ResultItems var paramsCtx map[string]interface{} if len(conditionResults) == 0 { - alertItem.Severity = "info" + alertItem.Priority = "info" if checkResults.QueryResult.Nodata { alertItem.State = alerting.AlertStateNodata } @@ -669,11 +669,11 @@ func (engine *Engine) Do(rule *alerting.Rule) error { alertItem.State = alerting.AlertStateAlerting var ( - severity = conditionResults[0].ConditionItem.Priority + priority = conditionResults[0].ConditionItem.Priority ) for _, conditionResult := range conditionResults { - if alerting.PriorityWeights[severity] < alerting.PriorityWeights[conditionResult.ConditionItem.Priority] { - severity = conditionResult.ConditionItem.Priority + if alerting.PriorityWeights[priority] < alerting.PriorityWeights[conditionResult.ConditionItem.Priority] { + priority = conditionResult.ConditionItem.Priority } } paramsCtx = newParameterCtx(rule, checkResults, util.MapStr{ @@ -681,7 +681,7 @@ func (engine *Engine) Do(rule *alerting.Rule) error { alerting2.ParamTimestamp: alertItem.Created.Unix(), }) - alertItem.Severity = severity + alertItem.Priority = priority err = attachTitleMessageToCtx(rule, paramsCtx) if err != nil { return err @@ -690,16 +690,16 @@ func (engine *Engine) Do(rule *alerting.Rule) error { alertItem.Title = paramsCtx[alerting2.ParamTitle].(string) if alertMessage == nil || alertMessage.Status == alerting.MessageStateRecovered { msg := &alerting.AlertMessage{ - RuleID: rule.ID, - Created: time.Now(), - Updated: time.Now(), - ID: util.GetUUID(), - ResourceID: rule.Resource.ID, + RuleID: rule.ID, + Created: time.Now(), + Updated: time.Now(), + ID: util.GetUUID(), + ResourceID: rule.Resource.ID, ResourceName: rule.Resource.Name, - Status: alerting.MessageStateAlerting, - Severity: severity, - Title: alertItem.Title, - Message: alertItem.Message, + Status: alerting.MessageStateAlerting, + Priority: priority, + Title: alertItem.Title, + Message: alertItem.Message, } err = saveAlertMessage(msg) if err != nil { @@ -744,9 +744,9 @@ func (engine *Engine) Do(rule *alerting.Rule) error { //log.Error(lastAlertItem.ID, period, periodDuration) if paramsCtx == nil { paramsCtx = newParameterCtx(rule, checkResults, util.MapStr{ - alerting2.ParamEventID: alertItem.ID, - alerting2.ParamTimestamp: alertItem.Created.Unix(), - "severity": severity, + alerting2.ParamEventID: alertItem.ID, + alerting2.ParamTimestamp: alertItem.Created.Unix(), + "priority": priority, }) } @@ -822,11 +822,11 @@ func newParameterCtx(rule *alerting.Rule, checkResults *alerting.ConditionResult var ( conditionParams []util.MapStr firstGroupValue string - firstThreshold string - severity string + firstThreshold string + priority string ) if len(checkResults.ResultItems) > 0 { - severity = checkResults.ResultItems[0].ConditionItem.Priority + priority = checkResults.ResultItems[0].ConditionItem.Priority sort.Slice(checkResults.ResultItems, func(i, j int) bool { if alerting.PriorityWeights[checkResults.ResultItems[i].ConditionItem.Priority] > alerting.PriorityWeights[checkResults.ResultItems[j].ConditionItem.Priority] { return true @@ -851,7 +851,7 @@ func newParameterCtx(rule *alerting.Rule, checkResults *alerting.ConditionResult } conditionParams = append(conditionParams, util.MapStr{ alerting2.ParamThreshold: resultItem.ConditionItem.Values, - alerting2.Severity: resultItem.ConditionItem.Priority, + alerting2.Priority: resultItem.ConditionItem.Priority, alerting2.ParamGroupValues: resultItem.GroupValues, alerting2.ParamIssueTimestamp: resultItem.IssueTimestamp, alerting2.ParamResultValue: resultItem.ResultValue, @@ -865,8 +865,8 @@ func newParameterCtx(rule *alerting.Rule, checkResults *alerting.ConditionResult alerting2.ParamResults: conditionParams, "first_group_value": firstGroupValue, "first_threshold": firstThreshold, - "rule_name": rule.Name, - "severity": severity, + "rule_name": rule.Name, + "priority": priority, } err := util.MergeFields(paramsCtx, extraParams, true) if err != nil { diff --git a/service/alerting/parameter.go b/service/alerting/parameter.go index 25ba5fcc..69c79e74 100644 --- a/service/alerting/parameter.go +++ b/service/alerting/parameter.go @@ -22,7 +22,7 @@ func GetTemplateParameters() []ParameterMeta { {ParamMessage, "string", "", "disk used 90%", nil}, {ParamResults, "array", "", "", []ParameterMeta{ {ParamThreshold, "array", "", "[\"90\"]", nil}, - {Severity, "string", "", "error", nil}, + {Priority, "string", "", "error", nil}, {ParamGroupValues, "array", "", "[\"cluster-xxx\", \"node-xxx\"]", nil}, {ParamIssueTimestamp, "date", "", "2022-05-11T11:50:55+08:00", nil}, {ParamResultValue, "float", "", "91.2", nil},