ssh health
This commit is contained in:
parent
f446a71540
commit
f040689a24
|
@ -92,77 +92,6 @@ func ToSocketErrorEnum(err error) SocketErrorEnum {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Duplication Method
|
|
||||||
func (s *SocketHealthCrawler) CheckHealth1(config *ocmsc.SensorConfig) (map[string]string, error) {
|
|
||||||
result := make(map[string]string, 0)
|
|
||||||
|
|
||||||
conn, cErr := s.GetConnection(config)
|
|
||||||
defer conn.Close()
|
|
||||||
|
|
||||||
if cErr != nil {
|
|
||||||
result["Error"] = cErr.Error()
|
|
||||||
return result, cErr
|
|
||||||
}
|
|
||||||
|
|
||||||
connection := config.Connection
|
|
||||||
port, _ := cuej.NumberToInt(connection.Port)
|
|
||||||
info := cnsm.NewMatchInfo(connection.IP, port)
|
|
||||||
|
|
||||||
if s.m.IsPrePacket() {
|
|
||||||
result["PacketType"] = "Pre"
|
|
||||||
|
|
||||||
buf := make([]byte, 1024)
|
|
||||||
n, _ := conn.Read(buf)
|
|
||||||
p := cnsm.NewPacket(buf, n)
|
|
||||||
if !s.m.Match(info, 0, p) {
|
|
||||||
result["Packet"] = convertBase64(buf)
|
|
||||||
result["Error"] = "Not Matched"
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < s.m.PacketCount(); i++ {
|
|
||||||
pack := s.m.Packet(i)
|
|
||||||
conn.Write(pack.Buffer)
|
|
||||||
buf := make([]byte, 1024)
|
|
||||||
n, _ := conn.Read(buf)
|
|
||||||
|
|
||||||
if !s.m.HasResponse(i + 1) { // empty last response
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
p := cnsm.NewPacket(buf, n)
|
|
||||||
if s.m.Match(info, i+1, p) == false {
|
|
||||||
result["Packet"] = convertBase64(buf)
|
|
||||||
result["Error"] = "Not Matched"
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
result["PacketType"] = "Post"
|
|
||||||
|
|
||||||
for i := 0; i < s.m.PacketCount(); i++ {
|
|
||||||
pack := s.m.Packet(i)
|
|
||||||
conn.Write(pack.Buffer)
|
|
||||||
buf := make([]byte, 1024)
|
|
||||||
n, _ := conn.Read(buf)
|
|
||||||
|
|
||||||
if !s.m.HasResponse(i) { // empty last response
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
p := cnsm.NewPacket(buf, n)
|
|
||||||
if s.m.Match(info, i, p) == false {
|
|
||||||
result["Packet"] = convertBase64(buf)
|
|
||||||
result["Error"] = "Not Matched"
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *SocketHealthCrawler) CheckHealth(config *ocmsc.SensorConfig, conn net.Conn) error {
|
func (s *SocketHealthCrawler) CheckHealth(config *ocmsc.SensorConfig, conn net.Conn) error {
|
||||||
|
|
||||||
connection := config.Connection
|
connection := config.Connection
|
||||||
|
|
|
@ -30,7 +30,6 @@ func (c *SSHHealthCrawler) Get(config *ocmsc.SensorConfig) (map[string]string, e
|
||||||
result := make(map[string]string, 0)
|
result := make(map[string]string, 0)
|
||||||
|
|
||||||
conn, cErr := c.GetConnection(config)
|
conn, cErr := c.GetConnection(config)
|
||||||
defer conn.Close()
|
|
||||||
|
|
||||||
if cErr != nil {
|
if cErr != nil {
|
||||||
sckEnum := health.ToSocketErrorEnum(cErr)
|
sckEnum := health.ToSocketErrorEnum(cErr)
|
||||||
|
@ -38,6 +37,7 @@ func (c *SSHHealthCrawler) Get(config *ocmsc.SensorConfig) (map[string]string, e
|
||||||
logging.Logger().Error("SSHHealthCrawler Connection Error: ", sckEnum.String())
|
logging.Logger().Error("SSHHealthCrawler Connection Error: ", sckEnum.String())
|
||||||
return result, cErr
|
return result, cErr
|
||||||
}
|
}
|
||||||
|
defer conn.Close()
|
||||||
|
|
||||||
for _, mci := range config.MetaCollectionItems {
|
for _, mci := range config.MetaCollectionItems {
|
||||||
switch mci.Key {
|
switch mci.Key {
|
||||||
|
|
|
@ -12,7 +12,7 @@ func TestMatch(t *testing.T) {
|
||||||
config := &ocmsc.SensorConfig{}
|
config := &ocmsc.SensorConfig{}
|
||||||
config.Connection = &ocmsc.SensorConfigConnection{
|
config.Connection = &ocmsc.SensorConfigConnection{
|
||||||
MetaIPTypeKey: "V4",
|
MetaIPTypeKey: "V4",
|
||||||
IP: "192.168.1.103",
|
IP: "192.168.1.111",
|
||||||
MetaPortTypeKey: "TCP",
|
MetaPortTypeKey: "TCP",
|
||||||
Port: "22",
|
Port: "22",
|
||||||
MetaCryptoTypeKey: "SSL",
|
MetaCryptoTypeKey: "SSL",
|
||||||
|
|
Loading…
Reference in New Issue
Block a user