Просмотр исходного кода

Merge branch 'master' of github.com:grafana/grafana

Torkel Ödegaard 8 лет назад
Родитель
Сommit
6a976a3f48

+ 2 - 0
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)
 * **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)
 * **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)
 * **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
 ## 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)
 * **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)
@@ -31,6 +32,7 @@
 
 
 * **Color picker**: Bug after using textbox input field to change/paste color string [#9769](https://github.com/grafana/grafana/issues/9769)
 * **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)
 * **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)
 # 4.6.1 (2017-11-01)
 
 

+ 4 - 3
docs/sources/project/building_from_source.md

@@ -14,8 +14,9 @@ dev environment. Grafana ships with its own required backend server; also comple
 ## Dependencies
 ## Dependencies
 
 
 - [Go 1.9.2](https://golang.org/dl/)
 - [Go 1.9.2](https://golang.org/dl/)
-- [NodeJS LTS](https://nodejs.org/download/)
 - [Git](https://git-scm.com/downloads)
 - [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
 ## 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:
 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
 #### 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:
 [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:
 
 

+ 122 - 0
pkg/services/alerting/notifiers/teams.go

@@ -0,0 +1,122 @@
+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: `
+      <h3 class="page-heading">Teams settings</h3>
+      <div class="gf-form max-width-30">
+        <span class="gf-form-label width-6">Url</span>
+        <input type="text" required class="gf-form-input max-width-30" ng-model="ctrl.model.settings.url" placeholder="Teams incoming webhook url"></input>
+      </div>
+    `,
+	})
+
+}
+
+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)
+	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
+}

+ 75 - 0
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")
+			})
+
+		})
+	})
+}

+ 1 - 0
public/app/features/alerting/alert_tab_ctrl.ts

@@ -95,6 +95,7 @@ export class AlertTabCtrl {
       case "hipchat": return "fa fa-mail-forward";
       case "hipchat": return "fa fa-mail-forward";
       case "pushover": return "fa fa-mobile";
       case "pushover": return "fa fa-mobile";
       case "kafka": return "fa fa-random";
       case "kafka": return "fa fa-random";
+      case "teams": return "fa fa-windows";
     }
     }
     return 'fa fa-bell';
     return 'fa fa-bell';
   }
   }