sensu-plugins/sensu-plugins-mesos

View on GitHub

Showing 35 of 35 total issues

Similar blocks of code found in 4 locations. Consider refactoring.
Open

class MesosMemBalanceCheck < Sensu::Plugin::Check::CLI
  check_name 'MesosMemBalanceCheck'
  @metrics_name = 'slaves'.freeze
  CHECK_TYPE = 'mem'.freeze

Severity: Major
Found in bin/check-mesos-mem-balance.rb and 3 other locations - About 1 day to fix
bin/check-mesos-cpu-balance.rb on lines 35..154
bin/check-mesos-disk-balance.rb on lines 34..153
bin/check-mesos-gpu-balance.rb on lines 35..154

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 362.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 4 locations. Consider refactoring.
Open

class MesosCpuBalanceCheck < Sensu::Plugin::Check::CLI
  check_name 'MesosCpuBalanceCheck'
  @metrics_name = 'slaves'.freeze
  CHECK_TYPE = 'cpus'.freeze

Severity: Major
Found in bin/check-mesos-cpu-balance.rb and 3 other locations - About 1 day to fix
bin/check-mesos-disk-balance.rb on lines 34..153
bin/check-mesos-gpu-balance.rb on lines 35..154
bin/check-mesos-mem-balance.rb on lines 35..154

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 362.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 4 locations. Consider refactoring.
Open

class MesosDiskBalanceCheck < Sensu::Plugin::Check::CLI
  check_name 'MesosDiskBalanceCheck'
  @metrics_name = 'slaves'.freeze
  CHECK_TYPE = 'disk'.freeze

Severity: Major
Found in bin/check-mesos-disk-balance.rb and 3 other locations - About 1 day to fix
bin/check-mesos-cpu-balance.rb on lines 35..154
bin/check-mesos-gpu-balance.rb on lines 35..154
bin/check-mesos-mem-balance.rb on lines 35..154

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 362.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 4 locations. Consider refactoring.
Open

class MesosGpuBalanceCheck < Sensu::Plugin::Check::CLI
  check_name 'MesosGpuBalanceCheck'
  @metrics_name = 'slaves'.freeze
  CHECK_TYPE = 'gpus'.freeze

Severity: Major
Found in bin/check-mesos-gpu-balance.rb and 3 other locations - About 1 day to fix
bin/check-mesos-cpu-balance.rb on lines 35..154
bin/check-mesos-disk-balance.rb on lines 34..153
bin/check-mesos-mem-balance.rb on lines 35..154

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 362.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

class ChronosNodeStatus < Sensu::Plugin::Check::CLI
  option :server,
         description: 'Chronos hosts, comma separated',
         short: '-s SERVER',
         long: '--server SERVER',
Severity: Major
Found in bin/check-chronos.rb and 1 other location - About 4 hrs to fix
bin/check-metronome.rb on lines 34..79

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 138.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

class MetronomeNodeStatus < Sensu::Plugin::Check::CLI
  option :server,
         description: 'Metronome hosts, comma separated',
         short: '-s SERVER',
         long: '--server SERVER',
Severity: Major
Found in bin/check-metronome.rb and 1 other location - About 4 hrs to fix
bin/check-chronos.rb on lines 34..79

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 138.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

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
Severity: Minor
Found in bin/check-marathon-apps.rb - About 2 hrs to fix

    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) }
    
    
    Severity: Minor
    Found in bin/check-marathon-apps.rb - About 2 hrs to fix

    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
    Severity: Minor
    Found in bin/check-marathon-task.rb - About 2 hrs to fix

    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

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

        begin
          server = get_leader_url server, port
          # remove comment for debugging purpose
          # puts(server)
    
    
    Severity: Major
    Found in bin/check-mesos-lost-tasks.rb and 1 other location - About 1 hr to fix
    bin/check-mesos-failed-tasks.rb on lines 97..113

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 71.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

          server = get_leader_url server, port
          r = RestClient::Resource.new("#{server}#{uri}", timeout).get
          tasks_failed = check_tasks(r)
          if config[:delta]
            db = Daybreak::DB.new '/tmp/mesos-metrics.db', default: 0
    Severity: Major
    Found in bin/check-mesos-failed-tasks.rb and 1 other location - About 1 hr to fix
    bin/check-mesos-lost-tasks.rb on lines 96..115

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 71.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    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
    
    
    Severity: Minor
    Found in bin/check-marathon-apps.rb - About 1 hr to fix

    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
    Severity: Minor
    Found in bin/check-mesos-running-tasks.rb - About 1 hr to fix

    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
    
    
    Severity: Minor
    Found in bin/check-mesos-failed-tasks.rb - About 1 hr to fix

      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
      Severity: Minor
      Found in bin/check-marathon-apps.rb - About 1 hr to fix

        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
        Severity: Minor
        Found in bin/metrics-mesos.rb - About 1 hr to fix

          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
          Severity: Minor
          Found in bin/check-marathon-task.rb - About 1 hr to fix

            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
            
            
            Severity: Minor
            Found in bin/check-mesos-lost-tasks.rb - About 1 hr to fix

              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
              Severity: Minor
              Found in bin/metrics-mesos.rb - About 1 hr to fix

              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) }
              
              
              Severity: Minor
              Found in bin/check-marathon-apps.rb - About 1 hr to fix
                Severity
                Category
                Status
                Source
                Language