Handle ds init errors
This commit is contained in:
@@ -164,6 +164,16 @@ func readZabbixSettings(dsInstanceSettings *backend.DataSourceInstanceSettings)
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if zabbixSettingsDTO.TrendsFrom == "" {
|
||||||
|
zabbixSettingsDTO.TrendsFrom = "7d"
|
||||||
|
}
|
||||||
|
if zabbixSettingsDTO.TrendsRange == "" {
|
||||||
|
zabbixSettingsDTO.TrendsRange = "4d"
|
||||||
|
}
|
||||||
|
if zabbixSettingsDTO.CacheTTL == "" {
|
||||||
|
zabbixSettingsDTO.CacheTTL = "1h"
|
||||||
|
}
|
||||||
|
|
||||||
trendsFrom, err := gtime.ParseInterval(zabbixSettingsDTO.TrendsFrom)
|
trendsFrom, err := gtime.ParseInterval(zabbixSettingsDTO.TrendsFrom)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -202,6 +212,7 @@ func (ds *ZabbixDatasource) GetDatasource(pluginContext backend.PluginContext) (
|
|||||||
|
|
||||||
ds.logger.Debug(fmt.Sprintf("Datasource cache miss (Org %d Id %d '%s' %s)", pluginContext.OrgID, dsSettings.ID, dsSettings.Name, dsInfoHash))
|
ds.logger.Debug(fmt.Sprintf("Datasource cache miss (Org %d Id %d '%s' %s)", pluginContext.OrgID, dsSettings.ID, dsSettings.Name, dsInfoHash))
|
||||||
|
|
||||||
|
ds.logger.Debug("DS config", "settings", pluginContext.DataSourceInstanceSettings)
|
||||||
dsInstance, err := ds.NewZabbixDatasource(pluginContext.DataSourceInstanceSettings)
|
dsInstance, err := ds.NewZabbixDatasource(pluginContext.DataSourceInstanceSettings)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ds.logger.Error("Error initializing datasource", "error", err)
|
ds.logger.Error("Error initializing datasource", "error", err)
|
||||||
|
|||||||
@@ -37,6 +37,11 @@ func (ds *ZabbixDatasource) zabbixAPIHandler(rw http.ResponseWriter, req *http.R
|
|||||||
|
|
||||||
pluginCxt := httpadapter.PluginConfigFromContext(req.Context())
|
pluginCxt := httpadapter.PluginConfigFromContext(req.Context())
|
||||||
dsInstance, err := ds.GetDatasource(pluginCxt)
|
dsInstance, err := ds.GetDatasource(pluginCxt)
|
||||||
|
if err != nil {
|
||||||
|
ds.logger.Error("Error loading datasource", "error", err)
|
||||||
|
WriteError(rw, http.StatusInternalServerError, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
apiReq := &ZabbixAPIRequest{Method: reqData.Method, Params: reqData.Params}
|
apiReq := &ZabbixAPIRequest{Method: reqData.Method, Params: reqData.Params}
|
||||||
|
|
||||||
|
|||||||
@@ -29,14 +29,14 @@ func (ds *ZabbixDatasourceInstance) ZabbixQuery(ctx context.Context, apiReq *Zab
|
|||||||
cachedResult, queryExistInCache := ds.queryCache.Get(requestHash)
|
cachedResult, queryExistInCache := ds.queryCache.Get(requestHash)
|
||||||
if !queryExistInCache {
|
if !queryExistInCache {
|
||||||
resultJson, err = ds.ZabbixRequest(ctx, apiReq.Method, apiReq.Params)
|
resultJson, err = ds.ZabbixRequest(ctx, apiReq.Method, apiReq.Params)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
if _, ok := NotCachedMethods[apiReq.Method]; !ok {
|
if _, ok := NotCachedMethods[apiReq.Method]; !ok {
|
||||||
ds.logger.Debug("Write result to cache", "method", apiReq.Method)
|
ds.logger.Debug("Write result to cache", "method", apiReq.Method)
|
||||||
ds.queryCache.Set(requestHash, resultJson)
|
ds.queryCache.Set(requestHash, resultJson)
|
||||||
}
|
}
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
var ok bool
|
var ok bool
|
||||||
resultJson, ok = cachedResult.(*simplejson.Json)
|
resultJson, ok = cachedResult.(*simplejson.Json)
|
||||||
|
|||||||
Reference in New Issue
Block a user