File tree 4 files changed +41
-12
lines changed
4 files changed +41
-12
lines changed Original file line number Diff line number Diff line change @@ -117,6 +117,11 @@ by hand. If you need to change it, see
117
117
The default ` snmp.yml ` file covers a variety of common hardware walking them
118
118
using SNMP v2 GETBULK.
119
119
120
+ The ` --config.file ` parameter can be used multiple times to load more than one file.
121
+ It also supports [ glob filename matching] ( https://pkg.go.dev/path/filepath#Glob ) . (i.e. ` snmp*.yml ` )
122
+
123
+ Duplicate ` module ` or ` auth ` entries are treated as invalid and can not be loaded.
124
+
120
125
## Prometheus Configuration
121
126
122
127
The URL params ` target ` , ` auth ` , and ` module ` can be controlled through relabelling.
Original file line number Diff line number Diff line change @@ -16,22 +16,31 @@ package config
16
16
import (
17
17
"fmt"
18
18
"os"
19
+ "path/filepath"
19
20
"regexp"
20
21
"time"
21
22
22
23
"github.com/gosnmp/gosnmp"
23
24
"gopkg.in/yaml.v2"
24
25
)
25
26
26
- func LoadFile (filename string ) (* Config , error ) {
27
- content , err := os .ReadFile (filename )
28
- if err != nil {
29
- return nil , err
30
- }
27
+ func LoadFile (paths []string ) (* Config , error ) {
31
28
cfg := & Config {}
32
- err = yaml .UnmarshalStrict (content , cfg )
33
- if err != nil {
34
- return nil , err
29
+ for _ , p := range paths {
30
+ files , err := filepath .Glob (p )
31
+ if err != nil {
32
+ return nil , err
33
+ }
34
+ for _ , f := range files {
35
+ content , err := os .ReadFile (f )
36
+ if err != nil {
37
+ return nil , err
38
+ }
39
+ err = yaml .UnmarshalStrict (content , cfg )
40
+ if err != nil {
41
+ return nil , err
42
+ }
43
+ }
35
44
}
36
45
return cfg , nil
37
46
}
Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ import (
22
22
23
23
func TestHideConfigSecrets (t * testing.T ) {
24
24
sc := & SafeConfig {}
25
- err := sc .ReloadConfig ("testdata/snmp-auth.yml" )
25
+ err := sc .ReloadConfig ([] string { "testdata/snmp-auth.yml" } )
26
26
if err != nil {
27
27
t .Errorf ("Error loading config %v: %v" , "testdata/snmp-auth.yml" , err )
28
28
}
@@ -41,7 +41,7 @@ func TestHideConfigSecrets(t *testing.T) {
41
41
42
42
func TestLoadConfigWithOverrides (t * testing.T ) {
43
43
sc := & SafeConfig {}
44
- err := sc .ReloadConfig ("testdata/snmp-with-overrides.yml" )
44
+ err := sc .ReloadConfig ([] string { "testdata/snmp-with-overrides.yml" } )
45
45
if err != nil {
46
46
t .Errorf ("Error loading config %v: %v" , "testdata/snmp-with-overrides.yml" , err )
47
47
}
@@ -52,3 +52,18 @@ func TestLoadConfigWithOverrides(t *testing.T) {
52
52
t .Errorf ("Error marshaling config: %v" , err )
53
53
}
54
54
}
55
+
56
+ func TestLoadMultipleConfigs (t * testing.T ) {
57
+ sc := & SafeConfig {}
58
+ configs := []string {"testdata/snmp-auth.yml" , "testdata/snmp-with-overrides.yml" }
59
+ err := sc .ReloadConfig (configs )
60
+ if err != nil {
61
+ t .Errorf ("Error loading configs %v: %v" , configs , err )
62
+ }
63
+ sc .RLock ()
64
+ _ , err = yaml .Marshal (sc .C )
65
+ sc .RUnlock ()
66
+ if err != nil {
67
+ t .Errorf ("Error marshaling config: %v" , err )
68
+ }
69
+ }
Original file line number Diff line number Diff line change @@ -41,7 +41,7 @@ import (
41
41
)
42
42
43
43
var (
44
- configFile = kingpin .Flag ("config.file" , "Path to configuration file." ).Default ("snmp.yml" ).String ()
44
+ configFile = kingpin .Flag ("config.file" , "Path to configuration file." ).Default ("snmp.yml" ).Strings ()
45
45
dryRun = kingpin .Flag ("dry-run" , "Only verify configuration is valid and exit." ).Default ("false" ).Bool ()
46
46
concurrency = kingpin .Flag ("snmp.module-concurrency" , "The number of modules to fetch concurrently per scrape" ).Default ("1" ).Int ()
47
47
metricsPath = kingpin .Flag (
@@ -152,7 +152,7 @@ type SafeConfig struct {
152
152
C * config.Config
153
153
}
154
154
155
- func (sc * SafeConfig ) ReloadConfig (configFile string ) (err error ) {
155
+ func (sc * SafeConfig ) ReloadConfig (configFile [] string ) (err error ) {
156
156
conf , err := config .LoadFile (configFile )
157
157
if err != nil {
158
158
return err
You can’t perform that action at this time.
0 commit comments