Initial commit

This commit is contained in:
nemunaire 2026-04-07 14:55:34 +07:00
commit 30d0e73ae7
13 changed files with 1168 additions and 0 deletions

121
checker/definition.go Normal file
View file

@ -0,0 +1,121 @@
// This file is part of the happyDomain (R) project.
// Copyright (c) 2020-2026 happyDomain
// Authors: Pierre-Olivier Mercier, et al.
//
// This program is offered under a commercial and under the AGPL license.
// For commercial licensing, contact us at <contact@happydomain.org>.
//
// For AGPL licensing:
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
package checker
import (
"time"
"git.happydns.org/happyDomain/model"
)
// Definition returns the CheckerDefinition for the dummy checker.
//
// A CheckerDefinition tells happyDomain everything it needs to know about
// your checker: its identity, where it can be applied, what options it
// accepts, what rules it provides, and how often it should run.
func Definition() *happydns.CheckerDefinition {
return &happydns.CheckerDefinition{
// ID is a unique, stable identifier for this checker. It is stored in
// the database, so never change it after release.
ID: "dummy",
// Name is the human-readable label shown in the happyDomain UI.
Name: "Dummy (example)",
// Availability controls where this checker appears in the UI.
// A checker can apply at the domain level, zone level, or service
// level. You can also restrict it to specific service types.
//
// Here we apply it at the domain level, which means users will see
// this checker in the "Domain checks" section and it does not require
// a specific service to be present.
Availability: happydns.CheckerAvailability{
ApplyToDomain: true,
},
// ObservationKeys lists the keys this checker produces. This ties
// the definition to the provider(s) that generate the data.
ObservationKeys: []happydns.ObservationKey{ObservationKeyDummy},
// Options documents what configuration the checker accepts. Options
// are grouped by audience (admin, user, domain, service, run):
//
// - AdminOpts: set once by the happyDomain administrator
// - UserOpts: editable by end-users in the checker settings UI
// - DomainOpts: auto-filled per domain (domain_name, etc.)
// - ServiceOpts: auto-filled per service (the service payload)
// - RunOpts: set at collect-time only (e.g., overrides)
//
// Each option has an Id (used as the key in CheckerOptions), a Type
// for the UI widget, a Label, and optionally a Default value.
Options: happydns.CheckerOptionsDocumentation{
UserOpts: []happydns.CheckerOptionDocumentation{
{
Id: "message",
Type: "string",
Label: "Custom message",
Description: "A message that will be included in the observation data.",
Default: "Hello from the dummy checker!",
},
{
Id: "warningThreshold",
Type: "number",
Label: "Warning threshold (score)",
Description: "If the score drops below this value, the check status becomes Warning.",
Default: float64(50),
},
{
Id: "criticalThreshold",
Type: "number",
Label: "Critical threshold (score)",
Description: "If the score drops below this value, the check status becomes Critical.",
Default: float64(20),
},
},
DomainOpts: []happydns.CheckerOptionDocumentation{
{
Id: "domain_name",
Label: "Domain name",
AutoFill: happydns.AutoFillDomainName,
},
},
},
// Rules lists the evaluation rules provided by this checker. Each
// rule will appear in the UI, and users can enable/disable them
// individually.
Rules: []happydns.CheckRule{
Rule(),
},
// Interval specifies how often the check should run.
Interval: &happydns.CheckIntervalSpec{
Min: 1 * time.Minute,
Max: 1 * time.Hour,
Default: 5 * time.Minute,
},
// HasMetrics indicates that this checker can produce time-series
// metrics (because our provider implements CheckerMetricsReporter).
HasMetrics: true,
}
}