mirror of
				https://github.com/ClusterCockpit/cc-metric-collector.git
				synced 2025-10-31 09:05:05 +01:00 
			
		
		
		
	Be more strict, when parsing json
This commit is contained in:
		| @@ -1,6 +1,7 @@ | ||||
| package sinks | ||||
|  | ||||
| import ( | ||||
| 	"bytes" | ||||
| 	"encoding/json" | ||||
| 	"errors" | ||||
| 	"fmt" | ||||
| @@ -94,9 +95,10 @@ func NewGangliaSink(name string, config json.RawMessage) (Sink, error) { | ||||
| 	s.config.AddTagsAsDesc = false | ||||
| 	s.config.AddGangliaGroup = false | ||||
| 	if len(config) > 0 { | ||||
| 		err := json.Unmarshal(config, &s.config) | ||||
| 		if err != nil { | ||||
| 			cclog.ComponentError(s.name, "Error reading config for", s.name, ":", err.Error()) | ||||
| 		d := json.NewDecoder(bytes.NewReader(config)) | ||||
| 		d.DisallowUnknownFields() | ||||
| 		if err := d.Decode(&s.config); err != nil { | ||||
| 			cclog.ComponentError(s.name, "Error reading config:", err.Error()) | ||||
| 			return nil, err | ||||
| 		} | ||||
| 	} | ||||
|   | ||||
| @@ -272,8 +272,10 @@ func NewHttpSink(name string, config json.RawMessage) (Sink, error) { | ||||
|  | ||||
| 	// Read config | ||||
| 	if len(config) > 0 { | ||||
| 		err := json.Unmarshal(config, &s.config) | ||||
| 		if err != nil { | ||||
| 		d := json.NewDecoder(bytes.NewReader(config)) | ||||
| 		d.DisallowUnknownFields() | ||||
| 		if err := d.Decode(&s.config); err != nil { | ||||
| 			cclog.ComponentError(s.name, "Error reading config:", err.Error()) | ||||
| 			return nil, err | ||||
| 		} | ||||
| 	} | ||||
|   | ||||
| @@ -1,6 +1,7 @@ | ||||
| package sinks | ||||
|  | ||||
| import ( | ||||
| 	"bytes" | ||||
| 	"context" | ||||
| 	"crypto/tls" | ||||
| 	"encoding/json" | ||||
| @@ -180,8 +181,10 @@ func NewInfluxAsyncSink(name string, config json.RawMessage) (Sink, error) { | ||||
| 	// 262144 524288 | ||||
|  | ||||
| 	if len(config) > 0 { | ||||
| 		err := json.Unmarshal(config, &s.config) | ||||
| 		if err != nil { | ||||
| 		d := json.NewDecoder(bytes.NewReader(config)) | ||||
| 		d.DisallowUnknownFields() | ||||
| 		if err := d.Decode(&s.config); err != nil { | ||||
| 			cclog.ComponentError(s.name, "Error reading config:", err.Error()) | ||||
| 			return nil, err | ||||
| 		} | ||||
| 	} | ||||
|   | ||||
| @@ -1,6 +1,7 @@ | ||||
| package sinks | ||||
|  | ||||
| import ( | ||||
| 	"bytes" | ||||
| 	"context" | ||||
| 	"crypto/tls" | ||||
| 	"encoding/json" | ||||
| @@ -364,9 +365,11 @@ func NewInfluxSink(name string, config json.RawMessage) (Sink, error) { | ||||
|  | ||||
| 	// Read config | ||||
| 	if len(config) > 0 { | ||||
| 		err := json.Unmarshal(config, &s.config) | ||||
| 		if err != nil { | ||||
| 			return s, err | ||||
| 		d := json.NewDecoder(bytes.NewReader(config)) | ||||
| 		d.DisallowUnknownFields() | ||||
| 		if err := d.Decode(&s.config); err != nil { | ||||
| 			cclog.ComponentError(s.name, "Error reading config:", err.Error()) | ||||
| 			return nil, err | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
|   | ||||
| @@ -66,6 +66,7 @@ void Ganglia_pool_destroy( Ganglia_pool pool ); | ||||
| import "C" | ||||
|  | ||||
| import ( | ||||
| 	"bytes" | ||||
| 	"encoding/json" | ||||
| 	"errors" | ||||
| 	"fmt" | ||||
| @@ -233,8 +234,9 @@ func NewLibgangliaSink(name string, config json.RawMessage) (Sink, error) { | ||||
| 	s.config.GmondConfig = string(GMOND_CONFIG_FILE) | ||||
| 	s.config.GangliaLib = string(GANGLIA_LIB_NAME) | ||||
| 	if len(config) > 0 { | ||||
| 		err = json.Unmarshal(config, &s.config) | ||||
| 		if err != nil { | ||||
| 		d := json.NewDecoder(bytes.NewReader(config)) | ||||
| 		d.DisallowUnknownFields() | ||||
| 		if err := d.Decode(&s.config); err != nil { | ||||
| 			cclog.ComponentError(s.name, "Error reading config:", err.Error()) | ||||
| 			return nil, err | ||||
| 		} | ||||
|   | ||||
| @@ -108,9 +108,10 @@ func NewNatsSink(name string, config json.RawMessage) (Sink, error) { | ||||
| 	s.name = fmt.Sprintf("NatsSink(%s)", name) | ||||
| 	s.flushDelay = 10 * time.Second | ||||
| 	if len(config) > 0 { | ||||
| 		err := json.Unmarshal(config, &s.config) | ||||
| 		if err != nil { | ||||
| 			cclog.ComponentError(s.name, "Error reading config for", s.name, ":", err.Error()) | ||||
| 		d := json.NewDecoder(bytes.NewReader(config)) | ||||
| 		d.DisallowUnknownFields() | ||||
| 		if err := d.Decode(&s.config); err != nil { | ||||
| 			cclog.ComponentError(s.name, "Error reading config:", err.Error()) | ||||
| 			return nil, err | ||||
| 		} | ||||
| 	} | ||||
|   | ||||
| @@ -1,6 +1,7 @@ | ||||
| package sinks | ||||
|  | ||||
| import ( | ||||
| 	"bytes" | ||||
| 	"context" | ||||
| 	"encoding/json" | ||||
| 	"errors" | ||||
| @@ -167,9 +168,10 @@ func NewPrometheusSink(name string, config json.RawMessage) (Sink, error) { | ||||
| 	s := new(PrometheusSink) | ||||
| 	s.name = "PrometheusSink" | ||||
| 	if len(config) > 0 { | ||||
| 		err := json.Unmarshal(config, &s.config) | ||||
| 		if err != nil { | ||||
| 			cclog.ComponentError(s.name, "Error reading config for", s.name, ":", err.Error()) | ||||
| 		d := json.NewDecoder(bytes.NewReader(config)) | ||||
| 		d.DisallowUnknownFields() | ||||
| 		if err := d.Decode(&s.config); err != nil { | ||||
| 			cclog.ComponentError(s.name, "Error reading config:", err.Error()) | ||||
| 			return nil, err | ||||
| 		} | ||||
| 	} | ||||
|   | ||||
| @@ -1,6 +1,7 @@ | ||||
| package sinks | ||||
|  | ||||
| import ( | ||||
| 	"bytes" | ||||
| 	"encoding/json" | ||||
| 	"fmt" | ||||
| 	"log" | ||||
| @@ -57,8 +58,10 @@ func NewSampleSink(name string, config json.RawMessage) (Sink, error) { | ||||
|  | ||||
| 	// Read in the config JSON | ||||
| 	if len(config) > 0 { | ||||
| 		err := json.Unmarshal(config, &s.config) | ||||
| 		if err != nil { | ||||
| 		d := json.NewDecoder(bytes.NewReader(config)) | ||||
| 		d.DisallowUnknownFields() | ||||
| 		if err := d.Decode(&s.config); err != nil { | ||||
| 			cclog.ComponentError(s.name, "Error reading config:", err.Error()) | ||||
| 			return nil, err | ||||
| 		} | ||||
| 	} | ||||
|   | ||||
| @@ -157,7 +157,7 @@ func (sm *sinkManager) AddOutput(name string, rawConfig json.RawMessage) error { | ||||
| 	} | ||||
| 	s, err := AvailableSinks[sinkConfig.Type](name, rawConfig) | ||||
| 	if err != nil { | ||||
| 		cclog.ComponentError("SinkManager", "SKIP", s.Name(), "initialization failed:", err.Error()) | ||||
| 		cclog.ComponentError("SinkManager", "SKIP", name, "initialization failed:", err.Error()) | ||||
| 		return err | ||||
| 	} | ||||
| 	sm.sinks[name] = s | ||||
|   | ||||
| @@ -1,12 +1,14 @@ | ||||
| package sinks | ||||
|  | ||||
| import ( | ||||
| 	"bytes" | ||||
| 	"encoding/json" | ||||
| 	"fmt" | ||||
| 	"os" | ||||
| 	"strings" | ||||
|  | ||||
| 	//	"time" | ||||
| 	cclog "github.com/ClusterCockpit/cc-metric-collector/pkg/ccLogger" | ||||
| 	lp "github.com/ClusterCockpit/cc-metric-collector/pkg/ccMetric" | ||||
| ) | ||||
|  | ||||
| @@ -42,8 +44,10 @@ func NewStdoutSink(name string, config json.RawMessage) (Sink, error) { | ||||
| 	s := new(StdoutSink) | ||||
| 	s.name = fmt.Sprintf("StdoutSink(%s)", name) | ||||
| 	if len(config) > 0 { | ||||
| 		err := json.Unmarshal(config, &s.config) | ||||
| 		if err != nil { | ||||
| 		d := json.NewDecoder(bytes.NewReader(config)) | ||||
| 		d.DisallowUnknownFields() | ||||
| 		if err := d.Decode(&s.config); err != nil { | ||||
| 			cclog.ComponentError(s.name, "Error reading config:", err.Error()) | ||||
| 			return nil, err | ||||
| 		} | ||||
| 	} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user