Inventory - cisco.com€¦ · Inventory...

4
Inventory The inventory search APIs provide similar functionality as described in Search. This set of APIs requires that the flow_inventory_query capability be associated with the API key. Query for Inventory Dimensions, on page 1 Inventory Search, on page 1 Inventory Statistics, on page 3 Inventory Count, on page 3 Query for Inventory Dimensions This endpoint returns the list of inventory columns on which search criteria (or filters) can be specified for inventory search queries. GET /openapi/v1/inventory/search/dimensions Inventory Search This endpoint returns a list of inventory items matching the specified criteria. POST /openapi/v1/inventory/search The list of columns that can be specified in the filter criteria can be obtained with the /openapi/v1/inventory/search/dimensions API. Parameters: Description Type Name A filter query. JSON object filter (Optional) Name of the scope by which to limit results. string scopeName (Optional) Maximum number of results to return. integer limit (Optional) Offset from the previous request to get the next page. integer offset Inventory 1

Transcript of Inventory - cisco.com€¦ · Inventory...

Page 1: Inventory - cisco.com€¦ · Inventory TheinventorysearchAPIsprovidesimilarfunctionalityasdescribedinSearch.ThissetofAPIsrequiresthat theflow_inventory_querycapabilitybeassociatedwiththeAPIkey

Inventory

The inventory search APIs provide similar functionality as described in Search. This set of APIs requires thatthe flow_inventory_query capability be associated with the API key.

• Query for Inventory Dimensions, on page 1• Inventory Search, on page 1• Inventory Statistics, on page 3• Inventory Count, on page 3

Query for Inventory DimensionsThis endpoint returns the list of inventory columns on which search criteria (or filters) can be specified forinventory search queries.GET /openapi/v1/inventory/search/dimensions

Inventory SearchThis endpoint returns a list of inventory items matching the specified criteria.POST /openapi/v1/inventory/search

The list of columns that can be specified in the filter criteria can be obtained with the/openapi/v1/inventory/search/dimensions API.

Parameters:

DescriptionTypeName

A filter query.JSON objectfilter

(Optional) Name of the scope by which to limitresults.

stringscopeName

(Optional) Maximum number of results to return.integerlimit

(Optional) Offset from the previous request to get thenext page.

integeroffset

Inventory1

Page 2: Inventory - cisco.com€¦ · Inventory TheinventorysearchAPIsprovidesimilarfunctionalityasdescribedinSearch.ThissetofAPIsrequiresthat theflow_inventory_querycapabilitybeassociatedwiththeAPIkey

The body of the request must be a JSON-formatted query. Here is an example of a query body:{

"filter": {"type": "contains","field": "hostname","value": "collector"

},"scopeName": "Default:Production:Web", # optional"limit": 100,"offset": <offset-object> # optional

}

To get the different types of filters supported, refer to “Filters” in Query for Flows.

The query body consists of a JSON object with the following keys:

ValuesKeys

Query filter. If filter is empty (that is, {}), then query matchesall inventory items.

filter

(Optional) Full name of the scope to which query is restricted.scopeName

(Optional) List of dimension names to be returned in the resultof inventory search API. This is an optional parameter; ifunspecified, result returns all available dimensions. This optionis useful for specifying a subset of available dimensions.

dimensions

(Optional) Limits number of response items returned.limit

(Optional) Offset object received from previous response.offset

Response

The response is a JSON object with the following properties:

DescriptionTypeName

Response offset to be passed for the next page ofresults.

integeroffset

List of results.array of objectsresults

The response may contain an offset field for paginated responses. You will need to specify the same offsetin the subsequent request to get the next set of results.

Sample Python code

req_payload = {"scopeName": "Tetration", # optional"limit": 2,"filter": {"type": "and",

"filters": [{"type": "eq", "field": "vrf_name", "value": "Tetration"},{"type": "subnet", "field": "ip", "value": "1.1.1.0/24"},{"type": "contains", "field": "hostname", "value": "collector"}

]}

}

Inventory2

InventoryInventory Search

Page 3: Inventory - cisco.com€¦ · Inventory TheinventorysearchAPIsprovidesimilarfunctionalityasdescribedinSearch.ThissetofAPIsrequiresthat theflow_inventory_querycapabilitybeassociatedwiththeAPIkey

resp = restclient.post('/inventory/search', json_body=json.dumps(req_payload))print resp.status_codeif resp.status_code == 200:

parsed_resp = json.loads(resp.content)print json.dumps(parsed_resp, indent=4, sort_keys=True)

Inventory StatisticsThis endpoint returns statistics for inventory items.GET /openapi/v1/inventory/{id}/stats?t0=<t0>&t1=<t1>&td=<td>

DescriptionPath Parameter

Inventory item ID, as {ip}-{vrf_id}; such as 1.1.1.1-123.id

DescriptionQuery Parameter

Start time for statistics, in epoch time.t0

End time for statistics, in epoch time.t1

Granularity for statistic aggregations. An integer specifies anumber of seconds. Strings, such as minute, hour and day, maybe passed.

td

Sample Python code

resp = restclient.get('/inventory/1.1.1.1-123/stats?t0=1483228800&t1=1485907200&td=day')

Inventory CountThis endpoint returns a count of inventory items matching the specified criteria.POST /openapi/v1/inventory/count

The list of columns that can be specified in the filter criteria can be obtained with the/openapi/v1/inventory/search/dimensions API.

Parameters:

DescriptionTypeName

A filter query.JSON objectfilter

(Optional) Name of the scope by which to limitresults.

stringscopeName

The body of the request must be a JSON-formatted query. An example of a query body is:{

"filter": {"type": "and",

Inventory3

InventoryInventory Statistics

Page 4: Inventory - cisco.com€¦ · Inventory TheinventorysearchAPIsprovidesimilarfunctionalityasdescribedinSearch.ThissetofAPIsrequiresthat theflow_inventory_querycapabilitybeassociatedwiththeAPIkey

"filters": [{

"type": "contains","field": "hostname","value": "prod"

},{

"type": "subnet","field": "ip""value": "6.6.6.0/24"

}]

},"scopeName": "Default:Production:Web", # optional

}

Response

The response is a JSON object in the body with the following property:

DescriptionKeys

Number of inventory items matching the filter criteria.count

Sample Python code

req_payload = {"scopeName": "Tetration", # optional"filter": {"type": "and",

"filters": [{"type": "eq", "field": "vrf_name", "value": "Tetration"},{"type": "subnet", "field": "ip", "value": "1.1.1.0/24"},{"type": "contains", "field": "hostname", "value": "collector"}

]}

}resp = restclient.post('/inventory/count', json_body=json.dumps(req_payload))print resp.status_code

if resp.status_code == 200:parsed_resp = json.loads(resp.content)print json.dumps(parsed_resp, indent=4, sort_keys=True)

Inventory4

InventoryInventory Count