From 959d943247286bc99638cc27adf8dcf8eaffa4a1 Mon Sep 17 00:00:00 2001 From: damianoneill Date: Thu, 5 Jul 2018 11:23:25 +0100 Subject: [PATCH] #4 log the request and response payloads to the csv file for review --- action/netconf.go | 21 +++++++++++++++++---- result/result.go | 2 ++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/action/netconf.go b/action/netconf.go index 27b033f..6f5651b 100644 --- a/action/netconf.go +++ b/action/netconf.go @@ -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" ) @@ -56,7 +58,7 @@ 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() @@ -64,9 +66,10 @@ func ExecuteNetconf(tsStart time.Time, cID int, action suite.Action, config *sui 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)) @@ -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 } diff --git a/result/result.go b/result/result.go index aa39c5e..0f13ca3 100644 --- a/result/result.go +++ b/result/result.go @@ -18,6 +18,8 @@ type NetconfResult struct { SessionID int Hostname string Operation string + Request string + Response string When float64 Err string Latency float64