Report Template

Hi I am trying to generate a report from foreman. I tried creating a new report template.

<%- load_hosts.each_record do |host| -%>
<%- report_row(
‘Name’: host.name,
‘IP’: host.ip,
‘Mac’: host.mac,
‘OS’: host.os,
‘Model’: host.model,
) -%>
<%- end -%>
<%= report_render -%>

If I need variables (methods) to extract BMC IP, BMC Addr, CPU cores, DIMM, Memory, DISK unit, DISK size, where do I find what variable or methods to use.

Hello,

you can click Help tab where you have all available methods listed (without any help as of now). Search fr Host::Managed object, that list is applicable on host variable in your example. You may need host.bmc_nic that gives yous Nic::BMC object, on which you can call things like ip, mac. So for example host.bmc_nic.ip will give you you BMC IP. Other things can be read from facts, but beware, if you include all facts, the report may take very long time to process, depends on amount of data in your DB.

I tried the below code but no luck.

<%- load_hosts.each_record do |host| -%>
<%- report_row(
‘Name’: host.name,
‘IP’: host.ip,
‘Mac’: host.mac,
‘OS’: host.os,
‘Model’: host.model,
‘bmcip’: host.bmc_nic.ip
) -%>
<%- end -%>
<%= report_render -%>

Error: There was an error rendering the demoreport template: undefined method ‘#ip’ for NilClass::Jail (NilClass)

Also, I would like to extract DIMM and CPU information. can you please let me know. Thanks!

Oh, seems some of your hosts don’t have bmc_nic, in that case, try host.bmc_nic&.ip which will call ip method only in case bmc_nic is defined.

To get facts, try host.facts['processors::count'] just beware this can be really slow and mem consuming if you have a lot of hosts and facts. You may want to try load_hosts(preload: :fact_values).

In Foreman 1.24, it is recommended to fetch data from reported data facet, see example here. These are the data you can get so far in efficient way.

Hi,

Can you please let me know how to get DIMM and Disk information using foreman reports.

Btw, for nic the below worked.
‘bmcip’: host.sp_ip,
‘bmcmac’: host.sp_mac

Thanks,
Karthik.

Did host.facts work? What exactly DIMM should return? RAM amount? What feeds your Foreman with data? Puppet, Ansible or something else?

I would like to know total how many DIMMs are in host and its capacity

Do you have such facts in your Foreman? Does puppet or some other source of information provide number of DIMMs? The total capacity should be available as

host.facts['memory::system::total']

if you’re using puppet of course.