Fix alerting queries with numeric query type
This commit is contained in:
@@ -3,9 +3,12 @@ package datasource
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/bitly/go-simplejson"
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend/log"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -121,5 +124,21 @@ func ReadQuery(query backend.DataQuery) (QueryModel, error) {
|
||||
return model, fmt.Errorf("could not read query: %w", err)
|
||||
}
|
||||
|
||||
if model.QueryType == "" {
|
||||
queryJSON, err := simplejson.NewJson(query.JSON)
|
||||
if err != nil {
|
||||
return model, fmt.Errorf("could not read query JSON: %w", err)
|
||||
}
|
||||
|
||||
queryType, err := queryJSON.Get("queryType").Int64()
|
||||
if err != nil {
|
||||
log.DefaultLogger.Warn("could not read query type", "error", err)
|
||||
log.DefaultLogger.Debug("setting query type to default value")
|
||||
model.QueryType = "0"
|
||||
} else {
|
||||
model.QueryType = strconv.FormatInt(queryType, 10)
|
||||
}
|
||||
}
|
||||
|
||||
return model, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user