sensu-plugins/sensu-plugins-network-checks

View on GitHub

Showing 33 of 33 total issues

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

  def run
    hosts = config[:hosts].split(',')
    okarray = []
    hosts.each do |host|
      case config[:pattern]
Severity: Minor
Found in bin/check-banner.rb - About 3 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 expiration_results has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
Open

  def expiration_results
    domains = config[:domain].split(',')
    warning_days = config[:warning].to_i
    critical_days = config[:critical].to_i
    max_retries = 4
Severity: Minor
Found in bin/check-whois-domain-expiration-multi.rb - About 3 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 23 (exceeds 5 allowed). Consider refactoring.
Open

  def run
    # Metrics borrowed from hoardd: https://github.com/coredump/hoardd

    metrics = %w[rxBytes
                 rxPackets
Severity: Minor
Found in bin/metrics-interface.rb - About 3 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 19 (exceeds 5 allowed). Consider refactoring.
Open

  def run
    timestamp = Time.now.to_i

    Dir.glob('/sys/class/net/*').each do |iface_path|
      next if File.file?(iface_path)
Severity: Minor
Found in bin/metrics-net.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

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

  def run
    results = expiration_results

    warn_results = results[:critical].merge(results[:warning]).map { |u, v| "#{u} (#{v} days left)" }
    unknown_results = results[:unknown].map { |u, v| "#{u} (#{v})" }
Severity: Major
Found in bin/check-jsonwhois-domain-expiration.rb and 1 other location - About 2 hrs to fix
bin/check-whois-domain-expiration-multi.rb on lines 137..152

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

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

  def run
    results = expiration_results

    warn_results = results[:critical].merge(results[:warning]).map { |u, v| "#{u} (#{v} days left)" }
    unknown_results = results[:unknown].map { |u, v| "#{u} (#{v})" }
Severity: Major
Found in bin/check-whois-domain-expiration-multi.rb and 1 other location - About 2 hrs to fix
bin/check-jsonwhois-domain-expiration.rb on lines 139..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 89.

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 17 (exceeds 5 allowed). Consider refactoring.
Open

  def run
    c = DNSBL::Client.new

    if config[:ip]
      ip_add = config[:ip]
Severity: Minor
Found in bin/check-rbl.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 acquire_banner has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
Open

  def acquire_banner(host)
    Timeout.timeout(config[:timeout]) do
      sock = TCPSocket.new(host, config[:port])

      if config[:ssl]
Severity: Minor
Found in bin/check-banner.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 16 (exceeds 5 allowed). Consider refactoring.
Open

  def run
    result = []
    pt = Net::Ping::External.new(config[:host], nil, config[:timeout])

    config[:count].times do |i|
Severity: Minor
Found in bin/check-ping.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 netstat has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

  def netstat(protocols = ['tcp'])
    state_counts = Hash.new(0)
    TCP_STATES.each_pair { |_hex, name| state_counts[name] = 0 }

    protocols.select { |p| File.exist?('/proc/net/' + p) }.each do |protocol|
Severity: Minor
Found in bin/check-netstat-tcp.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 portbinds has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

  def portbinds
    default_protocol = config[:hard] ? 'both' : 'tcp'
    binds = []

    config[:portbinds].split(',').each do |portbind|
Severity: Minor
Found in bin/check-ports-bind.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 expiration_results has 39 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def expiration_results
    domains = config[:domain].split(',')
    warning_days = config[:warning].to_i
    critical_days = config[:critical].to_i
    max_retries = 4
Severity: Minor
Found in bin/check-whois-domain-expiration-multi.rb - About 1 hr to fix

    Method netstat has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

      def netstat(protocol, pattern, state_counts)
        File.open('/proc/net/' + protocol).each do |line|
          line.strip!
          if m = line.match(pattern) # rubocop:disable AssignmentInCondition
            connection_state = m[5]
    Severity: Minor
    Found in bin/metrics-netstat-tcp.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 35 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def run
        c = DNSBL::Client.new
    
        if config[:ip]
          ip_add = config[:ip]
    Severity: Minor
    Found in bin/check-rbl.rb - About 1 hr to fix

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

        def run
          sar = `sar -n DEV #{config[:interval]} 1 | grep #{config[:average_key]} | grep -v IFACE`
          if sar.nil? || sar.empty?
            unknown 'sar is not installed or in $PATH'
          end
      Severity: Minor
      Found in bin/metrics-netif.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 31 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def run
          # Metrics borrowed from hoardd: https://github.com/coredump/hoardd
      
          metrics = %w[rxBytes
                       rxPackets
      Severity: Minor
      Found in bin/metrics-interface.rb - About 1 hr to fix

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

          def run
            timestamp = Time.now.to_i
        
            Dir.glob('/sys/class/net/*').each do |iface_path|
              next if File.file?(iface_path)
        Severity: Minor
        Found in bin/metrics-net.rb - About 1 hr to fix

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

            def run
              result = []
              pt = Net::Ping::External.new(config[:host], nil, config[:timeout])
          
              config[:count].times do |i|
          Severity: Minor
          Found in bin/check-ping.rb - About 1 hr to fix

            Method expiration_results has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

              def expiration_results
                domains = config[:domain].split(',')
                warning_days = config[:warning].to_i
                critical_days = config[:critical].to_i
                results = {
            Severity: Minor
            Found in bin/check-jsonwhois-domain-expiration.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 a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

              def run
                stdout, stderr = Open3.capture3(
                  ENV,
                  "nmap -P0 -p #{config[:ports]} #{config[:host]}"
                )
            Severity: Minor
            Found in bin/check-ports-nmap.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

            Severity
            Category
            Status
            Source
            Language