// Package cssh provides functionality. package cssh import ( "bufio" "errors" "net" "strings" "time" "rocketgit.ru/rsmon/worker/app/models" ) const stateERR = "ERR" // Perform provides functionality. func Perform(c *models.Check) *Result { result := &Result{} port := c.GetSettings().Port if port == "" { port = "22" } result.State = "START" client := &net.Dialer{ Timeout: 60 * time.Second, DualStack: true, } start := time.Now() conn, err := client.Dial("tcp", net.JoinHostPort(c.Monitor.Host, port)) if err != nil { result.State = stateERR result.Error = err result.Duration = time.Since(start) return result } result.Duration = time.Since(start) status, err := bufio.NewReader(conn).ReadString('\n') if err != nil { result.State = stateERR result.Error = err } if strings.Contains(status, "SSH") { result.State = "OK" } else { result.State = stateERR result.Error = errors.New("it's not SSH") } return result }