From 81102ccee1e01d0c1045b025530f0caa9a0f8cd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Mon, 13 Nov 2017 16:41:02 +0100 Subject: [PATCH 1/5] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 97fb7901a6d..c96a8e7bc8b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,7 @@ * **Color picker**: Bug after using textbox input field to change/paste color string [#9769](https://github.com/grafana/grafana/issues/9769) * **Cloudwatch**: Fix for cloudwatch templating query `ec2_instance_attribute` [#9667](https://github.com/grafana/grafana/issues/9667), thanks [@mtanda](https://github.com/mtanda) +* **Heatmap**: Fixed tooltip for "time series buckets" mode [#9332](https://github.com/grafana/grafana/issues/9332) # 4.6.1 (2017-11-01) From 6d7eacfa814f3b30b7cd779f080a965d02ec08fb Mon Sep 17 00:00:00 2001 From: Daniel Lee Date: Mon, 13 Nov 2017 23:42:05 +0100 Subject: [PATCH 2/5] docs: update building from source doc with node-gyp Adds dependencies for node-gyp to the building from source docs page. ref #9861 --- docs/sources/project/building_from_source.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/sources/project/building_from_source.md b/docs/sources/project/building_from_source.md index b91aacb2c2b..dba04164d00 100644 --- a/docs/sources/project/building_from_source.md +++ b/docs/sources/project/building_from_source.md @@ -14,8 +14,9 @@ dev environment. Grafana ships with its own required backend server; also comple ## Dependencies - [Go 1.9.2](https://golang.org/dl/) -- [NodeJS LTS](https://nodejs.org/download/) - [Git](https://git-scm.com/downloads) +- [NodeJS LTS](https://nodejs.org/download/) +- node-gyp is the Node.js native addon build tool and it requires extra dependencies: python 2.7, make and GCC. These are already installed for most Linux distros and MacOS. See the Building On Windows section or the [node-gyp installation instructions](https://github.com/nodejs/node-gyp#installation) for more details. ## Get Code Create a directory for the project and set your path accordingly (or use the [default Go workspace directory](https://golang.org/doc/code.html#GOPATH)). Then download and install Grafana into your $GOPATH directory: @@ -40,8 +41,8 @@ go run build.go build # (or 'go build ./pkg/cmd/grafana-server') ``` #### Building on Windows -The Grafana backend includes Sqlite3 which requires GCC to compile. So in order to compile Grafana on windows you need -to install GCC. We recommend [TDM-GCC](http://tdm-gcc.tdragon.net/download). + +The Grafana backend includes Sqlite3 which requires GCC to compile. So in order to compile Grafana on windows you need to install GCC. We recommend [TDM-GCC](http://tdm-gcc.tdragon.net/download). [node-gyp](https://github.com/nodejs/node-gyp#installation) is the Node.js native addon build tool and it requires extra dependencies to be installed on Windows. In a command prompt which is run as administrator, run: From fd2451823b14bb6636b84d49dd5a9b3886546d2b Mon Sep 17 00:00:00 2001 From: Anton Huck Date: Mon, 30 Oct 2017 16:31:24 +0100 Subject: [PATCH 3/5] Add Microsoft Teams notifier --- pkg/services/alerting/notifiers/teams.go | 123 ++++++++++++++++++ pkg/services/alerting/notifiers/teams_test.go | 75 +++++++++++ .../app/features/alerting/alert_tab_ctrl.ts | 1 + 3 files changed, 199 insertions(+) create mode 100644 pkg/services/alerting/notifiers/teams.go create mode 100644 pkg/services/alerting/notifiers/teams_test.go diff --git a/pkg/services/alerting/notifiers/teams.go b/pkg/services/alerting/notifiers/teams.go new file mode 100644 index 00000000000..9bb4d636867 --- /dev/null +++ b/pkg/services/alerting/notifiers/teams.go @@ -0,0 +1,123 @@ +package notifiers + +import ( + "encoding/json" + + "github.com/grafana/grafana/pkg/bus" + "github.com/grafana/grafana/pkg/log" + m "github.com/grafana/grafana/pkg/models" + "github.com/grafana/grafana/pkg/services/alerting" +) + +func init() { + alerting.RegisterNotifier(&alerting.NotifierPlugin{ + Type: "teams", + Name: "Microsoft Teams", + Description: "Sends notifications using Incomming Webhook connector to Microsoft Teams", + Factory: NewTeamsNotifier, + OptionsTemplate: ` +

Teams settings

+
+ Url + +
+ `, + }) + +} + +func NewTeamsNotifier(model *m.AlertNotification) (alerting.Notifier, error) { + url := model.Settings.Get("url").MustString() + if url == "" { + return nil, alerting.ValidationError{Reason: "Could not find url property in settings"} + } + + return &TeamsNotifier{ + NotifierBase: NewNotifierBase(model.Id, model.IsDefault, model.Name, model.Type, model.Settings), + Url: url, + log: log.New("alerting.notifier.teams"), + }, nil +} + +type TeamsNotifier struct { + NotifierBase + Url string + Recipient string + Mention string + log log.Logger +} + +func (this *TeamsNotifier) Notify(evalContext *alerting.EvalContext) error { + this.log.Info("Executing teams notification", "ruleId", evalContext.Rule.Id, "notification", this.Name) + + ruleUrl, err := evalContext.GetRuleUrl() + if err != nil { + this.log.Error("Failed get rule link", "error", err) + return err + } + + fields := make([]map[string]interface{}, 0) + fieldLimitCount := 4 + for index, evt := range evalContext.EvalMatches { + fields = append(fields, map[string]interface{}{ + "name": evt.Metric, + "value": evt.Value, + }) + if index > fieldLimitCount { + break + } + } + + if evalContext.Error != nil { + fields = append(fields, map[string]interface{}{ + "name": "Error message", + "value": evalContext.Error.Error(), + }) + } + + message := this.Mention + if evalContext.Rule.State != m.AlertStateOK { //dont add message when going back to alert state ok. + message += " " + evalContext.Rule.Message + } + + body := map[string]interface{}{ + "@type": "MessageCard", + "@context": "http://schema.org/extensions", + "summary": message, + "title": evalContext.GetNotificationTitle(), + "themeColor": evalContext.GetStateModel().Color, + "sections": []map[string]interface{}{ + { + "title": "Details", + "facts": fields, + "images": []map[string]interface{}{ + { + "image": evalContext.ImagePublicUrl, + }, + }, + "text": message, + "potentialAction": []map[string]interface{}{ + { + "@context": "http://schema.org", + "@type": "ViewAction", + "name": "View Rule", + "target": []string{ + ruleUrl, + }, + }, + }, + }, + }, + } + + data, _ := json.Marshal(&body) + print(string(data)) + cmd := &m.SendWebhookSync{Url: this.Url, Body: string(data)} + + if err := bus.DispatchCtx(evalContext.Ctx, cmd); err != nil { + this.log.Error("Failed to send teams notification", "error", err, "webhook", this.Name) + return err + } + + return nil +} diff --git a/pkg/services/alerting/notifiers/teams_test.go b/pkg/services/alerting/notifiers/teams_test.go new file mode 100644 index 00000000000..a9647350736 --- /dev/null +++ b/pkg/services/alerting/notifiers/teams_test.go @@ -0,0 +1,75 @@ +package notifiers + +import ( + "testing" + + "github.com/grafana/grafana/pkg/components/simplejson" + m "github.com/grafana/grafana/pkg/models" + . "github.com/smartystreets/goconvey/convey" +) + +func TestTeamsNotifier(t *testing.T) { + Convey("Teams notifier tests", t, func() { + + Convey("Parsing alert notification from settings", func() { + Convey("empty settings should return error", func() { + json := `{ }` + + settingsJSON, _ := simplejson.NewJson([]byte(json)) + model := &m.AlertNotification{ + Name: "ops", + Type: "teams", + Settings: settingsJSON, + } + + _, err := NewTeamsNotifier(model) + So(err, ShouldNotBeNil) + }) + + Convey("from settings", func() { + json := ` + { + "url": "http://google.com" + }` + + settingsJSON, _ := simplejson.NewJson([]byte(json)) + model := &m.AlertNotification{ + Name: "ops", + Type: "teams", + Settings: settingsJSON, + } + + not, err := NewTeamsNotifier(model) + teamsNotifier := not.(*TeamsNotifier) + + So(err, ShouldBeNil) + So(teamsNotifier.Name, ShouldEqual, "ops") + So(teamsNotifier.Type, ShouldEqual, "teams") + So(teamsNotifier.Url, ShouldEqual, "http://google.com") + }) + + Convey("from settings with Recipient and Mention", func() { + json := ` + { + "url": "http://google.com" + }` + + settingsJSON, _ := simplejson.NewJson([]byte(json)) + model := &m.AlertNotification{ + Name: "ops", + Type: "teams", + Settings: settingsJSON, + } + + not, err := NewTeamsNotifier(model) + teamsNotifier := not.(*TeamsNotifier) + + So(err, ShouldBeNil) + So(teamsNotifier.Name, ShouldEqual, "ops") + So(teamsNotifier.Type, ShouldEqual, "teams") + So(teamsNotifier.Url, ShouldEqual, "http://google.com") + }) + + }) + }) +} diff --git a/public/app/features/alerting/alert_tab_ctrl.ts b/public/app/features/alerting/alert_tab_ctrl.ts index 2c273c93a01..b65a559e426 100644 --- a/public/app/features/alerting/alert_tab_ctrl.ts +++ b/public/app/features/alerting/alert_tab_ctrl.ts @@ -95,6 +95,7 @@ export class AlertTabCtrl { case "hipchat": return "fa fa-mail-forward"; case "pushover": return "fa fa-mobile"; case "kafka": return "fa fa-random"; + case "teams": return "fa fa-windows"; } return 'fa fa-bell'; } From 3bb704144d7ec338e5276ca4e0a092a1c4f2c4bf Mon Sep 17 00:00:00 2001 From: bergquist Date: Tue, 14 Nov 2017 11:02:50 +0100 Subject: [PATCH 4/5] teams: removes print statement --- pkg/services/alerting/notifiers/teams.go | 1 - 1 file changed, 1 deletion(-) diff --git a/pkg/services/alerting/notifiers/teams.go b/pkg/services/alerting/notifiers/teams.go index 9bb4d636867..200a8594428 100644 --- a/pkg/services/alerting/notifiers/teams.go +++ b/pkg/services/alerting/notifiers/teams.go @@ -111,7 +111,6 @@ func (this *TeamsNotifier) Notify(evalContext *alerting.EvalContext) error { } data, _ := json.Marshal(&body) - print(string(data)) cmd := &m.SendWebhookSync{Url: this.Url, Body: string(data)} if err := bus.DispatchCtx(evalContext.Ctx, cmd); err != nil { From 9fc7303ddfc18f67233b2294f9ae989daec06b72 Mon Sep 17 00:00:00 2001 From: bergquist Date: Tue, 14 Nov 2017 11:14:27 +0100 Subject: [PATCH 5/5] changelog: adds note about closing #8523 --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c96a8e7bc8b..291d01cf8c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ * **Data Source Proxy**: Add support for whitelisting specified cookies that will be passed through to the data source when proxying data source requests [#5457](https://github.com/grafana/grafana/issues/5457), thanks [@robingustafsson](https://github.com/robingustafsson) * **Postgres/MySQL**: add __timeGroup macro for mysql [#9596](https://github.com/grafana/grafana/pull/9596), thanks [@svenklemm](https://github.com/svenklemm) * **Text**: Text panel are now edited in the ace editor. [#9698](https://github.com/grafana/grafana/pull/9698), thx [@mtanda](https://github.com/mtanda) +* **Teams**: Add Microsoft Teams notifier as [#8523](https://github.com/grafana/grafana/issues/8523), thx [@anthu](https://github.com/anthu) ## Minor * **Alert panel**: Adds placeholder text when no alerts are within the time range [#9624](https://github.com/grafana/grafana/issues/9624), thx [@straend](https://github.com/straend)