summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-06-01 15:00:59 +0300
committerPaul Buetow <paul@buetow.org>2025-06-01 15:00:59 +0300
commit9fe227b79ea15ffcde8bf175ff879f991d183eab (patch)
treeb033237472a35e60074591e8788ee99c7c5630cc
parent075ddd7ecec4ab3f0648015857e32c3bb5240743 (diff)
more on federation
-rw-r--r--internal/check.go15
-rw-r--r--internal/config.go3
-rw-r--r--internal/run.go2
-rw-r--r--internal/state.go9
4 files changed, 20 insertions, 9 deletions
diff --git a/internal/check.go b/internal/check.go
index 55b740a..70f0044 100644
--- a/internal/check.go
+++ b/internal/check.go
@@ -22,10 +22,11 @@ type namedCheck struct {
}
type checkResult struct {
- name string
- output string
- epoch int64
- status nagiosCode
+ name string
+ output string
+ epoch int64
+ status nagiosCode
+ federated bool
}
func (c check) run(ctx context.Context, name string) checkResult {
@@ -37,7 +38,7 @@ func (c check) run(ctx context.Context, name string) checkResult {
if err := cmd.Run(); err != nil {
if ctx.Err() == context.DeadlineExceeded {
- return checkResult{name, "Check command timed out", time.Now().Unix(), nagiosCritical}
+ return checkResult{name, "Check command timed out", time.Now().Unix(), nagiosCritical, false}
}
}
@@ -51,11 +52,11 @@ func (c check) run(ctx context.Context, name string) checkResult {
ec = int(nagiosUnknown)
}
- return checkResult{name, output, time.Now().Unix(), nagiosCode(ec)}
+ return checkResult{name, output, time.Now().Unix(), nagiosCode(ec), false}
}
func (c check) skip(name, output string) checkResult {
- return checkResult{name, output, time.Now().Unix(), nagiosUnknown}
+ return checkResult{name, output, time.Now().Unix(), nagiosUnknown, false}
}
func (c namedCheck) run(ctx context.Context) checkResult {
diff --git a/internal/config.go b/internal/config.go
index ccc3f36..222750b 100644
--- a/internal/config.go
+++ b/internal/config.go
@@ -15,7 +15,8 @@ type config struct {
StateDir string `json:"StateDir,omitempty"`
CheckTimeoutS int
CheckConcurrency int
- StaleThreshold int `json:"StaleThreshold,omitempty"`
+ StaleThreshold int `json:"StaleThreshold,omitempty"`
+ Federated []string `json:"Federated,omitempty"`
Checks map[string]check
}
diff --git a/internal/run.go b/internal/run.go
index 6066bc7..91fe323 100644
--- a/internal/run.go
+++ b/internal/run.go
@@ -17,13 +17,13 @@ func Run(ctx context.Context, configFile string, renotify, force bool) {
notifyError(conf, err)
}
- // TODO: Also read other state files? Merge them..
state, err := newState(conf)
if err != nil {
notifyError(conf, err)
}
state = runChecks(ctx, state, conf)
+ state = mergeFederated(ctx, state, conf)
if err := state.persist(); err != nil {
notifyError(conf, err)
diff --git a/internal/state.go b/internal/state.go
index cda360f..9580db6 100644
--- a/internal/state.go
+++ b/internal/state.go
@@ -70,6 +70,7 @@ func newState(conf config) (state, error) {
return s, nil
}
+
func (s state) update(result checkResult) {
prevStatus := nagiosUnknown
prevState, ok := s.checks[result.name]
@@ -93,6 +94,14 @@ func (s state) merge(other state) error {
return nil
}
+func (s state) mergeFromBytes(bytes []byte) error {
+ var other state
+ if err := json.Unmarshal(bytes, &other.checks); err != nil {
+ return err
+ }
+ return s.merge(other)
+}
+
func (s state) persist() error {
stateDir := filepath.Dir(s.stateFile)
if _, err := os.Stat(stateDir); os.IsNotExist(err) {