API to Get Hosts with "configuration_status_label=Active"

Hi All,

I want an API query which returns hosts with
"configuration_status_label=Active"

I am aware of the these APIs but not sure how can I add that query.

Can someone please help me here?

APIs I know of

"hosts": {
"List all hosts": "/api/hosts",
"Show a host": "/api/hosts/:id",
"Create a host": "/api/hosts",
"Update a host": "/api/hosts/:id",
"Delete a host": "/api/hosts/:id",
"Get configuration status of host": "/api/hosts/:id/status",
"Get status of host": "/api/hosts/:id/status/:type",
"Get vm attributes of host": "/api/hosts/:id/vm_compute_attributes",
"Force a Puppet agent run on the host": "/api/hosts/:id/puppetrun",
"Disassociate the host from a VM": "/api/hosts/:id/disassociate",
"Run a power operation on host": "/api/hosts/:id/power",
"Boot host from specified device": "/api/hosts/:id/boot",
"Upload facts for a host, creating the host if required": "/api/hosts/facts",
"Rebuild orchestration config": "/api/hosts/:id/rebuild_config",
"Preview rendered provisioning template content": "/api/hosts/:id/template/:kind"
},

Thanks

-Vishal Sarin

Hi Vishal,

> I want an API query which returns hosts with "configuration_status_label=Active"

I believe the key is 'host.configuration_status_label' (vs just 'configuration_status_label'), but I don't know if this is something that the search API can filter on or not.

Regards,

j

Use this API to list all hosts, but pass a search into it. The "active"
hosts are those with a certain search query, which you'll find if you
follow the active links from the Dashboard or look at your bookmarks
(under Administer).

e.g. GET
/api/v2/hosts?search=last_report%20%3E%20%2235%20minutes%20ago%22%20and%20(status.applied%20%3E%200%20or%20status.restarted%20%3E%200)%09

(URL-encoded version of last_report > "35 minutes ago" and
(status.applied > 0 or status.restarted > 0))

··· On 12/10/16 18:27, Vishal Sarin wrote: > I want an API query which returns hosts with > "configuration_status_label=Active" > > I am aware of the these APIs but not sure how can I add that query. > > Can someone please help me here? > > APIs I know of > > "hosts": { > "List all hosts": "/api/hosts",


Dominic Cleal
dominic@cleal.org

Thanks Dominic,

This search option is a proper approach to get active hosts rather than
"configuration_status_label=Active".

But adding to Vishal's query, our requirement is to list the active hosts
along with their facts values (like, hostname, macaddress, manufacturer,
etc.) using a single api.

API we are using to list all hosts and their facts values is:
"/api/fact_values"

We can add an external facts value to this api which will provide us
last_report > "35 minutes ago" .
But, we are not sure how to get this value.

Thanks,
Amrit

··· On Thursday, October 13, 2016 at 1:23:10 PM UTC+5:30, Dominic Cleal wrote: > > On 12/10/16 18:27, Vishal Sarin wrote: > > I want an API query which returns hosts with > > "configuration_status_label=Active" > > > > I am aware of the these APIs but not sure how can I add that query. > > > > Can someone please help me here? > > > > APIs I know of > > > > "hosts": { > > "List all hosts": "/api/hosts", > > Use this API to list all hosts, but pass a search into it. The "active" > hosts are those with a certain search query, which you'll find if you > follow the active links from the Dashboard or look at your bookmarks > (under Administer). > > e.g. GET > /api/v2/hosts?search=last_report%20%3E%20%2235%20minutes%20ago%22%20and%20(status.applied%20%3E%200%20or%20status.restarted%20%3E%200)%09 > > > (URL-encoded version of last_report > "35 minutes ago" and > (status.applied > 0 or status.restarted > 0)) > > -- > Dominic Cleal > dom...@cleal.org >

> Thanks Dominic,
>
> This search option is a proper approach to get active hosts rather than
> "configuration_status_label=Active".
>
> But adding to Vishal's query, our requirement is to list the active
> hosts along with their facts values (like, hostname, macaddress,
> manufacturer, etc.) using a single api.

Foreman doesn't have many APIs that try to combine things, you should
use multiple API calls.

> API we are using to list all hosts and their facts values is:
> "/api/fact_values"
>
> We can add an external facts value to this api which will provide us
> last_report > "35 minutes ago" .
> But, we are not sure how to get this value.

These searches will only work on the hosts list, the fact_values API has
a more limited ability to search details of hosts.

Fetch the list of hosts using /api/v2/hosts, then query the facts for
each one in turn with GET /api/v2/hosts/example.com/facts.

··· On 17/10/16 04:25, Amrit Atmajit wrote:


Dominic Cleal
dominic@cleal.org