50 lines
1.5 KiB
Go
50 lines
1.5 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
|
|
"git.faercol.me/faercol/dnsmasq-netbox-connector/internal/config"
|
|
"git.faercol.me/faercol/dnsmasq-netbox-connector/internal/dnsmasq"
|
|
"git.faercol.me/faercol/dnsmasq-netbox-connector/internal/healthchecks"
|
|
gohealthchecks "git.faercol.me/faercol/go-healthchecks"
|
|
)
|
|
|
|
func main() {
|
|
configPath := "/etc/dnmasq-netbox/config.json"
|
|
|
|
if len(os.Args) > 1 {
|
|
configPath = os.Args[1]
|
|
}
|
|
|
|
conf, err := config.New(configPath)
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, "Failed to read configuration: %s\n", err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
healtchecksClt := gohealthchecks.NewPingClient(conf.HostPingAPI)
|
|
|
|
check, err := healthchecks.Start(context.Background(), conf.HealthchecksConfig, healtchecksClt)
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, "Failed to notify process start: %s\n", err)
|
|
}
|
|
|
|
leases, err := dnsmasq.GetDynamicLeases(conf.LeasesPath, conf.DHCPRangeStart, conf.DHCPRangeEnd)
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, "Failed to parse leases: %s\n", err)
|
|
if err := healthchecks.Failure(context.Background(), conf.HealthchecksConfig, healtchecksClt, check, "failed to parse lease file"); err != nil {
|
|
fmt.Fprintf(os.Stderr, "Failed to notify failure: %s\n", err)
|
|
}
|
|
os.Exit(1)
|
|
}
|
|
|
|
for _, l := range leases {
|
|
fmt.Printf("Got lease %s\n", l)
|
|
}
|
|
|
|
if err := healthchecks.Success(context.Background(), conf.HealthchecksConfig, healtchecksClt, check); err != nil {
|
|
fmt.Fprintf(os.Stderr, "Failed to notify process success: %s\n", err)
|
|
}
|
|
}
|