mirror of
https://github.com/nshttpd/mikrotik-exporter.git
synced 2025-01-07 18:38:28 +01:00
Merge pull request #90 from breed808/env
Read credentials from env variable if not set
This commit is contained in:
commit
80008f80fa
@ -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
|
in the metrics output to prometheus. The `user` and `password` are the ones you
|
||||||
created for the exporter to use to access the API.
|
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
|
#### Config File
|
||||||
|
|
||||||
`./mikrotik-exporter -config-file config.yml`
|
`./mikrotik-exporter -config-file config.yml`
|
||||||
|
7
main.go
7
main.go
@ -116,6 +116,13 @@ func loadConfigFromFile() (*config.Config, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func loadConfigFromFlags() (*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 == "" {
|
if *device == "" || *address == "" || *user == "" || *password == "" {
|
||||||
return nil, fmt.Errorf("missing required param for single device configuration")
|
return nil, fmt.Errorf("missing required param for single device configuration")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user