feat(server): allow to specify offset, limit and pattern
parent
51c506c8fe
commit
a172b72aae
|
@ -279,13 +279,16 @@ func (c *Client) status(ctx context.Context, href string) (client.TaskStatus, er
|
|||
|
||||
// All returns all tasks in kapacitor
|
||||
func (c *Client) All(ctx context.Context) (map[string]*Task, error) {
|
||||
return c.List(ctx, &client.ListTasksOptions{})
|
||||
}
|
||||
|
||||
// List kapacitor tasks according to options supplied
|
||||
func (c *Client) List(ctx context.Context, opts *client.ListTasksOptions) (map[string]*Task, error) {
|
||||
kapa, err := c.kapaClient(c.URL, c.Username, c.Password, c.InsecureSkipVerify)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Only get the status, id and link section back
|
||||
opts := &client.ListTasksOptions{}
|
||||
tasks, err := kapa.ListTasks(opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -7,11 +7,13 @@ import (
|
|||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/bouk/httprouter"
|
||||
"github.com/influxdata/chronograf"
|
||||
kapa "github.com/influxdata/chronograf/kapacitor"
|
||||
"github.com/influxdata/kapacitor/client/v1"
|
||||
)
|
||||
|
||||
type postKapacitorRequest struct {
|
||||
|
@ -730,6 +732,16 @@ func (s *Service) KapacitorRulesGet(w http.ResponseWriter, r *http.Request) {
|
|||
Error(w, http.StatusUnprocessableEntity, err.Error(), s.Logger)
|
||||
return
|
||||
}
|
||||
// parse parameters
|
||||
params := r.URL.Query()
|
||||
opts := client.ListTasksOptions{}
|
||||
if _limit, err := strconv.ParseInt(params.Get("limit"), 0, 0); err != nil {
|
||||
opts.Limit = int(_limit)
|
||||
}
|
||||
if _offset, err := strconv.ParseInt(params.Get("limit"), 0, 0); err != nil {
|
||||
opts.Offset = int(_offset)
|
||||
}
|
||||
opts.Pattern = params.Get("pattern")
|
||||
|
||||
srcID, err := paramID("id", r)
|
||||
if err != nil {
|
||||
|
@ -745,7 +757,7 @@ func (s *Service) KapacitorRulesGet(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
c := kapa.NewClient(srv.URL, srv.Username, srv.Password, srv.InsecureSkipVerify)
|
||||
tasks, err := c.All(ctx)
|
||||
tasks, err := c.List(ctx, &opts)
|
||||
if err != nil {
|
||||
Error(w, http.StatusInternalServerError, err.Error(), s.Logger)
|
||||
return
|
||||
|
|
Loading…
Reference in New Issue