Module: ScoutAgent
- Defined in:
- lib/scout_agent.rb,
lib/scout_agent/api.rb,
lib/scout_agent/plan.rb,
lib/scout_agent/agent.rb,
lib/scout_agent/order.rb,
lib/scout_agent/server.rb,
lib/scout_agent/id_card.rb,
lib/scout_agent/mission.rb,
lib/scout_agent/tracked.rb,
lib/scout_agent/database.rb,
lib/scout_agent/lifeline.rb,
lib/scout_agent/wire_tap.rb,
lib/scout_agent/assignment.rb,
lib/scout_agent/dispatcher.rb,
lib/scout_agent/database/queue.rb,
lib/scout_agent/assignment/stop.rb,
lib/scout_agent/core_extensions.rb,
lib/scout_agent/assignment/queue.rb,
lib/scout_agent/assignment/reset.rb,
lib/scout_agent/assignment/start.rb,
lib/scout_agent/assignment/status.rb,
lib/scout_agent/assignment/update.rb,
lib/scout_agent/database/statuses.rb,
lib/scout_agent/agent/master_agent.rb,
lib/scout_agent/database/snapshots.rb,
lib/scout_agent/assignment/identify.rb,
lib/scout_agent/assignment/snapshot.rb,
lib/scout_agent/database/mission_log.rb,
lib/scout_agent/order/check_in_order.rb,
lib/scout_agent/order/snapshot_order.rb,
lib/scout_agent/assignment/upload_log.rb,
lib/scout_agent/assignment/configuration.rb,
lib/scout_agent/agent/communication_agent.rb,
lib/scout_agent/assignment/test.rb
Overview
The namespace for all agent software.
Defined Under Namespace
Modules: API, CoreExtensions, Dispatcher, Planned, Tracked Classes: Agent, Assignment, Database, IDCard, Lifeline, Mission, Order, Server, WireTap
Constant Summary collapse
- VERSION =
The version of this agent.
"3.2.7".freeze
- LIB_DIR =
A Pathname reference to the agent code directory, used in dynamic loading.
Pathname.new(File.dirname(__FILE__)) + agent_name
- Plan =
This constant holds all global configuration for the agent. There’s only this one instance of this data and all systems share it. This data is configured at startup and should never again change without a restart.
Users are free to add to this configuration as need (via their configuration file) and make use of those new values in their plugins.
OpenStruct.new.extend(Planned).set_defaults
- Plugin =
An alias to support older plugins.
Mission
Class Method Summary collapse
-
.agent_name ⇒ Object
Returns the name of the agent executable.
-
.prepare_wire_tap(process_name, skip_stdout = false) ⇒ Object
A helper that prepares a log for
process_name
. -
.proper_agent_name ⇒ Object
Returns agent_name() converted to a proper human-readable name.
-
.remove_old_log_files(log) ⇒ Object
A maintenance method used to remove log files written more than seven days ago.
Class Method Details
.agent_name ⇒ Object
Returns the name of the agent executable.
39 40 41 |
# File 'lib/scout_agent.rb', line 39 def self.agent_name name.snake_case end |
.prepare_wire_tap(process_name, skip_stdout = false) ⇒ Object
A helper that prepares a log for process_name
. This log will use the configured log level and be rotated daily. If the agent is not running as a daemon, the log will also be teed to $stdout
, but you can pass a true
value into skip_stdout
to prevent this.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/scout_agent.rb', line 54 def self.prepare_wire_tap(process_name, skip_stdout = false) wire_tap = WireTap.new(Plan.log_dir + "#{agent_name}.log", :daily) begin wire_tap.level = ScoutAgent::WireTap::Severity.const_get( Plan.logging_level ) rescue NameError # unrecognized level # do nothing: we will stick with the default end wire_tap.progname = process_name wire_tap.quiet = true wire_tap.tap = $stdout unless skip_stdout or Plan.run_as_daemon? wire_tap end |
.proper_agent_name ⇒ Object
Returns agent_name() converted to a proper human-readable name.
44 45 46 |
# File 'lib/scout_agent.rb', line 44 def self.proper_agent_name agent_name.tr("_", " ").gsub(/\w+/) { |w| w.capitalize } end |
.remove_old_log_files(log) ⇒ Object
A maintenance method used to remove log files written more than seven days ago. This prevents the hard drive from slowly filling with log files and thus is called as part of the main event loop as well as after snapshot and queue commands. A recent log
must be provided to notify of rotation errors.
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/scout_agent.rb', line 76 def self.remove_old_log_files(log) Plan.log_dir.each_entry do |log_file| if log_file.to_s =~ /\.(\d{4})(\d{2})(\d{2})\z/ log_day = Time.local(*$~.captures.map { |n| n.to_i }) if Time.now - log_day > 60 * 60 * 24 * 7 begin (Plan.log_dir + log_file).unlink rescue Exception => error # file cannot be unlinked log.error( "Failed to unlink old log file '#{log_file}': " + "#{error.} (#{error.class})." ) next end log.debug("Successfully unlinked old log file '#{log_file}'.") end end end end |