-
Notifications
You must be signed in to change notification settings - Fork 681
Closed
Description
snmp_exporter reads --config.file
or by default snmp.yml
. However, these go via glob expansion. If there are no matching files, then no error is logged and the exporter will run with an empty configuration, which is not useful.
A solution would be to generate a warning when any expansion is empty, and also to abort if the final configuration has no auths or modules.
A simpler solution would be to fail if any glob expansion is empty:
--- a/config/config.go
+++ b/config/config.go
@@ -32,6 +32,9 @@ func LoadFile(paths []string, expandEnvVars bool) (*Config, error) {
if err != nil {
return nil, err
}
+ if len(files) == 0 {
+ return nil, fmt.Errorf("No files matching '%s'", p)
+ }
for _, f := range files {
content, err := os.ReadFile(f)
if err != nil {
However that is not backwards-compatible, e.g. if someone is relying on --config.file=/etc/snmp_exporter.d/*.yml
when that directory may be legitimately empty. (Although the error could be downgraded to a warning if p contains a wildcard character?)
Metadata
Metadata
Assignees
Labels
No labels