container_network/crawler/health/ssh/SSHHealthCrawler.go

60 lines
1.2 KiB
Go
Raw Normal View History

2018-04-20 00:46:38 +09:00
package ssh
import (
2018-07-04 21:28:28 +09:00
"time"
2018-04-20 00:46:38 +09:00
cnsms "git.loafle.net/commons/service_matcher-go/ssh"
2018-04-26 17:50:26 +09:00
ocmsc "git.loafle.net/overflow/commons-go/model/sensorconfig"
2018-04-20 00:46:38 +09:00
"git.loafle.net/overflow/container_network/crawler/health"
2018-07-04 18:46:27 +09:00
"git.loafle.net/overflow/crawler-go"
2018-04-20 00:46:38 +09:00
)
type SSHHealthCrawler struct {
2018-07-02 20:53:06 +09:00
health.SocketHealthCrawler
2018-04-20 00:46:38 +09:00
}
2018-06-21 19:49:14 +09:00
func (c *SSHHealthCrawler) Key() string {
2018-04-20 12:07:24 +09:00
return "SSH_HEALTH"
}
func (c *SSHHealthCrawler) String() string {
return "SSH Health Crawler"
}
2018-04-23 19:23:29 +09:00
func (c *SSHHealthCrawler) Auth(auth map[string]interface{}) error {
2018-04-20 12:07:24 +09:00
return nil
2018-04-20 00:46:38 +09:00
}
2018-04-26 17:50:26 +09:00
func (c *SSHHealthCrawler) Get(config *ocmsc.SensorConfig) (map[string]string, error) {
2018-07-04 18:31:45 +09:00
result := make(map[string]string, 0)
2018-07-05 12:06:41 +09:00
conn, err := c.GetConnection(config)
if err != nil {
return nil, err
2018-07-04 18:31:45 +09:00
}
2018-07-04 21:50:57 +09:00
defer conn.Close()
2018-07-04 18:31:45 +09:00
2018-07-04 21:28:28 +09:00
for _, mci := range config.MetaCollectionItems {
switch mci.Key {
2018-07-05 14:41:03 +09:00
case "ssh.response_time":
2018-07-04 21:28:28 +09:00
start := time.Now().UTC()
if err := c.CheckHealth(config, conn); err != nil {
2018-07-05 12:06:41 +09:00
return nil, err
2018-07-04 21:28:28 +09:00
}
elapsed := time.Since(start)
result[mci.Key] = elapsed.String()
break
default:
break
}
2018-04-20 00:46:38 +09:00
}
2018-07-04 21:28:28 +09:00
return result, nil
2018-04-20 00:46:38 +09:00
}
func NewCrawler() crawler.Crawler {
c := &SSHHealthCrawler{}
c.SetMatcher(cnsms.NewMatcher())
return c
}