Skip to content

Commit

Permalink
[Datadog] fix price parsing API (#40)
Browse files Browse the repository at this point in the history
* fix harness to support multiple plugins

Signed-off-by: Alex Meijer <[email protected]>

* [Datadog] fix parsing of prices

Signed-off-by: Alex Meijer <[email protected]>

---------

Signed-off-by: Alex Meijer <[email protected]>
  • Loading branch information
ameijer authored Oct 11, 2024
1 parent 779ed10 commit f04fa90
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 f04fa90

Please sign in to comment.