Skip to content

Commit

Permalink
Merge pull request #80 from mcktr/feature/debug-mode
Browse files Browse the repository at this point in the history
Add debug mode parameter
  • Loading branch information
mcktr authored May 25, 2020
2 parents 78c6892 + 1aecb85 commit 01228bb
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 17 deletions.
4 changes: 2 additions & 2 deletions cmd/check_fritz/check_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func CheckConnectionStatus(aI ArgumentInformation) {
GlobalReturnCode = exitUnknown
return
}
go fritz.DoSoapRequest(&soapReq, resps, errs)
go fritz.DoSoapRequest(&soapReq, resps, errs, aI.Debug)

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

Expand Down Expand Up @@ -84,7 +84,7 @@ func CheckConnectionUptime(aI ArgumentInformation) {
GlobalReturnCode = exitUnknown
return
}
go fritz.DoSoapRequest(&soapReq, resps, errs)
go fritz.DoSoapRequest(&soapReq, resps, errs, aI.Debug)

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

Expand Down
4 changes: 2 additions & 2 deletions cmd/check_fritz/check_device.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func CheckDeviceUptime(aI ArgumentInformation) {
errs := make(chan error)

soapReq := fritz.CreateNewSoapData(*aI.Username, *aI.Password, *aI.Hostname, *aI.Port, "/upnp/control/deviceinfo", "DeviceInfo", "GetInfo")
go fritz.DoSoapRequest(&soapReq, resps, errs)
go fritz.DoSoapRequest(&soapReq, resps, errs, aI.Debug)

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

Expand Down Expand Up @@ -55,7 +55,7 @@ func CheckDeviceUpdate(aI ArgumentInformation) {
errs := make(chan error)

soapReq := fritz.CreateNewSoapData(*aI.Username, *aI.Password, *aI.Hostname, *aI.Port, "/upnp/control/userif", "UserInterface", "GetInfo")
go fritz.DoSoapRequest(&soapReq, resps, errs)
go fritz.DoSoapRequest(&soapReq, resps, errs, aI.Debug)

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

Expand Down
6 changes: 3 additions & 3 deletions cmd/check_fritz/check_downstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func CheckDownstreamMax(aI ArgumentInformation) {

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)
go fritz.DoSoapRequest(&soapReq, resps, errs, aI.Debug)

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

Expand Down Expand Up @@ -78,7 +78,7 @@ func CheckDownstreamCurrent(aI ArgumentInformation) {

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)
go fritz.DoSoapRequest(&soapReq, resps, errs, aI.Debug)

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

Expand Down Expand Up @@ -141,7 +141,7 @@ func CheckDownstreamUsage(aI ArgumentInformation) {

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)
go fritz.DoSoapRequest(&soapReq, resps, errs, aI.Debug)

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

Expand Down
8 changes: 4 additions & 4 deletions cmd/check_fritz/check_smart.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func CheckSpecificSmartStatus(aI ArgumentInformation) {

soapReq := fritz.CreateNewSoapData(*aI.Username, *aI.Password, *aI.Hostname, *aI.Port, "/upnp/control/x_homeauto", "X_AVM-DE_Homeauto", "GetSpecificDeviceInfos")
soapReq.AddSoapDataVariable(fritz.CreateNewSoapVariable("NewAIN", *aI.InputVariable))
go fritz.DoSoapRequest(&soapReq, resps, errs)
go fritz.DoSoapRequest(&soapReq, resps, errs, aI.Debug)

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

Expand Down Expand Up @@ -59,7 +59,7 @@ func CheckSpecificSmartHeaterTemperatur(aI ArgumentInformation) {

soapReq := fritz.CreateNewSoapData(*aI.Username, *aI.Password, *aI.Hostname, *aI.Port, "/upnp/control/x_homeauto", "X_AVM-DE_Homeauto", "GetSpecificDeviceInfos")
soapReq.AddSoapDataVariable(fritz.CreateNewSoapVariable("NewAIN", *aI.InputVariable))
go fritz.DoSoapRequest(&soapReq, resps, errs)
go fritz.DoSoapRequest(&soapReq, resps, errs, aI.Debug)

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

Expand Down Expand Up @@ -130,7 +130,7 @@ func CheckSpecificSmartSocketPower(aI ArgumentInformation) {

soapReq := fritz.CreateNewSoapData(*aI.Username, *aI.Password, *aI.Hostname, *aI.Port, "/upnp/control/x_homeauto", "X_AVM-DE_Homeauto", "GetSpecificDeviceInfos")
soapReq.AddSoapDataVariable(fritz.CreateNewSoapVariable("NewAIN", *aI.InputVariable))
go fritz.DoSoapRequest(&soapReq, resps, errs)
go fritz.DoSoapRequest(&soapReq, resps, errs, aI.Debug)

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

Expand Down Expand Up @@ -195,7 +195,7 @@ func CheckSpecificSmartSocketEnergy(aI ArgumentInformation) {

soapReq := fritz.CreateNewSoapData(*aI.Username, *aI.Password, *aI.Hostname, *aI.Port, "/upnp/control/x_homeauto", "X_AVM-DE_Homeauto", "GetSpecificDeviceInfos")
soapReq.AddSoapDataVariable(fritz.CreateNewSoapVariable("NewAIN", *aI.InputVariable))
go fritz.DoSoapRequest(&soapReq, resps, errs)
go fritz.DoSoapRequest(&soapReq, resps, errs, aI.Debug)

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

Expand Down
6 changes: 3 additions & 3 deletions cmd/check_fritz/check_upstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func CheckUpstreamMax(aI ArgumentInformation) {

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)
go fritz.DoSoapRequest(&soapReq, resps, errs, aI.Debug)

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

Expand Down Expand Up @@ -78,7 +78,7 @@ func CheckUpstreamCurrent(aI ArgumentInformation) {

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)
go fritz.DoSoapRequest(&soapReq, resps, errs, aI.Debug)

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

Expand Down Expand Up @@ -141,7 +141,7 @@ func CheckUpstreamUsage(aI ArgumentInformation) {

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)
go fritz.DoSoapRequest(&soapReq, resps, errs, aI.Debug)

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

Expand Down
15 changes: 15 additions & 0 deletions cmd/check_fritz/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type ArgumentInformation struct {
InputVariable *string
Timeout *int
Modelgroup *string
Debug bool
}

func createRequiredArgumentInformation(hostname string, port string, username string, password string, method string, timeout int, modelgroup string) ArgumentInformation {
Expand All @@ -45,6 +46,7 @@ func createRequiredArgumentInformation(hostname string, port string, username st
ai.Method = &method
ai.Modelgroup = &modelgroup
ai.Timeout = &timeout
ai.Debug = false

return ai
}
Expand All @@ -61,6 +63,10 @@ func (ai *ArgumentInformation) createInputVariable(v string) {
ai.InputVariable = &v
}

func (ai *ArgumentInformation) setDebugMode() {
ai.Debug = true
}

func printVersion() {
fmt.Println("check_fritz v" + version)
GlobalReturnCode = exitOk
Expand Down Expand Up @@ -136,6 +142,10 @@ func checkMain(c *cli.Context) error {
argInfo.createInputVariable(c.String("ain"))
}

if c.IsSet("debug") {
argInfo.setDebugMode()
}

if !checkRequiredFlags(&argInfo) {
os.Exit(exitUnknown)
}
Expand Down Expand Up @@ -247,6 +257,11 @@ func main() {
Aliases: []string{"c"},
Usage: "Specifies the critical threshold.",
},
&cli.BoolFlag{
Name: "debug",
Aliases: []string{"d"},
Usage: "Outputs debug information",
},
},
}

Expand Down
11 changes: 8 additions & 3 deletions modules/fritz/fritz_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

// DoSoapRequest does two request to authenticate and handle the SOAP request
func DoSoapRequest(soapRequest *SoapData, resps chan<- []byte, errs chan<- error) {
func DoSoapRequest(soapRequest *SoapData, resps chan<- []byte, errs chan<- error, debug bool) {
soapClient := createNewSoapClient()

// prepare first request
Expand Down Expand Up @@ -38,7 +38,9 @@ func DoSoapRequest(soapRequest *SoapData, resps chan<- []byte, errs chan<- error
resp.Body.Close()

// enable this for debug sessions
// fmt.Println(string(body))
if debug {
fmt.Printf("---\nFrist SOAP Response:\n---\n%v\n---\n", string(body))
}

// create immediately a new request with authentication
req, err = newSoapRequest(soapRequest)
Expand Down Expand Up @@ -92,7 +94,10 @@ func DoSoapRequest(soapRequest *SoapData, resps chan<- []byte, errs chan<- error
resp.Body.Close()

// enable this for debug sessions
// fmt.Println(string(body))

if debug {
fmt.Printf("---\nSecond SOAP Response:\n---\n%v\n---\n", string(body))
}

resps <- body
}
Expand Down

0 comments on commit 01228bb

Please sign in to comment.