ing
This commit is contained in:
parent
20fddbf86e
commit
5089fc2478
12
Gopkg.lock
generated
12
Gopkg.lock
generated
|
@ -93,7 +93,7 @@
|
||||||
"time/scheduler/storage",
|
"time/scheduler/storage",
|
||||||
"time/scheduler/task"
|
"time/scheduler/task"
|
||||||
]
|
]
|
||||||
revision = "4d4017d214d2a8fdde59d774254f421991fabe7e"
|
revision = "dd4f956c587b1947f84ad5eebd64722b3d6c5224"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
branch = "master"
|
branch = "master"
|
||||||
|
@ -111,7 +111,7 @@
|
||||||
"model/sensorconfig",
|
"model/sensorconfig",
|
||||||
"service/probe"
|
"service/probe"
|
||||||
]
|
]
|
||||||
revision = "904de1632643ddb9c8862cd5bf147570c1a59878"
|
revision = "e2c0324eb632822050f3d0379ddd1a13c2aac2b1"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
branch = "master"
|
branch = "master"
|
||||||
|
@ -169,12 +169,6 @@
|
||||||
revision = "792786c7400a136282c1664665ae0a8db921c6c2"
|
revision = "792786c7400a136282c1664665ae0a8db921c6c2"
|
||||||
version = "v1.0.0"
|
version = "v1.0.0"
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
name = "github.com/satori/go.uuid"
|
|
||||||
packages = ["."]
|
|
||||||
revision = "f58768cc1a7a7e77a3bd49e98cdd21419399b6a3"
|
|
||||||
version = "v1.2.0"
|
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
name = "github.com/stretchr/testify"
|
name = "github.com/stretchr/testify"
|
||||||
packages = ["assert"]
|
packages = ["assert"]
|
||||||
|
@ -238,6 +232,6 @@
|
||||||
[solve-meta]
|
[solve-meta]
|
||||||
analyzer-name = "dep"
|
analyzer-name = "dep"
|
||||||
analyzer-version = 1
|
analyzer-version = 1
|
||||||
inputs-digest = "864e2859063e93659cad5271506583b83051b8b1dc7c605b1a92f0c0e4b5efc4"
|
inputs-digest = "1df87b3131b7fea1a3a94e05b70b99d3c4f2b97eafb773486610e5f83be45a6a"
|
||||||
solver-name = "gps-cdcl"
|
solver-name = "gps-cdcl"
|
||||||
solver-version = 1
|
solver-version = 1
|
||||||
|
|
|
@ -21,7 +21,7 @@ func (s *SocketHealthCrawler) SetMatcher(m cnsm.Matcher) {
|
||||||
s.m = m
|
s.m = m
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SocketHealthCrawler) getConnection(config *ocmsc.SensorConfig) (net.Conn, error) {
|
func (s *SocketHealthCrawler) GetConnection(config *ocmsc.SensorConfig) (net.Conn, error) {
|
||||||
connection := config.Connection
|
connection := config.Connection
|
||||||
metaIPTypeKey := connection.MetaIPTypeKey
|
metaIPTypeKey := connection.MetaIPTypeKey
|
||||||
ip := connection.IP
|
ip := connection.IP
|
||||||
|
@ -73,16 +73,17 @@ func (s *SocketHealthCrawler) getConnection(config *ocmsc.SensorConfig) (net.Con
|
||||||
return conn, nil
|
return conn, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SocketHealthCrawler) CheckHealth(config *ocmsc.SensorConfig) (result map[string]string, err error) {
|
// Duplication Method
|
||||||
result = make(map[string]string, 0)
|
func (s *SocketHealthCrawler) CheckHealth(config *ocmsc.SensorConfig) (map[string]string, error) {
|
||||||
|
result := make(map[string]string, 0)
|
||||||
|
|
||||||
|
conn, cErr := s.GetConnection(config)
|
||||||
|
defer conn.Close()
|
||||||
|
|
||||||
conn, cErr := s.getConnection(config)
|
|
||||||
if cErr != nil {
|
if cErr != nil {
|
||||||
result["Error"] = cErr.Error()
|
result["Error"] = cErr.Error()
|
||||||
err = cErr
|
return result, cErr
|
||||||
return
|
|
||||||
}
|
}
|
||||||
defer conn.Close()
|
|
||||||
|
|
||||||
connection := config.Connection
|
connection := config.Connection
|
||||||
port, _ := cuej.NumberToInt(connection.Port)
|
port, _ := cuej.NumberToInt(connection.Port)
|
||||||
|
@ -97,7 +98,7 @@ func (s *SocketHealthCrawler) CheckHealth(config *ocmsc.SensorConfig) (result ma
|
||||||
if !s.m.Match(info, 0, p) {
|
if !s.m.Match(info, 0, p) {
|
||||||
result["Packet"] = convertBase64(buf)
|
result["Packet"] = convertBase64(buf)
|
||||||
result["Error"] = "Not Matched"
|
result["Error"] = "Not Matched"
|
||||||
return
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < s.m.PacketCount(); i++ {
|
for i := 0; i < s.m.PacketCount(); i++ {
|
||||||
|
@ -114,7 +115,7 @@ func (s *SocketHealthCrawler) CheckHealth(config *ocmsc.SensorConfig) (result ma
|
||||||
if s.m.Match(info, i+1, p) == false {
|
if s.m.Match(info, i+1, p) == false {
|
||||||
result["Packet"] = convertBase64(buf)
|
result["Packet"] = convertBase64(buf)
|
||||||
result["Error"] = "Not Matched"
|
result["Error"] = "Not Matched"
|
||||||
return
|
return result, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,12 +136,73 @@ func (s *SocketHealthCrawler) CheckHealth(config *ocmsc.SensorConfig) (result ma
|
||||||
if s.m.Match(info, i, p) == false {
|
if s.m.Match(info, i, p) == false {
|
||||||
result["Packet"] = convertBase64(buf)
|
result["Packet"] = convertBase64(buf)
|
||||||
result["Error"] = "Not Matched"
|
result["Error"] = "Not Matched"
|
||||||
return
|
return result, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *SocketHealthCrawler) CheckHealth1(config *ocmsc.SensorConfig, conn net.Conn, result map[string]string) (map[string]string, error) {
|
||||||
|
|
||||||
|
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 convertBase64(buf []byte) string {
|
func convertBase64(buf []byte) string {
|
||||||
|
|
|
@ -24,7 +24,18 @@ func (c *SSHHealthCrawler) Auth(auth map[string]interface{}) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *SSHHealthCrawler) Get(config *ocmsc.SensorConfig) (map[string]string, error) {
|
func (c *SSHHealthCrawler) Get(config *ocmsc.SensorConfig) (map[string]string, error) {
|
||||||
rss, err := c.CheckHealth(config)
|
result := make(map[string]string, 0)
|
||||||
|
|
||||||
|
conn, cErr := c.GetConnection(config)
|
||||||
|
defer conn.Close()
|
||||||
|
|
||||||
|
if cErr != nil {
|
||||||
|
result["Error"] = cErr.Error()
|
||||||
|
return result, cErr
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
rss, err := c.CheckHealth1(config, conn, result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user