Skip to content

Commit

Permalink
[Datadog] fix parsing of prices
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Meijer <[email protected]>
  • Loading branch information
Alex Meijer committed Oct 11, 2024
1 parent 2684d2e commit 18d5bc4
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pkg/plugins/datadog/cmd/main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down

0 comments on commit 18d5bc4

Please sign in to comment.