Exemple #1
0
func init() {
	bus.AddHandler("sql", GetApiKeys)
	bus.AddHandler("sql", GetApiKeyById)
	bus.AddHandler("sql", GetApiKeyByName)
	bus.AddHandler("sql", DeleteApiKey)
	bus.AddHandler("sql", AddApiKey)
}
Exemple #2
0
func ldapAutherScenario(desc string, fn scenarioFunc) {
	Convey(desc, func() {
		defer bus.ClearBusHandlers()

		sc := &scenarioContext{}

		bus.AddHandler("test", func(cmd *m.CreateUserCommand) error {
			sc.createUserCmd = cmd
			sc.createUserCmd.Result = m.User{Login: cmd.Login}
			return nil
		})

		bus.AddHandler("test", func(cmd *m.AddOrgUserCommand) error {
			sc.addOrgUserCmd = cmd
			return nil
		})

		bus.AddHandler("test", func(cmd *m.UpdateOrgUserCommand) error {
			sc.updateOrgUserCmd = cmd
			return nil
		})

		bus.AddHandler("test", func(cmd *m.RemoveOrgUserCommand) error {
			sc.removeOrgUserCmd = cmd
			return nil
		})

		bus.AddHandler("test", func(cmd *m.UpdateUserCommand) error {
			sc.updateUserCmd = cmd
			return nil
		})

		fn(sc)
	})
}
func init() {

	bus.AddHandler("sql", GetMaintenanceAlerts)
	bus.AddHandler("sql", GetMaintenanceAlertsByInterval)
	bus.AddHandler("sql", UpdateMaintenanceAlert)

}
func init() {
	bus.AddHandler("sql", CreateDashboardSnapshot)
	bus.AddHandler("sql", GetDashboardSnapshot)
	bus.AddHandler("sql", DeleteDashboardSnapshot)
	bus.AddHandler("sql", SearchDashboardSnapshots)
	bus.AddHandler("sql", DeleteExpiredSnapshots)
}
func init() {

	bus.AddHandler("sql", GetPendingAlertHistory)
	bus.AddHandler("sql", GetCompletedAlertHistory)
	bus.AddHandler("sql", GetPendingAlertActionHistory)
	bus.AddHandler("sql", UpdateAlertAction)
}
Exemple #6
0
func init() {
	bus.AddHandler("sql", SaveDashboard)
	bus.AddHandler("sql", GetDashboard)
	bus.AddHandler("sql", DeleteDashboard)
	bus.AddHandler("sql", SearchDashboards)
	bus.AddHandler("sql", GetDashboardTags)
}
Exemple #7
0
func Init() error {
	initMailQueue()

	bus.AddHandler("email", sendResetPasswordEmail)
	bus.AddHandler("email", validateResetPasswordCode)
	bus.AddHandler("email", sendEmailCommandHandler)

	bus.AddEventListener(userSignedUpHandler)

	mailTemplates = template.New("name")
	mailTemplates.Funcs(template.FuncMap{
		"Subject": subjectTemplateFunc,
	})

	templatePattern := filepath.Join(setting.StaticRootPath, setting.Smtp.TemplatesPattern)
	_, err := mailTemplates.ParseGlob(templatePattern)
	if err != nil {
		return err
	}

	if !util.IsEmail(setting.Smtp.FromAddress) {
		return errors.New("Invalid email address for smpt from_adress config")
	}

	if setting.EmailCodeValidMinutes == 0 {
		setting.EmailCodeValidMinutes = 120
	}

	return nil
}
func init() {

	bus.AddHandler("sql", GetMaintenanceHistory)
	bus.AddHandler("sql", GetMaintenanceHistoryByInterval)
	bus.AddHandler("sql", UpdateMaintenanceHistory)
	bus.AddHandler("sql", addMaintenanceActivity)

}
func init() {

	bus.AddHandler("sql", GetMaintenance)
	bus.AddHandler("sql", addMaintenance)
	bus.AddHandler("sql", RemoveMaintenance)
	bus.AddHandler("sql", GetMaintenanceById)
	bus.AddHandler("sql", UpdateMaintenance)
}
Exemple #10
0
func TestPluginDashboards(t *testing.T) {

	Convey("When asking plugin dashboard info", t, func() {
		setting.Cfg = ini.Empty()
		sec, _ := setting.Cfg.NewSection("plugin.test-app")
		sec.NewKey("path", "../../tests/test-app")
		err := Init()

		So(err, ShouldBeNil)

		bus.AddHandler("test", func(query *m.GetDashboardQuery) error {
			if query.Slug == "nginx-connections" {
				dash := m.NewDashboard("Nginx Connections")
				dash.Data.Set("revision", "1.1")
				query.Result = dash
				return nil
			}

			return m.ErrDashboardNotFound
		})

		bus.AddHandler("test", func(query *m.GetDashboardsByPluginIdQuery) error {
			var data = simplejson.New()
			data.Set("title", "Nginx Connections")
			data.Set("revision", 22)

			query.Result = []*m.Dashboard{
				{Slug: "nginx-connections", Data: data},
			}
			return nil
		})

		dashboards, err := GetPluginDashboards(1, "test-app")

		So(err, ShouldBeNil)

		Convey("should return 2 dashboarrd", func() {
			So(len(dashboards), ShouldEqual, 2)
		})

		Convey("should include installed version info", func() {
			So(dashboards[0].Title, ShouldEqual, "Nginx Connections")
			So(dashboards[0].Revision, ShouldEqual, 25)
			So(dashboards[0].ImportedRevision, ShouldEqual, 22)
			So(dashboards[0].ImportedUri, ShouldEqual, "db/nginx-connections")

			So(dashboards[1].Revision, ShouldEqual, 2)
			So(dashboards[1].ImportedRevision, ShouldEqual, 0)
		})
	})

}
Exemple #11
0
func TestSearch(t *testing.T) {

	Convey("Given search query", t, func() {
		jsonDashIndex = NewJsonDashIndex("../../../public/dashboards/")
		query := Query{Limit: 2000}

		bus.AddHandler("test", func(query *FindPersistedDashboardsQuery) error {
			query.Result = HitList{
				&Hit{Id: 16, Title: "CCAA", Tags: []string{"BB", "AA"}},
				&Hit{Id: 10, Title: "AABB", Tags: []string{"CC", "AA"}},
				&Hit{Id: 15, Title: "BBAA", Tags: []string{"EE", "AA", "BB"}},
			}
			return nil
		})

		bus.AddHandler("test", func(query *m.GetUserStarsQuery) error {
			query.Result = map[int64]bool{10: true, 12: true}
			return nil
		})

		Convey("That is empty", func() {
			err := searchHandler(&query)
			So(err, ShouldBeNil)

			Convey("should return sorted results", func() {
				So(query.Result[0].Title, ShouldEqual, "AABB")
				So(query.Result[1].Title, ShouldEqual, "BBAA")
				So(query.Result[2].Title, ShouldEqual, "CCAA")
			})

			Convey("should return sorted tags", func() {
				So(query.Result[1].Tags[0], ShouldEqual, "AA")
				So(query.Result[1].Tags[1], ShouldEqual, "BB")
				So(query.Result[1].Tags[2], ShouldEqual, "EE")
			})
		})

		Convey("That filters by tag", func() {
			query.Tags = []string{"BB", "AA"}
			err := searchHandler(&query)
			So(err, ShouldBeNil)

			Convey("should return correct results", func() {
				So(len(query.Result), ShouldEqual, 2)
				So(query.Result[0].Title, ShouldEqual, "BBAA")
				So(query.Result[1].Title, ShouldEqual, "CCAA")
			})

		})
	})
}
Exemple #12
0
func init() {
	bus.AddHandler("sql", SaveAlerts)
	bus.AddHandler("sql", HandleAlertsQuery)
	bus.AddHandler("sql", GetAlertById)
	bus.AddHandler("sql", DeleteAlertById)
	bus.AddHandler("sql", GetAllAlertQueryHandler)
	bus.AddHandler("sql", SetAlertState)
	bus.AddHandler("sql", GetAlertStatesForDashboard)
	bus.AddHandler("sql", PauseAlert)
	bus.AddHandler("sql", PauseAllAlerts)
}
Exemple #13
0
func TestPluginProxy(t *testing.T) {

	Convey("When getting proxy headers", t, func() {
		route := &plugins.AppPluginRoute{
			Headers: []plugins.AppPluginRouteHeader{
				{Name: "x-header", Content: "my secret {{.SecureJsonData.key}}"},
			},
		}

		setting.SecretKey = "password"

		bus.AddHandler("test", func(query *m.GetPluginSettingByIdQuery) error {
			query.Result = &m.PluginSetting{
				SecureJsonData: map[string][]byte{
					"key": util.Encrypt([]byte("123"), "password"),
				},
			}
			return nil
		})

		header, err := getHeaders(route, 1, "my-app")
		So(err, ShouldBeNil)

		Convey("Should render header template", func() {
			So(header.Get("x-header"), ShouldEqual, "my secret 123")
		})
	})

}
Exemple #14
0
func init() {
	bus.AddHandler("sql", SaveDashboard)
	bus.AddHandler("sql", GetDashboard)
	bus.AddHandler("sql", GetDashboards)
	bus.AddHandler("sql", DeleteDashboard)
	bus.AddHandler("sql", SearchDashboards)
	bus.AddHandler("sql", GetDashboardTags)
	bus.AddHandler("sql", GetDashboardSlugById)
	bus.AddHandler("sql", GetDashboardsByPluginId)
}
Exemple #15
0
func init() {
	bus.AddHandler("sql", GetMonitors)
	bus.AddHandler("sql", GetMonitorsForAlerts)
	bus.AddHandler("sql", GetMonitorById)
	bus.AddHandler("sql", GetMonitorTypes)
	bus.AddHandler("sql", AddMonitor)
	bus.AddHandler("sql", UpdateMonitor)
	bus.AddHandler("sql", DeleteMonitor)
	bus.AddHandler("sql", UpdateMonitorState)
}
Exemple #16
0
func (sc *scenarioContext) userQueryReturns(user *m.User) {
	bus.AddHandler("test", func(query *m.GetUserByLoginQuery) error {
		if user == nil {
			return m.ErrUserNotFound
		} else {
			query.Result = user
			return nil
		}
	})
}
Exemple #17
0
func init() {

	bus.AddHandler("sql", addProcess)
	bus.AddHandler("sql", GetProcess)
	bus.AddHandler("sql", RemoveOrgProcess)
	bus.AddHandler("sql", GetProcessById)
	//bus.AddHandler("sql",UpdateProcessUser)
	bus.AddHandler("sql", UpdateProcess)
	bus.AddHandler("sql", GetProcessByProcessId)
	bus.AddHandler("sql", GetProcessByName)
	bus.AddHandler("sql", GetProcessByProcessName)
}
Exemple #18
0
func init() {
	bus.AddHandler("sql", GetOrgQuotaByTarget)
	bus.AddHandler("sql", GetOrgQuotas)
	bus.AddHandler("sql", UpdateOrgQuota)
	bus.AddHandler("sql", GetUserQuotaByTarget)
	bus.AddHandler("sql", GetUserQuotas)
	bus.AddHandler("sql", UpdateUserQuota)
	bus.AddHandler("sql", GetGlobalQuotaByTarget)
}
Exemple #19
0
func init() {
	bus.AddHandler("sql", CreatePlaylist)
	bus.AddHandler("sql", UpdatePlaylist)
	bus.AddHandler("sql", DeletePlaylist)
	bus.AddHandler("sql", SearchPlaylists)
	bus.AddHandler("sql", GetPlaylist)
	bus.AddHandler("sql", GetPlaylistDashboards)
	bus.AddHandler("sql", GetPlaylistItem)
}
Exemple #20
0
func init() {
	bus.AddHandler("sql", GetOrgById)
	bus.AddHandler("sql", CreateOrg)
	bus.AddHandler("sql", UpdateOrg)
	bus.AddHandler("sql", UpdateOrgAddress)
	bus.AddHandler("sql", GetOrgByName)
	bus.AddHandler("sql", SearchOrgs)
	bus.AddHandler("sql", DeleteOrg)
}
Exemple #21
0
func init() {
	bus.AddHandler("sql", GetEndpoints)
	bus.AddHandler("sql", GetEndpointById)
	bus.AddHandler("sql", AddEndpoint)
	bus.AddHandler("sql", UpdateEndpoint)
	bus.AddHandler("sql", DeleteEndpoint)
	bus.AddHandler("sql", GetAllEndpointTags)
}
func init() {
	bus.AddHandler("sql", GetAlertNotifications)
	bus.AddHandler("sql", CreateAlertNotificationCommand)
	bus.AddHandler("sql", UpdateAlertNotification)
	bus.AddHandler("sql", DeleteAlertNotification)
	bus.AddHandler("sql", GetAlertNotificationsToSend)
	bus.AddHandler("sql", GetAllAlertNotifications)
}
Exemple #23
0
func init() {
	bus.AddHandler("sql", SaveAlerts)
	bus.AddHandler("sql", HandleAlertsQuery)
	bus.AddHandler("sql", GetAlertById)
	bus.AddHandler("sql", DeleteAlertById)
	bus.AddHandler("sql", GetAllAlertQueryHandler)
	bus.AddHandler("sql", SetAlertState)
}
Exemple #24
0
func init() {
	bus.AddHandler("sql", GetDataSources)
	bus.AddHandler("sql", AddDataSource)
	bus.AddHandler("sql", DeleteDataSource)
	bus.AddHandler("sql", UpdateDataSource)
	bus.AddHandler("sql", GetDataSourceById)
	bus.AddHandler("sql", GetDataSourceByName)
}
Exemple #25
0
func init() {

	bus.AddHandler("sql", GetSubProcess)
	bus.AddHandler("sql", addSubProcess)
	bus.AddHandler("sql", RemoveOrgSubProcess)
	bus.AddHandler("sql", UpdateSubProcess)
	bus.AddHandler("sql", GetSubProcessById)
	bus.AddHandler("sql", GetSubProcessByName)
}
Exemple #26
0
func init() {

	bus.AddHandler("sql", GetMachine)
	bus.AddHandler("sql", addMachine)
	bus.AddHandler("sql", RemoveOrgMachine)
	bus.AddHandler("sql", UpdateMachine)
	bus.AddHandler("sql", GetMachineByMachineId)
	bus.AddHandler("sql", GetMachineById)
}
Exemple #27
0
func Init() {
	bus.AddHandler("search", searchHandler)

	jsonIndexCfg, _ := setting.Cfg.GetSection("dashboards.json")
	jsonIndexEnabled := jsonIndexCfg.Key("enabled").MustBool(false)

	if jsonIndexEnabled {
		jsonFilesPath := jsonIndexCfg.Key("path").String()
		if !filepath.IsAbs(jsonFilesPath) {
			jsonFilesPath = filepath.Join(setting.HomePath, jsonFilesPath)
		}

		jsonDashIndex = NewJsonDashIndex(jsonFilesPath)
		go jsonDashIndex.updateLoop()
	}
}
Exemple #28
0
func queryConditionScenario(desc string, fn queryConditionScenarioFunc) {
	Convey(desc, func() {

		bus.AddHandler("test", func(query *m.GetDataSourceByIdQuery) error {
			query.Result = &m.DataSource{Id: 1, Type: "graphite"}
			return nil
		})

		ctx := &queryConditionTestContext{}
		ctx.result = &alerting.EvalContext{
			Rule: &alerting.Rule{},
		}

		fn(ctx)
	})
}
Exemple #29
0
func init() {
	bus.AddHandler("sql", GetPluginSettings)
	bus.AddHandler("sql", GetPluginSettingById)
	bus.AddHandler("sql", UpdatePluginSetting)
	bus.AddHandler("sql", UpdatePluginSettingVersion)
}
Exemple #30
0
func TestAlertRuleExtraction(t *testing.T) {

	Convey("Parsing alert rules  from dashboard json", t, func() {

		RegisterCondition("query", func(model *simplejson.Json, index int) (Condition, error) {
			return &FakeCondition{}, nil
		})

		Convey("Parsing and validating alerts from dashboards", func() {
			json := `{
        "id": 57,
        "title": "Graphite 4",
        "originalTitle": "Graphite 4",
        "tags": ["graphite"],
        "rows": [
        {
          "panels": [
          {
            "title": "Active desktop users",
            "editable": true,
            "type": "graph",
            "id": 3,
            "targets": [
            {
              "refId": "A",
              "target": "aliasByNode(statsd.fakesite.counters.session_start.desktop.count, 4)"
            }
            ],
            "datasource": null,
            "alert": {
              "name": "name1",
              "message": "desc1",
              "handler": 1,
              "frequency": "60s",
              "conditions": [
              {
                "type": "query",
                "query": {"params": ["A", "5m", "now"]},
                "reducer": {"type": "avg", "params": []},
                "evaluator": {"type": ">", "params": [100]}
              }
              ]
            }
          },
          {
            "title": "Active mobile users",
            "id": 4,
            "targets": [
              {"refId": "A", "target": ""},
              {"refId": "B", "target": "aliasByNode(statsd.fakesite.counters.session_start.mobile.count, 4)"}
            ],
            "datasource": "graphite2",
            "alert": {
              "name": "name2",
              "message": "desc2",
              "handler": 0,
              "frequency": "60s",
              "severity": "warning",
              "conditions": [
              {
                "type": "query",
                "query":  {"params": ["B", "5m", "now"]},
                "reducer": {"type": "avg", "params": []},
                "evaluator": {"type": ">", "params": [100]}
              }
              ]
            }
          }
          ]
        }
      ]
    }`
			dashJson, err := simplejson.NewJson([]byte(json))
			So(err, ShouldBeNil)

			dash := m.NewDashboardFromJson(dashJson)
			extractor := NewDashAlertExtractor(dash, 1)

			// mock data
			defaultDs := &m.DataSource{Id: 12, OrgId: 2, Name: "I am default", IsDefault: true}
			graphite2Ds := &m.DataSource{Id: 15, OrgId: 2, Name: "graphite2"}

			bus.AddHandler("test", func(query *m.GetDataSourcesQuery) error {
				query.Result = []*m.DataSource{defaultDs, graphite2Ds}
				return nil
			})

			bus.AddHandler("test", func(query *m.GetDataSourceByNameQuery) error {
				if query.Name == defaultDs.Name {
					query.Result = defaultDs
				}
				if query.Name == graphite2Ds.Name {
					query.Result = graphite2Ds
				}
				return nil
			})

			alerts, err := extractor.GetAlerts()

			Convey("Get rules without error", func() {
				So(err, ShouldBeNil)
			})

			Convey("all properties have been set", func() {
				So(len(alerts), ShouldEqual, 2)

				for _, v := range alerts {
					So(v.DashboardId, ShouldEqual, 57)
					So(v.Name, ShouldNotBeEmpty)
					So(v.Message, ShouldNotBeEmpty)
				}

				Convey("should extract handler property", func() {
					So(alerts[0].Handler, ShouldEqual, 1)
					So(alerts[1].Handler, ShouldEqual, 0)
				})

				Convey("should extract frequency in seconds", func() {
					So(alerts[0].Frequency, ShouldEqual, 60)
					So(alerts[1].Frequency, ShouldEqual, 60)
				})

				Convey("should extract panel idc", func() {
					So(alerts[0].PanelId, ShouldEqual, 3)
					So(alerts[1].PanelId, ShouldEqual, 4)
				})

				Convey("should extract name and desc", func() {
					So(alerts[0].Name, ShouldEqual, "name1")
					So(alerts[0].Message, ShouldEqual, "desc1")
					So(alerts[1].Name, ShouldEqual, "name2")
					So(alerts[1].Message, ShouldEqual, "desc2")
				})

				Convey("should set datasourceId", func() {
					condition := simplejson.NewFromAny(alerts[0].Settings.Get("conditions").MustArray()[0])
					query := condition.Get("query")
					So(query.Get("datasourceId").MustInt64(), ShouldEqual, 12)
				})

				Convey("should copy query model to condition", func() {
					condition := simplejson.NewFromAny(alerts[0].Settings.Get("conditions").MustArray()[0])
					model := condition.Get("query").Get("model")
					So(model.Get("target").MustString(), ShouldEqual, "aliasByNode(statsd.fakesite.counters.session_start.desktop.count, 4)")
				})
			})
		})
	})
}