theforeman / community-templates

A place to share templates for various OSes for Foreman's provisioning
GNU General Public License v3.0
144 stars 182 forks source link

new report template: host - system currency #723

Closed giovannisciortino closed 4 years ago

giovannisciortino commented 4 years ago

A new report template to extract "System Currency" report. It generate a score for each host based of a weighted sum of errata applicable to the host. It was present in previous version of Satellite 5 and some users have interest to have it also in Satellite 6 (ie. https://bugzilla.redhat.com/show_bug.cgi?id=1477117 )

giovannisciortino commented 4 years ago

@ares I would be interested but I haven't enough knowledge of Katello repository to identify where this part of report logic should be moved and how justify the existence of this logic in Katello repository

ares commented 4 years ago

Alrighty, that's good, let me help you. The method to calculate the currency for the host should be added to Content Facet definition which lives here, just put it as a new method before this end.

It should look like this

def errata_currency
  critical = 0
  important = 0
  ...
  score = critical*sc_crit + important*sc_imp + moderate*sc_mod + low*sc_low + bugfix*sc_bug + enhancement*sc_enh
  { score: score, critical: critical, ... }
end

Multipliers like sc_crit = 32 or sc_imp = 16 should be defined as constants in the same file, similarly like other existing constansts in that file.

Once you have that method, you'll need to allow access to it in templates, by adding its name to the list at the bottom.

After that, you can easily reduce this template to

load_hosts(search: input('Hosts filter'), includes: [:applicable_errata]).each_record do |host|
  score = host.errata_currency
  report_row "Score": score[:score], "Host": host.name, ...
end

Don't worry about sorting for now, we'll address that later, report templates now supports sorting natively. If you open the PR against Katello, feel free to ping me there, I can do the review. I don't have merge permissions there but I can ACK. Then we can continue here or by that time we may need to reopen this PR against Foreman core. This repository is about to be merged there.

Please let me know if you need any more hints.

tbrisker commented 4 years ago

On behalf of the Foreman team, thank you for your contribution to the Foreman community templates repository! This repository is being archived and all templates are migrated to the relevant repositories. If you wish to pursue this change, please re-open the PR against the relevant repository. For more information and background, please click here.