From 8c9ede8dab824240c01cfff29195c77870cc96e6 Mon Sep 17 00:00:00 2001 From: Michael Insel Date: Mon, 9 Sep 2019 17:13:11 +0200 Subject: [PATCH 1/4] Implements support for Fritz!Box cable models This implements support for Fritz!Box cable models since they have a slightly different query syntax for some check methods. --- cmd/check_fritz/check_connection.go | 17 ++++++++++++++++- cmd/check_fritz/main.go | 9 +++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/cmd/check_fritz/check_connection.go b/cmd/check_fritz/check_connection.go index e2fc1d3..d8df9c8 100644 --- a/cmd/check_fritz/check_connection.go +++ b/cmd/check_fritz/check_connection.go @@ -3,6 +3,7 @@ package main import ( "fmt" "strconv" + "strings" "github.com/mcktr/check_fritz/modules/fritz" "github.com/mcktr/check_fritz/modules/perfdata" @@ -13,7 +14,21 @@ func CheckConnectionStatus(aI ArgumentInformation) { resps := make(chan []byte) errs := make(chan error) - soapReq := fritz.CreateNewSoapData(*aI.Username, *aI.Password, *aI.Hostname, *aI.Port, "/upnp/control/wanpppconn1", "WANPPPConnection", "GetInfo") + modelgroup := strings.ToLower(*aI.Modelgroup) + + var soapReq fritz.SoapData + + switch modelgroup { + case "dsl": + soapReq = fritz.CreateNewSoapData(*aI.Username, *aI.Password, *aI.Hostname, *aI.Port, "/upnp/control/wanpppconn1", "WANPPPConnection", "GetInfo") + case "cable": + soapReq = fritz.CreateNewSoapData(*aI.Username, *aI.Password, *aI.Hostname, *aI.Port, "/upnp/control/wanipconnection1", "WanIPConnection", "GetInfo") + default: + fmt.Printf("UNKNOWN - Fritz!Box modelgroup '%s' is unknown. Supported modelgroups are: DSL, CABLE\n", modelgroup) + GlobalReturnCode = exitUnknown + return + } + go fritz.DoSoapRequest(&soapReq, resps, errs) res, err := fritz.ProcessSoapResponse(resps, errs, 1, *aI.Timeout) diff --git a/cmd/check_fritz/main.go b/cmd/check_fritz/main.go index d1333c6..17ab755 100644 --- a/cmd/check_fritz/main.go +++ b/cmd/check_fritz/main.go @@ -32,9 +32,10 @@ type ArgumentInformation struct { Index *string InputVariable *string Timeout *int + Modelgroup *string } -func createRequiredArgumentInformation(hostname string, port string, username string, password string, method string, timeout string) ArgumentInformation { +func createRequiredArgumentInformation(hostname string, port string, username string, password string, method string, timeout string, modelgroup string) ArgumentInformation { var ai ArgumentInformation ai.Hostname = &hostname @@ -42,6 +43,7 @@ func createRequiredArgumentInformation(hostname string, port string, username st ai.Username = &username ai.Password = &password ai.Method = &method + ai.Modelgroup = &modelgroup ai.createTimeout(timeout) @@ -135,6 +137,7 @@ func main() { cmdline.AddOption("i", "index", "value", "DEPRECATED: Specifies the index.") cmdline.AddOption("a", "ain", "value", "Specifies the AIN for smart devices.") cmdline.AddOption("t", "timeout", "value", "Specifies the timeout for the request.") + cmdline.AddOption("M", "modelgroup", "value", "Specifies the Fritz!Box model group (DSL or Cable).") cmdline.AddFlag("V", "version", "Returns the version") @@ -143,6 +146,7 @@ func main() { cmdline.SetOptionDefault("username", "dslf-config") cmdline.SetOptionDefault("method", "connection_status") cmdline.SetOptionDefault("timeout", "90") + cmdline.SetOptionDefault("modelgroup", "DSL") cmdline.Parse(os.Args) @@ -156,8 +160,9 @@ func main() { password := cmdline.OptionValue("password") method := cmdline.OptionValue("method") timeout := cmdline.OptionValue("timeout") + modelgroup := cmdline.OptionValue("modelgroup") - aI := createRequiredArgumentInformation(hostname, port, username, password, method, timeout) + aI := createRequiredArgumentInformation(hostname, port, username, password, method, timeout, modelgroup) if cmdline.IsOptionSet("warning") { aI.createWarningThreshold(cmdline.OptionValue("warning")) From f548490097af372f7b060c9a34f5a0d0267b85b8 Mon Sep 17 00:00:00 2001 From: Michael Insel Date: Mon, 9 Sep 2019 17:18:23 +0200 Subject: [PATCH 2/4] Add documentation for --modelgroup parameter --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4ce57d9..f6148bd 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,7 @@ Ensure that you also set the executable bit with `chmod +x check_fritz`. | `-i` | `--index` | **DEPRECATED.** **Optional.** Defines a index value required by some check methods. Defaults to none. _Marked for removal in v1.2.0._ | | `-a` | `--ain` | **Optional.** Defines the AIN required by smart device check methods. Defaults to none. | | `-t` | `--timeout` | **Optional.** Defines the timeout in seconds to wait for an answer from the Fritz!Box. Defaults to `90`. | +| `-M` | `--modelgroup` | **Optional.** Defines the Fritz!Box model group. Supported model groups are `DSL` and `Cable`. Defaults to `DSL`. | > **Note:** > @@ -113,7 +114,8 @@ object CheckCommand "fritz" { "--critical" = "$fritz_critical$" "--index" = "$fritz_index$" "--ain" = "$fritz_ain$" - "--timeout" = "$fritz_timeout" + "--timeout" = "$fritz_timeout$" + "--modelgroup" = "$fritz_modelgroup$" } vars.fritz_hostname = "$address$" From eda8b160f6e4f546c8ca30782c6217ab0aa81333 Mon Sep 17 00:00:00 2001 From: Michael Insel Date: Mon, 9 Sep 2019 17:34:11 +0200 Subject: [PATCH 3/4] Respect also CheckConnectionUptime function --- cmd/check_fritz/check_connection.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/cmd/check_fritz/check_connection.go b/cmd/check_fritz/check_connection.go index d8df9c8..7e8a198 100644 --- a/cmd/check_fritz/check_connection.go +++ b/cmd/check_fritz/check_connection.go @@ -28,7 +28,6 @@ func CheckConnectionStatus(aI ArgumentInformation) { GlobalReturnCode = exitUnknown return } - go fritz.DoSoapRequest(&soapReq, resps, errs) res, err := fritz.ProcessSoapResponse(resps, errs, 1, *aI.Timeout) @@ -71,7 +70,20 @@ func CheckConnectionUptime(aI ArgumentInformation) { resps := make(chan []byte) errs := make(chan error) - soapReq := fritz.CreateNewSoapData(*aI.Username, *aI.Password, *aI.Hostname, *aI.Port, "/upnp/control/wanpppconn1", "WANPPPConnection", "GetInfo") + modelgroup := strings.ToLower(*aI.Modelgroup) + + var soapReq fritz.SoapData + + switch modelgroup { + case "dsl": + soapReq = fritz.CreateNewSoapData(*aI.Username, *aI.Password, *aI.Hostname, *aI.Port, "/upnp/control/wanpppconn1", "WANPPPConnection", "GetInfo") + case "cable": + soapReq = fritz.CreateNewSoapData(*aI.Username, *aI.Password, *aI.Hostname, *aI.Port, "/upnp/control/wanipconnection1", "WanIPConnection", "GetInfo") + default: + fmt.Printf("UNKNOWN - Fritz!Box modelgroup '%s' is unknown. Supported modelgroups are: DSL, CABLE\n", modelgroup) + GlobalReturnCode = exitUnknown + return + } go fritz.DoSoapRequest(&soapReq, resps, errs) res, err := fritz.ProcessSoapResponse(resps, errs, 1, *aI.Timeout) From ab4d0e68ee74eefb315251c97d6552bd35d702f8 Mon Sep 17 00:00:00 2001 From: Michael Insel Date: Mon, 9 Sep 2019 17:37:46 +0200 Subject: [PATCH 4/4] Rename WANPPPConnectionResponse --- cmd/check_fritz/check_connection.go | 4 ++-- modules/fritz/fritz_response.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cmd/check_fritz/check_connection.go b/cmd/check_fritz/check_connection.go index 7e8a198..0607e43 100644 --- a/cmd/check_fritz/check_connection.go +++ b/cmd/check_fritz/check_connection.go @@ -37,7 +37,7 @@ func CheckConnectionStatus(aI ArgumentInformation) { return } - soapResp := fritz.WANPPPConnectionResponse{} + soapResp := fritz.WANConnectionInfoResponse{} err = fritz.UnmarshalSoapResponse(&soapResp, res) if err != nil { @@ -93,7 +93,7 @@ func CheckConnectionUptime(aI ArgumentInformation) { return } - soapResp := fritz.WANPPPConnectionResponse{} + soapResp := fritz.WANConnectionInfoResponse{} err = fritz.UnmarshalSoapResponse(&soapResp, res) if err != nil { diff --git a/modules/fritz/fritz_response.go b/modules/fritz/fritz_response.go index c49b22e..0b1fbee 100644 --- a/modules/fritz/fritz_response.go +++ b/modules/fritz/fritz_response.go @@ -10,8 +10,8 @@ import ( type TR064Response interface { } -// WANPPPConnectionResponse is the data structure for responses from WANPPPConnection -type WANPPPConnectionResponse struct { +// WANConnectionInfoResponse is the data structure for responses from WANPPPConnection +type WANConnectionInfoResponse struct { TR064Response NewEnable string `xml:"Body>GetInfoResponse>NewEnable"` NewConnectionStatus string `xml:"Body>GetInfoResponse>NewConnectionStatus"`