[% USE CSV -%]
[% IF opt %]
  [% CSV.dump(['Device' 'Description' 'Name' 'Class' 'Type' 'Model' 'Serial' 'HW Version' 'SW Version' 'FW Version']) %]

  [% FOREACH row IN results %]
    [% mylist = [] %]
    [% device = row.device.dns || row.device.name || row.ip %]
    [% FOREACH col IN [ device row.description row.name row.class.ucfirst row.type row.model row.serial row.hw_ver row.sw_ver row.fw_ver ] %]
      [% mylist.push(col) %]
    [% END %]
    [% CSV.dump(mylist) %]

  [% END %]
[% ELSE %]
  [% CSV.dump(['Class' 'Count']) %]

  [% FOREACH row IN results %]
    [% mylist = [] %]
    [% FOREACH col IN [ row.class.ucfirst row.count ] %]
      [% mylist.push(col) %]
    [% END %]
    [% CSV.dump(mylist) %]

  [% END %]
[% END %]
