Browse Source

Add additional flag to control the verification of tls connections.

pull/1/head
Christian Fritz 5 years ago
parent
commit
3f6ecd4a81
No known key found for this signature in database GPG Key ID: AB40486FCA9FA29C
  1. 4
      fritzbox_upnp/service.go
  2. 29
      main.go

4
fritzbox_upnp/service.go

@ -493,9 +493,9 @@ func convertResult(val string, arg *Argument) (interface{}, error) {
} }
// Load the services tree from an device. // Load the services tree from an device.
func LoadServices(baseurl string, username string, password string) (*Root, error) { 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 // disable certificate validation, since fritz.box uses self signed cert
http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true} http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
} }

29
main.go

@ -46,9 +46,10 @@ var (
flagAddr = flag.String("listen-address", "127.0.0.1:9042", "The address to listen on for HTTP requests.") flagAddr = flag.String("listen-address", "127.0.0.1:9042", "The address to listen on for HTTP requests.")
flagMetricsFile = flag.String("metrics-file", "metrics.json", "The JSON file with the metric definitions.") flagMetricsFile = flag.String("metrics-file", "metrics.json", "The JSON file with the metric definitions.")
flagGatewayUrl = flag.String("gateway-url", "http://fritz.box:49000", "The URL of the FRITZ!Box") flagGatewayUrl = flag.String("gateway-url", "http://fritz.box:49000", "The URL of the FRITZ!Box")
flagGatewayUsername = flag.String("username", "", "The user for the FRITZ!Box UPnP service") flagGatewayUsername = flag.String("username", "", "The user for the FRITZ!Box UPnP service")
flagGatewayPassword = flag.String("password", "", "The password for the FRITZ!Box UPnP service") flagGatewayPassword = 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 ( var (
@ -89,10 +90,11 @@ type Metric struct {
var metrics []*Metric var metrics []*Metric
type FritzboxCollector struct { type FritzboxCollector struct {
Url string Url string
Gateway string Gateway string
Username string Username string
Password string Password string
VerifyTls bool
sync.Mutex // protects Root sync.Mutex // protects Root
Root *upnp.Root Root *upnp.Root
@ -124,7 +126,7 @@ func (w *TestResponseWriter) String() string {
// LoadServices tries to load the service information. Retries until success. // LoadServices tries to load the service information. Retries until success.
func (fc *FritzboxCollector) LoadServices() { func (fc *FritzboxCollector) LoadServices() {
for { 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 { if err != nil {
fmt.Printf("cannot load services: %s\n", err) fmt.Printf("cannot load services: %s\n", err)
@ -315,7 +317,7 @@ func (fc *FritzboxCollector) Collect(ch chan<- prometheus.Metric) {
} }
func test() { func test() {
root, err := upnp.LoadServices(*flagGatewayUrl, *flagGatewayUsername, *flagGatewayPassword) root, err := upnp.LoadServices(*flagGatewayUrl, *flagGatewayUsername, *flagGatewayPassword, *flagGatewayVerifyTLS)
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -449,10 +451,11 @@ func main() {
} }
collector := &FritzboxCollector{ collector := &FritzboxCollector{
Url: *flagGatewayUrl, Url: *flagGatewayUrl,
Gateway: u.Hostname(), Gateway: u.Hostname(),
Username: *flagGatewayUsername, Username: *flagGatewayUsername,
Password: *flagGatewayPassword, Password: *flagGatewayPassword,
VerifyTls: *flagGatewayVerifyTLS,
} }
if *flagCollect { if *flagCollect {

Loading…
Cancel
Save