@@ -2,42 +2,47 @@ package config
22
33import (
44 "encoding/json"
5+ "fmt"
56 "time"
67)
78
89type (
910 Config struct {
10- Azure Azure `yaml :"azure"`
11+ Azure Azure `json :"azure"`
1112 Collectors struct {
12- General CollectorBase `yaml :"general"`
13- Resource CollectorBase `yaml :"resource"`
14- Quota CollectorBase `yaml :"quota"`
15- Defender CollectorBase `yaml :"defender"`
16- ResourceHealth CollectorResourceHealth `yaml :"resourceHealth"`
17- Iam CollectorBase `yaml :"iam"`
18- Graph CollectorGraph `yaml :"graph"`
19- Costs CollectorCosts `yaml :"costs"`
20- Budgets CollectorBudgets `yaml :"budgets"`
21- Reservation CollectorReservation `yaml :"reservation"`
22- Portscan CollectorPortscan `yaml :"portscan"`
23- } `yaml :"collectors"`
13+ General CollectorBase `json :"general"`
14+ Resource CollectorBase `json :"resource"`
15+ Quota CollectorBase `json :"quota"`
16+ Defender CollectorBase `json :"defender"`
17+ ResourceHealth CollectorResourceHealth `json :"resourceHealth"`
18+ Iam CollectorBase `json :"iam"`
19+ Graph CollectorGraph `json :"graph"`
20+ Costs CollectorCosts `json :"costs"`
21+ Budgets CollectorBudgets `json :"budgets"`
22+ Reservation CollectorReservation `json :"reservation"`
23+ Portscan CollectorPortscan `json :"portscan"`
24+ } `json :"collectors"`
2425 }
2526
2627 Azure struct {
27- Subscriptions []string `yaml :"subscriptions"`
28- Locations []string `yaml :"locations"`
28+ Subscriptions []string `json :"subscriptions"`
29+ Locations []string `json :"locations"`
2930
30- ResourceTags []string `yaml :"resourceTags"`
31- ResourceGroupTags []string `yaml :"resourceGroupTags"`
31+ ResourceTags []string `json :"resourceTags"`
32+ ResourceGroupTags []string `json :"resourceGroupTags"`
3233 }
3334
3435 CollectorBase struct {
35- ScrapeTime * time.Duration `yaml :"scrapeTime"`
36+ ScrapeTime * time.Duration `json :"scrapeTime"`
3637 // Cron *string
3738 }
3839)
3940
4041func (c * CollectorBase ) IsEnabled () bool {
42+ if c == nil {
43+ return false
44+ }
45+
4146 return c .ScrapeTime != nil && c .ScrapeTime .Seconds () > 0
4247}
4348
@@ -48,3 +53,22 @@ func (c *Config) GetJson() []byte {
4853 }
4954 return jsonBytes
5055}
56+
57+ func (c * CollectorBase ) UnmarshalJSON (b []byte ) error {
58+ aux := & struct {
59+ ScrapeTime * string `json:"scrapeTime"`
60+ }{}
61+ if err := json .Unmarshal (b , & aux ); err != nil {
62+ return err
63+ }
64+
65+ if aux .ScrapeTime != nil {
66+ scrapeTime , err := time .ParseDuration (* aux .ScrapeTime )
67+ if err != nil {
68+ return fmt .Errorf (`unable to parse "%s" as time.Duration: %w` , * aux .ScrapeTime , err )
69+ }
70+ c .ScrapeTime = & scrapeTime
71+ }
72+
73+ return nil
74+ }
0 commit comments