From f2f770904ba6d8a15fb933b043b952077ac2de7e Mon Sep 17 00:00:00 2001 From: Tobias Bauriedel Date: Wed, 14 Feb 2024 15:36:05 +0100 Subject: [PATCH] fix json formatting (#114) --- internal/collection/collection.go | 15 ++------------- modules/icinga2/api.go | 2 +- 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/internal/collection/collection.go b/internal/collection/collection.go index 8e9c62e..1ce75a1 100644 --- a/internal/collection/collection.go +++ b/internal/collection/collection.go @@ -3,7 +3,6 @@ package collection import ( "archive/zip" "bytes" - "encoding/json" "fmt" "io" "strings" @@ -141,18 +140,8 @@ func (c *Collection) AddFileYAML(fileName string, data interface{}) { _ = c.AddFileToOutput(file) } -func (c *Collection) AddFileJSON(fileName string, data interface{}) { - var buf bytes.Buffer - - err := json.NewEncoder(&buf).Encode(&data) - if err != nil { - c.Log.Debugf("could not encode JSON data for '%s': %s", fileName, err) - } - - file := NewFile(fileName) - file.Data = buf.Bytes() - - _ = c.AddFileToOutput(file) +func (c *Collection) AddFileJSON(fileName string, data []byte) { + c.AddFileDataRaw(fileName, data) } func (c *Collection) AddFiles(prefix, source string) { diff --git a/modules/icinga2/api.go b/modules/icinga2/api.go index c831f98..98874f6 100644 --- a/modules/icinga2/api.go +++ b/modules/icinga2/api.go @@ -115,7 +115,7 @@ func collectStatus(endpoint string, c *collection.Collection) error { } // add body to file - c.AddFileJSON(filepath.Join(ModuleName, fmt.Sprintf("api-v1_status_%s.json", extractHostname(endpoint))), string(body)) + c.AddFileJSON(filepath.Join(ModuleName, fmt.Sprintf("api-v1_status_%s.json", extractHostname(endpoint))), body) return nil }