diff --git a/crawler/health/SocketHeahthCrawler.go b/crawler/health/SocketHeahthCrawler.go index 6d7f341..e704a41 100644 --- a/crawler/health/SocketHeahthCrawler.go +++ b/crawler/health/SocketHeahthCrawler.go @@ -7,7 +7,6 @@ import ( "net" "os" "syscall" - "time" cnsm "git.loafle.net/commons/service_matcher-go" cuej "git.loafle.net/commons/util-go/encoding/json" @@ -53,9 +52,10 @@ func (s *SocketHealthCrawler) GetConnection(config *ocmsc.SensorConfig) (net.Con } } - conn, err := net.DialTimeout(network, addr, time.Second*5) + conn, err := net.Dial(network, addr) if err != nil { - return nil, err + ee := ToSocketErrorEnum(err) + return nil, fmt.Errorf(ee.String()) } switch metaCryptoTypeKey { @@ -78,6 +78,9 @@ func (s *SocketHealthCrawler) GetConnection(config *ocmsc.SensorConfig) (net.Con } func ToSocketErrorEnum(err error) SocketErrorEnum { + if e, ok := err.(net.Error); ok && e.Timeout() { + return SocketErrorEnumTIMOUT + } n, ok := err.(*net.OpError).Err.(*os.SyscallError).Err.(syscall.Errno) if !ok { return SocketErrorEnumUNKNOWN @@ -90,6 +93,7 @@ func ToSocketErrorEnum(err error) SocketErrorEnum { default: return SocketErrorEnumUNKNOWN } + } func (s *SocketHealthCrawler) CheckHealth(config *ocmsc.SensorConfig, conn net.Conn) error { diff --git a/crawler/health/socket_error.go b/crawler/health/socket_error.go index e47a226..d487d61 100644 --- a/crawler/health/socket_error.go +++ b/crawler/health/socket_error.go @@ -11,6 +11,7 @@ const ( SocketErrorEnumUNKNOWN SocketErrorEnum = iota + 1 SocketErrorEnumHOSTUNREACH SocketErrorEnumCONNREFUSED + SocketErrorEnumTIMOUT ) var ( @@ -18,12 +19,14 @@ var ( SocketErrorEnumUNKNOWN: "UNKNOWN", SocketErrorEnumHOSTUNREACH: "HOSTUNREACH", SocketErrorEnumCONNREFUSED: "CONNREFUSED", + SocketErrorEnumTIMOUT: "TIMEOUT", } socketErrorEnumKey = map[string]SocketErrorEnum{ "UNKNOWN": SocketErrorEnumUNKNOWN, "HOSTUNREACH": SocketErrorEnumHOSTUNREACH, "CONNREFUSED": SocketErrorEnumCONNREFUSED, + "TIMEOUT": SocketErrorEnumTIMOUT, } ) diff --git a/crawler/health/ssh/SSHHealthCrawler.go b/crawler/health/ssh/SSHHealthCrawler.go index e4f6739..b7ac7c1 100644 --- a/crawler/health/ssh/SSHHealthCrawler.go +++ b/crawler/health/ssh/SSHHealthCrawler.go @@ -3,7 +3,6 @@ package ssh import ( "time" - "git.loafle.net/commons/logging-go" cnsms "git.loafle.net/commons/service_matcher-go/ssh" ocmsc "git.loafle.net/overflow/commons-go/model/sensorconfig" "git.loafle.net/overflow/container_network/crawler/health" @@ -29,13 +28,9 @@ func (c *SSHHealthCrawler) Auth(auth map[string]interface{}) error { func (c *SSHHealthCrawler) Get(config *ocmsc.SensorConfig) (map[string]string, error) { result := make(map[string]string, 0) - conn, cErr := c.GetConnection(config) - - if cErr != nil { - sckEnum := health.ToSocketErrorEnum(cErr) - result["ERR"] = sckEnum.String() - logging.Logger().Error("SSHHealthCrawler Connection Error: ", sckEnum.String()) - return result, cErr + conn, err := c.GetConnection(config) + if err != nil { + return nil, err } defer conn.Close() @@ -44,7 +39,7 @@ func (c *SSHHealthCrawler) Get(config *ocmsc.SensorConfig) (map[string]string, e case "service.health.response_time": start := time.Now().UTC() if err := c.CheckHealth(config, conn); err != nil { - result["ERR"] = err.Error() + return nil, err } elapsed := time.Since(start) result[mci.Key] = elapsed.String() diff --git a/crawler/health/ssh/SSHHealthCrawler_test.go b/crawler/health/ssh/SSHHealthCrawler_test.go index d28fcbe..3b886bb 100644 --- a/crawler/health/ssh/SSHHealthCrawler_test.go +++ b/crawler/health/ssh/SSHHealthCrawler_test.go @@ -12,7 +12,7 @@ func TestMatch(t *testing.T) { config := &ocmsc.SensorConfig{} config.Connection = &ocmsc.SensorConfigConnection{ MetaIPTypeKey: "V4", - IP: "192.168.1.111", + IP: "192.168.1.103", MetaPortTypeKey: "TCP", Port: "22", MetaCryptoTypeKey: "SSL",