sensu-plugins/sensu-plugins-disk-checks

View on GitHub

Showing 26 of 26 total issues

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

  def run
    @smart_attributes = JSON.parse(IO.read(config[:json]), symbolize_names: true)[:smart][:attributes]
    @smart_debug = config[:debug] == 'on'

    # Load in the device configuration
Severity: Minor
Found in bin/check-smart-status.rb - About 1 day 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_tests has a Cognitive Complexity of 36 (exceeds 5 allowed). Consider refactoring.
Open

  def check_tests(dev)
    if dev.str.empty?
      @warnings << "#{dev.name}: No self-tests have been logged."
      return
    end
Severity: Minor
Found in bin/check-smart-tests.rb - About 5 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 32 (exceeds 5 allowed). Consider refactoring.
Open

  def run
    delim = config[:flatten] == true ? '_' : '.'
    # Get disk usage from df with used and avail in megabytes
    # #YELLOW
    command = if Gem::Platform.local.os == 'solaris'
Severity: Minor
Found in bin/metrics-disk-usage.rb - About 4 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 fs_mounts has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
Open

  def fs_mounts
    begin
      mounts = Filesystem.mounts
    rescue StandardError
      unknown 'An error occured getting the mount info'
Severity: Minor
Found in bin/check-disk-usage.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 70 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def run
    @smart_attributes = JSON.parse(IO.read(config[:json]), symbolize_names: true)[:smart][:attributes]
    @smart_debug = config[:debug] == 'on'

    # Load in the device configuration
Severity: Major
Found in bin/check-smart-status.rb - About 2 hrs to fix

    Method check_mounts has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

      def check_mounts
        @fstab.each do |line|
          next if line =~ /^\s*#/
          next if line =~ /^\s*$/
    
    
    Severity: Minor
    Found in bin/check-fstab-mounts.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 54 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def run
        # Get capacity metrics from DF as they don't appear in /proc
        command = if Gem::Platform.local.os == 'solaris'
                    'df -k'
                  else
    Severity: Major
    Found in bin/metrics-disk-capacity.rb - About 2 hrs to fix

      Method find_devices has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

        def find_devices
          # Search for devices without number
          devices = []
      
          # Return parameter value if it's defined
      Severity: Minor
      Found in bin/check-smart-status.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 15 (exceeds 5 allowed). Consider refactoring.
      Open

        def run
          # http://www.kernel.org/doc/Documentation/iostats.txt
          metrics = %w[reads readsMerged sectorsRead readTime writes writesMerged sectorsWritten writeTime ioInProgress ioTime ioTimeWeighted]
      
          File.open('/proc/diskstats', 'r').each_line do |line|
      Severity: Minor
      Found in bin/metrics-disk.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

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

          unless config[:short_test_interval].nil?
            dev.str.each_with_index do |t, i|
              if t['test_description'] != 'Short offline'
                if i == dev.str.length - 1
                  @warnings << "#{dev.name}: No short tests were run for this device in last #{dev.str.length} executions"
      Severity: Major
      Found in bin/check-smart-tests.rb and 1 other location - About 1 hr to fix
      bin/check-smart-tests.rb on lines 152..164

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

      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

          unless config[:long_test_interval].nil? # rubocop:disable Style/GuardClause
            dev.str.each_with_index do |t, i|
              if t['test_description'] != 'Extended offline'
                if i == dev.str.length - 1
                  @warnings << "#{dev.name}: No extended tests were run for this device in last #{dev.str.length} executions"
      Severity: Major
      Found in bin/check-smart-tests.rb and 1 other location - About 1 hr to fix
      bin/check-smart-tests.rb on lines 135..147

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

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

        def run
          # Get capacity metrics from DF as they don't appear in /proc
          command = if Gem::Platform.local.os == 'solaris'
                      'df -k'
                    else
      Severity: Minor
      Found in bin/metrics-disk-capacity.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_tests has 37 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def check_tests(dev)
          if dev.str.empty?
            @warnings << "#{dev.name}: No self-tests have been logged."
            return
          end
      Severity: Minor
      Found in bin/check-smart-tests.rb - About 1 hr to fix

        Method find_devices has 34 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def find_devices
            # Search for devices without number
            devices = []
        
            # Return parameter value if it's defined
        Severity: Minor
        Found in bin/check-smart-status.rb - About 1 hr to fix

          Method check_mount has 32 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def check_mount(line)
              begin
                fs_info = Filesystem.stat(line.mount_point)
              rescue StandardError
                @warn_fs << "#{line.mount_point} Unable to read."
          Severity: Minor
          Found in bin/check-disk-usage.rb - About 1 hr to fix

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

              def resolve_device(device)
                if device.start_with?('UUID=')
                  uuid = device.split('=')[1]
                  path = File.join('/', 'dev', 'disk', 'by-uuid', uuid)
                  if File.exist?(path) && File.symlink?(path)
            Severity: Minor
            Found in bin/check-fstab-mounts.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_mount has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
            Open

              def check_mount(line)
                begin
                  fs_info = Filesystem.stat(line.mount_point)
                rescue StandardError
                  @warn_fs << "#{line.mount_point} Unable to read."
            Severity: Minor
            Found in bin/check-disk-usage.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

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

                    if fs =~ /\/dev/
                      fs = fs.sub('/dev/', '')
                      metrics = {
                        disk: {
                          "#{fs}.used" => used,
            Severity: Major
            Found in bin/metrics-disk-capacity.rb and 1 other location - About 1 hr to fix
            bin/metrics-disk-capacity.rb on lines 99..110

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

            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 fs =~ /\/dev/
                        fs = fs.sub('/dev/', '')
                        metrics = {
                          disk: {
                            "#{fs}.iused" => used,
            Severity: Major
            Found in bin/metrics-disk-capacity.rb and 1 other location - About 1 hr to fix
            bin/metrics-disk-capacity.rb on lines 72..83

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

            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 scan_disks! has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

              def scan_disks!
                `lsblk -nro NAME,TYPE`.each_line do |line|
                  name, type = line.split
            
                  if type == 'disk'
            Severity: Minor
            Found in bin/check-smart.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

            Severity
            Category
            Status
            Source
            Language