[% nr = uniqnumber() %]
[% values = [] %]
[% IF type == 'host' %]
  [% FOREACH hst = avail_data.hosts.keys.sort.reverse %]
    [% available = get_availability_percents(hst, "") %]
    [% values.push([available.total.percent, loop.count]) %]
  [% END %]
[% ELSE %]
  [% x=1; FOREACH hst = avail_data.services.keys.sort.reverse %]
    [% FOREACH svc = avail_data.services.$hst.keys.sort.reverse %]
      [% available = get_availability_percents(hst, svc) %]
      [% values.push([available.total.percent, x]); x = x + 1; %]
    [% END %]
    [% IF type == 'both' %]
      [% available = get_availability_percents(hst, "") %]
      [% values.push([available.total.percent, x]); x = x + 1; %]
    [% END %]
  [% END %]
[% END %]

[% sla_averages_total = 0; sla_averages_num = 0; %]
<div id="flotgraph[% nr %]" class="flotgraph"></div>
<script>
<!--
jQuery(document).ready(function() {
    var graph_data = [% encode_json_obj(values) %];
    var label = [];
    [%+ IF type == 'host' +%]
      [% x=0; FOREACH hst = avail_data.hosts.keys.sort.reverse %]
        [% val = round_decimals(values.$x.0, param.decimals) %]
        [% IF values.$x.0 == -1 %][%# no data at all... #%]
          label[[% x; x = x + 1 %]] = "<span class='graph_hst_legend fittext js-hst-label'>[% _hst(hst) | html %]<\/span><span class='graph_percent_legend'>n/a<\/span>";
        [% ELSE %]
          label[[% x; x = x + 1 %]] = "<span class='graph_hst_legend fittext js-hst-label'>[% _hst(hst) | html %]<\/span><span class='graph_percent_legend[% IF val < param.sla %] sla_nok[% END %]'>[% val %] %<\/span>";
          [% sla_averages_total = sla_averages_total + val; sla_averages_num = sla_averages_num + 1; %]
        [% END %]
      [% END %]
    [% ELSE %]
      [% x=0; FOREACH hst = avail_data.services.keys.sort.reverse %]
        [% FOREACH svc = avail_data.services.$hst.keys.sort.reverse %]
          label[[% x %]] = "";
          [% val = round_decimals(values.$x.0, param.decimals) %]
          label[[% x %]] += "<span class='graph_svc_hst_legend fittext js-hst-label'>[% _hst(hst) | html %]<\/span>";
          label[[% x %]] += "<span class='graph_svc_legend fittext'> - [% _svc(hst, svc) | html %]<\/span>";
          [% IF values.$x.0 == -1 %][%# no data at all... #%]
            label[[% x %]] += "<span class='graph_percent_legend'>n/a<\/span>";
          [% ELSE %]
            label[[% x %]] += "<span class='graph_percent_legend[% IF val < param.sla %] sla_nok[% END %]'>[% val %] %<\/span>";
            [% sla_averages_total = sla_averages_total + val; sla_averages_num = sla_averages_num + 1; %]
          [% END %]
          [% x = x + 1 %]
        [% END %]
        [% IF type == 'both' %]
          [% val = round_decimals(values.$x.0, param.decimals) %]
          [% IF values.$x.0 == -1 %][%# no data at all... #%]
            label[[% x; x = x + 1 %]] = "<span class='graph_hst_legend fittext js-hst-label'>[% _hst(hst) | html %]<\/span><span class='graph_percent_legend'>n/a<\/span>";
          [% ELSE %]
            label[[% x; x = x + 1 %]] = "<span class='graph_hst_legend fittext js-hst-label'>[% _hst(hst) | html %]<\/span><span class='graph_percent_legend[% IF val < param.sla %] sla_nok[% END %]'>[% val %] %<\/span>";
            [% sla_averages_total = sla_averages_total + val; sla_averages_num = sla_averages_num + 1; %]
          [% END %]
        [% END %]
      [% END %]
    [%+ END +%]

    [% IF param.exists("overview_max_level") %]
    var tmp = render_apply_overview_threshold([% param.overview_max_level %], graph_data, label);
    graph_data = tmp.data;
    label      = tmp.label;
    if(tmp.hidden > 0) {
      jQuery("#hidden_[% nr %]").html("<span> ( excl. "+tmp.hidden+" x sla &gt;= [% param.overview_max_level %]% ) </span>");
      jQuery("#hidden_[% nr %]").parent("TR").show();
    }
    [% END %]

    var max_entries_per_page = 40;
    render_total_sla_graph([% nr %], "[% loc("Availability") %]", graph_data, [% param.sla %], [% param.graph_min_sla %], "[% type | html %]", label, max_entries_per_page);
});
-->
</script>

[% IF sla_averages_num > 0 %]
<table class="availability_details split_pages_lastpage_only">
  <tr>
    <th>[% loc("Average Availability") %]</th>
    <td>
    [% val   = sla_averages_total / sla_averages_num %]
    [% value = round_decimals(val, param.decimals) %]
    <span class='[% IF value < param.sla %] sla_nok[% END %]'>[% value %] %</span>
    </td>
  </tr>
  <tr style="display: none;">
    <td colspan="2" style="text-align: center;" id="hidden_[% nr %]"></td>
  </tr>
</table>
[% END %]
