container_network/crawler/ssh/SSHCrawler.go

88 lines
1.9 KiB
Go
Raw Permalink Normal View History

2018-04-19 15:46:38 +00:00
package ssh
import (
2018-04-26 08:50:26 +00:00
ocmsc "git.loafle.net/overflow/commons-go/model/sensorconfig"
2018-04-19 15:46:38 +00:00
"git.loafle.net/overflow/container_network/crawler/ssh/client"
crawler "git.loafle.net/overflow/crawler-go"
)
type SSHCrawler struct {
crawler.Crawler
}
2018-06-21 10:49:14 +00:00
func (c *SSHCrawler) Key() string {
2018-04-20 03:07:24 +00:00
return "SSH"
}
func (c *SSHCrawler) String() string {
return "SSH Crawler"
}
2018-04-23 10:23:29 +00:00
func (c *SSHCrawler) Auth(auth map[string]interface{}) error {
2018-04-20 03:07:24 +00:00
return nil
2018-04-19 15:46:38 +00:00
}
2018-04-26 08:50:26 +00:00
func (c *SSHCrawler) Get(config *ocmsc.SensorConfig) (map[string]string, error) {
2018-07-04 03:11:33 +00:00
_, err := client.New(config.Connection)
2018-04-19 15:46:38 +00:00
if nil != err {
return nil, err
}
2018-07-04 03:11:33 +00:00
// itemCount := len(config.Items.MetaCollectionItems)
2018-04-19 15:46:38 +00:00
results := make(map[string]string, 0)
2018-07-04 03:11:33 +00:00
// 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)
// buf, err := sshClient.RunCommand(commands)
// if nil != err {
// return nil, err
// }
// r := bytes.NewReader(buf)
// scanner := bufio.NewScanner(r)
// 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)
// }
// 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 !pScanner.Clean() {
// break
// }
// }
2018-04-19 15:46:38 +00:00
return results, nil
}
func NewCrawler() crawler.Crawler {
c := &SSHCrawler{}
return c
}