Class: ScoutAgent::Assignment::UploadLog

Inherits:
ScoutAgent::Assignment show all
Defined in:
lib/scout_agent/assignment/upload_log.rb

Overview

Invoke with:

scout_agent upload_log [FILE_DATE]

This command can help us troubleshoot problems with your agent. You can invoke this to pass a log file up to our servers, so we can look through it for problems. Note that this is never done automatically. You must invoke this command manually.

The FILE_DATE is just the date of the log file in the form YYYY-MM-DD.

Instance Attribute Summary

Attributes inherited from ScoutAgent::Assignment

#group, #other_args, #switches, #user

Instance Method Summary collapse

Methods inherited from ScoutAgent::Assignment

choose_group, choose_user, #initialize, plan, #prepare_and_execute

Methods included from Tracked

#clear_status, #force_status_database_reload, #status, #status_database, #status_log

Constructor Details

This class inherits a constructor from ScoutAgent::Assignment

Instance Method Details

#executeObject

Runs the upload_log command.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/scout_agent/assignment/upload_log.rb', line 23

def execute
  # build the log file name
  file_name = "#{ScoutAgent.agent_name}.log"
  if date = Array(other_args).shift
    file_name += ".#{date.delete('^0-9')}"
  end
  log_file = Plan.log_dir + file_name
  
  # ensure it exists
  unless log_file.exist?
    abort_with_not_found(file_name)
  end
  
  # copy the log to a zipped temporary file
  puts "Preparing file for the server.  This may take a moment..."
  begin
    upload_file = Tempfile.new("#{file_name}.gz")
    gzipped     = Zlib::GzipWriter.new(upload_file)
    log_file.each_line do |line|
      gzipped << line
    end
    gzipped.close
    upload_file.open  # reopen what Zlib closed
  rescue Exception => error  # Zlib or IOError
    abort_with_preparation_error(error)
  end
  puts "Done."
  
  # upload the zipped temporary file to the server
  puts "Sending file to the server.  This may take a moment..."
  server = Server.new
  if server.post_log(upload_file)
    puts "Log '#{file_name}' received.  Thanks."
  else
    abort_with_server_error
  end
end