Note: the Inventory Query API is deprecated in favor of the JSON Store API.
Inventory Queries are used to access data stored in an Inventory.
The REST API provides support working with inventory queries:
Creates a new inventory query with specified query.
/api/v1/org/{orgName}/inventory/${inventoryName}/query/${queryName}
POST
Authorization
, Content-Type: text/plain
or Content-Type: application/json
SELECT CAST(json_build_object('host', item_data->'host') as varchar) FROM inventory_data;
Success response
Content-Type: application/json
{
"result": "CREATED",
"ok": true,
"id": "..."
}
Executes an inventory query. The response data varies depending on the selected columns in the inventory query.
/api/v1/org/{orgName}/inventory/${inventoryName}/query/${queryName}/exec
POST
Authorization
, Content-Type: application/json
Success response
Content-Type: application/json
[
{
"host": "my.host.example.com"
},
...
]
Below is a set of queries and execution parameters for a small example data set of two servers in the same datacenter, but used for different environments.
{
"host": "myhost.cert.example.com",
"meta": {
"env": "cert",
"datacenter": "US-South"
}
}
{
"host": "myhost.prod.example.com",
"meta": {
"env": "prod",
"datacenter": "US-South"
}
}
Create the inventory query to simply return all data for each item in the inventory.
curl -u myusername \
-H 'Content-Type: text/plain' \
-d 'SELECT CAST(item_data as varchar) FROM inventory_data;' \
https://concord.example.com/api/v1/org/Default/inventory/my-inventory/query/all-data
Execute the query.
curl -u myusername \
-X POST \
-H 'Content-Type: application/json' \
https://concord.example.com/api/v1/org/Default/inventory/my-inventory/query/all-data/exec
The query will return all of the inventory data.
[
{
"host": "myhost.cert.example.com",
"meta": {
"env": "cert",
"datacenter": "US-South"
}
},
{
"host": "myhost.prod.example.com",
"meta": {
"env": "prod",
"datacenter": "US-South"
}
}
]
Create the inventory query to return only the host
for each item in the inventory.
curl -u myusername \
-H 'Content-Type: text/plain' \
-d "SELECT CAST(json_build_object('host', item_data->'host') as varchar) FROM inventory_data;" \
https://concord.example.com/api/v1/org/Default/inventory/my-inventory/query/host-only
Execute the query.
curl -u myusername \
-X POST
-H 'Content-Type: application/json' \
https://concord.example.com/api/v1/org/Default/inventory/my-inventory/query/host-only/exec
The query will extract only the host
value from each item.
[
{
"host": "myhost.cert.example.com"
},
{
"host": "myhost.prod.example.com"
}
]
Create the parameterized query.
curl -u myusername \
-H 'Content-Type: text/plain' \
-d "SELECT CAST(item_data as varchar) FROM inventory_data WHERE item_data @> ?::jsonb;" \
https://concord.example.com/api/v1/org/Default/inventory/my-inventory/query/parameterized-all-data
Execute the query to match only hosts in the cert
environment.
curl -u myusername \
-H 'Content-Type: application/json' \
-d '{ "meta": { "env": "cert" } }' \
https://concord.example.com/api/v1/org/Default/inventory/my-inventory/query/parameterized-all-data/exec
The results will be filtered by the env
value and all data for the host matching
the env
value given in the filter.
[
{
"host": "myhost.cert.example.com",
"meta": {
"env": "cert",
"datacenter": "US-South"
}
}
]
Create the parameterized query to return only the host
for each item in
the inventory.
curl -u myusername \
-H 'Content-Type: text/plain' \
-d "SELECT CAST(json_build_object('host', item_data->>'host') as varchar) FROM inventory_data WHERE item_data @> ?::jsonb;" \
https://concord.example.com/api/v1/org/Default/inventory/my-inventory/query/parameterized-host-only
Execute the query to match only hosts in the US-South
datacenter.
curl -u myusername \
-H 'Content-Type: application/json' \
-d '{ "meta": { "datacenter": "US-South" } }' \
https://concord.example.com/api/v1/org/Default/inventory/my-inventory/query/parameterized-host-only/exec
The results will be filtered by the datacenter
value and only the host value
will be returned.
[
{
"host": "myhost.cert.example.com"
},
{
"host": "myhost.prod.example.com"
}
]
Deletes an inventory query.
/api/v1/org/{orgName}/inventory/${inventoryName}/query/${queryName}
DELETE
Authorization
Content-Type: application/json
{
"ok": true,
"result": "DELETED"
}
Lists inventory queries for an inventory.
/api/v1/org/{orgName}/inventory/${inventoryName}
GET
Authorization
Success response
Content-Type: application/json
[
{
"id": "...",
"name": "query-name",
"inventoryId": "...",
"text": "SELECT CAST(json_build_object('host', item_data->'host') as varchar) FROM inventory_data;"
},
...
]
Below is a set of queries and execution parameters for a small example data set of two servers in the same datacenter, but used for different environments.
{
"host": "myhost.cert.example.com",
"meta": {
"env": "cert",
"datacenter": "US-South"
}
}
{
"host": "myhost.prod.example.com",
"meta": {
"env": "prod",
"datacenter": "US-South"
}
}
Query:
SELECT CAST(item_data as varchar) FROM inventory_data;
Results:
[
{
"host": "myhost.cert.example.com",
"meta": {
"env": "cert",
"datacenter": "US-South"
}
},
{
"host": "myhost.prod.example.com",
"meta": {
"env": "prod",
"datacenter": "US-South"
}
}
]
Query:
SELECT CAST(json_build_object('host', item_data->'host') as varchar) FROM inventory_data;
Results:
[
{
"host": "myhost.cert.example.com"
},
{
"host": "myhost.prod.example.com"
}
]
Query:
SELECT CAST(json_build_object('host', item_data->>'host') as varchar) FROM inventory_data WHERE item_data @> ?::jsonb;
Execution Filter:
{
"meta": {
"datacenter": "US-South"
}
}
Results:
[
{
"host": "myhost.cert.example.com"
},
{
"host": "myhost.prod.example.com"
}
]
Query:
SELECT CAST(item_data as varchar) FROM inventory_data WHERE item_data @> ?::jsonb;
Execution Filter:
{
"meta": {
"env": "cert"
}
}
Result:
[
{
"host": "myhost.cert.example.com",
"meta": {
"env": "cert",
"datacenter": "US-South"
}
}
]