sensu-plugins/sensu-plugins-http

View on GitHub

Showing 45 of 45 total issues

Method follow_uri has 30 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def follow_uri(uri, total_redirects, get_redirects, auth_count)
    location = URI(uri)
    http = Net::HTTP.new(location.host, location.port)

    if location.port == 443
Severity: Minor
Found in bin/check-head-redirect.rb - About 1 hr to fix

    Method follow_uri has 30 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def follow_uri(uri, total_redirects, get_redirects, auth_count)
        location = URI(uri)
        http = Net::HTTP.new(location.host, location.port)
    
        if location.port == 443
    Severity: Minor
    Found in bin/check-last-modified.rb - About 1 hr to fix

      Method run has 29 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def run
          if config[:url]
            uri = URI.parse(config[:url])
            config[:host] = uri.host
            config[:port] = uri.port
      Severity: Minor
      Found in bin/check-http.rb - About 1 hr to fix

        Method run has 28 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def run
            found = false
            attempts = 0
            until found || attempts >= 10
              attempts += 1
        Severity: Minor
        Found in bin/metrics-http-json-deep.rb - About 1 hr to fix

          Method run has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

            def run
              merge_s3_config
          
              url = config[:url]
              threshold = config[:threshold]
          Severity: Minor
          Found in bin/check-last-modified.rb - About 55 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 8 (exceeds 5 allowed). Consider refactoring.
          Open

            def run
              if config[:url]
                uri = URI.parse(config[:url])
                config[:host] = uri.host
                config[:path] = uri.path
          Severity: Minor
          Found in bin/check-http-json.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

          Avoid deeply nested control flow statements.
          Open

                    if config[:redirectto] == res['Location'] # rubocop:disable Metrics/BlockNesting
                      ok "#{res.code} found redirect to #{res['Location']}" + body
                    else
                      critical "Expected redirect to #{config[:redirectto]} instead redirected to #{res['Location']}" + body
                    end
          Severity: Major
          Found in bin/check-http.rb - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                    ok("#{res.code}, #{size} bytes" + body) unless config[:response_code]
            Severity: Major
            Found in bin/check-http.rb - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                      if Digest::SHA256.hexdigest(res.body).eql? config[:sha256checksum]
                        ok "#{res.code}, checksum match #{config[:sha256checksum]} in #{size} bytes" + body
                      else
                        critical "#{res.code}, checksum did not match #{config[:sha256checksum]} in #{size} bytes: #{res.body[0...200]}..."
                      end
              Severity: Major
              Found in bin/check-http.rb - About 45 mins to fix

                Method run has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                  def run
                    if config[:url]
                      uri = URI.parse(config[:url])
                      config[:host] = uri.host
                      config[:port] = uri.port
                Severity: Minor
                Found in bin/check-http.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 run has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                  def run
                    if config[:url]
                      uri = URI.parse(config[:url])
                      config[:host] = uri.host
                      config[:path] = uri.path
                Severity: Minor
                Found in bin/check-http-cors.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 deep_value has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                  def deep_value(hash, scheme = '')
                    hash.each do |key, value|
                      ekey = key.gsub(/\s/, '_')
                      if value.is_a?(Hash)
                        deep_value(value, "#{scheme}.#{ekey}")
                Severity: Minor
                Found in bin/metrics-http-json-deep.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

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

                    if auth_count > 0 && config[:user] && config[:password] && total_redirects == config[:follow_redirects]
                      http.use_ssl = true
                      request.basic_auth(config[:user], config[:password])
                      auth_count -= 1
                    end
                Severity: Minor
                Found in bin/check-head-redirect.rb and 1 other location - About 35 mins to fix
                bin/check-last-modified.rb on lines 122..126

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

                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

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

                    if auth_count > 0 && config[:user] && config[:password] && total_redirects == config[:follow_redirects]
                      http.use_ssl = true
                      request.basic_auth(config[:user], config[:password])
                      auth_count -= 1
                    end
                Severity: Minor
                Found in bin/check-last-modified.rb and 1 other location - About 35 mins to fix
                bin/check-head-redirect.rb on lines 116..120

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

                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 3 locations. Consider refactoring.
                Open

                      if config[:value]
                        raise "unexpected value for key: '#{leaf}' != '#{config[:value]}'" unless leaf.to_s == config[:value].to_s
                
                        message += "equals '#{config[:value]}'"
                      end
                Severity: Minor
                Found in bin/check-http-json.rb and 2 other locations - About 30 mins to fix
                bin/check-http-json.rb on lines 210..214
                bin/check-http-json.rb on lines 215..219

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

                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 3 locations. Consider refactoring.
                Open

                      if config[:valueLt]
                        raise "unexpected value for key: '#{leaf}' not < '#{config[:valueLt]}'" unless leaf.to_f < config[:valueLt].to_f
                
                        message += "less than '#{config[:valueLt]}'"
                      end
                Severity: Minor
                Found in bin/check-http-json.rb and 2 other locations - About 30 mins to fix
                bin/check-http-json.rb on lines 205..209
                bin/check-http-json.rb on lines 210..214

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

                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 3 locations. Consider refactoring.
                Open

                      if config[:valueGt]
                        raise "unexpected value for key: '#{leaf}' not > '#{config[:valueGt]}'" unless leaf.to_f > config[:valueGt].to_f
                
                        message += "greater than '#{config[:valueGt]}'"
                      end
                Severity: Minor
                Found in bin/check-http-json.rb and 2 other locations - About 30 mins to fix
                bin/check-http-json.rb on lines 205..209
                bin/check-http-json.rb on lines 215..219

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

                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

                    if config[:headers]
                      config[:headers].split(',').each do |header|
                        h, v = header.split(':', 2)
                        header_dict[h] = v.strip
                Severity: Minor
                Found in bin/metrics-http-json.rb and 3 other locations - About 20 mins to fix
                bin/check-http-cors.rb on lines 92..95
                bin/check-http-cors.rb on lines 136..139
                bin/check-http-json.rb on lines 182..185

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

                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

                    if config[:header]
                      config[:header].split(',').each do |header|
                        h, v = header.split(':', 2)
                        req[h] = v.strip
                Severity: Minor
                Found in bin/check-http-json.rb and 3 other locations - About 20 mins to fix
                bin/check-http-cors.rb on lines 92..95
                bin/check-http-cors.rb on lines 136..139
                bin/metrics-http-json.rb on lines 95..98

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

                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

                    if config[:header]
                      config[:header].split(',').each do |header|
                        h, v = header.split(':', 2)
                        req[h] = v.strip
                Severity: Minor
                Found in bin/check-http-cors.rb and 3 other locations - About 20 mins to fix
                bin/check-http-cors.rb on lines 92..95
                bin/check-http-json.rb on lines 182..185
                bin/metrics-http-json.rb on lines 95..98

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

                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

                Severity
                Category
                Status
                Source
                Language