mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
AlertingAPI: Change list response query prop (#33419)
* Alerting: change to full []AlertQuery as json in a string and not just model.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
@@ -90,10 +91,17 @@ func (srv PrometheusSrv) RouteGetRuleStatuses(c *models.ReqContext) response.Res
|
||||
|
||||
stateMap := srv.manager.GetStatesByRuleUID()
|
||||
for _, rule := range alertRuleQuery.Result {
|
||||
var queryStr string
|
||||
encodedQuery, err := json.Marshal(rule.Data)
|
||||
if err != nil {
|
||||
queryStr = err.Error()
|
||||
} else {
|
||||
queryStr = string(encodedQuery)
|
||||
}
|
||||
alertingRule := apimodels.AlertingRule{
|
||||
State: "inactive",
|
||||
Name: rule.Title,
|
||||
Query: rule.DataToString(), // TODO: don't escape <>& etc
|
||||
Query: queryStr, // TODO: don't escape <>& etc
|
||||
Duration: rule.For.Seconds(),
|
||||
Annotations: rule.Annotations,
|
||||
}
|
||||
|
||||
@@ -70,18 +70,6 @@ type AlertRule struct {
|
||||
Labels map[string]string
|
||||
}
|
||||
|
||||
func (alertRule *AlertRule) DataToString() string {
|
||||
response := "["
|
||||
for i, part := range alertRule.Data {
|
||||
response += string(part.Model)
|
||||
if i < len(alertRule.Data)-1 {
|
||||
response += ","
|
||||
}
|
||||
}
|
||||
response += "]"
|
||||
return response
|
||||
}
|
||||
|
||||
// AlertRuleKey is the alert definition identifier
|
||||
type AlertRuleKey struct {
|
||||
OrgID int64
|
||||
|
||||
Reference in New Issue
Block a user