From ae24c129c97a3216634e4197c90962549f28aa0d Mon Sep 17 00:00:00 2001 From: Tobias Bauriedel Date: Wed, 14 Feb 2024 15:31:54 +0100 Subject: [PATCH] fix json formatting --- internal/collection/collection.go | 15 ++------------- modules/icinga2/api.go | 3 +-- 2 files changed, 3 insertions(+), 15 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..f9c5a6f 100644 --- a/modules/icinga2/api.go +++ b/modules/icinga2/api.go @@ -115,8 +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 }