Некоторые проверки не удались
CI / test (push) Successful in 2m5s
Docker / Build and publish worker image (push) Failing after 31s
50 строки
971 B
Go
50 строки
971 B
Go
// 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
|
|
}
|