Browse Source

fix lint

pull/305/head
Richard van der Hoff 6 years ago
parent
commit
05aaf714d3
  1. 4
      src/github.com/matrix-org/go-neb/services/alertmanager/alertmanager.go
  2. 30
      src/github.com/matrix-org/go-neb/services/alertmanager/alertmanager_test.go
  3. 4
      src/github.com/matrix-org/go-neb/services/github/github.go
  4. 10
      src/github.com/matrix-org/go-neb/services/rssbot/rssbot.go

4
src/github.com/matrix-org/go-neb/services/alertmanager/alertmanager.go

@ -11,8 +11,8 @@ import (
"github.com/matrix-org/gomatrix"
html "html/template"
"net/http"
text "text/template"
"strings"
text "text/template"
)
// ServiceType of the Alertmanager service.
@ -93,7 +93,7 @@ func (s *Service) OnReceiveWebhook(w http.ResponseWriter, req *http.Request, cli
for label, val := range alert.Labels {
filters = append(filters, fmt.Sprintf("%s%%3D\"%s\"", label, val))
}
alert.SilenceURL = fmt.Sprintf("%s#silences/new?filter={%s}", notif.ExternalURL, strings.Join(filters, ",") )
alert.SilenceURL = fmt.Sprintf("%s#silences/new?filter={%s}", notif.ExternalURL, strings.Join(filters, ","))
}
for roomID, templates := range s.Rooms {

30
src/github.com/matrix-org/go-neb/services/alertmanager/alertmanager_test.go

@ -1,19 +1,19 @@
package alertmanager
import (
"bytes"
"encoding/json"
"fmt"
"github.com/matrix-org/go-neb/database"
"github.com/matrix-org/go-neb/testutils"
"github.com/matrix-org/go-neb/types"
"github.com/matrix-org/gomatrix"
"net/http"
"strings"
"fmt"
"encoding/json"
"io/ioutil"
"bytes"
"testing"
"github.com/matrix-org/go-neb/types"
"net/http"
"net/http/httptest"
"regexp"
"strings"
"testing"
)
func TestNotify(t *testing.T) {
@ -40,31 +40,31 @@ func TestNotify(t *testing.T) {
matrixCli.Client = &http.Client{Transport: matrixTrans}
// create the service
html_template, err := json.Marshal(
htmlTemplate, err := json.Marshal(
`{{range .Alerts}}
{{index .Labels "severity" }} : {{- index .Labels "alertname" -}}
<a href="{{ .GeneratorURL }}">source</a>
<a href="{{ .SilenceURL }}">silence</a>
{{- end }}
`,
)
)
if err != nil {
t.Fatal(err)
}
text_template, err := json.Marshal(`{{range .Alerts}}{{index .Labels "alertname"}} {{end}}`)
textTemplate, err := json.Marshal(`{{range .Alerts}}{{index .Labels "alertname"}} {{end}}`)
if err != nil {
t.Fatal(err)
}
config := fmt.Sprintf(`{
config := fmt.Sprintf(`{
"rooms":{ "!testroom:id" : {
"text_template":%s,
"html_template":%s,
"msg_type":"m.text"
}}
}`, text_template, html_template,
}`, textTemplate, htmlTemplate,
)
srv, err := types.CreateService("id", "alertmanager", "@neb:hs", []byte(config))
@ -114,17 +114,17 @@ func TestNotify(t *testing.T) {
t.Errorf("Wrong msgtype: got %s want m.text", msg.MsgType)
}
lines := strings.Split(msg.FormattedBody, "\n" )
lines := strings.Split(msg.FormattedBody, "\n")
// <a href="http://alertmanager#silences/new?filter=%7balertname%3D%22alert%202%22,severity%3D%22tiny%22%7d">silence</a>
silenceRegexp := regexp.MustCompile(`<a href="([^"]*)">silence</a>`)
matchedSilence := 0
for _, line := range lines {
if ! strings.Contains(line, "silence") {
if !strings.Contains(line, "silence") {
continue
}
matchedSilence += 1
matchedSilence++
m := silenceRegexp.FindStringSubmatch(line)
if m == nil {
t.Errorf("silence line %s had bad format", line)

4
src/github.com/matrix-org/go-neb/services/github/github.go

@ -450,8 +450,8 @@ func (s *Service) expandCommit(roomID, userID, owner, repo, sha string) interfac
if err != nil {
log.WithError(err).WithFields(log.Fields{
"owner": owner,
"repo": repo,
"sha": sha,
"repo": repo,
"sha": sha,
}).Print("Failed to fetch commit")
return nil
}

10
src/github.com/matrix-org/go-neb/services/rssbot/rssbot.go

@ -353,13 +353,13 @@ func itemToHTML(feed *gofeed.Feed, item gofeed.Item) gomatrix.HTMLMessage {
Body: fmt.Sprintf("%s: %s ( %s )",
html.EscapeString(feed.Title), html.EscapeString(item.Title), html.EscapeString(item.Link)),
MsgType: "m.notice",
Format: "org.matrix.custom.html",
Format: "org.matrix.custom.html",
FormattedBody: fmt.Sprintf("<strong>%s</strong>:<br><a href=\"%s\"><strong>%s</strong></a>",
html.EscapeString(feed.Title), html.EscapeString(item.Link), html.EscapeString(item.Title)),
// <strong>FeedTitle</strong>:
// <br>
// <a href="url-of-the-entry"><strong>Title of the Entry</strong></a>
}
// <strong>FeedTitle</strong>:
// <br>
// <a href="url-of-the-entry"><strong>Title of the Entry</strong></a>
}
}
func ensureItemsHaveGUIDs(feed *gofeed.Feed) {

Loading…
Cancel
Save