sensu-plugins/sensu-plugins-mesos

View on GitHub

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
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

    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 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 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 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

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

                  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
                  Severity: Minor
                  Found in bin/check-marathon-apps.rb - About 45 mins 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 5 arguments (exceeds 4 allowed). Consider refactoring.
                  Open

                    def check_mesos_tasks(metric_value, mode, value, min, max)
                  Severity: Minor
                  Found in bin/check-mesos-running-tasks.rb - About 35 mins to fix

                    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
                    Severity: Minor
                    Found in bin/check-marathon-apps.rb - About 35 mins 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_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}"
                    Severity: Minor
                    Found in bin/check-marathon-task.rb - About 35 mins 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 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|
                    Severity: Minor
                    Found in bin/metrics-marathon.rb - About 35 mins 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 6 (exceeds 5 allowed). Consider refactoring.
                    Open

                      def run
                        servers = config[:server]
                        uri = config[:uri]
                        port = config[:port]
                        failures = []
                    Severity: Minor
                    Found in bin/check-mesos.rb - About 25 mins 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 6 (exceeds 5 allowed). Consider refactoring.
                    Open

                      def run
                        servers = config[:server]
                        uri = config[:uri]
                        failures = []
                        servers.split(',').each do |server|
                    Severity: Minor
                    Found in bin/check-chronos.rb - About 25 mins 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

                    Severity
                    Category
                    Status
                    Source
                    Language