Report Engine in Satellite 6.5: What it is and Why

Red Hat Satellite is a system management solution that makes it easy to deploy, scale, and manage Red Hat infrastructure across physical, virtual, and cloud environments. Satellite allows users to configure and update systems to ensure they operate efficiently and securely in accordance with various standards. By automating most system uptime tasks, Satellite helps organizations improve efficiency, reduce operating costs, and more readily respond to strategic business needs.

Report Engine in Satellite 6.5: What it is and Why

While you can perform basic administrative tasks with the Red Hat services included with a Red Hat Enterprise Linux subscription, Red Hat Satellite adds extensive lifecycle management capabilities.

Among these possibilities:

  • Installing patches;
  • Subscription management;
  • Initialization;
  • Configuration management.

From a single console, you can manage thousands of systems as easily as one, increasing availability, reliability, and providing system auditing capabilities.

And now we have the new Red Hat Satellite 6.5!

One of the cool things coming with Red Hat Satellite 6.5 is the new reporting engine.

The Satellite Server is often the hub for all information about Red Hat enterprise systems, and this latest engine allows you to create and export reports containing information about Satellite client hosts, software subscriptions, and software defects to be fixed (applicable errata) and etc. Reports are programmed in the embedded Ruby language (ERB).

Satellite 6.5 comes with ready-made reports, and the engine allows users to customize these reports or create their own. Satellite 6.5's built-in reports are generated in CSV format, however in this post we'll show you how to generate reports in HTML format as well.

Satellite 6.5 Embedded Reports

Satellite 6.5 includes four built-in reports:

  • Applicable errata – list of software defects (errata) to be eliminated on content hosts (optionally filtered by hosts or defects);
  • host statuses – Satellite hosts status report (optionally filtered by hosts);
  • Registered hosts – information about Satellite hosts: IP address, OS version, software subscriptions (optionally filtered by hosts);
  • Subscriptions – information about software subscriptions: total number of subscriptions, number of free ones, SKU codes (optionally filtered by subscription parameters).

To generate a report, open the menu Monitor, Select Report Templates and click the Generate button to the right of the desired report. Leave the filter field blank to include all data in the report, or enter something there to limit the results. For example, if you want to display only RHEL 8 hosts in the Registered Hosts report, then specify the filter os = RedHat and os_major = 8as shown in the screenshot below:

Report Engine in Satellite 6.5: What it is and Why

After generating a report, it can be downloaded and opened in a spreadsheet such as LibreOffice Calc, which imports data from CSV and sorts them into columns, for example, as a report Applicable errata on the screenshot below:

Report Engine in Satellite 6.5: What it is and Why

Please note that in the properties of the built-in reports, the option is enabled By default (Default), so they are automatically added to any new organizations and locations you create in the Satellite.

Customization of built-in reports

Let's analyze customization using the example of a built-in report Subscriptions. By default, this report displays the total number of subscriptions (1) as well as the number of available, i.e. free subscriptions (2). We will add one more column to it with the number of subscriptions used, which is defined as (1) - (2). For example, if we have 50 RHEL subscriptions in total and 10 of them are free, then 40 subscriptions are used.

Since editing of built-in reports is blocked and it is not recommended to change them, you will have to clone the built-in report, give it a new name, and then modify this clone copy.

So if we want to modify the report Subscriptions, then it must first be cloned. So let's open the menu. Monitor, choose Report Templates and in the dropdown menu to the right of the template Subscriptions Choose Clone. Then we enter the name of the clone report (let's call it Custom Subscriptions) and between lines Available ΠΈ Quantity add a line to it 'Used': pool.quantity - pool.available, - note the comma at the end of the line. Here's what it looks like in the screenshot:

Report Engine in Satellite 6.5: What it is and Why

Then we press the button Submit, which brings us back to the page Report Templates. Click the button there Generate to the right of the newly created report Custom Subscriptions. Leave the Subscriptions filter field empty and click Submit. After that, a report is created and loaded, in which there is a column added by us Used.

Report Engine in Satellite 6.5: What it is and Why

Help for the built-in Ruby language is on the tab Help in the report editing window. It contains an overview of the syntax and the available variables and methods.

Create your own report

Now let's look at creating our own reports using the example of a report on Ansible roles assigned to hosts in the Satellite. Opening the menu Monitor, click Report Templates and then press the button create template. Let's call our report Ansible Role Report and paste the following ERB code into it:

