Skip to content

Commit

Permalink
Merge pull request #97 from mcktr/bugfix/wrong-values-up-downstream
Browse files Browse the repository at this point in the history
Fix wrong values for max down-/upstream
  • Loading branch information
mcktr authored Oct 9, 2020
2 parents 1b4ae72 + e7ccfd0 commit c84a679
Show file tree
Hide file tree
Showing 4 changed files with 238 additions and 22 deletions.
106 changes: 95 additions & 11 deletions cmd/check_fritz/check_downstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,20 @@ func CheckDownstreamMax(aI ArgumentInformation) {
resps := make(chan []byte)
errs := make(chan error)

soapReq := fritz.CreateNewSoapData(*aI.Username, *aI.Password, *aI.Hostname, *aI.Port, "/upnp/control/wancommonifconfig1", "WANCommonInterfaceConfig", "X_AVM-DE_GetOnlineMonitor")
soapReq.AddSoapDataVariable(fritz.CreateNewSoapVariable("NewSyncGroupIndex", "0"))
var soapReq fritz.SoapData

isDSL := false

if strings.ToLower(*aI.Modelgroup) == "dsl" {
isDSL = true
}

if isDSL {
soapReq = fritz.CreateNewSoapData(*aI.Username, *aI.Password, *aI.Hostname, *aI.Port, "/upnp/control/wandslifconfig1", "WANDSLInterfaceConfig", "GetInfo")
} else {
soapReq = fritz.CreateNewSoapData(*aI.Username, *aI.Password, *aI.Hostname, *aI.Port, "/upnp/control/wancommonifconfig1", "WANCommonInterfaceConfig", "GetCommonLinkProperties")
}

go fritz.DoSoapRequest(&soapReq, resps, errs, aI.Debug)

res, err := fritz.ProcessSoapResponse(resps, errs, 1, *aI.Timeout)
Expand All @@ -26,16 +38,40 @@ func CheckDownstreamMax(aI ArgumentInformation) {
return
}

soapResp := fritz.WANCommonInterfaceOnlineMonitorResponse{}
err = fritz.UnmarshalSoapResponse(&soapResp, res)
var downstream float64

downstream, err := strconv.ParseFloat(soapResp.NewMaxDS, 64)
if isDSL {
soapResp := fritz.WANDSLInterfaceGetInfoResponse{}
err = fritz.UnmarshalSoapResponse(&soapResp, res)

if err != nil {
panic(err)
if err != nil {
panic(err)
}

ups, err := strconv.ParseFloat(soapResp.NewDownstreamCurrRate, 64)

if err != nil {
panic(err)
}

downstream = ups / 1000
} else {
soapResp := fritz.WANCommonInterfaceCommonLinkPropertiesResponse{}
err = fritz.UnmarshalSoapResponse(&soapResp, res)

if err != nil {
panic(err)
}

ups, err := strconv.ParseFloat(soapResp.NewLayer1DownstreamMaxBitRate, 64)

if err != nil {
panic(err)
}

downstream = ups / 1000000
}

downstream = downstream * 8 / 1000000
perfData := perfdata.CreatePerformanceData("downstream_max", downstream, "")

GlobalReturnCode = exitOk
Expand Down Expand Up @@ -160,14 +196,62 @@ func CheckDownstreamUsage(aI ArgumentInformation) {
panic(err)
}

downstreamMax, err := strconv.ParseFloat(soapResp.NewMaxDS, 64)
isDSL := false

if strings.ToLower(*aI.Modelgroup) == "dsl" {
isDSL = true
}

if isDSL {
soapReq = fritz.CreateNewSoapData(*aI.Username, *aI.Password, *aI.Hostname, *aI.Port, "/upnp/control/wandslifconfig1", "WANDSLInterfaceConfig", "GetInfo")
} else {
soapReq = fritz.CreateNewSoapData(*aI.Username, *aI.Password, *aI.Hostname, *aI.Port, "/upnp/control/wancommonifconfig1", "WANCommonInterfaceConfig", "GetCommonLinkProperties")
}

go fritz.DoSoapRequest(&soapReq, resps, errs, aI.Debug)

res, err = fritz.ProcessSoapResponse(resps, errs, 1, *aI.Timeout)

if err != nil {
panic(err)
fmt.Printf("UNKNOWN - %s\n", err)
return
}

var downstreamMax float64

if isDSL {
soapResp := fritz.WANDSLInterfaceGetInfoResponse{}
err = fritz.UnmarshalSoapResponse(&soapResp, res)

if err != nil {
panic(err)
}

ups, err := strconv.ParseFloat(soapResp.NewDownstreamCurrRate, 64)

if err != nil {
panic(err)
}

downstreamMax = ups / 1000
} else {
soapResp := fritz.WANCommonInterfaceCommonLinkPropertiesResponse{}
err = fritz.UnmarshalSoapResponse(&soapResp, res)

if err != nil {
panic(err)
}

ups, err := strconv.ParseFloat(soapResp.NewLayer1DownstreamMaxBitRate, 64)

if err != nil {
panic(err)
}

downstreamMax = ups / 1000000
}

downstreamCurrent = downstreamCurrent * 8 / 1000000
downstreamMax = downstreamMax * 8 / 1000000

if downstreamMax == 0 {
fmt.Printf("UNKNOWN - Maximum Downstream is 0\n")
Expand Down
106 changes: 95 additions & 11 deletions cmd/check_fritz/check_upstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,20 @@ func CheckUpstreamMax(aI ArgumentInformation) {
resps := make(chan []byte)
errs := make(chan error)

soapReq := fritz.CreateNewSoapData(*aI.Username, *aI.Password, *aI.Hostname, *aI.Port, "/upnp/control/wancommonifconfig1", "WANCommonInterfaceConfig", "X_AVM-DE_GetOnlineMonitor")
soapReq.AddSoapDataVariable(fritz.CreateNewSoapVariable("NewSyncGroupIndex", "0"))
var soapReq fritz.SoapData

isDSL := false

if strings.ToLower(*aI.Modelgroup) == "dsl" {
isDSL = true
}

if isDSL {
soapReq = fritz.CreateNewSoapData(*aI.Username, *aI.Password, *aI.Hostname, *aI.Port, "/upnp/control/wandslifconfig1", "WANDSLInterfaceConfig", "GetInfo")
} else {
soapReq = fritz.CreateNewSoapData(*aI.Username, *aI.Password, *aI.Hostname, *aI.Port, "/upnp/control/wancommonifconfig1", "WANCommonInterfaceConfig", "GetCommonLinkProperties")
}

go fritz.DoSoapRequest(&soapReq, resps, errs, aI.Debug)

res, err := fritz.ProcessSoapResponse(resps, errs, 1, *aI.Timeout)
Expand All @@ -26,16 +38,40 @@ func CheckUpstreamMax(aI ArgumentInformation) {
return
}

soapResp := fritz.WANCommonInterfaceOnlineMonitorResponse{}
err = fritz.UnmarshalSoapResponse(&soapResp, res)
var upstream float64

upstream, err := strconv.ParseFloat(soapResp.NewMaxUS, 64)
if isDSL {
soapResp := fritz.WANDSLInterfaceGetInfoResponse{}
err = fritz.UnmarshalSoapResponse(&soapResp, res)

if err != nil {
panic(err)
if err != nil {
panic(err)
}

ups, err := strconv.ParseFloat(soapResp.NewUpstreamCurrRate, 64)

if err != nil {
panic(err)
}

upstream = ups / 1000
} else {
soapResp := fritz.WANCommonInterfaceCommonLinkPropertiesResponse{}
err = fritz.UnmarshalSoapResponse(&soapResp, res)

if err != nil {
panic(err)
}

ups, err := strconv.ParseFloat(soapResp.NewLayer1UpstreamMaxBitRate, 64)

if err != nil {
panic(err)
}

upstream = ups / 1000000
}

upstream = upstream * 8 / 1000000
perfData := perfdata.CreatePerformanceData("upstream_max", upstream, "")

GlobalReturnCode = exitOk
Expand Down Expand Up @@ -160,14 +196,62 @@ func CheckUpstreamUsage(aI ArgumentInformation) {
panic(err)
}

upstreamMax, err := strconv.ParseFloat(soapResp.NewMaxUS, 64)
isDSL := false

if strings.ToLower(*aI.Modelgroup) == "dsl" {
isDSL = true
}

if isDSL {
soapReq = fritz.CreateNewSoapData(*aI.Username, *aI.Password, *aI.Hostname, *aI.Port, "/upnp/control/wandslifconfig1", "WANDSLInterfaceConfig", "GetInfo")
} else {
soapReq = fritz.CreateNewSoapData(*aI.Username, *aI.Password, *aI.Hostname, *aI.Port, "/upnp/control/wancommonifconfig1", "WANCommonInterfaceConfig", "GetCommonLinkProperties")
}

go fritz.DoSoapRequest(&soapReq, resps, errs, aI.Debug)

res, err = fritz.ProcessSoapResponse(resps, errs, 1, *aI.Timeout)

if err != nil {
panic(err)
fmt.Printf("UNKNOWN - %s\n", err)
return
}

var upstreamMax float64

if isDSL {
soapResp := fritz.WANDSLInterfaceGetInfoResponse{}
err = fritz.UnmarshalSoapResponse(&soapResp, res)

if err != nil {
panic(err)
}

ups, err := strconv.ParseFloat(soapResp.NewUpstreamCurrRate, 64)

if err != nil {
panic(err)
}

upstreamMax = ups / 1000
} else {
soapResp := fritz.WANCommonInterfaceCommonLinkPropertiesResponse{}
err = fritz.UnmarshalSoapResponse(&soapResp, res)

if err != nil {
panic(err)
}

ups, err := strconv.ParseFloat(soapResp.NewLayer1UpstreamMaxBitRate, 64)

if err != nil {
panic(err)
}

upstreamMax = ups / 1000000
}

upstreamCurrent = upstreamCurrent * 8 / 1000000
upstreamMax = upstreamMax * 8 / 1000000

if upstreamMax == 0 {
fmt.Printf("UNKNOWN - Maximum Downstream is 0\n")
Expand Down
19 changes: 19 additions & 0 deletions doc/upgrading.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,25 @@
The parameter `-i` (`--index`) got removed with the release of v1.2.0. Use the successor `-a` (`--ain`) instead, please
read the upgrading to v1.1.0 for details on how to optain the AIN from the Fritz!Box web interface.

### Downstream and Upstream calculation

A bug was discovered that makes it necessary to provide the `--modelgroup` (short `-M`) parameter to the following
functions, if you use a non DSL Fritz!Box e.g. a Fritz!Box 6591 Cable.

* `downstream_max`
* `downstream_usage`
* `upstream_max`
* `upstream_usage`

_Example:_

```
$ ./check_fritz --password secret --method downstream_usage --modelgroup cable
```

If you are using a DSL Fritz!Box e.g. a Fritz!Box 7490 you don't need to provide the `--modelgroup` parameter because
the default will use `DSL` as modelgroup.

## Upgrading to v1.1.0

### Index parameter
Expand Down
29 changes: 29 additions & 0 deletions modules/fritz/fritz_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,35 @@ type SmartSpecificDeviceInfoResponse struct {
NewHkrComfortTemperature string `xml:"Body>GetSpecificDeviceInfosResponse>NewHkrComfortTemperature"`
}

// WANCommonInterfaceCommonLinkPropertiesResponse is the date structure for responses from GetCommonLinkProperties
type WANCommonInterfaceCommonLinkPropertiesResponse struct {
TR064Response
NewWANAccessType string `xml:"Body>GetCommonLinkPropertiesResponse>GetCommonLinkPropertiesResponse"`
NewLayer1UpstreamMaxBitRate string `xml:"Body>GetCommonLinkPropertiesResponse>NewLayer1UpstreamMaxBitRate"`
NewLayer1DownstreamMaxBitRate string `xml:"Body>GetCommonLinkPropertiesResponse>NewLayer1DownstreamMaxBitRate"`
NewPhysicalLinkStatus string `xml:"Body>GetCommonLinkPropertiesResponse>NewPhysicalLinkStatus"`
}

// WANDSLInterfaceGetInfoResponse is the date structure for responses from GetInfo
type WANDSLInterfaceGetInfoResponse struct {
TR064Response
NewEnable string `xml:"Body>GetInfoResponse>NewEnable"`
NewStatus string `xml:"Body>GetInfoResponse>NewStatus"`
NewDataPath string `xml:"Body>GetInfoResponse>NewDataPath"`
NewUpstreamCurrRate string `xml:"Body>GetInfoResponse>NewUpstreamCurrRate"`
NewDownstreamCurrRate string `xml:"Body>GetInfoResponse>NewDownstreamCurrRate"`
NewUpstreamMaxRate string `xml:"Body>GetInfoResponse>NewUpstreamMaxRate"`
NewDownstreamMaxRate string `xml:"Body>GetInfoResponse>NewDownstreamMaxRate"`
NewUpstreamNoiseMargin string `xml:"Body>GetInfoResponse>NewUpstreamNoiseMargin"`
NewDownstreamNoiseMargin string `xml:"Body>GetInfoResponse>NewDownstreamNoiseMargin"`
NewUpstreamAttenuation string `xml:"Body>GetInfoResponse>NewUpstreamAttenuation"`
NewDownstreamAttenuation string `xml:"Body>GetInfoResponse>NewDownstreamAttenuation"`
NewATURVendor string `xml:"Body>GetInfoResponse>NewATURVendor"`
NewATURCountry string `xml:"Body>GetInfoResponse>NewATURCountry"`
NewUpstreamPower string `xml:"Body>GetInfoResponse>NewUpstreamPower"`
NewDownstreamPower string `xml:"Body>GetInfoResponse>NewDownstreamPower"`
}

// UnmarshalSoapResponse unmarshals the soap response to the data structure
func UnmarshalSoapResponse(resp TR064Response, inputXML [][]byte) error {
for i := range inputXML {
Expand Down

0 comments on commit c84a679

Please sign in to comment.