mirror of
https://github.com/eko/pihole-exporter.git
synced 2024-11-21 11:05:22 +01:00
Removed 'interval' configuration. Add timeout
This commit is contained in:
parent
2a939bf754
commit
4381338fae
@ -31,7 +31,7 @@ type EnvConfig struct {
|
||||
PIHolePassword []string `config:"pihole_password"`
|
||||
PIHoleApiToken []string `config:"pihole_api_token"`
|
||||
Port uint16 `config:"port"`
|
||||
Interval time.Duration `config:"interval"`
|
||||
Timeout time.Duration `config:"timeout"`
|
||||
}
|
||||
|
||||
func getDefaultEnvConfig() *EnvConfig {
|
||||
@ -42,7 +42,7 @@ func getDefaultEnvConfig() *EnvConfig {
|
||||
PIHolePassword: []string{},
|
||||
PIHoleApiToken: []string{},
|
||||
Port: 9617,
|
||||
Interval: 10 * time.Second,
|
||||
Timeout: 5 * time.Second,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -51,7 +51,7 @@ type Client struct {
|
||||
}
|
||||
|
||||
// NewClient method initializes a new PI-Hole client.
|
||||
func NewClient(config *config.Config) *Client {
|
||||
func NewClient(config *config.Config, envConfig *config.EnvConfig) *Client {
|
||||
err := config.Validate()
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
@ -66,6 +66,7 @@ func NewClient(config *config.Config) *Client {
|
||||
CheckRedirect: func(req *http.Request, via []*http.Request) error {
|
||||
return http.ErrUseLastResponse
|
||||
},
|
||||
Timeout: envConfig.Timeout,
|
||||
},
|
||||
Status: make(chan *ClientChannel, 1),
|
||||
}
|
||||
|
6
main.go
6
main.go
@ -20,7 +20,7 @@ func main() {
|
||||
|
||||
serverDead := make(chan struct{})
|
||||
|
||||
clients := buildClients(clientConfigs)
|
||||
clients := buildClients(clientConfigs, envConf)
|
||||
|
||||
s := server.NewServer(envConf.Port, clients)
|
||||
go func() {
|
||||
@ -43,12 +43,12 @@ func main() {
|
||||
log.Println("pihole-exporter HTTP server stopped")
|
||||
}
|
||||
|
||||
func buildClients(clientConfigs []config.Config) []*pihole.Client {
|
||||
func buildClients(clientConfigs []config.Config, envConfig *config.EnvConfig) []*pihole.Client {
|
||||
clients := make([]*pihole.Client, 0, len(clientConfigs))
|
||||
for i := range clientConfigs {
|
||||
clientConfig := &clientConfigs[i]
|
||||
|
||||
client := pihole.NewClient(clientConfig)
|
||||
client := pihole.NewClient(clientConfig, envConfig)
|
||||
clients = append(clients, client)
|
||||
}
|
||||
return clients
|
||||
|
Loading…
Reference in New Issue
Block a user