mirror of
https://github.com/sberk42/fritzbox_exporter.git
synced 2026-02-14 11:49:50 +00:00
Add additional flag to control the verification of tls connections.
This commit is contained in:
@@ -500,10 +500,10 @@ func convertResult(val string, arg *Argument) (interface{}, error) {
|
||||
}
|
||||
}
|
||||
|
||||
// LoadServices load the services tree from an device.
|
||||
func LoadServices(baseurl string, username string, password string) (*Root, error) {
|
||||
// LoadServices loads the services tree from an device.
|
||||
func LoadServices(baseurl string, username string, password string, verifyTls bool) (*Root, error) {
|
||||
|
||||
if strings.HasPrefix(baseurl, "https://") {
|
||||
if !verifyTls && strings.HasPrefix(baseurl, "https://") {
|
||||
// disable certificate validation, since fritz.box uses self signed cert
|
||||
http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
|
||||
}
|
||||
|
||||
9
main.go
9
main.go
@@ -57,6 +57,7 @@ var (
|
||||
flagGatewayLuaURL = flag.String("gateway-luaurl", "http://fritz.box", "The URL of the FRITZ!Box UI")
|
||||
flagUsername = flag.String("username", "", "The user for the FRITZ!Box UPnP service")
|
||||
flagPassword = flag.String("password", "", "The password for the FRITZ!Box UPnP service")
|
||||
flagGatewayVerifyTLS = flag.Bool("verifyTls", false, "Verify the tls connection when connecting to the FRITZ!Box")
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -184,6 +185,7 @@ type FritzboxCollector struct {
|
||||
Gateway string
|
||||
Username string
|
||||
Password string
|
||||
VerifyTls bool
|
||||
|
||||
// support for lua collector
|
||||
LuaSession *lua.LuaSession
|
||||
@@ -219,7 +221,7 @@ func (w *testResponseWriter) String() string {
|
||||
// LoadServices tries to load the service information. Retries until success.
|
||||
func (fc *FritzboxCollector) LoadServices() {
|
||||
for {
|
||||
root, err := upnp.LoadServices(fc.URL, fc.Username, fc.Password)
|
||||
root, err := upnp.LoadServices(fc.URL, fc.Username, fc.Password, fc.VerifyTls)
|
||||
if err != nil {
|
||||
fmt.Printf("cannot load services: %s\n", err)
|
||||
|
||||
@@ -536,7 +538,7 @@ func (fc *FritzboxCollector) reportLuaMetric(ch chan<- prometheus.Metric, lm *Lu
|
||||
}
|
||||
|
||||
func test() {
|
||||
root, err := upnp.LoadServices(*flagGatewayURL, *flagUsername, *flagPassword)
|
||||
root, err := upnp.LoadServices(*flagGatewayURL, *flagUsername, *flagPassword, *flagGatewayVerifyTLS)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -806,8 +808,9 @@ func main() {
|
||||
Gateway: u.Hostname(),
|
||||
Username: *flagUsername,
|
||||
Password: *flagPassword,
|
||||
VerifyTls: *flagGatewayVerifyTLS,
|
||||
|
||||
LuaSession: luaSession,
|
||||
LuaSession: luaSession,
|
||||
LabelRenames: luaLabelRenames,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user