feat: publish standalone worker
Separate worker packaging and service lifecycle from the control plane.
Этот коммит содержится в:
49
checks/cssh/cssh.go
Обычный файл
49
checks/cssh/cssh.go
Обычный файл
@@ -0,0 +1,49 @@
|
||||
// Package cssh provides functionality.
|
||||
package cssh
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"errors"
|
||||
"net"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"rsgit.ru/rsmon/rsmon/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
|
||||
}
|
||||
10
checks/cssh/result.go
Обычный файл
10
checks/cssh/result.go
Обычный файл
@@ -0,0 +1,10 @@
|
||||
package cssh
|
||||
|
||||
import (
|
||||
"rsgit.ru/rsmon/rsmon/internal/checkresult"
|
||||
)
|
||||
|
||||
// Result is a result of a check
|
||||
type Result struct {
|
||||
checkresult.CheckResult
|
||||
}
|
||||
Ссылка в новой задаче
Block a user