Files
worker/checks/cssh/cssh.go
Gleb Tv 2c884c5612
Некоторые проверки не удались
CI / test (push) Successful in 2m5s
Docker / Build and publish worker image (push) Failing after 31s
refactor: adopt worker module path
2026-07-13 17:56:12 +03:00

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
}