-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprobe.go
executable file
·73 lines (66 loc) · 1.85 KB
/
probe.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package main
import (
"errors"
"os"
"time"
)
type Probe interface {
Start()
Stop()
}
// Probe defines and contains information to create a new probe like a NewRelicProbe
type ProbeDef struct {
ID string `json:"id"`
Type string `json:"type"`
Data map[string]string `json:"data"`
}
// ProbeRef references which probe to use along wiht any data
type ProbeRef struct {
RefID string `json:"probeRefId"`
Data map[string]string `json:"data"`
}
// CreateProbes create the probes defined in the config
func CreateProbes(probeDefs []ProbeDef, statuses []*Status, updateChan chan StatusUpdate) ([]Probe, error) {
probes := []Probe{}
for _, probe := range probeDefs {
switch probe.Type {
case NewRelicType:
logger.Debug("Creating new probe", "refID", probe.ID, "type", probe.Type)
err := checkForMapKeys(probe.Data, []string{NewRelicIntervalKey, NewRelicAPIEnvKey, NewRelicAccountNumberKey})
if err != nil {
return nil, errors.New("Error making probe " + probe.ID + " with error: " + err.Error())
}
probeInterval, err := time.ParseDuration(probe.Data[NewRelicIntervalKey])
if err != nil {
return nil, err
}
nrpc := &NewRelicProbeConfig{
id: probe.ID,
update: updateChan,
interval: probeInterval,
key: os.Getenv(probe.Data[NewRelicAPIEnvKey]),
account: probe.Data[NewRelicAccountNumberKey],
}
nrp := NewNewRelicProbe(nrpc)
err = nrp.Initialize(statuses)
if err != nil {
logger.Critical("Could not initialize New Relic probe")
return nil, err
}
probes = append(probes, nrp)
default:
logger.Critical("Unknown probe type", "probe type", probe.Type)
}
}
return probes, nil
}
func StartProbes(probes []Probe) {
for _, probe := range probes {
go probe.Start()
}
}
func StopProbes(probes []Probe) {
for _, probe := range probes {
probe.Stop()
}
}