-
Notifications
You must be signed in to change notification settings - Fork 18
/
defaults.go
101 lines (81 loc) · 3.35 KB
/
defaults.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
package main
import (
"strings"
"github.com/spf13/viper"
)
const (
// ExporterName name of the exporter
ExporterName = "aci-exporter"
// MetricsPrefix the prefix for all internal metrics
MetricsPrefix = "aci_exporter_"
)
// ExporterNameAsEnv return the ExportName as an env prefix
func ExporterNameAsEnv() string {
return strings.ToUpper(strings.ReplaceAll(ExporterName, "-", "_"))
}
// SetDefaultValues define all default values
func SetDefaultValues() {
// If set as env vars use the ExporterName as prefix like ACI_EXPORTER_PORT for the port var
viper.SetEnvPrefix(ExporterNameAsEnv())
// All fields with . will be replaced with _ for ENV vars
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
viper.AutomaticEnv()
// aci-exporter
viper.SetDefault("port", 9643)
viper.BindEnv("port")
viper.SetDefault("logfile", "")
viper.BindEnv("logfile")
viper.SetDefault("logformat", "json")
viper.BindEnv("logformat")
viper.SetDefault("loglevel", "info")
viper.BindEnv("loglevel")
viper.SetDefault("config", "config")
viper.BindEnv("config")
viper.SetDefault("config_dir", "config.d")
viper.BindEnv("config_dir")
viper.SetDefault("prefix", "aci_")
viper.BindEnv("prefix")
viper.SetDefault("pport", "localhost:6060")
viper.BindEnv("pport")
// If set to true response will always be in openmetrics format
viper.SetDefault("openmetrics", false)
viper.BindEnv("openmetrics")
// HTTPClient - used for connecting to APIC
viper.SetDefault("HTTPClient.timeout", 0)
viper.BindEnv("HTTPClient.timeout")
viper.SetDefault("HTTPClient.keepalive", 15)
viper.BindEnv("HTTPClient.keepalive")
// The page size when using paging
viper.SetDefault("HTTPClient.pagesize", 1000)
viper.BindEnv("HTTPClient.pagesize")
// If parallel paging is enabled the exporter will fetch multiple pages at the same time
viper.SetDefault("HTTPClient.parallel_paging", false)
viper.BindEnv("HTTPClient.parallel_paging")
// This is currently not used
viper.SetDefault("HTTPClient.tlshandshaketimeout", 10)
viper.BindEnv("HTTPClient.tlshandshaketimeout")
viper.SetDefault("HTTPClient.insecureHTTPS", true)
viper.BindEnv("HTTPClient.insecureHTTPS")
// HTTPServer
viper.SetDefault("httpserver.read_timeout", 0)
viper.BindEnv("httpserver.read_timeout")
viper.SetDefault("httpserver.write_timeout", 0)
viper.BindEnv("httpserver.write_timeout")
// Service discovery
viper.SetDefault("service_discovery.labels", []string{"address", "dn", "fabricDomain", "fabricId", "id",
"inbMgmtAddr", "name", "nameAlias", "nodeType", "oobMgmtAddr", "podId", "role", "serial", "siteId", "state",
"version",
})
viper.SetDefault("service_discovery.target_fields", []string{"aci_exporter_fabric", "oobMgmtAddr"})
viper.SetDefault("service_discovery.target_format", "%s#%s")
}