-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.go
59 lines (45 loc) · 1.39 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
49
50
51
52
53
54
55
56
57
58
59
package main
import (
"context"
"fmt"
"os"
"github.com/aws/aws-sdk-go/service/rds"
"github.com/go-kit/kit/log"
"gopkg.in/alecthomas/kingpin.v2"
"github.com/prometheus/prometheus/documentation/examples/custom-sd/adapter"
)
var version string
const (
sdName = "RDSSD"
)
var (
a = kingpin.New("RDS SD Usage", "Tool to generate file_sd target files for AWS RDS SD .")
outputFile = a.Flag("output.file", "Output file for file_sd compatible file.").Default("rds_sd.json").String()
refreshInterval = a.Flag("refresh.interval", "Refresh interval to re-read the instance list.").Default("120").Int()
filters = rdsFilters(a.Flag("filters", "The filters for describe-db-instances.").PlaceHolder("Name=NAME,Values=VALUES"))
logger log.Logger
)
type sdConfig struct {
RefreshInterval int
Filters []*rds.Filter
}
func main() {
a.Version(version)
a.HelpFlag.Short('h')
_, err := a.Parse(os.Args[1:])
if err != nil {
fmt.Println("err: ", err)
return
}
logger = log.NewSyncLogger(log.NewLogfmtLogger(os.Stdout))
logger = log.With(logger, "ts", log.DefaultTimestampUTC, "caller", log.DefaultCaller)
ctx := context.Background()
cfg := sdConfig{
RefreshInterval: *refreshInterval,
Filters: *filters,
}
disc, err := newDiscovery(cfg, logger)
sdAdapter := adapter.NewAdapter(ctx, *outputFile, sdName, disc, logger)
sdAdapter.Run()
<-ctx.Done()
}