Skip to content

Commit

Permalink
#4 log the request and response payloads to the csv file for review
Browse files Browse the repository at this point in the history
  • Loading branch information
alrighttheresham committed Jul 5, 2018
1 parent 5a9c8ad commit 959d943
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
21 changes: 17 additions & 4 deletions action/netconf.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"github.com/Juniper/go-netconf/netconf"
"github.com/damianoneill/nc-hammer/result"
"github.com/damianoneill/nc-hammer/suite"
"github.com/tdewolff/minify"
"github.com/tdewolff/minify/xml"
"golang.org/x/crypto/ssh"
)

Expand Down Expand Up @@ -56,17 +58,18 @@ func ExecuteNetconf(tsStart time.Time, cID int, action suite.Action, config *sui
return
}

xml, err := action.Netconf.ToXMLString()
xmlNetconf, err := action.Netconf.ToXMLString()
if err != nil {
fmt.Printf("E")
result.Err = err.Error()
resultChannel <- result
return
}

raw := netconf.RawMethod(xml)
raw := netconf.RawMethod(xmlNetconf)
result.Request = raw.MarshalMethod()
start := time.Now()
_, err = session.Exec(raw)
response, err := session.Exec(raw)
if err != nil {
if err.Error() == "WaitForFunc failed" {
delete(gSessions, strconv.Itoa(cID)+config.Hostname+":"+strconv.Itoa(config.Port))
Expand All @@ -77,10 +80,20 @@ func ExecuteNetconf(tsStart time.Time, cID int, action suite.Action, config *sui
return
}
elapsed := time.Since(start)

result.When = float64(time.Since(tsStart).Nanoseconds() / int64(time.Millisecond))
result.Latency = float64(elapsed.Nanoseconds() / int64(time.Millisecond))

m := minify.New()
m.AddFunc("text/xml", xml.Minify)
minified, err := m.String("text/xml", response.RawReply)
if err != nil {
fmt.Printf("E")
result.Err = err.Error()
resultChannel <- result
return
}
result.Response = minified

resultChannel <- result
}

Expand Down
2 changes: 2 additions & 0 deletions result/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ type NetconfResult struct {
SessionID int
Hostname string
Operation string
Request string
Response string
When float64
Err string
Latency float64
Expand Down

0 comments on commit 959d943

Please sign in to comment.