-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathnotifier_flapjack.go
52 lines (40 loc) · 950 Bytes
/
notifier_flapjack.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
package main
import (
flapjack "github.com/flapjack/flapjack/src/flapjack"
"log"
Url "net/url"
"strconv"
)
func NotifyFlapjackRedis(nc *NotifierConf) func(*Log) {
return func(l *Log) {
Hurl, err := Url.Parse(l.Monitor.Conf.Url)
if err != nil {
log.Printf("Flapjack Notifier: Unable to parse %s", l.Monitor.Conf.Url)
return
}
duration := " [" + strconv.FormatInt(l.Duration/1000000, 10) + "ms]"
event := flapjack.Event{
Entity: Hurl.Host,
Check: l.Monitor.Conf.Name,
State: NewState(l),
Summary: l.Message + duration,
Type: "service",
Time: l.Time.Unix(),
}
address := nc.Address
database := 0 //production
transport, err := flapjack.Dial(address, database)
if err != nil {
log.Printf("FlapjackNotifier: unable to connect to redis %s", address)
return
}
transport.Send(event)
}
}
func NewState(l *Log) string {
ns := "critical"
if l.Up {
ns = "ok"
}
return ns
}