Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query all sync groups on downstream_max/upstream_max #83

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,20 @@ Ensure that you also set the executable bit with `chmod +x check_fritz`.

### Parameter

| Parameter (short) | Parameter (long) | Description |
|-------------------|------------------|---------------------------------------------------------------------------------------------------------------------------------------|
| `-H` | `--hostname` | **Optional.** IP-Address or Hostname of the Fritz!Box. Defaults to `fritz.box`. |
| `-P` | `--port` | **Optional.** Port for TR-064 over SSL. Defaults to `49443`. |
| `-u` | `--username` | **Optional.** Fritz!Box web interface Username for authentication. Defaults to `dslf-config`. |
| `-p` | `--password` | **Required.** Fritz!Box web interface Password for authentication. |
| `-m` | `--method` | **Optional.** Defines the used check method. Defaults to `connection_status`. |
| `-w` | `--warning` | **Optional.** Defines a warning threshold. Defaults to none. |
| `-c` | `--critical` | **Optional.** Defines a critical threshold. Defaults to none. |
| `-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`. |
| Parameter (short) | Parameter (long) | Description |
| ----------------- | -------------------- | ----------------------------------------------------------------------------------------------------------------- |
| `-H` | `--hostname` | **Optional.** IP-Address or Hostname of the Fritz!Box. Defaults to `fritz.box`. |
| `-P` | `--port` | **Optional.** Port for TR-064 over SSL. Defaults to `49443`. |
| `-u` | `--username` | **Optional.** Fritz!Box web interface Username for authentication. Defaults to `dslf-config`. |
| `-p` | `--password` | **Required.** Fritz!Box web interface Password for authentication. |
| `-m` | `--method` | **Optional.** Defines the used check method. Defaults to `connection_status`. |
| `-w` | `--warning` | **Optional.** Defines a warning threshold. Defaults to none. |
| `-c` | `--critical` | **Optional.** Defines a critical threshold. Defaults to none. |
| `-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`. |
| | `--ignoresyncgroups` | **Optional.** Set a ignore list for SyncGroups (separate multiple values by comma (,). |
| `-d` | `--debug` | **Optional.** Enable debug output. |

> **Note:**
>
Expand All @@ -78,7 +80,7 @@ Ensure that you also set the executable bit with `chmod +x check_fritz`.
### Methods

| Name | Description |
|--------------------------|-----------------------------------------------------------------------------|
| ------------------------ | --------------------------------------------------------------------------- |
| `connection_status` | WAN connection status. |
| `connection_uptime` | WAN connection uptime in seconds. |
| `device_uptime` | Device uptime in seconds. |
Expand Down
123 changes: 105 additions & 18 deletions cmd/check_fritz/check_downstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,51 +12,138 @@ import (

// CheckDownstreamMax checks the maximum downstream that is available on this internet connection
func CheckDownstreamMax(aI ArgumentInformation) {
resps := make(chan []byte)
errs := make(chan error)
// First query to collect total number of sync groups
initialResponses := make(chan []byte)
initialErrors := 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"))
go fritz.DoSoapRequest(&soapReq, resps, errs, aI.Debug)

res, err := fritz.ProcessSoapResponse(resps, errs, 1, *aI.Timeout)
initialSoapRequest := fritz.CreateNewSoapData(*aI.Username, *aI.Password, *aI.Hostname, *aI.Port, "/upnp/control/wancommonifconfig1", "WANCommonInterfaceConfig", "X_AVM-DE_GetOnlineMonitor")
initialSoapRequest.AddSoapDataVariable(fritz.CreateNewSoapVariable("NewSyncGroupIndex", "0"))
go fritz.DoSoapRequest(&initialSoapRequest, initialResponses, initialErrors, aI.Debug)

initialResponse, err := fritz.ProcessSoapResponse(initialResponses, initialErrors, 1, *aI.Timeout)
if err != nil {
fmt.Printf("UNKNOWN - %s\n", err)
return
}

soapResp := fritz.WANCommonInterfaceOnlineMonitorResponse{}
err = fritz.UnmarshalSoapResponse(&soapResp, res)
initialSoapResponse := fritz.WANCommonInterfaceOnlineMonitorResponse{}
err = fritz.UnmarshalSoapResponse(&initialSoapResponse, initialResponse)
if err != nil {
fmt.Printf("UNKNOWN - %s\n", err)
return
}

downstream, err := strconv.ParseFloat(soapResp.NewMaxDS, 64)
soapResponses := []fritz.WANCommonInterfaceOnlineMonitorResponse{}
soapResponses = append(soapResponses, initialSoapResponse)

totalNumberSyncGroups, err := strconv.Atoi(initialSoapResponse.NewTotalNumberSyncGroups)
if err != nil {
panic(err)
fmt.Printf("UNKNOWN - %s\n", err)
return
}

downstream = downstream * 8 / 1000000
perfData := perfdata.CreatePerformanceData("downstream_max", downstream, "")
// If there are more sync groups query all other sync groups, starting with the next one
if totalNumberSyncGroups > 1 {
for i := 1; i < totalNumberSyncGroups; i++ {
responses := make(chan []byte)
errors := make(chan error)

soapRequest := initialSoapRequest
soapRequest.AddSoapDataVariable(fritz.CreateNewSoapVariable("NewSyncGroupIndex", strconv.Itoa(i)))

go fritz.DoSoapRequest(&soapRequest, responses, errors, aI.Debug)

response, err := fritz.ProcessSoapResponse(responses, errors, 1, *aI.Timeout)
if err != nil {
fmt.Printf("UNKNOWN - %s\n", err)
return
}

soapResponse := fritz.WANCommonInterfaceOnlineMonitorResponse{}
err = fritz.UnmarshalSoapResponse(&soapResponse, response)
if err != nil {
fmt.Printf("UNKNOWN - %s\n", err)
return
}

soapResponses = append(soapResponses, soapResponse)
}
}

downstreamCombined := 0.0
output := ""
performanceData := []perfdata.PerformanceData{}
GlobalReturnCode = exitOk

for _, r := range soapResponses {
if totalNumberSyncGroups > 1 {
if isInIgnoreList(aI.SyncGroupIgnoreList, r.NewSyncGroupName) {
if aI.Debug {
fmt.Printf("Ignoring sync group '%s' since it is in the ignore list\n", r.NewSyncGroupName)
}

continue
}
} else {
if aI.Debug {
fmt.Printf("The total number of sync groups is > 1, there is noting to ignore\n")
}
}

downstream, err := strconv.ParseFloat(r.NewMaxDS, 64)
if err != nil {
fmt.Printf("UNKNOWN - %s\n", err)
return
}

downstreamCombined += downstream
downstream = downstream * 8 / 1000000

output += fmt.Sprintf(", Downstream SyncGroup '%s': %.2f Mbit/s", r.NewSyncGroupName, downstream)

pd := perfdata.CreatePerformanceData("downstream_max_"+fmt.Sprintf("%s", r.NewSyncGroupName), downstream, "")

if thresholds.IsSet(aI.Warning) {
pd.SetWarning(*aI.Warning)

if thresholds.CheckLower(*aI.Warning, downstream) {
GlobalReturnCode = exitWarning
}
}

if thresholds.IsSet(aI.Critical) {
pd.SetCritical(*aI.Critical)

if thresholds.CheckLower(*aI.Critical, downstream) {
GlobalReturnCode = exitCritical
}
}

performanceData = append(performanceData, *pd)
}

downstreamCombined = downstreamCombined * 8 / 1000000
pdDownstreamCombined := perfdata.CreatePerformanceData("downstream_max", downstreamCombined, "")

if thresholds.IsSet(aI.Warning) {
perfData.SetWarning(*aI.Warning)
pdDownstreamCombined.SetWarning(*aI.Warning)

if thresholds.CheckLower(*aI.Warning, downstream) {
if thresholds.CheckLower(*aI.Warning, downstreamCombined) {
GlobalReturnCode = exitWarning
}
}

if thresholds.IsSet(aI.Critical) {
perfData.SetCritical(*aI.Critical)
pdDownstreamCombined.SetCritical(*aI.Critical)

if thresholds.CheckLower(*aI.Critical, downstream) {
if thresholds.CheckLower(*aI.Critical, downstreamCombined) {
GlobalReturnCode = exitCritical
}
}

output := " - Max Downstream: " + fmt.Sprintf("%.2f", downstream) + " Mbit/s " + perfData.GetPerformanceDataAsString()
performanceData = append(performanceData, *pdDownstreamCombined)

output = " - Max Downstream: " + fmt.Sprintf("%.2f", downstreamCombined) + " Mbit/s" + output + perfdata.FormatAsString(performanceData)

switch GlobalReturnCode {
case exitOk:
Expand Down
123 changes: 105 additions & 18 deletions cmd/check_fritz/check_upstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,51 +12,138 @@ import (

// CheckUpstreamMax checks the maximum upstream that is available on this internet connection
func CheckUpstreamMax(aI ArgumentInformation) {
resps := make(chan []byte)
errs := make(chan error)
// First query to collect total number of sync groups
initialResponses := make(chan []byte)
initialErrors := 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"))
go fritz.DoSoapRequest(&soapReq, resps, errs, aI.Debug)

res, err := fritz.ProcessSoapResponse(resps, errs, 1, *aI.Timeout)
initialSoapRequest := fritz.CreateNewSoapData(*aI.Username, *aI.Password, *aI.Hostname, *aI.Port, "/upnp/control/wancommonifconfig1", "WANCommonInterfaceConfig", "X_AVM-DE_GetOnlineMonitor")
initialSoapRequest.AddSoapDataVariable(fritz.CreateNewSoapVariable("NewSyncGroupIndex", "0"))
go fritz.DoSoapRequest(&initialSoapRequest, initialResponses, initialErrors, aI.Debug)

initialResponse, err := fritz.ProcessSoapResponse(initialResponses, initialErrors, 1, *aI.Timeout)
if err != nil {
fmt.Printf("UNKNOWN - %s\n", err)
return
}

soapResp := fritz.WANCommonInterfaceOnlineMonitorResponse{}
err = fritz.UnmarshalSoapResponse(&soapResp, res)
initialSoapResponse := fritz.WANCommonInterfaceOnlineMonitorResponse{}
err = fritz.UnmarshalSoapResponse(&initialSoapResponse, initialResponse)
if err != nil {
fmt.Printf("UNKNOWN - %s\n", err)
return
}

upstream, err := strconv.ParseFloat(soapResp.NewMaxUS, 64)
soapResponses := []fritz.WANCommonInterfaceOnlineMonitorResponse{}
soapResponses = append(soapResponses, initialSoapResponse)

totalNumberSyncGroups, err := strconv.Atoi(initialSoapResponse.NewTotalNumberSyncGroups)
if err != nil {
panic(err)
fmt.Printf("UNKNOWN - %s\n", err)
return
}

upstream = upstream * 8 / 1000000
perfData := perfdata.CreatePerformanceData("upstream_max", upstream, "")
// If there are more sync groups query all other sync groups, starting with the next one
if totalNumberSyncGroups > 1 {
for i := 1; i < totalNumberSyncGroups; i++ {
responses := make(chan []byte)
errors := make(chan error)

soapRequest := initialSoapRequest
soapRequest.AddSoapDataVariable(fritz.CreateNewSoapVariable("NewSyncGroupIndex", strconv.Itoa(i)))

go fritz.DoSoapRequest(&soapRequest, responses, errors, aI.Debug)

response, err := fritz.ProcessSoapResponse(responses, errors, 1, *aI.Timeout)
if err != nil {
fmt.Printf("UNKNOWN - %s\n", err)
return
}

soapResponse := fritz.WANCommonInterfaceOnlineMonitorResponse{}
err = fritz.UnmarshalSoapResponse(&soapResponse, response)
if err != nil {
fmt.Printf("UNKNOWN - %s\n", err)
return
}

soapResponses = append(soapResponses, soapResponse)
}
}

upstreamCombined := 0.0
output := ""
performanceData := []perfdata.PerformanceData{}
GlobalReturnCode = exitOk

for _, r := range soapResponses {
if totalNumberSyncGroups > 1 {
if isInIgnoreList(aI.SyncGroupIgnoreList, r.NewSyncGroupName) {
if aI.Debug {
fmt.Printf("Ignoring sync group '%s' since it is in the ignore list\n", r.NewSyncGroupName)
}

continue
}
} else {
if aI.Debug {
fmt.Printf("The total number of sync groups is > 1, there is noting to ignore\n")
}
}

upstream, err := strconv.ParseFloat(r.NewMaxUS, 64)
if err != nil {
fmt.Printf("UNKNOWN - %s\n", err)
return
}

upstreamCombined += upstream
upstream = upstream * 8 / 1000000

output += fmt.Sprintf(", Upstream SyncGroup '%s': %.2f Mbit/s", r.NewSyncGroupName, upstream)

pd := perfdata.CreatePerformanceData("upstream_max_"+fmt.Sprintf("%s", r.NewSyncGroupName), upstream, "")

if thresholds.IsSet(aI.Warning) {
pd.SetWarning(*aI.Warning)

if thresholds.CheckLower(*aI.Warning, upstream) {
GlobalReturnCode = exitWarning
}
}

if thresholds.IsSet(aI.Critical) {
pd.SetCritical(*aI.Critical)

if thresholds.CheckLower(*aI.Critical, upstream) {
GlobalReturnCode = exitCritical
}
}

performanceData = append(performanceData, *pd)
}

upstreamCombined = upstreamCombined * 8 / 1000000
pdUpstreamCombined := perfdata.CreatePerformanceData("upstream_max", upstreamCombined, "")

if thresholds.IsSet(aI.Warning) {
perfData.SetWarning(*aI.Warning)
pdUpstreamCombined.SetWarning(*aI.Warning)

if thresholds.CheckLower(*aI.Warning, upstream) {
if thresholds.CheckLower(*aI.Warning, upstreamCombined) {
GlobalReturnCode = exitWarning
}
}

if thresholds.IsSet(aI.Critical) {
perfData.SetCritical(*aI.Critical)
pdUpstreamCombined.SetCritical(*aI.Critical)

if thresholds.CheckLower(*aI.Critical, upstream) {
if thresholds.CheckLower(*aI.Critical, upstreamCombined) {
GlobalReturnCode = exitCritical
}
}

output := " - Max Upstream: " + fmt.Sprintf("%.2f", upstream) + " Mbit/s " + perfData.GetPerformanceDataAsString()
performanceData = append(performanceData, *pdUpstreamCombined)

output = " - Max Upstream: " + fmt.Sprintf("%.2f", upstreamCombined) + " Mbit/s" + output + perfdata.FormatAsString(performanceData)

switch GlobalReturnCode {
case exitOk:
Expand Down
Loading