Files
worker/checks/cwhois/whois.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

70 строки
1.6 KiB
Go

package cwhois
import (
"net"
"strings"
"time"
"github.com/glebtv/whois"
"github.com/weppos/publicsuffix-go/publicsuffix"
"rocketgit.ru/rsmon/worker/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
}