dnsmasq-netbox-connector/internal/healthchecks/healthchecks.go

39 lines
1 KiB
Go
Raw Normal View History

package healthchecks
import (
"context"
"fmt"
"git.faercol.me/faercol/dnsmasq-netbox-connector/internal/config"
go_healthchecks "git.faercol.me/faercol/go-healthchecks"
"github.com/google/uuid"
)
func Start(ctx context.Context, conf config.HealthchecksConfig, clt go_healthchecks.PingClient) (go_healthchecks.Check, error) {
if !conf.Enabled {
return nil, nil
}
runID := uuid.New()
check, err := go_healthchecks.NewSlugCheck(conf.PingKey, "dnsmasq-netbox-connector", true, runID.String())
if err != nil {
return nil, fmt.Errorf("failed to create check: %w", err)
}
return check, clt.ReportStart(ctx, check)
}
func Success(ctx context.Context, conf config.HealthchecksConfig, clt go_healthchecks.PingClient, check go_healthchecks.Check) error {
if !conf.Enabled {
return nil
}
return clt.ReportSuccess(ctx, check)
}
func Failure(ctx context.Context, conf config.HealthchecksConfig, clt go_healthchecks.PingClient, check go_healthchecks.Check, msg string) error {
if !conf.Enabled {
return nil
}
return clt.ReportFailure(ctx, check, msg)
}