-
Notifications
You must be signed in to change notification settings - Fork 1
/
heartbeat.go
42 lines (35 loc) · 1.08 KB
/
heartbeat.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
package sink
import (
"time"
"github.com/agalue/gominion/api"
"github.com/agalue/gominion/log"
)
// HeartbeatModule represents the heartbeat module
type HeartbeatModule struct{}
// GetID gets the ID of the sink module
func (module *HeartbeatModule) GetID() string {
return "Heartbeat"
}
// Start initiates a blocking loop that sends heartbeats to OpenNMS
func (module *HeartbeatModule) Start(config *api.MinionConfig, sink api.Sink) error {
log.Infof("Starting Sink Heartbeat Module")
go func() {
for {
log.Infof("Sending heartbeat for Minion with id %s at location %s", config.ID, config.Location)
sendXMLResponse(module.GetID(), config, sink, module.getIdentity(config))
time.Sleep(30 * time.Second)
}
}()
return nil
}
// Stop shutdowns the sink module
func (module *HeartbeatModule) Stop() {
log.Warnf("Stopping Sink Heartbeat Module")
}
func (module *HeartbeatModule) getIdentity(config *api.MinionConfig) *api.MinionIdentityDTO {
return &api.MinionIdentityDTO{
ID: config.ID,
Location: config.Location,
Timestamp: &api.Timestamp{Time: time.Now()},
}
}