forked from zoni/nagios-check-runner
-
Notifications
You must be signed in to change notification settings - Fork 1
/
spew_publisher.go
50 lines (43 loc) · 1.25 KB
/
spew_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
package nca
import (
"fmt"
"github.com/davecgh/go-spew/spew"
"github.com/mitchellh/mapstructure"
log "gopkg.in/inconshreveable/log15.v2"
)
// SpewPublisherConfig describes the configuration used by the SpewPublisher.
type SpewPublisherConfig struct {
}
// SpewPublisher is a publisher which simply spews check results to stdout.
// This publisher is mainly useful for debugging
// and to use as a simple reference implementation for a Publisher.
type SpewPublisher struct {
config SpewPublisherConfig
log log.Logger
}
// Start starts this publisher.
func (p *SpewPublisher) Start() error {
p.log = Log.New("component", "spewpublisher")
p.log.Info("Publisher ready")
return nil
}
// Stop stops this publisher.
func (p *SpewPublisher) Stop() error {
p.log.Info("Publisher stopped")
return nil
}
// Publish prints the result of a check to stdout.
func (p *SpewPublisher) Publish(result *CheckResult) error {
fmt.Println("\nReceived a check result:\n")
spew.Dump(result)
return nil
}
// Configure sets the configuration to be used by the publisher.
func (p *SpewPublisher) Configure(cfg map[string]interface{}) error {
var result SpewPublisherConfig
if err := mapstructure.Decode(cfg, &result); err != nil {
return err
}
p.config = result
return nil
}