Showing 23 of 35 total issues
File check-marathon-apps.rb
has 289 lines of code (exceeds 250 allowed). Consider refactoring. Open
require 'sensu-plugin/check/cli'
require 'rest-client'
require 'json'
# This plugin checks Marathon apps based on https://mesosphere.github.io/marathon/docs/marathon-ui.html#application-status-reference
Method parse_app_labels
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
def parse_app_labels(app_labels)
config = {}
# Only grab labels that starts with SENSU_MARATHON
labels = app_labels.to_h.select { |e| /^SENSU_MARATHON/.match(e) }
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method run
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
def run
if !config[:username].nil? && config[:password].nil? ||
config[:username].nil? && !config[:password].nil?
unknown 'You must provide both username and password'
end
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method run
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
def run
if !config[:username].nil? && config[:password].nil? || config[:username].nil? && !config[:password].nil?
unknown 'You must provide both username and password to authenticate on Marathon API'
end
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method check_mesos_tasks
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def check_mesos_tasks(metric_value, mode, value, min, max)
if config[:delta]
db = Daybreak::DB.new '/tmp/mesos-metrics.db', default: 0
prev_value = db['task_running']
db.lock do
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method run
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
def run
if config[:value].to_i.negative?
unknown 'Number of failed tasks cannot be negative'
end
Method run
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
def run
uri = config[:uri]
case config[:mode]
when 'master'
port = config[:port] || MASTER_DEFAULT_PORT
Method process_app_results
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
def process_app_results(app, queue, check_config)
app_result_pushed = true
# Select app queue if any
app_queue = queue.select { |q| q['app']['id'][/^#{app['id']}$/] }.to_a.first
Method run
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
def run
if !config[:username].nil? && config[:password].nil? ||
config[:username].nil? && !config[:password].nil?
unknown 'You must provide both username and password'
end
Method run
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
def run
if config[:value].negative?
unknown 'Number of lost tasks cannot be negative, please set --value to a number greater or equal to 0'
end
Method run
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def run
uri = config[:uri]
case config[:mode]
when 'master'
port = config[:port] || MASTER_DEFAULT_PORT
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method parse_app_labels
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
def parse_app_labels(app_labels)
config = {}
# Only grab labels that starts with SENSU_MARATHON
labels = app_labels.to_h.select { |e| /^SENSU_MARATHON/.match(e) }
Method run
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
def run
if !config[:username].nil? && config[:password].nil? || config[:username].nil? && !config[:password].nil?
unknown 'You must provide both username and password to authenticate on Marathon API'
end
Method get_marathon_app_health
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def get_marathon_app_health(app)
# https://mesosphere.github.io/marathon/docs/marathon-ui.html#application-health-reference
if app['tasks'].to_a.length.zero? && app['deployments'].to_a.length.zero?
'unscheduled'
elsif app['instances'].to_i < app['tasksRunning'].to_i
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method check_mesos_tasks
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def check_mesos_tasks(metric_value, mode, value, min, max)
Method get_marathon_app_status
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def get_marathon_app_status(app, app_queue)
# https://mesosphere.github.io/marathon/docs/marathon-ui.html#application-status-reference
if app_queue.to_h.dig('delay', 'overdue') == true
'waiting'
elsif app_queue.to_h.dig('delay', 'overdue') == false
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method check_tasks
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def check_tasks(data)
begin
tasks = JSON.parse(data)['tasks']
rescue JSON::ParserError
raise "Could not parse JSON response: #{data}"
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method run
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def run
r = RestClient::Resource.new("#{config[:protocol]}://#{config[:server]}:#{config[:port]}#{config[:uri]}", timeout: config[:timeout]).get
all_metrics = JSON.parse(r)
metric_groups = all_metrics.keys - SKIP_ROOT_KEYS
metric_groups.each do |metric_groups_key|
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method run
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def run
servers = config[:server]
uri = config[:uri]
port = config[:port]
failures = []
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method run
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def run
servers = config[:server]
uri = config[:uri]
failures = []
servers.split(',').each do |server|
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"