diff --git a/crawler/impl/ssh/SSHCrawler.go b/crawler/impl/ssh/SSHCrawler.go new file mode 100644 index 0000000..3510d73 --- /dev/null +++ b/crawler/impl/ssh/SSHCrawler.go @@ -0,0 +1,86 @@ +package ssh + +import ( + "fmt" + "reflect" + + configM "git.loafle.net/overflow/overflow_commons_go/modules/config/model" + "git.loafle.net/overflow/overflow_probe_container_network/crawler" +) + +type SSHCrawler struct { + crawler.Crawlers +} + +func (c *SSHCrawler) Name() string { + return "SSH_CRAWLER" +} + +func (c *SSHCrawler) InternalGet(config *configM.Config) (map[string]string, error) { + + return c.start(config) +} + +func (c *SSHCrawler) start(config *configM.Config) (map[string]string, error) { + ip := config.Target.Connection.IP + port := config.Target.Connection.Port + user := config.Target.Auth["id"].(string) + pw := config.Target.Auth["pw"].(string) + keyFilePathObj := config.Target.Auth["keyFilePath"] + keyFilePath := "" + + if keyFilePathObj != nil { + keyFilePath = keyFilePathObj.(string) + } + + cr, err := crawler.New(ip, port, user, pw, keyFilePath) + + if err != nil { + fmt.Println(err) + } + + var inter crawler.SSHCrawlerModuler + var resultMap map[string]string = make(map[string]string) + var tempMap map[string]string = nil + var temp interface{} = nil + for _, item := range c.Items { + mode := item.QueryInfo.Extend["mode"].(string) + + switch mode { + case "cpu": + inter = stat.CPUStat{} + break + case "mem": + inter = stat.MemStat{} + break + default: + continue + } + + ch := make(chan interface{}) + cr.Process(inter, ch, item) + temp = <-ch + + if reflect.TypeOf(temp).String() == "map[string]string" { + tempMap = temp.(map[string]string) + for k, v := range tempMap { + resultMap[k] = v + } + } else { + var errr error = temp.(error) + + return nil, errr + } + + } + + return &resultMap, nil + +} + +func NewCrawler() crawler.Crawler { + c := &SSHCrawler{} + c.Internal = c + + return c +}