-
Notifications
You must be signed in to change notification settings - Fork 8
/
main.go
48 lines (38 loc) · 1.04 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"context"
"time"
log "github.com/sirupsen/logrus"
"github.com/camptocamp/prometheus-puppetdb-sd/internal/config"
"github.com/camptocamp/prometheus-puppetdb-sd/internal/outputs"
"github.com/camptocamp/prometheus-puppetdb-sd/internal/puppetdb"
)
var version = "undefined"
func main() {
ctx, cancelFunc := context.WithCancel(context.Background())
defer cancelFunc()
cfg := config.LoadConfig(version)
o, err := outputs.Setup(&cfg.Output)
if err != nil {
log.Fatalf("Failed to setup output: %s", err)
return
}
puppetDBClient, err := puppetdb.NewClient(&cfg.PuppetDB)
if err != nil {
log.Fatalf("Failed to build a PuppetDB client: %s", err)
return
}
for {
scrapeConfigs, err := puppetDBClient.GetScrapeConfigs(&cfg.PrometheusSD)
if err != nil {
log.Errorf("Failed to generate scrape_configs: %s", err)
} else {
err = o.WriteOutput(ctx, scrapeConfigs)
if err != nil {
log.Errorf("Failed to write output: %s", err)
}
}
log.Infof("Sleeping for %v", cfg.Sleep)
time.Sleep(cfg.Sleep)
}
}