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.*", "onTrendUp": true, "onTrendDown": false, "onValueGt": false, "onValueLt": false, "onTrendUpAndValueGt": false, "onTrendDownAndValueLt": false, "thresholdMax": 0, "thresholdMin": 0, "trustLine": 30 } 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 info.
GET /api/info 200 { "numMetric": 1000 }
Index ¶
- Variables
- func Init(c *config.Config, d *storage.DB)
- func RequestBind(r *http.Request, v interface{}) error
- func ResponseError(w http.ResponseWriter, err *WebError) error
- func ResponseJSON(w http.ResponseWriter, code int, v interface{}) error
- func ResponseJSONOK(w http.ResponseWriter, v interface{}) error
- func Start(c *config.Config, d *storage.DB)
- type WebError
Constants ¶
This section is empty.
Variables ¶
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") ErrProjectNameEmpty = NewWebError(http.StatusBadRequest, "Empty project name") ErrProjectNameTooLong = NewWebError(http.StatusBadRequest, "Project name too long") 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") ErrUserNameEmpty = NewWebError(http.StatusBadRequest, "Empty user name") ErrUserNameTooLong = NewWebError(http.StatusBadRequest, "User name too long") ErrUserEmail = NewWebError(http.StatusBadRequest, "Bad user email") ErrUserEmailEmpty = NewWebError(http.StatusBadRequest, "Empty user email") ErrUserPhone = NewWebError(http.StatusBadRequest, "Bad user phone format") ErrUserPhoneLen = NewWebError(http.StatusBadRequest, "Bad user phone length") ErrUserNotFound = NewWebError(http.StatusNotFound, "User not found") ErrDuplicateUserName = NewWebError(http.StatusForbidden, "Duplicate user name") // Rule ErrRuleID = NewWebError(http.StatusBadRequest, "Bad rule id") ErrRulePattern = NewWebError(http.StatusBadRequest, "Bad rule pattern") ErrRulePatternEmpty = NewWebError(http.StatusBadRequest, "Empty rule pattern") ErrRulePatternTooLong = NewWebError(http.StatusBadRequest, "Rule pattern too long") ErrRulePatternContainsSpace = NewWebError(http.StatusBadRequest, "Space found in rule pattern") ErrRuleWhen = NewWebError(http.StatusBadRequest, "Bad rule condition") ErrDuplicateRulePattern = NewWebError(http.StatusForbidden, "Duplicate rule pattern") ErrRuleNotFound = NewWebError(http.StatusNotFound, "Rule not found") ErrRuleNoCondition = NewWebError(http.StatusBadRequest, "No condition specified") ErrRuleThresholdMaxRequired = NewWebError(http.StatusBadRequest, "ThresholdMax is required") ErrRuleThresholdMinRequired = NewWebError(http.StatusBadRequest, "ThresholdMin is required") // Metric ErrMetricNotFound = NewWebError(http.StatusNotFound, "Metric not found") )
Errors
Functions ¶
func RequestBind ¶
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.
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 ¶
NewUnexceptedWebError returns an unexcepted WebError.
func NewWebError ¶
NewWebError creates a WebError.