Chore: Enable Go linter gocritic (#26224)
* Chore: Enable gocritic linter Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
@@ -85,7 +85,7 @@ func (kn *KafkaNotifier) Notify(evalContext *alerting.EvalContext) error {
|
||||
|
||||
customData := triggMetrString
|
||||
for _, evt := range evalContext.EvalMatches {
|
||||
customData = customData + fmt.Sprintf("%s: %v\n", evt.Metric, evt.Value)
|
||||
customData += fmt.Sprintf("%s: %v\n", evt.Metric, evt.Value)
|
||||
}
|
||||
|
||||
kn.log.Info("Notifying Kafka", "alert_state", state)
|
||||
|
||||
@@ -67,13 +67,11 @@ type LineNotifier struct {
|
||||
// Notify send an alert notification to LINE
|
||||
func (ln *LineNotifier) Notify(evalContext *alerting.EvalContext) error {
|
||||
ln.log.Info("Executing line notification", "ruleId", evalContext.Rule.ID, "notification", ln.Name)
|
||||
|
||||
var err error
|
||||
switch evalContext.Rule.State {
|
||||
case models.AlertStateAlerting:
|
||||
err = ln.createAlert(evalContext)
|
||||
if evalContext.Rule.State == models.AlertStateAlerting {
|
||||
return ln.createAlert(evalContext)
|
||||
}
|
||||
return err
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ln *LineNotifier) createAlert(evalContext *alerting.EvalContext) error {
|
||||
|
||||
@@ -142,7 +142,7 @@ func (on *OpsGenieNotifier) createAlert(evalContext *alerting.EvalContext) error
|
||||
|
||||
customData := triggMetrString
|
||||
for _, evt := range evalContext.EvalMatches {
|
||||
customData = customData + fmt.Sprintf("%s: %v\n", evt.Metric, evt.Value)
|
||||
customData += fmt.Sprintf("%s: %v\n", evt.Metric, evt.Value)
|
||||
}
|
||||
|
||||
bodyJSON := simplejson.New()
|
||||
|
||||
@@ -130,11 +130,12 @@ func (sn *SensuNotifier) Notify(evalContext *alerting.EvalContext) error {
|
||||
bodyJSON.Set("output", "Grafana Metric Condition Met")
|
||||
bodyJSON.Set("evalMatches", evalContext.EvalMatches)
|
||||
|
||||
if evalContext.Rule.State == "alerting" {
|
||||
switch evalContext.Rule.State {
|
||||
case "alerting":
|
||||
bodyJSON.Set("status", 2)
|
||||
} else if evalContext.Rule.State == "no_data" {
|
||||
case "no_data":
|
||||
bodyJSON.Set("status", 1)
|
||||
} else {
|
||||
default:
|
||||
bodyJSON.Set("status", 0)
|
||||
}
|
||||
|
||||
|
||||
@@ -125,16 +125,16 @@ func (tn *TelegramNotifier) buildMessageLinkedImage(evalContext *alerting.EvalCo
|
||||
|
||||
ruleURL, err := evalContext.GetRuleURL()
|
||||
if err == nil {
|
||||
message = message + fmt.Sprintf("URL: %s\n", ruleURL)
|
||||
message += fmt.Sprintf("URL: %s\n", ruleURL)
|
||||
}
|
||||
|
||||
if evalContext.ImagePublicURL != "" {
|
||||
message = message + fmt.Sprintf("Image: %s\n", evalContext.ImagePublicURL)
|
||||
message += fmt.Sprintf("Image: %s\n", evalContext.ImagePublicURL)
|
||||
}
|
||||
|
||||
metrics := generateMetricsMessage(evalContext)
|
||||
if metrics != "" {
|
||||
message = message + fmt.Sprintf("\n<i>Metrics:</i>%s", metrics)
|
||||
message += fmt.Sprintf("\n<i>Metrics:</i>%s", metrics)
|
||||
}
|
||||
|
||||
return tn.generateTelegramCmd(message, "text", "sendMessage", func(w *multipart.Writer) {
|
||||
|
||||
@@ -177,10 +177,10 @@ func (notifier *ThreemaNotifier) Notify(evalContext *alerting.EvalContext) error
|
||||
evalContext.Rule.Name, evalContext.Rule.Message)
|
||||
ruleURL, err := evalContext.GetRuleURL()
|
||||
if err == nil {
|
||||
message = message + fmt.Sprintf("*URL:* %s\n", ruleURL)
|
||||
message += fmt.Sprintf("*URL:* %s\n", ruleURL)
|
||||
}
|
||||
if notifier.NeedsImage() && evalContext.ImagePublicURL != "" {
|
||||
message = message + fmt.Sprintf("*Image:* %s\n", evalContext.ImagePublicURL)
|
||||
message += fmt.Sprintf("*Image:* %s\n", evalContext.ImagePublicURL)
|
||||
}
|
||||
data.Set("text", message)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user