Class: Rearview::Configuration
- Inherits:
-
Object
- Object
- Rearview::Configuration
show all
- Includes:
- ActiveModel::Model
- Defined in:
- lib/rearview/configuration.rb
Defined Under Namespace
Classes: DirectoryValidator, UrlValidator
Constant Summary
collapse
- ATTRIBUTES =
[:default_from, :graphite_connection, :pagerduty_url, :sandbox_exec,
:sandbox_timeout, :sandbox_dir, :enable_alerts, :preload_jobs,
:logger, :enable_monitor, :verify, :default_url_options,
:authentication, :enable_stats, :statsd_connection,
:enable_metrics_validator, :metrics_validator_schedule]
Instance Method Summary
collapse
Constructor Details
#initialize(attributes = {}) ⇒ Configuration
Returns a new instance of Configuration.
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/rearview/configuration.rb', line 57
def initialize(attributes={})
@default_from = "rearview@localhost"
@sandbox_timeout = 5
@enable_alerts = true
@preload_jobs = true
@verify = false
@enable_monitor = true
@authentication = { strategy: :database }
@enable_stats = false
@default_url_options = {:host=>"localhost",:port=>"3000"}
@pagerduty_url = "https://events.pagerduty.com/generic/2010-04-15/create_event.json"
@graphite_connection = {}
@enable_metrics_validator = false
@metrics_validator_schedule = nil
super
end
|
Instance Method Details
#alerts_enabled? ⇒ Boolean
74
75
76
|
# File 'lib/rearview/configuration.rb', line 74
def alerts_enabled?
enable_alerts
end
|
#dump ⇒ Object
146
147
148
|
# File 'lib/rearview/configuration.rb', line 146
def dump
ATTRIBUTES.sort.map { |attrib| "#{attrib.to_s}=#{(self.send(attrib).nil? ? "nil" : self.send(attrib))}" }.join("\n")
end
|
#metrics_validator_enabled? ⇒ Boolean
82
83
84
|
# File 'lib/rearview/configuration.rb', line 82
def metrics_validator_enabled?
enable_metrics_validator
end
|
#monitor_enabled? ⇒ Boolean
78
79
80
|
# File 'lib/rearview/configuration.rb', line 78
def monitor_enabled?
enable_monitor
end
|
#preload_jobs? ⇒ Boolean
86
87
88
|
# File 'lib/rearview/configuration.rb', line 86
def preload_jobs?
preload_jobs
end
|
#stats_enabled? ⇒ Boolean
90
91
92
|
# File 'lib/rearview/configuration.rb', line 90
def stats_enabled?
enable_stats
end
|
#validate_graphite_connection ⇒ Object
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
# File 'lib/rearview/configuration.rb', line 130
def validate_graphite_connection
if graphite_connection.present?
if !graphite_connection[:url].present?
self.errors.add(:graphite_connection, "graphite URL can't be blank")
else
url_validator = UrlValidator.new({ attributes: [:graphite_connection], message: "does not contain a valid URL" })
if url_validator.validate_each(self,:graphite_connection,graphite_connection[:url])
client = Graphite::Client.new(graphite_connection)
unless(client.reachable?)
self.errors.add(:graphite_connection, "graphite cannot be reached")
end
end
end
end
end
|
#validate_sandbox_execution ⇒ Object
117
118
119
120
121
122
123
124
125
126
127
128
|
# File 'lib/rearview/configuration.rb', line 117
def validate_sandbox_execution
script_file = File.join(sandbox_dir,"verify_sandbox.rb")
cmd = sandbox_exec.clone << script_file
process_builder = ProcessBuilder.new(cmd).redirectErrorStream(true)
process_builder.directory(java.io.File.new(sandbox_dir.to_s))
process_builder.environment.delete("GEM_HOME")
process_builder.environment.delete("GEM_PATH")
process = process_builder.start
exit_code = process.waitFor
output = process.get_input_stream.to_io.read
exit_code == 0
end
|
#verify? ⇒ Boolean
94
95
96
|
# File 'lib/rearview/configuration.rb', line 94
def verify?
verify
end
|
#with_argv(argv) ⇒ Object
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
# File 'lib/rearview/configuration.rb', line 98
def with_argv(argv)
OptionParser.new do |opts|
opts.on("--[no-]preload", "Enable/disable job loading") { |v| self.preload_jobs = v }
opts.on("--[no-]alerts", "Enable/disable alerts") { |v| self.enable_alerts = v }
opts.on("--[no-]monitor", "Enable/disable monitor") { |v| self.enable_monitor = v }
opts.on("--[no-]verify", "Enable/disable verification") { |v| self.verify = v }
opts.on("--[no-]stats-service", "Enable/disable stats service") { |v| self.enable_stats = v }
opts.on("--[no-]validation-service", "Enable/disable validation service") { |v| self.enable_metrics_validator = v }
opts.on("--[no-]soft-boot", "Enable/disable soft boot") { |v|
if v
self.preload_jobs = false
self.enable_stats = false
self.enable_metrics_validator = false
self.enable_alerts = false
end
}
end.parse!(argv)
end
|