Некоторые проверки не удались
CI / test (push) Successful in 2m5s
Docker / Build and publish worker image (push) Failing after 31s
62 строки
1.4 KiB
Go
62 строки
1.4 KiB
Go
package crkn
|
|
|
|
import (
|
|
"errors"
|
|
"time"
|
|
|
|
"rocketgit.ru/rsmon/worker/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")
|
|
}
|
|
}
|