Report template generating

  1. How to schedule a report template?
  2. how to run a report template in command line to generate the output as csv

I suppose you are asking about how to do it from CLI

First, find out the number of the report template by

hammer report-template list

You’ll get a table of templates and their ids, in my case it looks like this

----|--------------------------
ID  | NAME                     
----|--------------------------
175 | Ansible Inventory        
143 | Applicable errata        
159 | Applied Errata           
165 | Entitlements             
144 | Host statuses            
150 | Host statuses CSV clone  
158 | Host statuses CSV clone 2
166 | List of registered users 
145 | Registered hosts         
157 | Registered hosts clone   
146 | Subscriptions            
----|-------------------------

Let’s say I want to generate host statuses on Christmas

hammer report-template schedule --generate-at '2019-12-24 12:00:00' --id 144

I’ll receive a reply that the task has been scheduled and the job id is printed

The report has been scheduled. Job ID: 5830b450-bb00-4296-83ea-57128dee1d22

When the time comes, to download the result, you can download the report by running this command

hammer report-template report-data --id 144 --job-id 5830b450-bb00-4296-83ea-57128dee1d22

The reply is either that the data is not ready in case the task hasn’t finished yet. Otherwise you get the report printed to STDOUT. Note that the report is available for download 24 hours after it’s rendered. If you prefer to store the report into a file, specify --path $dir where the report should be stored. E.g.

hammer report-template report-data --id 144 --job-id 5830b450-bb00-4296-83ea-57128dee1d22 --path /tmp

The you should see the message similar to this

The response has been saved to /tmp/Host statuses-2019-12-11.csv

how to run a report template in command line to generate the output as csv

This depends on whether the report supports it. All default reports support all formats. To specify format, use --report-format csv but it’s the default. Note the format needs to be specified when you schedule the report, not when you download it. The full command may look like this

hammer report-template schedule --id 144 --report-format csv

Currently, we support csv, json, yaml, html.

Hope that helps. I’d be interested in how you use reports. Perhaps this writeup could be converted to our manual if you find it useful.

Thanks for the great explanation but unfortunately it doesnt solve my issue, can u please tell me how i can query from linux terminal the forman database and put the output to a file.

#su - postgres -c “psql foreman” ‘COPY (SELECT name FROM hosts;) TO STDOUT’ >> /tmp/testing/hostdata.txt

the above command not working when combined by separately works as below

#su - postgres -c “psql foreman”
foreman=#SELECT name FROM hosts;