From 18d5bc4d64dfc9d64aef8dca697aeba576269e03 Mon Sep 17 00:00:00 2001 From: Alex Meijer Date: Fri, 11 Oct 2024 11:27:37 -0400 Subject: [PATCH] [Datadog] fix parsing of prices Signed-off-by: Alex Meijer --- pkg/plugins/datadog/cmd/main/main.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pkg/plugins/datadog/cmd/main/main.go b/pkg/plugins/datadog/cmd/main/main.go index 7ae5b2e..d3253c0 100644 --- a/pkg/plugins/datadog/cmd/main/main.go +++ b/pkg/plugins/datadog/cmd/main/main.go @@ -677,7 +677,7 @@ func scrapeDatadogPrices(url string) (*datadogplugin.PricingInformation, error) } response.Body.Close() res := datadogplugin.DatadogProJSON{} - r := regexp.MustCompile(`var productDetailData = \s*(.*?)\s*;`) + r := regexp.MustCompile(`var productDetailData = \s*(.*?)\s*};`) log.Tracef("got response: %s", string(b)) matches := r.FindAllStringSubmatch(string(b), -1) if len(matches) != 1 { @@ -688,7 +688,8 @@ func scrapeDatadogPrices(url string) (*datadogplugin.PricingInformation, error) } log.Tracef("matches[0][1]:" + matches[0][1]) - err = json.Unmarshal([]byte(matches[0][1]), &res) + // add back in the closing curly brace that was used to pattern match + err = json.Unmarshal([]byte(matches[0][1]+"}"), &res) if err != nil { errTry = err log.Errorf("failed to read pricing page body: %v", err)