bin/check-cucumber.rb in sensu-plugins-cucumber-0.0.1 vs bin/check-cucumber.rb in sensu-plugins-cucumber-1.0.0
- old
+ new
@@ -11,11 +11,11 @@
# PLATFORMS:
# Linux
#
# DEPENDENCIES:
# gem: sensu-plugin
-# gem: <?>
+# gem: english
#
# USAGE:
# #YELLOW
#
# NOTES:
@@ -99,11 +99,11 @@
option :debug,
description: 'Print debug information',
long: '--debug',
boolean: true
- def parse_options(argv) # rubocop:disable all
+ def parse_options(argv)
env = {}
event_data = {}
process_env_option = lambda do |config_value|
name, value = config_value.split('=', 2)
@@ -121,11 +121,11 @@
options[:event_data][:proc] = process_event_data_option
super(argv)
end
- def run # rubocop:disable all
+ def run
return unless config_is_valid?
result = nil
begin
@@ -153,11 +153,11 @@
sensu_events = []
utc_timestamp = Time.now.getutc.to_i
results.each do |feature|
# #YELLOW
- Array(feature[:elements]).each do |element| # rubocop:disable Style/Next
+ Array(feature[:elements]).each do |element|
if element[:type] == 'scenario'
event_name = "#{config[:name]}.#{generate_name_from_scenario(feature, element)}"
scenario_status = get_scenario_status(element)
sensu_events << generate_sensu_event(event_name, feature, element, scenario_status)
@@ -205,11 +205,11 @@
when :unknown
unknown data
end
end
- def config_is_valid? # rubocop:disable all
+ def config_is_valid?
if config[:name].nil?
unknown_error 'No name specified'
return false
end
@@ -262,27 +262,27 @@
Array(scenario[:steps]).each do |step|
step[:embeddings] = [] if step.key?(:embeddings)
end
end
- def generate_name_from_scenario(feature, scenario) # rubocop:disable all
+ def generate_name_from_scenario(feature, scenario)
name = scenario[:id]
name += ";#{feature[:profile]}" if feature.key? :profile
- name = name.gsub(/\./, '-')
- .gsub(/;/, '.')
- .gsub(/[^a-zA-Z0-9\._-]/, '-')
- .gsub(/^\.+/, '')
- .gsub(/\.+$/, '')
- .gsub(/\.+/, '.')
+ name = name.tr('.', '-')
+ .tr(';', '.')
+ .gsub(/[^a-zA-Z0-9\._-]/, '-')
+ .gsub(/^\.+/, '')
+ .gsub(/\.+$/, '')
+ .gsub(/\.+/, '.')
parts = []
name.split('.').each do |part|
part = part.gsub(/^-+/, '')
- .gsub(/-+$/, '')
- .gsub(/-+/, '-')
+ .gsub(/-+$/, '')
+ .gsub(/-+/, '-')
parts << part unless part.length == 0
end
name = parts.join('.')
@@ -309,11 +309,11 @@
end
errors
end
- def generate_metrics_from_scenario(feature, scenario, scenario_status, utc_timestamp) # rubocop:disable all
+ def generate_metrics_from_scenario(feature, scenario, scenario_status, utc_timestamp)
metrics = []
if scenario_status == :passed
scenario_duration = 0
@@ -339,15 +339,15 @@
metrics.unshift scenario_metrics
end
end
end
- if metrics.length == 0
- metrics = nil
- else
- metrics = metrics.join("\n")
- end
+ metrics = if metrics.length == 0
+ nil
+ else
+ metrics.join("\n")
+ end
metrics
end
private
@@ -390,11 +390,11 @@
end
socket.close
end
- def generate_sensu_event(event_name, feature, scenario, scenario_status) # rubocop:disable all
+ def generate_sensu_event(event_name, feature, scenario, scenario_status)
scenario_clone = deep_dup(scenario)
remove_attachments_from_scenario(scenario_clone) unless config[:attachments]
feature_clone = deep_dup(feature)
feature_clone[:elements] = [scenario_clone]
scenario_results = [feature_clone]
@@ -406,11 +406,11 @@
OK
when :failed
CRITICAL
when :pending, :undefined
WARNING
- end
+ end
sensu_event = {
name: event_name,
handlers: [config[:handler]],
status: scenario_status_code,
@@ -448,11 +448,11 @@
def get_scenario_status(scenario)
scenario_status = :passed
# #YELLOW
- Array(scenario[:steps]).each do |step| # rubocop:disable Style/Next
+ Array(scenario[:steps]).each do |step|
if step.key? :result
step_status = step[:result][:status]
if %w(failed pending undefined).include? step_status
scenario_status = step_status.to_sym
@@ -462,10 +462,10 @@
end
scenario_status
end
- def get_output_for_scenario(scenario, scenario_status) # rubocop:disable all
+ def get_output_for_scenario(scenario, scenario_status)
steps_output = []
Array(scenario[:steps]).each_with_index do |step, index|
has_result = step.key?(:result)
step_status = has_result ? step[:result][:status] : 'UNKNOWN'