forked from zoni/nagios-check-runner
-
Notifications
You must be signed in to change notification settings - Fork 1
/
memory_publisher.go
53 lines (45 loc) · 1.22 KB
/
memory_publisher.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
package nca
import (
log "gopkg.in/inconshreveable/log15.v2"
"sync"
)
// MemoryPublisher is a simple Publisher which stores all check results in memory.
// This publisher is used for testing and is not meant to be used normally.
type MemoryPublisher struct {
sync.Mutex
log log.Logger
events map[string][]*CheckResult
}
// Start starts this publisher.
func (p *MemoryPublisher) Start() error {
p.log = Log.New("component", "memorypublisher")
p.log.Info("Publisher ready")
p.events = make(map[string][]*CheckResult)
return nil
}
// Stop stops this publisher.
func (p *MemoryPublisher) Stop() error {
p.log.Info("Publisher stopped")
return nil
}
func (p *MemoryPublisher) Publish(result *CheckResult) error {
p.Lock()
defer p.Unlock()
n := result.Name
p.events[n] = append(p.events[n], result)
return nil
}
func (p *MemoryPublisher) EventCount(checkname string) int {
p.Lock()
defer p.Unlock()
return len(p.events[checkname])
}
func (p *MemoryPublisher) GetEvent(checkname string, index int) *CheckResult {
p.Lock()
defer p.Unlock()
return p.events[checkname][index]
}
// Configure sets the configuration to be used by the publisher.
func (p *MemoryPublisher) Configure(cfg map[string]interface{}) error {
return nil
}