|
@@ -1,9 +1,6 @@
|
1
|
1
|
package httplistener
|
2
|
2
|
|
3
|
3
|
import (
|
4
|
|
- "bytes"
|
5
|
|
- "encoding/json"
|
6
|
|
- "fmt"
|
7
|
4
|
"github.com/juju/loggo"
|
8
|
5
|
"github.com/spf13/viper"
|
9
|
6
|
"github.com/thoj/go-ircevent"
|
|
@@ -32,36 +29,3 @@ func New(irc *irc.Connection) (*HTTPListener, error) {
|
32
|
29
|
go hl.http.ListenAndServe()
|
33
|
30
|
return &hl, nil
|
34
|
31
|
}
|
35
|
|
-
|
36
|
|
-type grafanaMatch struct {
|
37
|
|
- Metric string
|
38
|
|
- Value float32
|
39
|
|
-}
|
40
|
|
-
|
41
|
|
-type grafanaAlert struct {
|
42
|
|
- Title string
|
43
|
|
- RuleName string
|
44
|
|
- RuleUrl string
|
45
|
|
- State string
|
46
|
|
- ImageUrl string
|
47
|
|
- Message string
|
48
|
|
- EvalMatches []grafanaMatch
|
49
|
|
-}
|
50
|
|
-
|
51
|
|
-func (hl *HTTPListener) grafanaAlertHandler(w http.ResponseWriter, request *http.Request) {
|
52
|
|
- if request.Method != "POST" {
|
53
|
|
- http.NotFound(w, request)
|
54
|
|
- return
|
55
|
|
- }
|
56
|
|
-
|
57
|
|
- var alert grafanaAlert
|
58
|
|
- buf := new(bytes.Buffer)
|
59
|
|
- buf.ReadFrom(request.Body)
|
60
|
|
- json.Unmarshal(buf.Bytes(), &alert)
|
61
|
|
- msg := fmt.Sprintf("[Grafana] [%s] %s: %s.", alert.State, alert.RuleName, alert.Message)
|
62
|
|
- for _, match := range alert.EvalMatches {
|
63
|
|
- msg += fmt.Sprintf(" %s:%f", match.Metric, match.Value)
|
64
|
|
- }
|
65
|
|
- msg += " " + alert.RuleUrl
|
66
|
|
- hl.irc.Privmsgf(viper.GetString("http.listeners.grafana"), msg)
|
67
|
|
-}
|