Files
worker/internal/checkexec/exec.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

96 строки
3.5 KiB
Go

// Package checkexec provides DB-free check execution for distributed workers.
// It executes checks without saving results to database or InfluxDB,
// allowing remote workers to report results via API.
package checkexec
import (
"rocketgit.ru/rsmon/worker/app/models"
"rocketgit.ru/rsmon/worker/checks/calls"
"rocketgit.ru/rsmon/worker/checks/cbssl"
"rocketgit.ru/rsmon/worker/checks/cdns"
"rocketgit.ru/rsmon/worker/checks/cftp"
"rocketgit.ru/rsmon/worker/checks/chttp"
"rocketgit.ru/rsmon/worker/checks/cping"
"rocketgit.ru/rsmon/worker/checks/cssh"
"rocketgit.ru/rsmon/worker/checks/cssl"
"rocketgit.ru/rsmon/worker/checks/ctcp"
"rocketgit.ru/rsmon/worker/checks/cudp"
"rocketgit.ru/rsmon/worker/checks/cwhois"
"rocketgit.ru/rsmon/worker/checks/llmhttp"
"rocketgit.ru/rsmon/worker/internal/checkresult"
"rocketgit.ru/rsmon/worker/internal/wire"
)
// ExecutedCheck is the DB-free result of a distributed check execution.
type ExecutedCheck struct {
Result checkresult.CheckResult
Metrics []wire.MetricPoint
}
// Execute runs checks without saving to DB or InfluxDB.
// Results are returned for reporting via API to the control plane.
// This is designed for distributed workers that have no direct DB access.
func Execute(m *models.Monitor, checks []models.Check) []ExecutedCheck {
results := make([]ExecutedCheck, 0, len(checks))
for i := range checks {
c := &checks[i]
c.Monitor = m
switch c.Kind {
case "http":
r := chttp.Perform(c)
results = append(results, executedWithMetric(c, r.CheckResult, r.InfluxTags(*c), r.InfluxFields()))
case "ssl":
r := cssl.Perform(c)
results = append(results, executed(&r.CheckResult))
case "ssh":
r := cssh.Perform(c)
results = append(results, executed(&r.CheckResult))
case "ftp":
r := cftp.Perform(c)
results = append(results, executed(&r.CheckResult))
case "dns":
r := cdns.Perform(c)
results = append(results, executedWithMetric(c, r.CheckResult, r.InfluxTags(*c), r.InfluxFields()))
case "whois":
r := cwhois.Perform(c)
results = append(results, executed(&r.CheckResult))
case "bssl":
r := cbssl.Perform(c)
results = append(results, executedWithMetric(c, r.CheckResult, r.InfluxTags(*c), r.InfluxFields()))
case "llm":
r := calls.Perform(c)
results = append(results, executed(&r.CheckResult))
case "llm-http":
r := llmhttp.Perform(c)
results = append(results, executedWithMetric(c, r.CheckResult, r.InfluxTags(*c), r.InfluxFields()))
case "ping":
r := cping.Perform(c)
results = append(results, executedWithMetric(c, r.CheckResult, r.InfluxTags(*c), r.InfluxFields()))
case "tcp":
r := ctcp.Perform(c)
results = append(results, executedWithMetric(c, r.CheckResult, r.InfluxTags(*c), r.InfluxFields()))
case "udp":
r := cudp.Perform(c)
results = append(results, executedWithMetric(c, r.CheckResult, r.InfluxTags(*c), r.InfluxFields()))
}
// Note: "rkn" checks are intentionally omitted as they are Russia-specific
// regulatory checks that should not run on distributed workers.
}
return results
}
func executed(result *checkresult.CheckResult) ExecutedCheck {
return ExecutedCheck{Result: *result}
}
func executedWithMetric(c *models.Check, result checkresult.CheckResult, tags map[string]string, fields map[string]interface{}) ExecutedCheck { //nolint:gocritic,lll // helper keeps typed check results close to execution
return ExecutedCheck{
Result: result,
Metrics: []wire.MetricPoint{{
Metric: c.MetricName(),
Tags: tags,
Fields: fields,
}},
}
}