From d6b8992433d8d37c64fb6eac3eabc4f0fefa391c Mon Sep 17 00:00:00 2001 From: Alexander Zobnin Date: Tue, 25 Aug 2020 13:36:36 +0300 Subject: [PATCH] Refine log messages --- pkg/datasource/datasource.go | 2 +- pkg/datasource/zabbix.go | 8 +++----- pkg/plugin.go | 8 ++++---- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/pkg/datasource/datasource.go b/pkg/datasource/datasource.go index cec5c55..f277f35 100644 --- a/pkg/datasource/datasource.go +++ b/pkg/datasource/datasource.go @@ -80,7 +80,7 @@ func (ds *ZabbixDatasource) CheckHealth(ctx context.Context, req *backend.CheckH if err != nil { res.Status = backend.HealthStatusError res.Message = err.Error() - ds.logger.Error("Error connecting zabbix", "err", err) + ds.logger.Error("Error connecting Zabbix server", "err", err) return res, nil } diff --git a/pkg/datasource/zabbix.go b/pkg/datasource/zabbix.go index 0cb64e5..87d67c8 100644 --- a/pkg/datasource/zabbix.go +++ b/pkg/datasource/zabbix.go @@ -37,7 +37,7 @@ func (ds *ZabbixDatasourceInstance) ZabbixQuery(ctx context.Context, apiReq *Zab } if _, ok := CachedMethods[apiReq.Method]; ok { - ds.logger.Debug("Write result to cache", "method", apiReq.Method) + ds.logger.Debug("Writing result to cache", "method", apiReq.Method) ds.queryCache.SetAPIRequest(apiReq, resultJson) } } else { @@ -80,14 +80,12 @@ func (ds *ZabbixDatasourceInstance) TestConnection(ctx context.Context) (string, } resultByte, _ := response.MarshalJSON() - ds.logger.Debug("TestConnection", "result", string(resultByte)) - return string(resultByte), nil } // ZabbixRequest checks authentication and makes a request to the Zabbix API func (ds *ZabbixDatasourceInstance) ZabbixRequest(ctx context.Context, method string, params ZabbixAPIParams) (*simplejson.Json, error) { - ds.logger.Debug("Invoke Zabbix API request", "ds", ds.dsInfo.Name, "method", method) + ds.logger.Debug("Zabbix API request", "datasource", ds.dsInfo.Name, "method", method) var result *simplejson.Json var err error @@ -449,7 +447,7 @@ func (ds *ZabbixDatasourceInstance) getHistotyOrTrend(ctx context.Context, query history := History{} err = json.Unmarshal(pointJSON, &history) if err != nil { - ds.logger.Warn(fmt.Sprintf("Could not map Zabbix response to History: %s", err.Error())) + ds.logger.Error("Error handling history response", "error", err.Error()) } else { allHistory = append(allHistory, history...) } diff --git a/pkg/plugin.go b/pkg/plugin.go index 47e0b5c..950c5af 100644 --- a/pkg/plugin.go +++ b/pkg/plugin.go @@ -20,7 +20,7 @@ func main() { ds := Init(pluginLogger, mux) httpResourceHandler := httpadapter.New(mux) - pluginLogger.Debug("Starting Zabbix backend datasource") + pluginLogger.Debug("Starting Zabbix datasource") err := backend.Serve(backend.ServeOpts{ CallResourceHandler: httpResourceHandler, @@ -28,7 +28,7 @@ func main() { CheckHealthHandler: ds, }) if err != nil { - pluginLogger.Error(err.Error()) + pluginLogger.Error("Error starting Zabbix datasource", "error", err.Error()) } } @@ -36,9 +36,9 @@ func Init(logger log.Logger, mux *http.ServeMux) *datasource.ZabbixDatasource { variableName := "GFX_ZABBIX_DATA_PATH" path, exist := os.LookupEnv(variableName) if !exist { - logger.Error("could not read environment variable", variableName) + logger.Debug("Could not read environment variable", variableName) } else { - logger.Debug("environment variable for storage found", "variable", variableName, "value", path) + logger.Debug("Environment variable for storage found", "variable", variableName, "value", path) } ds := datasource.NewZabbixDatasource()