sensu-plugins/sensu-plugins-disk-checks

View on GitHub

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

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

            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

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

              def percent_bytes(fs_info)
                if config[:ignore_reserved]
                  u100 = fs_info.bytes_used * 100.0
                  nonroot_total = fs_info.bytes_used + fs_info.bytes_available
                  if nonroot_total.zero?
            Severity: Minor
            Found in bin/check-disk-usage.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 set_devices has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

              def set_devices
                if config[:devices] == 'all'
                  `lsblk -plnd -o NAME`.split.each do |name|
                    unless name =~ /\/dev\/loop.*/
                      dev = Device.new(name, config[:executable])
            Severity: Minor
            Found in bin/check-smart-tests.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