container_network/crawler/health/ssh/SSHHealthCrawler.go
2018-07-04 21:50:57 +09:00

65 lines
1.4 KiB
Go

package ssh
import (
"time"
"git.loafle.net/commons/logging-go"
cnsms "git.loafle.net/commons/service_matcher-go/ssh"
ocmsc "git.loafle.net/overflow/commons-go/model/sensorconfig"
"git.loafle.net/overflow/container_network/crawler/health"
"git.loafle.net/overflow/crawler-go"
)
type SSHHealthCrawler struct {
health.SocketHealthCrawler
}
func (c *SSHHealthCrawler) Key() string {
return "SSH_HEALTH"
}
func (c *SSHHealthCrawler) String() string {
return "SSH Health Crawler"
}
func (c *SSHHealthCrawler) Auth(auth map[string]interface{}) error {
return nil
}
func (c *SSHHealthCrawler) Get(config *ocmsc.SensorConfig) (map[string]string, error) {
result := make(map[string]string, 0)
conn, cErr := c.GetConnection(config)
if cErr != nil {
sckEnum := health.ToSocketErrorEnum(cErr)
result["ERR"] = sckEnum.String()
logging.Logger().Error("SSHHealthCrawler Connection Error: ", sckEnum.String())
return result, cErr
}
defer conn.Close()
for _, mci := range config.MetaCollectionItems {
switch mci.Key {
case "service.health.response_time":
start := time.Now().UTC()
if err := c.CheckHealth(config, conn); err != nil {
result["ERR"] = err.Error()
}
elapsed := time.Since(start)
result[mci.Key] = elapsed.String()
break
default:
break
}
}
return result, nil
}
func NewCrawler() crawler.Crawler {
c := &SSHHealthCrawler{}
c.SetMatcher(cnsms.NewMatcher())
return c
}