From a6950ce09aecaf18f1948fe9cd22c4dc2ef15e45 Mon Sep 17 00:00:00 2001 From: Simon Plourde Date: Thu, 14 Apr 2016 08:21:26 -0400 Subject: [PATCH] Prevent infinite pagination loop --- uchiwa/sensu/methods.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/uchiwa/sensu/methods.go b/uchiwa/sensu/methods.go index 23bc6b4..1cda32f 100644 --- a/uchiwa/sensu/methods.go +++ b/uchiwa/sensu/methods.go @@ -48,7 +48,6 @@ func (api *API) getSlice(endpoint string, limit int) ([]interface{}, error) { if err != nil { return nil, fmt.Errorf("Could not parse the JSON-encoded response body: %v", err) } - // Verify if the endpoint supports pagination if limit != -1 && res.Header.Get("X-Pagination") != "" { var xPagination structs.XPagination @@ -74,6 +73,11 @@ func (api *API) getSlice(endpoint string, limit int) ([]interface{}, error) { return nil, fmt.Errorf("Could not parse the JSON-encoded response body: %v", err) } + if len(partialList) == 0 { + logger.Debugf("No additional elements found, exiting pagination for %s endpoint", endpoint) + break + } + for _, e := range partialList { list = append(list, e) }