Merge branch 'main' into fix/readme-accuracy
All checks were successful
check / check (push) Successful in 8s
All checks were successful
check / check (push) Successful in 8s
This commit is contained in:
@@ -204,6 +204,12 @@ the following precedence (highest to lowest):
|
|||||||
| `DNSWATCHER_METRICS_USERNAME` | Basic auth username for /metrics | `""` |
|
| `DNSWATCHER_METRICS_USERNAME` | Basic auth username for /metrics | `""` |
|
||||||
| `DNSWATCHER_METRICS_PASSWORD` | Basic auth password for /metrics | `""` |
|
| `DNSWATCHER_METRICS_PASSWORD` | Basic auth password for /metrics | `""` |
|
||||||
|
|
||||||
|
**`DNSWATCHER_TARGETS` is required.** dnswatcher will refuse to start if no
|
||||||
|
monitoring targets are configured. A monitoring daemon with nothing to monitor
|
||||||
|
is a misconfiguration, so dnswatcher fails fast with a clear error message
|
||||||
|
rather than running silently. Set `DNSWATCHER_TARGETS` to a comma-separated
|
||||||
|
list of DNS names before starting.
|
||||||
|
|
||||||
### Example `.env`
|
### Example `.env`
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
|
|||||||
@@ -23,6 +23,11 @@ const (
|
|||||||
defaultTLSExpiryWarning = 7
|
defaultTLSExpiryWarning = 7
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ErrNoTargets is returned when no monitoring targets are configured.
|
||||||
|
var ErrNoTargets = errors.New(
|
||||||
|
"no monitoring targets configured: set DNSWATCHER_TARGETS environment variable",
|
||||||
|
)
|
||||||
|
|
||||||
// Params contains dependencies for Config.
|
// Params contains dependencies for Config.
|
||||||
type Params struct {
|
type Params struct {
|
||||||
fx.In
|
fx.In
|
||||||
@@ -132,11 +137,9 @@ func buildConfig(
|
|||||||
tlsInterval = defaultTLSInterval
|
tlsInterval = defaultTLSInterval
|
||||||
}
|
}
|
||||||
|
|
||||||
domains, hostnames, err := ClassifyTargets(
|
domains, hostnames, err := parseAndValidateTargets()
|
||||||
parseCSV(viper.GetString("TARGETS")),
|
|
||||||
)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("invalid targets configuration: %w", err)
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg := &Config{
|
cfg := &Config{
|
||||||
@@ -162,6 +165,23 @@ func buildConfig(
|
|||||||
return cfg, nil
|
return cfg, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func parseAndValidateTargets() ([]string, []string, error) {
|
||||||
|
domains, hostnames, err := ClassifyTargets(
|
||||||
|
parseCSV(viper.GetString("TARGETS")),
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, fmt.Errorf(
|
||||||
|
"invalid targets configuration: %w", err,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(domains) == 0 && len(hostnames) == 0 {
|
||||||
|
return nil, nil, ErrNoTargets
|
||||||
|
}
|
||||||
|
|
||||||
|
return domains, hostnames, nil
|
||||||
|
}
|
||||||
|
|
||||||
func parseCSV(input string) []string {
|
func parseCSV(input string) []string {
|
||||||
if input == "" {
|
if input == "" {
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
Reference in New Issue
Block a user