Skip to content

Commit

Permalink
add example config file to packages
Browse files Browse the repository at this point in the history
  • Loading branch information
skoef committed Apr 28, 2022
1 parent 3b13f4d commit c62d0a6
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 28 deletions.
33 changes: 19 additions & 14 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,36 @@ nfpms:
license: MIT
contents:
- src: dist/systemd/birdwatcher.service
dst: /lib/system/systemd/birdwatcher.service
dst: /lib/systemd/system/birdwatcher.service
packager: deb
file_info:
owner: root
group: root
mode: 0644
dependencies:
- libc6
formats:
- deb
- package_name: birdwatcher
homepage: https://github.com/skoef/birdwatcher
maintainer: "Reinier Schoof <[email protected]>"
description: healthchecker for BIRD-anycasted services
license: MIT
contents:
- src: dist/systemd/birdwatcher.service
dst: /usr/lib/system/systemd/birdwatcher.service
dst: /usr/lib/systemd/system/birdwatcher.service
packager: rpm
file_info:
owner: root
group: root
mode: 0644
- src: dist/birdwatcher.conf
dst: /etc/birdwatcher.conf
type: config|noreplace
file_info:
owner: root
group: root
mode: 0644
dependencies:
- glibc
formats:
- deb
- rpm
overrides:
deb:
dependencies:
- libc6
rpm:
dependencies:
- glibc
changelog:
sort: asc
filters:
Expand Down
25 changes: 18 additions & 7 deletions birdwatcher/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ type Config struct {
Services map[string]*ServiceCheck
}

const (
defaultConfigFile = "/etc/bird/birdwatcher.conf"
defaultReloadCommand = "/usr/sbin/birdc configure"

defaultFunctionName = "match_route"
defaultCheckInterval = 1
defaultServiceTimeout = 10
defaultServiceFail = 1
defaultServiceRise = 1
)

// ReadConfig reads TOML config from given file into given Config or returns
// error on invalid configuration
func ReadConfig(conf *Config, configFile string) error {
Expand All @@ -34,11 +45,11 @@ func ReadConfig(conf *Config, configFile string) error {
}

if conf.ConfigFile == "" {
conf.ConfigFile = "/etc/bird/birdwatcher.conf"
conf.ConfigFile = defaultConfigFile
}

if conf.ReloadCommand == "" {
conf.ReloadCommand = "/usr/sbin/birdc configure"
conf.ReloadCommand = defaultReloadCommand
}

if len(conf.Services) == 0 {
Expand All @@ -51,7 +62,7 @@ func ReadConfig(conf *Config, configFile string) error {
s.name = name

if s.FunctionName == "" {
s.FunctionName = "match_route"
s.FunctionName = defaultFunctionName
}

// validate service
Expand Down Expand Up @@ -90,19 +101,19 @@ func (c Config) validateService(s *ServiceCheck) error {
}

if s.Interval <= 0 {
s.Interval = 1
s.Interval = defaultCheckInterval
}

if s.Timeout <= 0 {
s.Timeout = 10
s.Timeout = defaultServiceTimeout
}

if s.Fail <= 0 {
s.Fail = 1
s.Fail = defaultServiceFail
}

if s.Rise <= 0 {
s.Rise = 1
s.Rise = defaultServiceRise
}

if len(s.Prefixes) == 0 {
Expand Down
14 changes: 7 additions & 7 deletions birdwatcher/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,15 @@ func TestConfig(t *testing.T) {
return
}

assert.Equal(t, "/etc/bird/birdwatcher.conf", testConf.ConfigFile)
assert.Equal(t, "/usr/sbin/birdc configure", testConf.ReloadCommand)
assert.Equal(t, defaultConfigFile, testConf.ConfigFile)
assert.Equal(t, defaultReloadCommand, testConf.ReloadCommand)
assert.Equal(t, 1, len(testConf.Services))
assert.Equal(t, "foo", testConf.Services["foo"].name)
assert.Equal(t, 1, testConf.Services["foo"].Interval)
assert.Equal(t, "match_route", testConf.Services["foo"].FunctionName)
assert.Equal(t, 1, testConf.Services["foo"].Fail)
assert.Equal(t, 1, testConf.Services["foo"].Rise)
assert.Equal(t, 10, testConf.Services["foo"].Timeout)
assert.Equal(t, defaultCheckInterval, testConf.Services["foo"].Interval)
assert.Equal(t, defaultFunctionName, testConf.Services["foo"].FunctionName)
assert.Equal(t, defaultServiceFail, testConf.Services["foo"].Fail)
assert.Equal(t, defaultServiceRise, testConf.Services["foo"].Rise)
assert.Equal(t, defaultServiceTimeout, testConf.Services["foo"].Timeout)
assert.Equal(t, 1, len(testConf.Services["foo"].prefixes))
assert.Equal(t, "192.168.0.0/24", testConf.Services["foo"].prefixes[0].String())

Expand Down
19 changes: 19 additions & 0 deletions dist/birdwatcher.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# This is the default birdwatcher config file.
# Refer to https://github.com/skoef/birdwatcher for all configuration options

# the config file BIRD should be including
configfile = "/etc/bird/birdwatcher.conf"
# reload command birdwatcher will call when configfile was updated
reloadcommand = "/usr/sbin/birdc configure"

[services]
# example service
#
# [services."foo"]
# command = "/usr/bin/my_check.sh"
# functionname = "match_route"
# interval = 1
# timeout = 10
# fail = 1
# rise = 1
# prefixes = ["192.168.0.0/24", "fc00::/7"]

0 comments on commit c62d0a6

Please sign in to comment.