This repository has been archived by the owner on Feb 25, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* remove flags, only support config file * update vendored modules Given we need to pass a password, don't expose it on the command line or in the environment.
- Loading branch information
1 parent
8e577f9
commit 66e215f
Showing
49 changed files
with
12,265 additions
and
346 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
netgear_cm_exporter | ||
/netgear_cm_exporter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
|
||
"github.com/pkg/errors" | ||
yaml "gopkg.in/yaml.v2" | ||
) | ||
|
||
type Modem struct { | ||
Address string `yaml:"address"` | ||
Username string `yaml:"username"` | ||
Password string `yaml:"password"` | ||
} | ||
|
||
type Telemetry struct { | ||
ListenAddress string `yaml:"listen_address"` | ||
MetricsPath string `yaml:"metrics_path"` | ||
} | ||
|
||
type Config struct { | ||
Modem Modem `yaml:"modem"` | ||
Telemetry Telemetry `yaml:"telemetry"` | ||
} | ||
|
||
func NewConfigFromFile(path string) (*Config, error) { | ||
content, err := ioutil.ReadFile(path) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "failed to read config file") | ||
} | ||
|
||
// Setup default config. | ||
config := Config{ | ||
Modem: Modem{ | ||
Address: "192.168.100.1", | ||
Username: "admin", | ||
}, | ||
Telemetry: Telemetry{ | ||
ListenAddress: ":9527", | ||
MetricsPath: "/metrics", | ||
}, | ||
} | ||
|
||
if err := yaml.Unmarshal(content, &config); err != nil { | ||
return nil, errors.Wrap(err, "unable to parse config YAML") | ||
} | ||
|
||
if config.Modem.Password == "" { | ||
return nil, fmt.Errorf("modem password isn't set in config") | ||
} | ||
|
||
return &config, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package main | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
) | ||
|
||
func TestNewConfigFromFile(t *testing.T) { | ||
want := &Config{ | ||
Modem: Modem{ | ||
Address: "192.168.100.1", | ||
Username: "admin", | ||
Password: "foobaz", | ||
}, | ||
Telemetry: Telemetry{ | ||
ListenAddress: ":9527", | ||
MetricsPath: "/metrics", | ||
}, | ||
} | ||
|
||
got, err := NewConfigFromFile("testdata/minimal.yml") | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
if diff := cmp.Diff(want, got); diff != "" { | ||
t.Errorf("config differs (-want, +got): %s", diff) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
modem: | ||
address: 192.168.100.1 | ||
username: admin | ||
password: yourpassword | ||
|
||
telemetry: | ||
listen_address: 127.0.0.1:9527 | ||
metrics_path: /metrics |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
modem: | ||
password: foobaz |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.