{%- extends 'layout.html' %}
{%- import '_macros.html' as macros %}
{% block content %}
Scroll to: Logs, Events, Metrics.
Summary
  
    
      | Certname | Configuration version | Start time | End time | Duration | 
  
  
    
      | {{ report.node }} | {{report.version|safe}} | {{report.start}} | {{report.end}} | {{report.end - report.start}} | 
  
Logs
{{ macros.checkbox_toggle("friendly", current_show_error_as, "friendly", "raw", "Friendly error messages") }}
  
    
      | Timestamp | Level | Source | Tags | Message | Location | Location (short) | 
  
  
  
Events
  
    
      | Resource | Status | Changed From | Changed To | 
  
  
  
Metrics
  
    
      | Category | Name | Value | 
  
  
    {% for metric in metrics %}
      
        | {{metric.category}} | {{metric.name}} | {{metric.value|round(2)}} | 
    {% endfor %}
  
{% endblock content %}
{% block onload_script %}
$.fn.dataTable.ext.errMode = 'throw';
// Init the DataTable for Logs
var logs = {{ logs|tojson }}
var logs_table = $('#logs_table').DataTable({
    "data": logs,
    'columns': [
        { data: 'timestamp', name: 'timestamp',
          // don't show the date as puppet runs (almost never) span across multiple days
          // and we already show the full date in the "Summary" section
          render: function ( data, type, row, meta ) {
              parsed_date = moment(data);
              if (!parsed_date.isValid()) return data;
              return parsed_date.format('HH:mm:ss');
          }
        },
        { data: 'level', name: 'level' },
        { data: 'source', name: 'source', visible: false },
        { data: 'tags', name: 'tags', visible: false },
        { data: 'message', name: 'message' },
        // see also the comment about these columns in reports.py
        { data: 'location', name: 'location', visible: false },
        { data: 'short_location', name: 'short_location' },
    ],
    "paging": false,
    'createdRow': function (row, data, index) {
        // color the row based on log level
        if (data['level'] == 'info' || data['level'] == 'notice') {
            $(row).addClass('positive');
        } else if (data['level'] == 'warning') {
            $(row).addClass('warning');
        } else if (data['level'] != 'debug') {
            $(row).addClass('error');
        }
        // fixed-width font for message and location columns
        $('td', row).eq(2).addClass('code');
        $('td', row).eq(3).addClass('code');
    },
    buttons: [
        {
            extend: 'colvisGroup',
            name: 'columns_new',
            text: 'Minimal columns',
            show: ['timestamp:name', 'level:name', 'message:name', 'short_location:name'],
            hide: ['source:name', 'tags:name', 'location:name'],
        },
        {
            extend: 'colvisGroup',
            name: 'columns_old',
            text: 'More columns (classic)',
            show: ['timestamp:name', 'source:name', 'tags:name', 'message:name', 'location:name'],
            hide: ['level:name', 'short_location:name'],
        },
    ],
    dom: "<'ui stackable grid'"+
            "<'row'"+
                "<'eight wide column'B>"+
                "<'right aligned eight wide column'f>"+
            ">"+
            "<'row dt-table'"+
                "<'sixteen wide column'tr>"+
            ">"+
            "<'row'>"+
        ">",
});
// on any button click show the clicked button as active and all other button(s) as inactive
logs_table.on( 'buttons-action', function ( e, button, dataTable, node, config ) {
    dataTable.buttons().active(false);
    button.active(true);
} );
logs_table.button("columns_new:name").active( true );
// Init the DataTable for Events
var events = {{ events|tojson }}
var events_table = $('#events_table').DataTable({
    "data": events,
    'columns': [
        { data: 'resource' },
        { data: 'status' },
        { data: 'old' },
        { data: 'new' },
    ],
    "ordering": false,
    "paging": false,
    createdRow: function (row, data, index) {
        if (!data['failed'] && data['old'] != data['new']) {
            $(row).addClass('ui line changed');
        } else if (data['failed']) {
            $(row).addClass('ui line failed');
        } else {
            $(row).addClass('ui line ' + data['status']);
        }
    },
    dom: "<'ui stackable grid'"+
            "<'row'"+
                "<'eight wide column'B>"+
                "<'right aligned eight wide column'f>"+
            ">"+
            "<'row dt-table'"+
                "<'sixteen wide column'tr>"+
            ">"+
            "<'row'>"+
        ">",
});
var metrics_table = $('#metrics_table').DataTable({
  info: false,
  paging: false
});
{% endblock onload_script %}