Retrieving the factname values for every host in v1.2 API

Hi,

I want to get data from every host for a certain fact value. It looks like
this was available in the 1.1 API in the following form.

/facts/<factname>/valuesGETreturn all hosts with the given factname and its
value

What would this translate to in foreman 1.2 without going through and
traversing through every host using /api/hosts/:host_id/facts.

–Matt

If you request /api/fact_values you get every fact back sorted by host,
but you can use the "search" parameter to restrict this to the fact
you're interested in (same parameters as the search in the web UI).

Try using /api/fact_values?search=name=ipaddress.

··· On 09/12/13 19:34, Matthew Heck wrote: > Hi, > > I want to get data from every host for a certain fact value. It looks > like this was available in the 1.1 API in the following form. > > /facts//values GET return all hosts with the given factname > and its value > > > What would this translate to in foreman 1.2 without going through and > traversing through every host using /api/hosts/:host_id/facts.


Dominic Cleal
Red Hat Engineering

I believe that unfortunately that's not possible with the current API (the
one whose endpoints start with '/api').

I can give you a temporary solution though, if you are familiar with Rails,
you can go to Foreman's root directory (/usr/share/foreman by default), and
start a rails console "RAILS_ENV=production rails console", and run the
following command.

result = FactValue.find_all_by_fact_name_id(FactName.find_by_name('WRITE
HERE YOUR FACT NAME')).map { |factvalue| [factvalue.host, factvalue.value] }

This will create an array containing all [host, value] pairs for a
particular fact. You can convert this to JSON or anything else with
"result.to_json" if you need to process it.

As an upside, this sounds like a good feature, I will open a ticket to have
this back in the API.

··· On Mon, Dec 9, 2013 at 8:34 PM, Matthew Heck wrote:

Hi,

I want to get data from every host for a certain fact value. It looks like
this was available in the 1.1 API in the following form.

/facts//valuesGETreturn all hosts with the given factname and
its value

What would this translate to in foreman 1.2 without going through and
traversing through every host using /api/hosts/:host_id/facts.

–Matt


You received this message because you are subscribed to the Google Groups
"Foreman users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to foreman-users+unsubscribe@googlegroups.com.
To post to this group, send email to foreman-users@googlegroups.com.
Visit this group at http://groups.google.com/group/foreman-users.
For more options, visit https://groups.google.com/groups/opt_out.


Daniel Lobato

@elobatoss
blog.daniellobato.me
daniellobato.me

GPG: http://keys.gnupg.net/pks/lookup?op=get&search=0x7A92D6DD38D6DE30

Thanks Dominic, this was the method I ended up using and was going to
document that I fixed my issue by looking at the web ui. Thanks all for
your help.

/api/fact_values?search=name+<fact_value>&per_page=10000

–Matt

··· On Tuesday, 10 December 2013 04:51:15 UTC-8, Dominic Cleal wrote: > > On 09/12/13 19:34, Matthew Heck wrote: > > Hi, > > > > I want to get data from every host for a certain fact value. It looks > > like this was available in the 1.1 API in the following form. > > > > /facts//values GET return all hosts with the > given factname > > and its value > > > > > > What would this translate to in foreman 1.2 without going through and > > traversing through every host using /api/hosts/:host_id/facts. > > If you request /api/fact_values you get every fact back sorted by host, > but you can use the "search" parameter to restrict this to the fact > you're interested in (same parameters as the search in the web UI). > > Try using /api/fact_values?search=name=ipaddress. > > -- > Dominic Cleal > Red Hat Engineering >

> I believe that unfortunately that's not possible with the current API (the
> one whose endpoints start with '/api').
>
> I can give you a temporary solution though, if you are familiar with
> Rails, you can go to Foreman's root directory (/usr/share/foreman by
> default), and start a rails console "RAILS_ENV=production rails console",
> and run the following command.
>
> result = FactValue.find_all_by_fact_name_id(FactName.find_by_name('WRITE
> HERE YOUR FACT NAME')).map { |factvalue| [factvalue.host, factvalue.value] }
>

nitpick - in favor of performance, I would write:

FactValue.joins(:fact_name).where(:fact_names => {:name => '<your fact
>'}).includes(:host).map {|v| [v.host.name, v.value]}

as a side note, you can get that result via the api using search, for
example:

https://foreman/api/fact_values?search=fact=<your fact name>

Ohad

··· On Tue, Dec 10, 2013 at 2:30 PM, Daniel Lobato wrote:

This will create an array containing all [host, value] pairs for a
particular fact. You can convert this to JSON or anything else with
"result.to_json" if you need to process it.

As an upside, this sounds like a good feature, I will open a ticket to
have this back in the API.

On Mon, Dec 9, 2013 at 8:34 PM, Matthew Heck macheck@gmail.com wrote:

Hi,

I want to get data from every host for a certain fact value. It looks
like this was available in the 1.1 API in the following form.

/facts//valuesGETreturn all hosts with the given factname and
its value

What would this translate to in foreman 1.2 without going through and
traversing through every host using /api/hosts/:host_id/facts.

–Matt


You received this message because you are subscribed to the Google Groups
"Foreman users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to foreman-users+unsubscribe@googlegroups.com.
To post to this group, send email to foreman-users@googlegroups.com.
Visit this group at http://groups.google.com/group/foreman-users.
For more options, visit https://groups.google.com/groups/opt_out.


Daniel Lobato

@elobatoss
blog.daniellobato.me
daniellobato.me

GPG: http://keys.gnupg.net/pks/lookup?op=get&search=0x7A92D6DD38D6DE30


You received this message because you are subscribed to the Google Groups
"Foreman users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to foreman-users+unsubscribe@googlegroups.com.
To post to this group, send email to foreman-users@googlegroups.com.
Visit this group at http://groups.google.com/group/foreman-users.
For more options, visit https://groups.google.com/groups/opt_out.