From 8f73e25dd7d625f50c68e9f3351a72366fc4cff3 Mon Sep 17 00:00:00 2001 From: crusader Date: Wed, 4 Jul 2018 12:11:33 +0900 Subject: [PATCH] ing --- crawler/ssh/SSHCrawler.go | 89 ++++++++++++++++++--------------------- 1 file changed, 41 insertions(+), 48 deletions(-) diff --git a/crawler/ssh/SSHCrawler.go b/crawler/ssh/SSHCrawler.go index c0114a0..230af7a 100644 --- a/crawler/ssh/SSHCrawler.go +++ b/crawler/ssh/SSHCrawler.go @@ -1,15 +1,8 @@ package ssh import ( - "bufio" - "bytes" - "fmt" - - uuid "github.com/satori/go.uuid" - ocmsc "git.loafle.net/overflow/commons-go/model/sensorconfig" "git.loafle.net/overflow/container_network/crawler/ssh/client" - "git.loafle.net/overflow/container_network/crawler/ssh/parser" crawler "git.loafle.net/overflow/crawler-go" ) @@ -30,59 +23,59 @@ func (c *SSHCrawler) Auth(auth map[string]interface{}) error { } func (c *SSHCrawler) Get(config *ocmsc.SensorConfig) (map[string]string, error) { - sshClient, err := client.New(config.Target) + _, err := client.New(config.Connection) if nil != err { return nil, err } - itemCount := len(config.Items) + // itemCount := len(config.Items.MetaCollectionItems) results := make(map[string]string, 0) - boundary := uuid.NewV4().String() - commands := "" + // boundary := uuid.NewV4().String() + // commands := "" - for i := 0; i < itemCount; i++ { - switch i { - case 0: - commands = config.Items[i].QueryInfo.Query - default: - commands = fmt.Sprintf("%s ; echo \"--%s\" ; %s ", commands, boundary, config.Items[i].QueryInfo.Query) - } - } - commands = fmt.Sprintf("%s ; echo \"--%s--\" ", commands, boundary) + // for i := 0; i < itemCount; i++ { + // switch i { + // case 0: + // commands = config.Items[i].QueryInfo.Query + // default: + // commands = fmt.Sprintf("%s ; echo \"--%s\" ; %s ", commands, boundary, config.Items[i].QueryInfo.Query) + // } + // } + // commands = fmt.Sprintf("%s ; echo \"--%s--\" ", commands, boundary) - buf, err := sshClient.RunCommand(commands) - if nil != err { - return nil, err - } - r := bytes.NewReader(buf) - scanner := bufio.NewScanner(r) + // buf, err := sshClient.RunCommand(commands) + // if nil != err { + // return nil, err + // } + // r := bytes.NewReader(buf) + // scanner := bufio.NewScanner(r) - pScanner := parser.NewParserScanner(scanner, boundary) + // pScanner := parser.NewParserScanner(scanner, boundary) - for i := 0; i < itemCount; i++ { - item := config.Items[i] - mode := item.QueryInfo.Extend["mode"].(string) - p := parser.GetParser(mode) - if nil == p { - return nil, fmt.Errorf("Container: Parser[%s] is not exist", mode) - } + // for i := 0; i < itemCount; i++ { + // item := config.Items[i] + // mode := item.QueryInfo.Extend["mode"].(string) + // p := parser.GetParser(mode) + // if nil == p { + // return nil, fmt.Errorf("Container: Parser[%s] is not exist", mode) + // } - rm, err := p.Parse(pScanner) - if nil != err { - return nil, err - } + // rm, err := p.Parse(pScanner) + // if nil != err { + // return nil, err + // } - if nil != rm { - mm := ocmsc.KeysToMap(item.Keys) - for key, value := range mm { - results[value] = rm[key] - } - } + // if nil != rm { + // mm := ocmsc.KeysToMap(item.Keys) + // for key, value := range mm { + // results[value] = rm[key] + // } + // } - if !pScanner.Clean() { - break - } - } + // if !pScanner.Clean() { + // break + // } + // } return results, nil }