feat: publish standalone worker
Separate worker packaging and service lifecycle from the control plane.
Этот коммит содержится в:
14
checks/cwhois/result.go
Обычный файл
14
checks/cwhois/result.go
Обычный файл
@@ -0,0 +1,14 @@
|
||||
// Package cwhois provides functionality.
|
||||
package cwhois
|
||||
|
||||
import (
|
||||
"github.com/glebtv/whois"
|
||||
|
||||
"rsgit.ru/rsmon/rsmon/internal/checkresult"
|
||||
)
|
||||
|
||||
// Result is a result of a check
|
||||
type Result struct {
|
||||
checkresult.CheckResult
|
||||
Raw whois.Result
|
||||
}
|
||||
69
checks/cwhois/whois.go
Обычный файл
69
checks/cwhois/whois.go
Обычный файл
@@ -0,0 +1,69 @@
|
||||
package cwhois
|
||||
|
||||
import (
|
||||
"net"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/glebtv/whois"
|
||||
"github.com/weppos/publicsuffix-go/publicsuffix"
|
||||
|
||||
"rsgit.ru/rsmon/rsmon/app/models"
|
||||
)
|
||||
|
||||
// Perform provides functionality.
|
||||
func Perform(c *models.Check) *Result {
|
||||
result := &Result{}
|
||||
result.State = "FAIL"
|
||||
host := c.Monitor.Host
|
||||
|
||||
if host == "localhost" || strings.HasPrefix(host, "localhost:") {
|
||||
result.Warnings = append(result.Warnings, "WHOIS check not possible for localhost, please disable")
|
||||
return result
|
||||
}
|
||||
|
||||
addr := net.ParseIP(host)
|
||||
if addr != nil {
|
||||
result.Warnings = append(result.Warnings, "WHOIS check not possible for ip address, please disable")
|
||||
return result
|
||||
}
|
||||
|
||||
zname, err := publicsuffix.Domain(host)
|
||||
if err != nil {
|
||||
result.Warnings = append(result.Warnings, "Failed to get public suffix: "+err.Error())
|
||||
zname = host
|
||||
}
|
||||
if zname != host {
|
||||
result.Infos = append(result.Infos, "not top level domain, running WHOIS check for "+zname)
|
||||
}
|
||||
|
||||
start := time.Now()
|
||||
response := whois.Whois(zname)
|
||||
result.Raw = *response
|
||||
result.Error = result.Raw.Error
|
||||
if result.Error == nil {
|
||||
result.State = "OK"
|
||||
}
|
||||
result.Duration = time.Since(start)
|
||||
|
||||
if result.Error != nil {
|
||||
result.State = "ERR"
|
||||
}
|
||||
|
||||
if response.Expires.IsZero() {
|
||||
if result.State == "OK" {
|
||||
result.State = "WARN"
|
||||
}
|
||||
result.Warnings = append(result.Warnings, "unable to get whois expiration for "+host)
|
||||
return result
|
||||
}
|
||||
result.Expires = &response.Expires
|
||||
exp := time.Until(*result.Expires).Hours() / 24
|
||||
|
||||
if exp < 3 {
|
||||
result.State = "WARN"
|
||||
result.Warnings = append(result.Warnings, "Domain expires in a few days")
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
Ссылка в новой задаче
Block a user