-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Add result_type field to net_response input plugin #2990
Changes from 9 commits
a90f940
59ab761
f3758b9
24d7891
db45f70
ca03c6f
cff126b
f495f08
925eeef
9011ff6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,7 +64,12 @@ func (n *NetResponse) TcpGather() (map[string]interface{}, error) { | |
responseTime := time.Since(start).Seconds() | ||
// Handle error | ||
if err != nil { | ||
return nil, err | ||
if e, ok := err.(net.Error); ok && e.Timeout() { | ||
fields["result_type"] = "timeout" | ||
} else { | ||
fields["result_type"] = "connection_failed" | ||
} | ||
return fields, nil | ||
} | ||
defer conn.Close() | ||
// Send string if needed | ||
|
@@ -87,18 +92,21 @@ func (n *NetResponse) TcpGather() (map[string]interface{}, error) { | |
responseTime = time.Since(start).Seconds() | ||
// Handle error | ||
if err != nil { | ||
fields["string_found"] = false | ||
fields["result_type"] = "string_mismatch" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know I told you to have this be string_mismatch, but I was wrong...it should be read_failed. Sorry. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No worries, will take care of it! |
||
} else { | ||
// Looking for string in answer | ||
RegEx := regexp.MustCompile(`.*` + n.Expect + `.*`) | ||
find := RegEx.FindString(string(data)) | ||
if find != "" { | ||
fields["result_type"] = "success" | ||
fields["string_found"] = true | ||
} else { | ||
fields["result_type"] = "string_mismatch" | ||
fields["string_found"] = false | ||
} | ||
} | ||
|
||
} else { | ||
fields["result_type"] = "success" | ||
} | ||
fields["response_time"] = responseTime | ||
return fields, nil | ||
|
@@ -114,11 +122,16 @@ func (n *NetResponse) UdpGather() (map[string]interface{}, error) { | |
LocalAddr, err := net.ResolveUDPAddr("udp", "127.0.0.1:0") | ||
// Connecting | ||
conn, err := net.DialUDP("udp", LocalAddr, udpAddr) | ||
defer conn.Close() | ||
// Handle error | ||
if err != nil { | ||
return nil, err | ||
if e, ok := err.(net.Error); ok && e.Timeout() { | ||
fields["result_type"] = "timeout" | ||
} else { | ||
fields["result_type"] = "connection_failed" | ||
} | ||
return fields, nil | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it even possible to get in here with UDP? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think so. The more generic "connection_failed" probably makes more sense here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or if the fact that UDP is connectionless is not consistent with such a name, perhaps add a new failure state. What do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be a good starting point to just have |
||
} | ||
defer conn.Close() | ||
// Send string | ||
msg := []byte(n.Send) | ||
conn.Write(msg) | ||
|
@@ -132,14 +145,17 @@ func (n *NetResponse) UdpGather() (map[string]interface{}, error) { | |
responseTime := time.Since(start).Seconds() | ||
// Handle error | ||
if err != nil { | ||
return nil, err | ||
fields["result_type"] = "read_failed" | ||
return fields, nil | ||
} else { | ||
// Looking for string in answer | ||
RegEx := regexp.MustCompile(`.*` + n.Expect + `.*`) | ||
find := RegEx.FindString(string(buf)) | ||
if find != "" { | ||
fields["result_type"] = "success" | ||
fields["string_found"] = true | ||
} else { | ||
fields["result_type"] = "string_mismatch" | ||
fields["string_found"] = false | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we still need this line so we don't change the existing item yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops -- yeah definitely. I'll take care of that.