2014-12-15 14:25:02 -06:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
2016-01-13 08:38:54 -06:00
|
|
|
"github.com/go-macaron/binding"
|
2016-02-20 16:51:22 -06:00
|
|
|
"github.com/grafana/grafana/pkg/api/avatar"
|
2015-02-05 03:37:13 -06:00
|
|
|
"github.com/grafana/grafana/pkg/api/dtos"
|
|
|
|
"github.com/grafana/grafana/pkg/middleware"
|
|
|
|
m "github.com/grafana/grafana/pkg/models"
|
2014-12-15 14:25:02 -06:00
|
|
|
)
|
|
|
|
|
2015-01-14 07:25:12 -06:00
|
|
|
// Register adds http routes
|
2016-12-21 07:36:32 -06:00
|
|
|
func (hs *HttpServer) registerRoutes() {
|
|
|
|
r := hs.macaron
|
2015-01-15 05:16:54 -06:00
|
|
|
reqSignedIn := middleware.Auth(&middleware.AuthOptions{ReqSignedIn: true})
|
2015-01-16 07:32:18 -06:00
|
|
|
reqGrafanaAdmin := middleware.Auth(&middleware.AuthOptions{ReqSignedIn: true, ReqGrafanaAdmin: true})
|
2015-01-19 11:01:04 -06:00
|
|
|
reqEditorRole := middleware.RoleAuth(m.ROLE_EDITOR, m.ROLE_ADMIN)
|
2015-12-03 09:43:55 -06:00
|
|
|
reqOrgAdmin := middleware.RoleAuth(m.ROLE_ADMIN)
|
2015-09-11 10:17:10 -05:00
|
|
|
quota := middleware.Quota
|
2015-01-16 04:54:19 -06:00
|
|
|
bind := binding.Bind
|
2014-12-15 14:25:02 -06:00
|
|
|
|
2016-08-29 07:45:28 -05:00
|
|
|
// automatically set HEAD for every GET
|
|
|
|
r.SetAutoHead(true)
|
|
|
|
|
2015-01-14 07:25:12 -06:00
|
|
|
// not logged in views
|
2015-01-16 04:54:19 -06:00
|
|
|
r.Get("/", reqSignedIn, Index)
|
2015-01-29 08:46:54 -06:00
|
|
|
r.Get("/logout", Logout)
|
2015-09-11 10:17:10 -05:00
|
|
|
r.Post("/login", quota("session"), bind(dtos.LoginCommand{}), wrap(LoginPost))
|
|
|
|
r.Get("/login/:name", quota("session"), OAuthLogin)
|
2015-01-27 03:09:54 -06:00
|
|
|
r.Get("/login", LoginView)
|
2015-08-10 06:46:59 -05:00
|
|
|
r.Get("/invite/:code", Index)
|
2014-12-15 14:25:02 -06:00
|
|
|
|
2015-01-14 07:25:12 -06:00
|
|
|
// authed views
|
2015-01-19 12:10:29 -06:00
|
|
|
r.Get("/profile/", reqSignedIn, Index)
|
2016-04-04 12:52:41 -05:00
|
|
|
r.Get("/profile/password", reqSignedIn, Index)
|
2016-04-09 12:27:06 -05:00
|
|
|
r.Get("/profile/switch-org/:id", reqSignedIn, ChangeActiveOrgAndRedirectToHome)
|
2015-02-25 07:27:34 -06:00
|
|
|
r.Get("/org/", reqSignedIn, Index)
|
2015-06-11 01:16:09 -05:00
|
|
|
r.Get("/org/new", reqSignedIn, Index)
|
2015-02-25 07:27:34 -06:00
|
|
|
r.Get("/datasources/", reqSignedIn, Index)
|
2016-06-17 06:35:29 -05:00
|
|
|
r.Get("/datasources/new", reqSignedIn, Index)
|
2015-02-28 01:25:13 -06:00
|
|
|
r.Get("/datasources/edit/*", reqSignedIn, Index)
|
2015-02-25 07:27:34 -06:00
|
|
|
r.Get("/org/users/", reqSignedIn, Index)
|
|
|
|
r.Get("/org/apikeys/", reqSignedIn, Index)
|
|
|
|
r.Get("/dashboard/import/", reqSignedIn, Index)
|
2016-03-03 16:05:08 -06:00
|
|
|
r.Get("/admin", reqGrafanaAdmin, Index)
|
2015-02-12 08:46:14 -06:00
|
|
|
r.Get("/admin/settings", reqGrafanaAdmin, Index)
|
2015-01-28 04:33:50 -06:00
|
|
|
r.Get("/admin/users", reqGrafanaAdmin, Index)
|
2015-02-10 09:26:23 -06:00
|
|
|
r.Get("/admin/users/create", reqGrafanaAdmin, Index)
|
|
|
|
r.Get("/admin/users/edit/:id", reqGrafanaAdmin, Index)
|
2015-08-11 08:20:50 -05:00
|
|
|
r.Get("/admin/orgs", reqGrafanaAdmin, Index)
|
|
|
|
r.Get("/admin/orgs/edit/:id", reqGrafanaAdmin, Index)
|
2016-01-24 23:18:17 -06:00
|
|
|
r.Get("/admin/stats", reqGrafanaAdmin, Index)
|
2015-10-20 09:02:56 -05:00
|
|
|
|
2016-03-28 06:10:42 -05:00
|
|
|
r.Get("/styleguide", reqSignedIn, Index)
|
|
|
|
|
2016-02-29 05:54:36 -06:00
|
|
|
r.Get("/plugins", reqSignedIn, Index)
|
|
|
|
r.Get("/plugins/:id/edit", reqSignedIn, Index)
|
|
|
|
r.Get("/plugins/:id/page/:page", reqSignedIn, Index)
|
2015-12-04 05:21:33 -06:00
|
|
|
|
2015-01-16 04:54:19 -06:00
|
|
|
r.Get("/dashboard/*", reqSignedIn, Index)
|
2016-09-22 04:46:58 -05:00
|
|
|
r.Get("/dashboard-solo/snapshot/*", Index)
|
2015-10-20 09:02:56 -05:00
|
|
|
r.Get("/dashboard-solo/*", reqSignedIn, Index)
|
2016-05-03 09:40:21 -05:00
|
|
|
r.Get("/import/dashboard", reqSignedIn, Index)
|
2016-05-19 04:03:10 -05:00
|
|
|
r.Get("/dashboards/*", reqSignedIn, Index)
|
2014-12-16 05:04:08 -06:00
|
|
|
|
2015-12-22 04:07:15 -06:00
|
|
|
r.Get("/playlists/", reqSignedIn, Index)
|
|
|
|
r.Get("/playlists/*", reqSignedIn, Index)
|
2016-06-06 02:17:29 -05:00
|
|
|
r.Get("/alerting/", reqSignedIn, Index)
|
2016-06-15 03:48:04 -05:00
|
|
|
r.Get("/alerting/*", reqSignedIn, Index)
|
2015-12-22 04:07:15 -06:00
|
|
|
|
2015-01-14 07:25:12 -06:00
|
|
|
// sign up
|
2015-07-19 05:34:03 -05:00
|
|
|
r.Get("/signup", Index)
|
2015-08-31 04:35:07 -05:00
|
|
|
r.Get("/api/user/signup/options", wrap(GetSignUpOptions))
|
2015-09-11 10:17:10 -05:00
|
|
|
r.Post("/api/user/signup", quota("user"), bind(dtos.SignUpForm{}), wrap(SignUp))
|
2015-08-28 02:24:30 -05:00
|
|
|
r.Post("/api/user/signup/step2", bind(dtos.SignUpStep2Form{}), wrap(SignUpStep2))
|
2014-12-15 14:25:02 -06:00
|
|
|
|
2015-07-20 08:52:49 -05:00
|
|
|
// invited
|
|
|
|
r.Get("/api/user/invite/:code", wrap(GetInviteInfoByCode))
|
2015-07-20 10:46:48 -05:00
|
|
|
r.Post("/api/user/invite/complete", bind(dtos.CompleteInviteForm{}), wrap(CompleteInvite))
|
2015-07-20 08:52:49 -05:00
|
|
|
|
2015-06-08 03:57:01 -05:00
|
|
|
// reset password
|
|
|
|
r.Get("/user/password/send-reset-email", Index)
|
|
|
|
r.Get("/user/password/reset", Index)
|
|
|
|
|
|
|
|
r.Post("/api/user/password/send-reset-email", bind(dtos.SendResetPasswordEmailForm{}), wrap(SendResetPasswordEmail))
|
2015-06-08 06:39:02 -05:00
|
|
|
r.Post("/api/user/password/reset", bind(dtos.ResetUserPasswordForm{}), wrap(ResetPassword))
|
2014-12-15 14:25:02 -06:00
|
|
|
|
2015-03-21 07:53:16 -05:00
|
|
|
// dashboard snapshots
|
2015-04-15 03:39:03 -05:00
|
|
|
r.Get("/dashboard/snapshot/*", Index)
|
2016-01-19 07:05:24 -06:00
|
|
|
r.Get("/dashboard/snapshots/", reqSignedIn, Index)
|
2015-03-26 14:34:58 -05:00
|
|
|
|
2016-01-19 07:05:24 -06:00
|
|
|
// api for dashboard snapshots
|
|
|
|
r.Post("/api/snapshots/", bind(m.CreateDashboardSnapshotCommand{}), CreateDashboardSnapshot)
|
2015-10-14 09:39:57 -05:00
|
|
|
r.Get("/api/snapshot/shared-options/", GetSharingOptions)
|
2015-03-21 07:53:16 -05:00
|
|
|
r.Get("/api/snapshots/:key", GetDashboardSnapshot)
|
2016-03-18 03:13:34 -05:00
|
|
|
r.Get("/api/snapshots-delete/:key", reqEditorRole, DeleteDashboardSnapshot)
|
2015-03-21 07:53:16 -05:00
|
|
|
|
2015-04-07 02:25:00 -05:00
|
|
|
// api renew session based on remember cookie
|
2015-09-11 10:17:10 -05:00
|
|
|
r.Get("/api/login/ping", quota("session"), LoginApiPing)
|
2015-04-07 02:25:00 -05:00
|
|
|
|
2015-01-14 07:25:12 -06:00
|
|
|
// authed api
|
2015-01-16 04:54:19 -06:00
|
|
|
r.Group("/api", func() {
|
2015-05-19 04:47:14 -05:00
|
|
|
|
|
|
|
// user (signed in)
|
2015-01-19 11:01:04 -06:00
|
|
|
r.Group("/user", func() {
|
2015-05-18 10:28:15 -05:00
|
|
|
r.Get("/", wrap(GetSignedInUser))
|
2015-05-18 12:06:19 -05:00
|
|
|
r.Put("/", bind(m.UpdateUserCommand{}), wrap(UpdateSignedInUser))
|
2015-05-20 07:59:38 -05:00
|
|
|
r.Post("/using/:id", wrap(UserSetUsingOrg))
|
2015-05-18 10:28:15 -05:00
|
|
|
r.Get("/orgs", wrap(GetSignedInUserOrgList))
|
2016-04-02 15:54:06 -05:00
|
|
|
|
2015-05-20 07:59:38 -05:00
|
|
|
r.Post("/stars/dashboard/:id", wrap(StarDashboard))
|
|
|
|
r.Delete("/stars/dashboard/:id", wrap(UnstarDashboard))
|
2016-04-02 15:54:06 -05:00
|
|
|
|
2015-05-20 07:59:38 -05:00
|
|
|
r.Put("/password", bind(m.ChangeUserPasswordCommand{}), wrap(ChangeUserPassword))
|
2015-09-11 10:17:10 -05:00
|
|
|
r.Get("/quotas", wrap(GetUserQuotas))
|
2016-11-09 03:41:39 -06:00
|
|
|
r.Put("/helpflags/:id", wrap(SetHelpFlag))
|
|
|
|
// For dev purpose
|
|
|
|
r.Get("/helpflags/clear", wrap(ClearHelpFlags))
|
2016-04-02 15:54:06 -05:00
|
|
|
|
2016-04-01 19:34:30 -05:00
|
|
|
r.Get("/preferences", wrap(GetUserPreferences))
|
2016-04-02 15:54:06 -05:00
|
|
|
r.Put("/preferences", bind(dtos.UpdatePrefsCmd{}), wrap(UpdateUserPreferences))
|
2015-01-19 11:01:04 -06:00
|
|
|
})
|
|
|
|
|
2015-05-19 04:47:14 -05:00
|
|
|
// users (admin permission required)
|
2015-05-18 10:28:15 -05:00
|
|
|
r.Group("/users", func() {
|
2015-05-19 04:47:14 -05:00
|
|
|
r.Get("/", wrap(SearchUsers))
|
2015-05-18 12:06:19 -05:00
|
|
|
r.Get("/:id", wrap(GetUserById))
|
2015-05-19 02:09:21 -05:00
|
|
|
r.Get("/:id/orgs", wrap(GetUserOrgList))
|
2017-01-30 23:25:55 -06:00
|
|
|
// query parameters /users/lookup?loginOrEmail=admin@example.com
|
|
|
|
r.Get("/lookup", wrap(GetUserByLoginOrEmail))
|
2015-05-18 12:06:19 -05:00
|
|
|
r.Put("/:id", bind(m.UpdateUserCommand{}), wrap(UpdateUser))
|
2016-05-25 23:51:23 -05:00
|
|
|
r.Post("/:id/using/:orgId", wrap(UpdateUserActiveOrg))
|
2015-05-18 10:28:15 -05:00
|
|
|
}, reqGrafanaAdmin)
|
|
|
|
|
2015-09-10 12:18:36 -05:00
|
|
|
// org information available to all users.
|
2015-02-23 11:29:01 -06:00
|
|
|
r.Group("/org", func() {
|
2015-05-19 03:16:32 -05:00
|
|
|
r.Get("/", wrap(GetOrgCurrent))
|
2015-09-11 10:17:10 -05:00
|
|
|
r.Get("/quotas", wrap(GetOrgQuotas))
|
2015-09-10 12:18:36 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
// current org
|
|
|
|
r.Group("/org", func() {
|
2015-09-08 07:22:44 -05:00
|
|
|
r.Put("/", bind(dtos.UpdateOrgForm{}), wrap(UpdateOrgCurrent))
|
|
|
|
r.Put("/address", bind(dtos.UpdateOrgAddressForm{}), wrap(UpdateOrgAddressCurrent))
|
2015-09-11 10:17:10 -05:00
|
|
|
r.Post("/users", quota("user"), bind(m.AddOrgUserCommand{}), wrap(AddOrgUserToCurrentOrg))
|
2015-05-19 03:16:32 -05:00
|
|
|
r.Get("/users", wrap(GetOrgUsersForCurrentOrg))
|
|
|
|
r.Patch("/users/:userId", bind(m.UpdateOrgUserCommand{}), wrap(UpdateOrgUserForCurrentOrg))
|
|
|
|
r.Delete("/users/:userId", wrap(RemoveOrgUserForCurrentOrg))
|
2015-07-17 02:51:34 -05:00
|
|
|
|
|
|
|
// invites
|
|
|
|
r.Get("/invites", wrap(GetPendingOrgInvites))
|
2015-09-11 10:17:10 -05:00
|
|
|
r.Post("/invites", quota("user"), bind(dtos.AddInviteForm{}), wrap(AddOrgInvite))
|
2015-07-20 10:46:48 -05:00
|
|
|
r.Patch("/invites/:code/revoke", wrap(RevokeInvite))
|
2015-12-17 23:46:40 -06:00
|
|
|
|
2016-04-02 15:54:06 -05:00
|
|
|
// prefs
|
|
|
|
r.Get("/preferences", wrap(GetOrgPreferences))
|
|
|
|
r.Put("/preferences", bind(dtos.UpdatePrefsCmd{}), wrap(UpdateOrgPreferences))
|
2015-12-03 09:43:55 -06:00
|
|
|
}, reqOrgAdmin)
|
2015-05-19 03:16:32 -05:00
|
|
|
|
|
|
|
// create new org
|
2015-09-11 10:17:10 -05:00
|
|
|
r.Post("/orgs", quota("org"), bind(m.CreateOrgCommand{}), wrap(CreateOrg))
|
2015-05-19 03:16:32 -05:00
|
|
|
|
2015-05-19 04:47:14 -05:00
|
|
|
// search all orgs
|
|
|
|
r.Get("/orgs", reqGrafanaAdmin, wrap(SearchOrgs))
|
|
|
|
|
2015-05-19 03:16:32 -05:00
|
|
|
// orgs (admin routes)
|
|
|
|
r.Group("/orgs/:orgId", func() {
|
2015-08-11 08:20:50 -05:00
|
|
|
r.Get("/", wrap(GetOrgById))
|
2015-09-08 07:22:44 -05:00
|
|
|
r.Put("/", bind(dtos.UpdateOrgForm{}), wrap(UpdateOrg))
|
|
|
|
r.Put("/address", bind(dtos.UpdateOrgAddressForm{}), wrap(UpdateOrgAddress))
|
2015-08-12 01:59:25 -05:00
|
|
|
r.Delete("/", wrap(DeleteOrgById))
|
2015-05-19 03:16:32 -05:00
|
|
|
r.Get("/users", wrap(GetOrgUsers))
|
|
|
|
r.Post("/users", bind(m.AddOrgUserCommand{}), wrap(AddOrgUser))
|
|
|
|
r.Patch("/users/:userId", bind(m.UpdateOrgUserCommand{}), wrap(UpdateOrgUser))
|
|
|
|
r.Delete("/users/:userId", wrap(RemoveOrgUser))
|
2015-07-20 07:51:27 -05:00
|
|
|
r.Get("/quotas", wrap(GetOrgQuotas))
|
2015-09-11 10:17:10 -05:00
|
|
|
r.Put("/quotas/:target", bind(m.UpdateOrgQuotaCmd{}), wrap(UpdateOrgQuota))
|
2015-05-19 03:16:32 -05:00
|
|
|
}, reqGrafanaAdmin)
|
2015-01-26 13:26:17 -06:00
|
|
|
|
2016-01-12 15:50:56 -06:00
|
|
|
// orgs (admin routes)
|
|
|
|
r.Group("/orgs/name/:name", func() {
|
|
|
|
r.Get("/", wrap(GetOrgByName))
|
|
|
|
}, reqGrafanaAdmin)
|
|
|
|
|
2015-01-27 01:26:11 -06:00
|
|
|
// auth api keys
|
|
|
|
r.Group("/auth/keys", func() {
|
2015-05-18 14:23:40 -05:00
|
|
|
r.Get("/", wrap(GetApiKeys))
|
2015-09-11 10:17:10 -05:00
|
|
|
r.Post("/", quota("api_key"), bind(m.AddApiKeyCommand{}), wrap(AddApiKey))
|
2015-05-18 14:23:40 -05:00
|
|
|
r.Delete("/:id", wrap(DeleteApiKey))
|
2015-12-03 09:43:55 -06:00
|
|
|
}, reqOrgAdmin)
|
2015-01-26 13:26:17 -06:00
|
|
|
|
2016-03-17 01:35:06 -05:00
|
|
|
// Preferences
|
|
|
|
r.Group("/preferences", func() {
|
|
|
|
r.Post("/set-home-dash", bind(m.SavePreferencesCommand{}), wrap(SetHomeDashboard))
|
|
|
|
})
|
2016-03-11 08:30:05 -06:00
|
|
|
|
2015-01-14 07:25:12 -06:00
|
|
|
// Data sources
|
2015-01-16 04:54:19 -06:00
|
|
|
r.Group("/datasources", func() {
|
2015-06-01 05:15:49 -05:00
|
|
|
r.Get("/", GetDataSources)
|
2015-09-11 10:17:10 -05:00
|
|
|
r.Post("/", quota("data_source"), bind(m.AddDataSourceCommand{}), AddDataSource)
|
2016-12-07 11:09:17 -06:00
|
|
|
r.Put("/:id", bind(m.UpdateDataSourceCommand{}), wrap(UpdateDataSource))
|
2015-01-16 04:54:19 -06:00
|
|
|
r.Delete("/:id", DeleteDataSource)
|
2015-11-13 02:43:25 -06:00
|
|
|
r.Get("/:id", wrap(GetDataSourceById))
|
2016-03-10 03:31:10 -06:00
|
|
|
r.Get("/name/:name", wrap(GetDataSourceByName))
|
2015-12-03 09:43:55 -06:00
|
|
|
}, reqOrgAdmin)
|
|
|
|
|
2016-03-10 03:31:10 -06:00
|
|
|
r.Get("/datasources/id/:name", wrap(GetDataSourceIdByName), reqSignedIn)
|
2016-03-07 14:25:26 -06:00
|
|
|
|
2016-04-13 11:23:29 -05:00
|
|
|
r.Get("/plugins", wrap(GetPluginList))
|
2016-04-13 12:03:41 -05:00
|
|
|
r.Get("/plugins/:pluginId/settings", wrap(GetPluginSettingById))
|
2016-09-22 12:46:11 -05:00
|
|
|
r.Get("/plugins/:pluginId/readme", wrap(GetPluginReadme))
|
2016-03-11 02:57:20 -06:00
|
|
|
|
2016-04-13 11:23:29 -05:00
|
|
|
r.Group("/plugins", func() {
|
2016-03-13 13:21:44 -05:00
|
|
|
r.Get("/:pluginId/dashboards/", wrap(GetPluginDashboards))
|
2016-03-11 02:57:20 -06:00
|
|
|
r.Post("/:pluginId/settings", bind(m.UpdatePluginSettingCmd{}), wrap(UpdatePluginSetting))
|
2015-12-03 09:43:55 -06:00
|
|
|
}, reqOrgAdmin)
|
|
|
|
|
2015-02-18 07:06:44 -06:00
|
|
|
r.Get("/frontend/settings/", GetFrontendSettings)
|
2015-02-10 03:19:43 -06:00
|
|
|
r.Any("/datasources/proxy/:id/*", reqSignedIn, ProxyDataSourceRequest)
|
2015-05-19 16:47:39 -05:00
|
|
|
r.Any("/datasources/proxy/:id", reqSignedIn, ProxyDataSourceRequest)
|
2015-02-10 03:19:43 -06:00
|
|
|
|
2015-01-14 07:25:12 -06:00
|
|
|
// Dashboard
|
2015-02-03 08:04:35 -06:00
|
|
|
r.Group("/dashboards", func() {
|
|
|
|
r.Combo("/db/:slug").Get(GetDashboard).Delete(DeleteDashboard)
|
2016-07-08 02:35:06 -05:00
|
|
|
r.Post("/db", reqEditorRole, bind(m.SaveDashboardCommand{}), wrap(PostDashboard))
|
2015-05-12 07:11:30 -05:00
|
|
|
r.Get("/file/:file", GetDashboardFromJsonFile)
|
2016-05-25 02:56:45 -05:00
|
|
|
r.Get("/home", wrap(GetHomeDashboard))
|
2015-05-13 03:45:53 -05:00
|
|
|
r.Get("/tags", GetDashboardTags)
|
2016-03-13 13:21:44 -05:00
|
|
|
r.Post("/import", bind(dtos.ImportDashboardCommand{}), wrap(ImportDashboard))
|
2015-01-14 07:25:12 -06:00
|
|
|
})
|
2015-01-26 13:26:17 -06:00
|
|
|
|
2016-01-19 07:05:24 -06:00
|
|
|
// Dashboard snapshots
|
|
|
|
r.Group("/dashboard/snapshots", func() {
|
|
|
|
r.Get("/", wrap(SearchDashboardSnapshots))
|
|
|
|
})
|
2016-01-19 03:37:36 -06:00
|
|
|
|
2015-12-22 04:07:15 -06:00
|
|
|
// Playlist
|
|
|
|
r.Group("/playlists", func() {
|
2016-01-08 07:21:30 -06:00
|
|
|
r.Get("/", wrap(SearchPlaylists))
|
|
|
|
r.Get("/:id", ValidateOrgPlaylist, wrap(GetPlaylist))
|
2016-01-12 07:36:04 -06:00
|
|
|
r.Get("/:id/items", ValidateOrgPlaylist, wrap(GetPlaylistItems))
|
|
|
|
r.Get("/:id/dashboards", ValidateOrgPlaylist, wrap(GetPlaylistDashboards))
|
2016-01-08 07:21:30 -06:00
|
|
|
r.Delete("/:id", reqEditorRole, ValidateOrgPlaylist, wrap(DeletePlaylist))
|
2016-01-18 09:00:11 -06:00
|
|
|
r.Put("/:id", reqEditorRole, bind(m.UpdatePlaylistCommand{}), ValidateOrgPlaylist, wrap(UpdatePlaylist))
|
|
|
|
r.Post("/", reqEditorRole, bind(m.CreatePlaylistCommand{}), wrap(CreatePlaylist))
|
2015-12-22 04:07:15 -06:00
|
|
|
})
|
|
|
|
|
2015-01-14 07:25:12 -06:00
|
|
|
// Search
|
2015-01-16 04:54:19 -06:00
|
|
|
r.Get("/search/", Search)
|
2015-01-26 13:26:17 -06:00
|
|
|
|
2015-01-14 07:25:12 -06:00
|
|
|
// metrics
|
2016-09-27 11:17:39 -05:00
|
|
|
r.Post("/tsdb/query", bind(dtos.MetricRequest{}), wrap(QueryMetrics))
|
|
|
|
r.Get("/tsdb/testdata/scenarios", wrap(GetTestDataScenarios))
|
2015-07-20 09:38:25 -05:00
|
|
|
|
2016-06-03 08:06:57 -05:00
|
|
|
// metrics
|
|
|
|
r.Get("/metrics", wrap(GetInternalMetrics))
|
2015-07-20 09:38:25 -05:00
|
|
|
|
2016-07-14 06:32:16 -05:00
|
|
|
r.Group("/alerts", func() {
|
2016-07-21 03:29:11 -05:00
|
|
|
r.Post("/test", bind(dtos.AlertTestCommand{}), wrap(AlertTest))
|
2016-10-19 01:01:14 -05:00
|
|
|
r.Post("/:alertId/pause", bind(dtos.PauseAlertCommand{}), wrap(PauseAlert), reqEditorRole)
|
2016-07-14 06:32:16 -05:00
|
|
|
r.Get("/:alertId", ValidateOrgAlert, wrap(GetAlert))
|
|
|
|
r.Get("/", wrap(GetAlerts))
|
2016-09-30 10:37:47 -05:00
|
|
|
r.Get("/states-for-dashboard", wrap(GetAlertStatesForDashboard))
|
2016-04-26 10:36:50 -05:00
|
|
|
})
|
|
|
|
|
2016-07-14 06:32:16 -05:00
|
|
|
r.Get("/alert-notifications", wrap(GetAlertNotifications))
|
2017-01-06 05:04:25 -06:00
|
|
|
r.Get("/alert-notifiers", wrap(GetAlertNotifiers))
|
2016-07-14 06:32:16 -05:00
|
|
|
|
|
|
|
r.Group("/alert-notifications", func() {
|
2016-09-05 07:43:53 -05:00
|
|
|
r.Post("/test", bind(dtos.NotificationTestCommand{}), wrap(NotificationTest))
|
2016-07-14 06:32:16 -05:00
|
|
|
r.Post("/", bind(m.CreateAlertNotificationCommand{}), wrap(CreateAlertNotification))
|
|
|
|
r.Put("/:notificationId", bind(m.UpdateAlertNotificationCommand{}), wrap(UpdateAlertNotification))
|
|
|
|
r.Get("/:notificationId", wrap(GetAlertNotificationById))
|
|
|
|
r.Delete("/:notificationId", wrap(DeleteAlertNotification))
|
2016-10-19 01:01:14 -05:00
|
|
|
}, reqEditorRole)
|
2016-07-14 06:32:16 -05:00
|
|
|
|
2016-09-08 04:25:45 -05:00
|
|
|
r.Get("/annotations", wrap(GetAnnotations))
|
2016-10-14 02:33:16 -05:00
|
|
|
r.Post("/annotations/mass-delete", reqOrgAdmin, bind(dtos.DeleteAnnotationsCmd{}), wrap(DeleteAnnotations))
|
2016-09-08 04:25:45 -05:00
|
|
|
|
2016-06-07 03:05:10 -05:00
|
|
|
// error test
|
|
|
|
r.Get("/metrics/error", wrap(GenerateError))
|
|
|
|
|
2015-01-15 05:16:54 -06:00
|
|
|
}, reqSignedIn)
|
|
|
|
|
|
|
|
// admin api
|
2015-01-16 04:54:19 -06:00
|
|
|
r.Group("/api/admin", func() {
|
2015-02-12 08:46:14 -06:00
|
|
|
r.Get("/settings", AdminGetSettings)
|
2015-02-10 08:36:51 -06:00
|
|
|
r.Post("/users", bind(dtos.AdminCreateUserForm{}), AdminCreateUser)
|
2015-02-23 04:24:22 -06:00
|
|
|
r.Put("/users/:id/password", bind(dtos.AdminUpdateUserPasswordForm{}), AdminUpdateUserPassword)
|
2015-02-26 08:43:48 -06:00
|
|
|
r.Put("/users/:id/permissions", bind(dtos.AdminUpdateUserPermissionsForm{}), AdminUpdateUserPermissions)
|
2015-02-11 09:47:22 -06:00
|
|
|
r.Delete("/users/:id", AdminDeleteUser)
|
2015-09-11 10:17:10 -05:00
|
|
|
r.Get("/users/:id/quotas", wrap(GetUserQuotas))
|
|
|
|
r.Put("/users/:id/quotas/:target", bind(m.UpdateUserQuotaCmd{}), wrap(UpdateUserQuota))
|
2016-01-24 23:18:17 -06:00
|
|
|
r.Get("/stats", AdminGetStats)
|
2016-12-19 07:36:44 -06:00
|
|
|
r.Post("/pause-all-alerts", bind(dtos.PauseAllAlertsCommand{}), wrap(PauseAllAlerts))
|
2015-01-16 07:32:18 -06:00
|
|
|
}, reqGrafanaAdmin)
|
2014-12-15 14:25:02 -06:00
|
|
|
|
|
|
|
// rendering
|
2015-01-16 04:54:19 -06:00
|
|
|
r.Get("/render/*", reqSignedIn, RenderToPng)
|
2015-01-06 02:11:00 -06:00
|
|
|
|
2016-04-08 15:42:33 -05:00
|
|
|
// grafana.net proxy
|
|
|
|
r.Any("/api/gnet/*", reqSignedIn, ProxyGnetRequest)
|
|
|
|
|
2016-02-20 16:51:22 -06:00
|
|
|
// Gravatar service.
|
|
|
|
avt := avatar.CacheServer()
|
|
|
|
r.Get("/avatar/:hash", avt.ServeHTTP)
|
|
|
|
|
2016-03-03 16:05:08 -06:00
|
|
|
// Websocket
|
2016-12-21 07:36:32 -06:00
|
|
|
r.Any("/ws", hs.streamManager.Serve)
|
2016-03-03 16:05:08 -06:00
|
|
|
|
2016-03-14 10:18:07 -05:00
|
|
|
// streams
|
2016-12-21 07:36:32 -06:00
|
|
|
//r.Post("/api/streams/push", reqSignedIn, bind(dtos.StreamMessage{}), liveConn.PushToStream)
|
2016-03-14 10:18:07 -05:00
|
|
|
|
2016-01-21 11:15:04 -06:00
|
|
|
InitAppPluginRoutes(r)
|
2015-10-06 04:20:50 -05:00
|
|
|
|
2016-11-16 10:08:49 -06:00
|
|
|
r.NotFound(NotFoundHandler)
|
2014-12-15 14:25:02 -06:00
|
|
|
}
|