feat: publish standalone worker
Separate worker packaging and service lifecycle from the control plane.
Этот коммит содержится в:
61
checks/crkn/rkn_init.go
Обычный файл
61
checks/crkn/rkn_init.go
Обычный файл
@@ -0,0 +1,61 @@
|
||||
package crkn
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"rsgit.ru/rsmon/rsmon/app/models"
|
||||
)
|
||||
|
||||
// Perform checks if a domain or IP is in the RKN registry
|
||||
func Perform(m *models.Monitor) *Result {
|
||||
result := &Result{}
|
||||
start := time.Now()
|
||||
|
||||
blocked, err := models.IsRknDomainBlocked(m.Host)
|
||||
if err != nil {
|
||||
failResult(err, result, start)
|
||||
return result
|
||||
}
|
||||
if blocked {
|
||||
testResult(true, result, "Domain is contained in RKN registry", start)
|
||||
return result
|
||||
}
|
||||
|
||||
for _, dnsRecord := range m.DNSRecords {
|
||||
if dnsRecord.Kind != "A" && dnsRecord.Kind != "AAAA" {
|
||||
continue
|
||||
}
|
||||
findIP, err := models.IsRknIPBlocked(dnsRecord.Value.Inet.String())
|
||||
if err != nil {
|
||||
failResult(err, result, start)
|
||||
return result
|
||||
}
|
||||
if findIP {
|
||||
testResult(true, result, "IP is contained in RKN registry", start)
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
testResult(false, result, "", start)
|
||||
return result
|
||||
}
|
||||
|
||||
func failResult(err error, result *Result, start time.Time) {
|
||||
result.State = "FAIL"
|
||||
result.Error = err
|
||||
result.Duration = time.Since(start)
|
||||
}
|
||||
|
||||
func testResult(find bool, result *Result, msg string, start time.Time) {
|
||||
if find {
|
||||
result.State = "ERR"
|
||||
result.Error = errors.New(msg)
|
||||
result.Duration = time.Since(start)
|
||||
result.Warnings = append(result.Warnings, "Resource is blocked in Russia according to RKN registry")
|
||||
} else {
|
||||
result.State = "OK"
|
||||
result.Duration = time.Since(start)
|
||||
result.Infos = append(result.Infos, "Resource is not in RKN registry")
|
||||
}
|
||||
}
|
||||
Ссылка в новой задаче
Block a user