webapp

package
v0.0.0-...-299c846 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 3, 2016 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package webapp implements a simple http web server to visualize detection results and to manage alerting rules.

Web API

1. Get config.

Basic auth required.

GET /api/config

200
{
	"interval": 10,
	...
}

2. Get interval.

GET /api/interval

200
{
	"interval": 10
}

3. Get all projects.

GET /api/projects

200
[
	{"id": 1, "name": "foo"},
	...
]

4. Get project by id.

GET /api/project/:id

200
{"id": 1, "name": "foo"}

5. Create project.

Baisc auth required.

POST /api/project -d {"name": "myNewProject"}

200
{
	"id": 12,
	"name": "myNewProject"
}

6. Update project.

Baisc auth required.

PATCH /api/project/:id -d {"name": "newProjectName"}

200
{
	"id": 12,
	"name": "newProjectName"
}

7. Delete project.

Basic auth required.

DELETE /api/project/:id

200

8. Get rules of a project.

Basic auth required.

GET /api/project/:id/rules

200
[
	{"id": 1, "pattern": "timer.count_ps.*", ...},
	...
]

9. Get users of a project.

Basic auth required.

GET /api/project/:id/users

200
[
	{"id": 1, "name": "jack", ...},
	...
]

10. Create user.

Basic auth required.

POST /api/user -d
{
	"name": "jack",
	"email": "jack@gmail.com",
	"enableEmail": false,
	"phone": "18718718718",
	"enablePhone": true,
	"universal": true
}

200
{
	"id": 1,
	"name": "jack",
	...
}

11. Get all users.

Baisc auth required.

GET /api/users

200
[
	{"id": 1, "name": "jack", "email": "jack@gmail.com", ...},
	...
]

12. Get user by id.

Baisc auth required.

GET /api/user/:id

200
{
	"id": 1,
	"name": "jack",
	"email": "jack@gmail.com",
	...
}

14. Delete user by id.

Basic auth required.

DELETE /api/user/:id

200

15. Get projects of a user.

Basic auth required.

GET /api/user/:id/projects

200
[
	{
		"id": 1,
		"name", "foo"
	},
	...
]

16. Add user to a project.

Basic auth required.

POST /api/project/:id/user -d
{
	"name": "jack"
}

200

17. Delete user from a project.

Baisc auth required.

DELETE /api/project/:id/user/:user_id

200

18. Create a rule for a project.

Baisc auth required.

POST /api/project/:id/rule -d
{
	"pattern": "timer.count_ps.*",
	"trendUp": true,
	"trendDown": false,
	"thresholdMax": 0,
	"thresholdMin": 0,
	"repr": "trend ↑"
}

200
{
	"id": 1,
	"pattern": "timer.count_ps.*",
	...
}

19. Delete a rule.

Baisc auth required.

DELETE /api/rule/:id

200

20. Get metric indexes.

GET /api/metric/indexes?limit=<number>&sort=<up|down>&pattern=timer.*
Or
GET /api/metric/indexes?limit=<number>&sort=<up|down>&project=1

200
[
	{"name": "timer.mean_90.foo", "score": 1.21},
	...
]

21. Get metric values.

GET /api/metric/data?start=<timstamp>&stop=<timestamp>&name=timer.count_ps.foo

200
[
	{"name": "timer.count_ps.foo", "stamp": ..., "value": ..., "score": ...},
	...
]

22. Get metric matched rules.

GET /api/metric/rules/<name>

200
[
	{"id": 1, "projectID": 1, ..},
	...
]

23. Get health info.

GET /api/info

200
{
	"aggregationInterval": 300,
	"numIndexTotal": 3115,
	"numClients": 40,
	"detectionCost": 5.480208245735771,
	"numMetricIncomed": 1148119,
	"numMetricDetected": 35880,
	"numAlertingEvents": 2
}

24. Get banshee version.

GET /api/version

200
{
	"version": "0.1.1"
}

25. Get webapp notice.

GET /api/notice

200
{
	"name": "url"
}

26. Get webapp language.

GET /api/language

200
{
	"language": "zh"
}

Index

Constants

This section is empty.

Variables

View Source
var (
	// Common
	ErrBadRequest = NewWebError(http.StatusBadRequest, "Bad request")
	ErrNotNull    = NewWebError(http.StatusBadRequest, "Null value")
	ErrPrimaryKey = NewWebError(http.StatusForbidden, "Primarykey voilated")
	ErrUnique     = NewWebError(http.StatusForbidden, "Value should be unique")
	ErrNotFound   = NewWebError(http.StatusNotFound, "Not found")
	// Project
	ErrProjectID            = NewWebError(http.StatusBadRequest, "Bad project id")
	ErrProjectNotFound      = NewWebError(http.StatusNotFound, "Project not found")
	ErrDuplicateProjectName = NewWebError(http.StatusForbidden, "Duplicate project name")
	ErrDuplicateProjectUser = NewWebError(http.StatusForbidden, "Duplicate user to project")
	ErrProjectUniversalUser = NewWebError(http.StatusForbidden, "Cannot add universal user to project")
	// User
	ErrUserID            = NewWebError(http.StatusBadRequest, "Bad user id")
	ErrUserNotFound      = NewWebError(http.StatusNotFound, "User not found")
	ErrDuplicateUserName = NewWebError(http.StatusForbidden, "Duplicate user name")
	// Rule
	ErrRuleID               = NewWebError(http.StatusBadRequest, "Bad rule id")
	ErrDuplicateRulePattern = NewWebError(http.StatusForbidden, "Duplicate rule pattern")
	ErrRuleNotFound         = NewWebError(http.StatusNotFound, "Rule not found")
	ErrRuleNoCondition      = NewWebError(http.StatusBadRequest, "No condition specified")
	ErrRuleCommentNotValid  = NewWebError(http.StatusBadRequest, "Rule comment is not valid, empty?")
	ErrRuleUpdateFailed     = NewWebError(http.StatusBadRequest, "Failed to update rule")
	// Metric
	ErrMetricNotFound = NewWebError(http.StatusNotFound, "Metric not found")
)

Errors

Functions

func Init

func Init(c *config.Config, d *storage.DB)

Init globals.

func RequestBind

func RequestBind(r *http.Request, v interface{}) error

RequestBind binds request data into value.

func ResponseError

func ResponseError(w http.ResponseWriter, err *WebError) error

ResponseError writes WebError as response.

func ResponseJSON

func ResponseJSON(w http.ResponseWriter, code int, v interface{}) error

ResponseJSON encodes value to json and write as response.

func ResponseJSONOK

func ResponseJSONOK(w http.ResponseWriter, v interface{}) error

ResponseJSONOK writes ok response.

func Start

func Start(c *config.Config, d *storage.DB, f *filter.Filter)

Start http server.

Types

type WebError

type WebError struct {
	// HTTP status code
	Code int `json:"code"`
	// Message
	Msg string `json:"msg"`
}

WebError is errors for web operations.

func NewUnexceptedWebError

func NewUnexceptedWebError(err error) *WebError

NewUnexceptedWebError returns an unexcepted WebError.

func NewValidationWebError

func NewValidationWebError(err error) *WebError

NewValidationWebError creates a validation WebError from error.

func NewWebError

func NewWebError(code int, text string) *WebError

NewWebError creates a WebError.

func (*WebError) Error

func (err *WebError) Error() string

Error returns the string format of the WebError.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL