TimeSeries

class cloudpassage.TimeSeries(session, start_time, start_url, item_key, params={})
__iter__()

Yields one item from a time-series query against Halo. Forever.

adjust_batch_size(adjustment_factor)

Adjust the batch size for subsequent queries against Halo API.

We will never take the batch size below 1 or over the original maximum thread count.

Parameters:adjustent_factor (int) – Number, positive or negative, by which we should increase or decrease the number of concurrent requsts agains the Halo API.
allowed_urls = ['/v1/events', '/v1/scans', '/v1/issues']

Wrap time-series object retrieval in a generator.

Parameters:
  • session (object) – HaloSession object.
  • start_time (str) – ISO 8601-formatted timestamp.
  • start_url (str) – Path from URL, no hostname and no URL-encoded params.
  • item_key (str) – Top-level key, below which is a list of target items.
  • params (dict) – Parameters for URL, which will be URL-encoded.
stop

bool

Set to False by default. When set to True, the

``__iter__()`` will raise StopIteration, effecting a clean exit.
classmethod create_url_batch(path, batch_size, params={})

Create a batch of URLs for pulling time-series objects from Halo.

Parameters:
  • base_url (str) – This is the path of the URL, not including hostname or parameters.
  • batch_size (int) – This is the number of URLs that will be generated.
  • params (dict) – These are parameters that will be added to each URL.
Returns:

This returns a list of tuples, where the first item in the tuple is the URL path, the second is the params to be appended to the URL when retrieved.

Return type:

list

classmethod get_adjustment_factor(pages, page_size, item_key)

Return adjustment factor, to optimize parallelization of API req.

Parameters:
  • pages (list) – Pages from query.
  • page_size (int) – Number of items in a full page
Returns:

Positive or negative integer, which should be used to either increase or decrease the number of threads used to pull pages from the Halo API.

Return type:

int

get_next_batch()

Gets the next batch of time-series items from the Halo API

classmethod get_number_of_empty_pages(pages, item_key)

Determine number of empty pages from list of pages.

Parameters:
  • pages (list) – List of pages as pulled from Halo API.
  • item_key (str) – Top-level key, below which are target items.
Returns:

Number of ampty pages from query.

Return type:

int

classmethod get_number_of_full_pages(pages, page_size, item_key)

Return the number of full pages from query.

Parameters:
  • pages (list) – List of pages as pulled from Halo API.
  • page_size (int) – Expected number of items found in a full page.
  • item_key (str) – Top-level key, below which are target items.
Returns:

Number of full pages in query.

Return type:

int

get_page(get_tup)

Gets one page’s contents.

Parameters:get_tup (tuple) – First item in tuple is a string, the URL. The second item is the params to be used in the query.
Returns:Page contents as dict
Return type:dict
get_pages(url_list)

Map URLs to threads, return all when complete

classmethod remove_duplicate_items(items_in)

Remove duplicate items by id.

classmethod sorted_items_from_pages(pages, item_key, sort_key)

Return all items, sorted by specific key.

Parameters:
  • pages (list) – Pages from (multiple) API queries. Raw JSON.
  • item_key (str) – Top-level key, below which are target items.
  • sort_key (str) – Key which is present in every item, by which the entire result will be sorted.
Returns:

List of items, extracted from pages using item_key, and sorted by sort_key.

Return type:

list