<%#
name: Ansible Roles Report
snippet: false
template_inputs:
- name: hosts
 required: false
 input_type: user
 description: Limit the report only on hosts found by this search query. Keep empty
   for report on all available hosts.
 advanced: false
model: ReportTemplate
-%>
<% load_hosts(search: input('hosts'), includes: :ansible_roles).each_record do |host| -%>
<%   report_row({
       'Name': host.name,
       'All Ansible Roles': host.all_ansible_roles
     }) -%>
<% end -%>
<%= report_render -%>

This code generates a report on hosts, displaying the "all_ansible_roles" attribute for them.

Then go to the tab Inputs and click the button +AddInput. We say that name is hosts, and description type is Filter by hosts (optional). Then we click Submit and then press the button Generate to the right of the newly created report. Next, you can set a host filter or immediately click Submitto generate a report for all hosts. The generated report will look like this in LibreOffice Calc:

Report Engine in Satellite 6.5: What it is and Why

Creating HTML Reports

The Satellite Reporting Engine allows you to generate reports in more than just CSV format. As an example, we will create our own report based on the built-in Host report. Statuses, but only as an HTML table with color-coded cells based on status. For this we clone Host statuses, and then replace its ERB code with the following:

<!DOCTYPE html>
<html>
<head>
   <title>Host Statuses</title>
   <style>
       th {
           background-color: black;
           color: white;
       }
       td.green {
           background-color:#92d400;
           color:black;
       }
       td.yellow {
           background-color:#f0ab00;
           color:black;
       }
       td.red {
           background-color:#CC0000;
           color:black;
       }
       table,th,td {
               border-collapse:collapse;
               border: 1px solid black;
       }
   </style> 
</head>
<body>
<table>
<tr> 
       <th> Hostname </th>
       <th> Status </th> 
<% load_hosts(search: input('hosts'), includes: :host_statuses).each_record do |host| -%>
   <% all_host_statuses_hash(host).each do |key, value|  -%>
       <th> <%= key %> </th>
   <% end -%>
   <% break -%>
<% end -%>
</tr>

<%- load_hosts(search: input('hosts'), includes: :host_statuses).each_record do |host| -%>
   <tr> 
   <td> <%= host.name   %> </td> 
   <% if host.global_status == 0 -%>
       <td class="green"> OK </td>
   <% elsif host.global_status == 1 -%>
       <td class="yellow"> Warning </td>
   <% else -%>
       <td class="red"> Error (<%= host.global_status %>) </td>
   <% end -%>

   <% all_host_statuses_hash(host).each do |key, value|  -%>
       <% if value == 0 -%>
           <td class="green"> OK </td>
       <% elsif value == 1  -%>
           <td class="yellow"> Warning </td>
       <% else -%>
           <td class="red"> Error (<%= value %>) </td>
       <% end -%>
   <% end -%>
   </tr>
<% end -%>

</table>
</body>
</html>

This report generates HTML that will look something like this in a browser:

Report Engine in Satellite 6.5: What it is and Why

Running reports from the command line

To run a report from the command line, use the command hammer, and the cron utility allows you to automate this process.

Use the command hammer report-template generate --name "", for example:

# hammer report-template generate β€”name "Host statuses HTML"

The contents of the report will be displayed on the console. The information can be redirected to a file, and then cron can be configured to run a shell script to generate a report and send it by email. The HTML format is perfectly displayed in email clients, which allows you to organize regular delivery of reports to interested parties in a form that is easy to understand.

Thus, the reporting engine in Satellite 6.5 is a powerful tool for exporting important data that companies have in Satellite. It is very flexible and allows you to use both built-in reports and their modified versions. In addition, users can create their own reports from scratch. Details on the Satellite Reporting Engine are available in our YouTube video.

On July 9 at 11:00 Moscow time, don't miss the webinar about the new version of Red Hat Enterprise Linux 8

Our speaker is Aram Kananov, Manager of Platform Development and Management Systems at Red Hat in Europe, the Middle East and Africa. Aram's work at Red Hat includes in-depth market, industry and competitor analysis, as well as product positioning and marketing for the platform business unit, which includes managing the entire product lifecycle from implementation to end-of-life.

Source: habr.com

Add a comment