feat: data request with more log outputs
This commit is contained in:
16
http.go
16
http.go
@@ -9,6 +9,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Investigating template
|
// Investigating template
|
||||||
@@ -47,12 +48,19 @@ type HTTPMonitor struct {
|
|||||||
// TODO: test
|
// TODO: test
|
||||||
func (monitor *HTTPMonitor) test() bool {
|
func (monitor *HTTPMonitor) test() bool {
|
||||||
var dataBuffer *bytes.Buffer = nil
|
var dataBuffer *bytes.Buffer = nil
|
||||||
|
var req *http.Request
|
||||||
|
var err error
|
||||||
if monitor.Data != "" {
|
if monitor.Data != "" {
|
||||||
|
fmt.Println("Data: ", monitor.Data)
|
||||||
dataBuffer = bytes.NewBuffer([]byte(monitor.Data))
|
dataBuffer = bytes.NewBuffer([]byte(monitor.Data))
|
||||||
|
req, err = http.NewRequest(monitor.Method, monitor.Target, dataBuffer)
|
||||||
|
} else {
|
||||||
|
req, err = http.NewRequest(monitor.Method, monitor.Target, nil)
|
||||||
}
|
}
|
||||||
|
fmt.Println("Target: ", monitor.Target)
|
||||||
req, err := http.NewRequest(monitor.Method, monitor.Target, dataBuffer)
|
fmt.Println("Target: ", dataBuffer)
|
||||||
for k, v := range monitor.Headers {
|
for k, v := range monitor.Headers {
|
||||||
|
fmt.Println(k, ": ", v)
|
||||||
req.Header.Add(k, v)
|
req.Header.Add(k, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,6 +73,7 @@ func (monitor *HTTPMonitor) test() bool {
|
|||||||
|
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
fmt.Println(err.Error())
|
||||||
monitor.lastFailReason = err.Error()
|
monitor.lastFailReason = err.Error()
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@@ -73,6 +82,7 @@ func (monitor *HTTPMonitor) test() bool {
|
|||||||
|
|
||||||
if monitor.ExpectedStatusCode > 0 && resp.StatusCode != monitor.ExpectedStatusCode {
|
if monitor.ExpectedStatusCode > 0 && resp.StatusCode != monitor.ExpectedStatusCode {
|
||||||
monitor.lastFailReason = "Expected HTTP response status: " + strconv.Itoa(monitor.ExpectedStatusCode) + ", got: " + strconv.Itoa(resp.StatusCode)
|
monitor.lastFailReason = "Expected HTTP response status: " + strconv.Itoa(monitor.ExpectedStatusCode) + ", got: " + strconv.Itoa(resp.StatusCode)
|
||||||
|
fmt.Println(monitor.lastFailReason)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,11 +91,13 @@ func (monitor *HTTPMonitor) test() bool {
|
|||||||
responseBody, err := ioutil.ReadAll(resp.Body)
|
responseBody, err := ioutil.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
monitor.lastFailReason = err.Error()
|
monitor.lastFailReason = err.Error()
|
||||||
|
fmt.Println(err.Error())
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if !monitor.bodyRegexp.Match(responseBody) {
|
if !monitor.bodyRegexp.Match(responseBody) {
|
||||||
monitor.lastFailReason = "Unexpected body: " + string(responseBody) + ".\nExpected to match: " + monitor.ExpectedBody
|
monitor.lastFailReason = "Unexpected body: " + string(responseBody) + ".\nExpected to match: " + monitor.ExpectedBody
|
||||||
|
fmt.Println(monitor.lastFailReason)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user