@@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/bitly/go-simplejson"
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
||||
)
|
||||
|
||||
func convertTo(value *simplejson.Json, result interface{}) error {
|
||||
@@ -14,6 +15,7 @@ func convertTo(value *simplejson.Json, result interface{}) error {
|
||||
|
||||
err = json.Unmarshal(valueJSON, result)
|
||||
if err != nil {
|
||||
backend.Logger.Debug("Error unmarshalling JSON", "error", err, "result", result)
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/dlclark/regexp2"
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
||||
)
|
||||
|
||||
func (item *Item) ExpandItemName() string {
|
||||
@@ -79,7 +80,7 @@ func parseFilter(filter string) (*regexp2.Regexp, error) {
|
||||
if flagRE.MatchString(matches[2]) {
|
||||
pattern += "(?" + matches[2] + ")"
|
||||
} else {
|
||||
return nil, fmt.Errorf("error parsing regexp: unsupported flags `%s` (expected [%s])", matches[2], vaildREModifiers)
|
||||
return nil, backend.DownstreamError(fmt.Errorf("error parsing regexp: unsupported flags `%s` (expected [%s])", matches[2], vaildREModifiers))
|
||||
}
|
||||
}
|
||||
pattern += matches[1]
|
||||
|
||||
@@ -95,7 +95,7 @@ func (zabbix *Zabbix) request(ctx context.Context, method string, params ZabbixA
|
||||
result, err := zabbix.api.Request(ctx, method, params, zabbix.version)
|
||||
notAuthorized := isNotAuthorized(err)
|
||||
isTokenAuth := zabbix.settings.AuthType == settings.AuthTypeToken
|
||||
if err == zabbixapi.ErrNotAuthenticated || (notAuthorized && !isTokenAuth) {
|
||||
if err == backend.DownstreamError(zabbixapi.ErrNotAuthenticated) || (notAuthorized && !isTokenAuth) {
|
||||
if notAuthorized {
|
||||
zabbix.logger.Debug("Authentication token expired, performing re-login")
|
||||
}
|
||||
@@ -121,7 +121,7 @@ func (zabbix *Zabbix) Authenticate(ctx context.Context) error {
|
||||
if authType == settings.AuthTypeToken {
|
||||
token, exists := zabbix.dsInfo.DecryptedSecureJSONData["apiToken"]
|
||||
if !exists {
|
||||
return errors.New("cannot find Zabbix API token")
|
||||
return backend.DownstreamError(errors.New("cannot find Zabbix API token"))
|
||||
}
|
||||
err = zabbix.api.AuthenticateWithToken(ctx, token)
|
||||
if err != nil {
|
||||
|
||||
@@ -2,9 +2,10 @@ package zabbix
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/alexanderzobnin/grafana-zabbix/pkg/settings"
|
||||
"testing"
|
||||
|
||||
"github.com/alexanderzobnin/grafana-zabbix/pkg/settings"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
||||
|
||||
Reference in New Issue
Block a user