test
This commit is contained in:
parent
f040689a24
commit
3228ee9601
|
@ -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 {
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
)
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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",
|
||||
|
|
Loading…
Reference in New Issue
Block a user