Class: RightScale::LogLevelManager

Inherits:
Object
  • Object
show all
Defined in:
lib/right_agent/scripts/log_level_manager.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.runObject

Convenience wrapper for creating and running log level manager

Return

true

Always return true



48
49
50
51
# File 'lib/right_agent/scripts/log_level_manager.rb', line 48

def self.run
  m = LogLevelManager.new
  m.manage(m.parse_args)
end

Instance Method Details

#manage(options) ⇒ Object

Handle log level request

Parameters

options(Hash)

Command line options

Return

true

Always return true



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/right_agent/scripts/log_level_manager.rb', line 60

def manage(options)
  # Initialize configuration directory setting
  AgentConfig.cfg_dir = options[:cfg_dir]

  # Determine command
  level = options[:level]
  command = { :name => (level ? 'set_log_level' : 'get_log_level') }
  command[:level] = level.to_sym if level

  # Determine candidate agents
  agent_names = if options[:agent_name]
    [options[:agent_name]]
  else
    AgentConfig.cfg_agents
  end
  fail("No agents configured") if agent_names.empty?

  # Perform command for each agent
  count = 0
  agent_names.each do |agent_name|
    count += 1 if request_log_level(agent_name, command, options)
  end
  puts("No agents running") if count == 0
  true
end

#parse_argsObject

Create options hash from command line arguments

Return

options(Hash)

Hash of options as defined by the command line



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/right_agent/scripts/log_level_manager.rb', line 90

def parse_args
  options = { :verbose => false }
  options[:agent_name] = ARGV[0] unless ARGV[0] =~ /^-/

  opts = OptionParser.new do |opts|

    opts.on('-l', '--log-level LEVEL') do |l|
      fail("Invalid log level '#{l}'") unless AgentManager::LEVELS.include?(l.downcase.to_sym)
      options[:level] = l.downcase
    end

    opts.on("-c", "--cfg-dir DIR") do |d|
      options[:cfg_dir] = d
    end

    opts.on('-v', '--verbose') do
      options[:verbose] = true
    end

  end

  opts.on_tail('--help') do
     puts Usage.scan(__FILE__)
     exit
  end

  begin
    opts.parse!(ARGV)
  rescue Exception => e
    exit 0 if e.is_a?(SystemExit)
    fail(e.message + "\nUse 'rlog --help' for additional information")
  end
  options
end