代码拉取完成,页面将自动刷新
package tcp
import (
"time"
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/outputs/transport"
"github.com/elastic/beats/heartbeat/look"
"github.com/elastic/beats/heartbeat/reason"
)
func pingHost(
dialer transport.Dialer,
host string,
timeout time.Duration,
validator ConnCheck,
) (common.MapStr, error) {
start := time.Now()
deadline := start.Add(timeout)
conn, err := dialer.Dial("tcp", host)
if err != nil {
debugf("dial failed with: %v", err)
return nil, reason.IOFailed(err)
}
defer conn.Close()
if validator == nil {
// no additional validation step => ping success
return common.MapStr{}, nil
}
if err := conn.SetDeadline(deadline); err != nil {
debugf("setting connection deadline failed with: %v", err)
return nil, reason.IOFailed(err)
}
validateStart := time.Now()
err = validator.Validate(conn)
if err != nil && err != errRecvMismatch {
debugf("check failed with: %v", err)
return nil, reason.IOFailed(err)
}
end := time.Now()
event := common.MapStr{
"tcp": common.MapStr{
"rtt": common.MapStr{
"validate": look.RTT(end.Sub(validateStart)),
},
},
}
if err != nil {
event["error"] = reason.FailValidate(err)
}
return event, nil
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。