Merge pull request #90 from breed808/env

Read credentials from env variable if not set
This commit is contained in:
Steve Brunton 2021-03-22 22:42:00 -04:00 committed by GitHub
commit 80008f80fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 0 deletions

View File

@ -35,6 +35,14 @@ where `address` is the address of your router. `device` is the label name for th
in the metrics output to prometheus. The `user` and `password` are the ones you
created for the exporter to use to access the API.
User and password flags can be set with the `MIKROTIK_USER` and `MIKROTIK_PASSWORD` environment variables, respectively.
```
MIKROTIK_USER=prometheus
MIKROTIK_PASSWORD=changeme
./mikrotik-exporter -address 10.10.0.1 -device my_router
```
#### Config File
`./mikrotik-exporter -config-file config.yml`

View File

@ -116,6 +116,13 @@ func loadConfigFromFile() (*config.Config, error) {
}
func loadConfigFromFlags() (*config.Config, error) {
// Attempt to read credentials from env if not already defined
if *user == "" {
*user = os.Getenv("MIKROTIK_USER")
}
if *password == "" {
*password = os.Getenv("MIKROTIK_PASSWORD")
}
if *device == "" || *address == "" || *user == "" || *password == "" {
return nil, fmt.Errorf("missing required param for single device configuration")
}