@@ -17,6 +17,7 @@ import (
17
17
log "github.com/sirupsen/logrus"
18
18
19
19
"github.com/camptocamp/prometheus-puppetdb/internal/outputs"
20
+ "github.com/camptocamp/prometheus-puppetdb/internal/types"
20
21
)
21
22
22
23
var version = "undefined"
@@ -39,24 +40,6 @@ type Config struct {
39
40
Manpage bool `short:"m" long:"manpage" description:"Output manpage."`
40
41
}
41
42
42
- // Exporter contains exporter targets and labels
43
- type Exporter struct {
44
- URL string
45
- Labels map [string ]string
46
- }
47
-
48
- // Node contains Puppet node informations
49
- type Node struct {
50
- Certname string `json:"certname"`
51
- Exporters map [string ]interface {} `json:"value"`
52
- }
53
-
54
- // StaticConfig contains Prometheus static targets
55
- type StaticConfig struct {
56
- Targets []string `yaml:"targets"`
57
- Labels map [string ]string `yaml:"labels"`
58
- }
59
-
60
43
func loadConfig (version string ) (c Config , err error ) {
61
44
parser := flags .NewParser (& c , flags .Default )
62
45
_ , err = parser .Parse ()
@@ -79,7 +62,7 @@ func loadConfig(version string) (c Config, err error) {
79
62
return
80
63
}
81
64
82
- func getNodes (client * http.Client , puppetdb string , query string ) (nodes []Node , err error ) {
65
+ func getNodes (client * http.Client , puppetdb string , query string ) (nodes []types. Node , err error ) {
83
66
form := strings .NewReader (fmt .Sprintf ("{\" query\" :\" %s\" }" , query ))
84
67
puppetdbURL := fmt .Sprintf ("%s/pdb/query/v4" , puppetdb )
85
68
req , err := http .NewRequest ("POST" , puppetdbURL , form )
@@ -102,8 +85,8 @@ func getNodes(client *http.Client, puppetdb string, query string) (nodes []Node,
102
85
return
103
86
}
104
87
105
- func getTargets () (staticConfigs []StaticConfig , err error ) {
106
- staticConfigs = []StaticConfig {}
88
+ func getTargets () (staticConfigs []types. StaticConfig , err error ) {
89
+ staticConfigs = []types. StaticConfig {}
107
90
108
91
nodes , err := getNodes (client , cfg .PuppetDBURL , cfg .Query )
109
92
if err != nil {
@@ -140,7 +123,7 @@ func getTargets() (staticConfigs []StaticConfig, err error) {
140
123
for k , v := range vt .Labels {
141
124
labels [k ] = v
142
125
}
143
- staticConfig := StaticConfig {
126
+ staticConfig := types. StaticConfig {
144
127
Targets : []string {url .Host },
145
128
Labels : labels ,
146
129
}
@@ -159,31 +142,31 @@ func getTargets() (staticConfigs []StaticConfig, err error) {
159
142
}
160
143
161
144
// Allow backward compatibility (to remove)
162
- func extractTargets (targets interface {}) (t []Exporter , err error ) {
145
+ func extractTargets (targets interface {}) (t []types. Exporter , err error ) {
163
146
switch v := targets .(type ) {
164
147
case string :
165
148
log .Warningf ("Deprecated: target should be a struct Exporter, not a String: %v" , v )
166
- e := Exporter {
149
+ e := types. Exporter {
167
150
URL : v ,
168
151
Labels : make (map [string ]string ),
169
152
}
170
- t = []Exporter {e }
153
+ t = []types. Exporter {e }
171
154
case []interface {}:
172
155
switch v [0 ].(type ) {
173
156
case string :
174
157
log .Warningf ("Deprecated: target should be a struct Exporter, not an Array of Strings: %v" , v )
175
- t = make ([]Exporter , len (v ))
158
+ t = make ([]types. Exporter , len (v ))
176
159
for i := range v {
177
- t [i ] = Exporter {
160
+ t [i ] = types. Exporter {
178
161
URL : v [i ].(string ),
179
162
Labels : make (map [string ]string ),
180
163
}
181
164
}
182
165
case map [string ]interface {}:
183
- t = make ([]Exporter , len (v ))
166
+ t = make ([]types. Exporter , len (v ))
184
167
for i := range v {
185
168
a := v [i ].(map [string ]interface {})
186
- t [i ] = Exporter {
169
+ t [i ] = types. Exporter {
187
170
URL : a ["url" ].(string ),
188
171
Labels : make (map [string ]string ),
189
172
}
0 commit comments