module IDRAC::Utility

def generate_and_download_tsr(output_file: nil, data_selector_values: nil, wait_timeout: 600)

Returns:
  • (String, nil) - Path to downloaded file or nil if failed

Parameters:
  • wait_timeout (Integer) -- Maximum time to wait for generation in seconds (default: 600)
  • data_selector_values (Array) -- Array of log types to include (optional)
  • output_file (String) -- Path to save the TSR file (optional)
def generate_and_download_tsr(output_file: nil, data_selector_values: nil, wait_timeout: 600)
  debug "Starting TSR generation and download process...", 1
  
  output_file ||= "supportassist_#{@host}_#{Time.now.strftime('%Y%m%d_%H%M%S')}.zip"
  
  # First, generate the TSR
  result = generate_tsr_logs(data_selector_values: data_selector_values)
  
  if result[:status] == :success && result[:job]
    debug "TSR generation completed successfully", 1, :green
    
    # Check if the job response has a location for the file
    if result[:location]
      return download_tsr_from_location(result[:location], output_file: output_file)
    else
      # Try alternative download methods based on Dell's Python script approach
      debug "Attempting to locate generated TSR file...", 1, :yellow
      
      # Wait a moment for the file to be available
      sleep 2
      
      # Try known endpoints where the file might be available
      possible_locations = [
        "/redfish/v1/Dell/Managers/iDRAC.Embedded.1/DellLCService/ExportedFiles/SupportAssist",
        "/redfish/v1/Managers/iDRAC.Embedded.1/Oem/Dell/DellLCService/ExportedFiles",
        "/downloads/supportassist_collection.zip",
        "/sysmgmt/2016/server/support_assist_collection"
      ]
      
      possible_locations.each do |location|
        debug "Trying location: #{location}", 2
        file_response = authenticated_request(:get, location)
        
        if file_response.status == 200 && file_response.body && file_response.body.size > 1024
          File.open(output_file, 'wb') do |f|
            f.write(file_response.body)
          end
          debug "TSR saved to: #{output_file} (#{File.size(output_file)} bytes)", 1, :green
          return output_file
        end
      end
      
      debug "Could not locate TSR file for direct download", 1, :yellow
      debug "The collection was generated but may require network share export", 1, :yellow
    end
  elsif result[:status] == :accepted
    debug "TSR generation was accepted but status unknown", 1, :yellow
  else
    debug "Failed to initiate TSR generation: #{result[:error]}", 1, :red
  end
  
  nil
end