From f040689a243aa252d05e1298eff247eeb03b6e3b Mon Sep 17 00:00:00 2001 From: insanity Date: Wed, 4 Jul 2018 21:50:57 +0900 Subject: [PATCH] ssh health --- crawler/health/SocketHeahthCrawler.go | 71 --------------------- crawler/health/ssh/SSHHealthCrawler.go | 2 +- crawler/health/ssh/SSHHealthCrawler_test.go | 2 +- 3 files changed, 2 insertions(+), 73 deletions(-) diff --git a/crawler/health/SocketHeahthCrawler.go b/crawler/health/SocketHeahthCrawler.go index 829d192..6d7f341 100644 --- a/crawler/health/SocketHeahthCrawler.go +++ b/crawler/health/SocketHeahthCrawler.go @@ -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 { connection := config.Connection diff --git a/crawler/health/ssh/SSHHealthCrawler.go b/crawler/health/ssh/SSHHealthCrawler.go index 0774683..e4f6739 100644 --- a/crawler/health/ssh/SSHHealthCrawler.go +++ b/crawler/health/ssh/SSHHealthCrawler.go @@ -30,7 +30,6 @@ func (c *SSHHealthCrawler) Get(config *ocmsc.SensorConfig) (map[string]string, e result := make(map[string]string, 0) conn, cErr := c.GetConnection(config) - defer conn.Close() if cErr != nil { 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()) return result, cErr } + defer conn.Close() for _, mci := range config.MetaCollectionItems { switch mci.Key { diff --git a/crawler/health/ssh/SSHHealthCrawler_test.go b/crawler/health/ssh/SSHHealthCrawler_test.go index 3b886bb..d28fcbe 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.103", + IP: "192.168.1.111", MetaPortTypeKey: "TCP", Port: "22", MetaCryptoTypeKey: "SSL",