sensu-plugins/sensu-plugins-http

View on GitHub
bin/check-http.rb

Summary

Maintainability
F
3 days
Test Coverage

Method handle_response has a Cognitive Complexity of 47 (exceeds 5 allowed). Consider refactoring.
Open

  def handle_response(res, size, body)
    case res.code
    when /^2/
      if config[:redirectto]
        critical "Expected redirect to #{config[:redirectto]} but got #{res.code}" + body
Severity: Minor
Found in bin/check-http.rb - About 7 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 acquire_resource has a Cognitive Complexity of 41 (exceeds 5 allowed). Consider refactoring.
Open

  def acquire_resource
    http = nil

    if config[:no_proxy]
      http = Net::HTTP.new(config[:host], config[:port], nil, nil)
Severity: Minor
Found in bin/check-http.rb - About 6 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

File check-http.rb has 338 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'sensu-plugins-http'
require 'sensu-plugin/check/cli'
require 'net/http'
require 'net/https'
require 'digest'
Severity: Minor
Found in bin/check-http.rb - About 4 hrs to fix

    Method acquire_resource has 89 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def acquire_resource
        http = nil
    
        if config[:no_proxy]
          http = Net::HTTP.new(config[:host], config[:port], nil, nil)
    Severity: Major
    Found in bin/check-http.rb - About 3 hrs to fix

      Method handle_response has 49 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def handle_response(res, size, body)
          case res.code
          when /^2/
            if config[:redirectto]
              critical "Expected redirect to #{config[:redirectto]} but got #{res.code}" + body
      Severity: Minor
      Found in bin/check-http.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

          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

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

                      if config[:cert]
                        cert_data = File.read(config[:cert])
                        http.cert = OpenSSL::X509::Certificate.new(cert_data)
                        http.key = OpenSSL::PKey::RSA.new(cert_data, nil)
                Severity: Minor
                Found in bin/check-http.rb and 1 other location - About 15 mins to fix
                bin/check-http-cors.rb on lines 122..125

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

                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

                    if config[:min_bytes] && res.body.length < config[:min_bytes]
                      critical "Response was #{res.body.length} bytes instead of the indicated minimum #{config[:min_bytes]}" + body
                    end
                Severity: Minor
                Found in bin/check-http.rb and 1 other location - About 15 mins to fix
                bin/check-http.rb on lines 389..391

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

                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

                    if config[:require_bytes] && res.body.length != config[:require_bytes]
                      critical "Response was #{res.body.length} bytes instead of #{config[:require_bytes]}" + body
                    end
                Severity: Minor
                Found in bin/check-http.rb and 1 other location - About 15 mins to fix
                bin/check-http.rb on lines 393..395

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

                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

                There are no issues that match your filters.

                Category
                Status