-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Basic config and some initialisation
- Loading branch information
Showing
7 changed files
with
117 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package goplum | ||
|
||
import ( | ||
"encoding/json" | ||
"os" | ||
"time" | ||
) | ||
|
||
type Config struct { | ||
Checks []ConfiguredCheck `json:"checks"` | ||
} | ||
|
||
type ConfiguredCheck struct { | ||
Name string `json:"name"` | ||
Check string `json:"check"` | ||
Interval time.Duration `json:"interval"` | ||
Params json.RawMessage `json:"params"` | ||
} | ||
|
||
func LoadConfig(path string) (*Config, error) { | ||
f, err := os.Open(path) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer f.Close() | ||
|
||
config := &Config{} | ||
return config, json.NewDecoder(f).Decode(config) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"checks": [ | ||
{ | ||
"name": "Google", | ||
"check": "http", | ||
"params": { | ||
"url": "https://www.google.com/" | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package goplum | ||
|
||
import "log" | ||
|
||
func Initialise(plugins []Plugin, configPath string) { | ||
config, err := LoadConfig(configPath) | ||
if err != nil { | ||
log.Fatalf("Unable to read config: %v", err) | ||
} | ||
|
||
checks := make(map[string]Check) | ||
for i := range plugins { | ||
cs := plugins[i].Checks() | ||
for j := range cs { | ||
checks[cs[j].Name()] = cs[j] | ||
} | ||
} | ||
log.Printf("Found %d checks from %d plugins\n", len(checks), len(plugins)) | ||
|
||
tasks := make([]Task, 0) | ||
for i := range config.Checks { | ||
cc := config.Checks[i] | ||
check, ok := checks[cc.Check] | ||
if !ok { | ||
log.Fatalf("Invalid check name in config: %s", cc.Check) | ||
} | ||
|
||
t, err := check.Create(cc.Params) | ||
if err != nil { | ||
log.Fatalf("Unable to create check '%s': %v", cc.Name, err) | ||
} | ||
|
||
tasks = append(tasks, t) | ||
} | ||
} |