sensu-plugins/sensu-plugins-elasticsearch

View on GitHub

Showing 68 of 68 total issues

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

  def run
    # invert various stats depending on if some flags are set
    os_stat = !config[:disable_os_stats]
    process_stats = !config[:disable_process_stats]
    jvm_stats = !config[:disable_jvm_stats]
Severity: Minor
Found in bin/metrics-es-node-graphite.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

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

  def kibana_info
    kibana_date_format = '%Y-%m-%dT%H:%M:%S.%LZ'
    unless config[:kibana_url].nil?
      index = config[:index]
      unless config[:date_index].nil?
Severity: Major
Found in bin/check-es-query-average.rb and 1 other location - About 5 hrs to fix
bin/check-es-query-count.rb on lines 210..241

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

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 kibana_info
    kibana_date_format = '%Y-%m-%dT%H:%M:%S.%LZ'
    unless config[:kibana_url].nil?
      index = config[:index]
      unless config[:date_index].nil?
Severity: Major
Found in bin/check-es-query-count.rb and 1 other location - About 5 hrs to fix
bin/check-es-query-average.rb on lines 222..253

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

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 133 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def run
    # invert various stats depending on if some flags are set
    os_stat = !config[:disable_os_stats]
    process_stats = !config[:disable_process_stats]
    jvm_stats = !config[:disable_jvm_stats]
Severity: Major
Found in bin/metrics-es-node-graphite.rb - About 5 hrs to fix

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

      def get_es_resource(resource)
        headers = {}
        if config[:user] && config[:password]
          auth = 'Basic ' + Base64.strict_encode64("#{config[:user]}:#{config[:password]}").chomp
          headers = { 'Authorization' => auth }
    Severity: Major
    Found in bin/check-es-circuit-breakers.rb and 2 other locations - About 3 hrs to fix
    bin/check-es-cluster-status.rb on lines 96..127
    bin/check-es-heap.rb on lines 108..139

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

    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

      def get_es_resource(resource)
        headers = {}
        if config[:user] && config[:password]
          auth = 'Basic ' + Base64.strict_encode64("#{config[:user]}:#{config[:password]}").chomp
          headers = { 'Authorization' => auth }
    Severity: Major
    Found in bin/check-es-cluster-status.rb and 2 other locations - About 3 hrs to fix
    bin/check-es-circuit-breakers.rb on lines 83..114
    bin/check-es-heap.rb on lines 108..139

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

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

      def run
        # If only one cluster is given, no need to check the indexes
        ok 'All indexes are unique' if config[:cluster].length == 1
    
        port = ':9200'
    Severity: Minor
    Found in bin/check-es-indexes.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

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

      def acquire_es_resource(resource)
        headers = {}
        if config[:user] && config[:password]
          auth = 'Basic ' + Base64.strict_encode64("#{config[:user]}:#{config[:password]}").chomp
          headers = { 'Authorization' => auth }
    Severity: Major
    Found in bin/check-es-heap.rb and 2 other locations - About 3 hrs to fix
    bin/check-es-circuit-breakers.rb on lines 83..114
    bin/check-es-cluster-status.rb on lines 96..127

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

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

      def run
        dividend_query = config[:dividend]
        divisor_query = config[:divisor]
        config.delete(:dividend)
        config.delete(:divisor)
    Severity: Minor
    Found in bin/check-es-query-ratio.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

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

      def get_es_resource(resource)
        headers = {}
        if config[:user] && config[:password]
          auth = 'Basic ' + Base64.strict_encode64("#{config[:user]}:#{config[:password]}").chomp
          headers = { 'Authorization' => auth }
    Severity: Major
    Found in bin/metrics-es-node.rb and 1 other location - About 3 hrs to fix
    bin/metrics-es-cluster.rb on lines 102..129

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

    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 get_es_resource(resource)
        headers = {}
        if config[:user] && config[:password]
          auth = 'Basic ' + Base64.strict_encode64("#{config[:user]}:#{config[:password]}").chomp
          headers = { 'Authorization' => auth }
    Severity: Major
    Found in bin/metrics-es-cluster.rb and 1 other location - About 3 hrs to fix
    bin/metrics-es-node.rb on lines 83..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 118.

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

      def run
        fieldcounts = indexfieldcount
        limits = fieldlimitsetting
    
        warnings = {}
    Severity: Minor
    Found in bin/check-es-indices-field-count.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 build_request_options has 66 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def build_request_options
        end_time = (Time.now.utc - config[:offset])
        options = {
    
          index: indices(end_time),
    Severity: Major
    Found in lib/sensu-plugins-elasticsearch/elasticsearch-query.rb - About 2 hrs to fix

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

        def run
          response = client.search(build_request_options)
          if config[:invert]
            if response['aggregations']['average']['value'] < config[:crit]
              critical "Query average (#{response['aggregations']['average']['value']}) was below critical threshold. #{kibana_info}"
      Severity: Minor
      Found in bin/check-es-query-average.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 19 (exceeds 5 allowed). Consider refactoring.
      Open

        def run
          response = client.count(build_request_options)
          if config[:invert]
            if response['count'] < config[:crit]
              critical "Query count (#{response['count']}) was below critical threshold. #{kibana_info}"
      Severity: Minor
      Found in bin/check-es-query-count.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 indices has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
      Open

        def indices(end_time)
          if !config[:index].nil?
            return config[:index]
          elsif !config[:date_index].nil?
            indices = []
      Severity: Minor
      Found in lib/sensu-plugins-elasticsearch/elasticsearch-query.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 kibana_info has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

        def kibana_info
          kibana_date_format = '%Y-%m-%dT%H:%M:%S.%LZ'
          unless config[:kibana_url].nil?
            index = config[:index]
            unless config[:date_index].nil?
      Severity: Minor
      Found in bin/check-es-query-ratio.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 kibana_info has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

        def kibana_info
          kibana_date_format = '%Y-%m-%dT%H:%M:%S.%LZ'
          unless config[:kibana_url].nil?
            index = config[:index]
            unless config[:date_index].nil?
      Severity: Minor
      Found in bin/check-es-query-count.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 kibana_info has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

        def kibana_info
          kibana_date_format = '%Y-%m-%dT%H:%M:%S.%LZ'
          unless config[:kibana_url].nil?
            index = config[:index]
            unless config[:date_index].nil?
      Severity: Minor
      Found in bin/check-es-query-average.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 44 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def run
          dividend_query = config[:dividend]
          divisor_query = config[:divisor]
          config.delete(:dividend)
          config.delete(:divisor)
      Severity: Minor
      Found in bin/check-es-query-ratio.rb - About 1 hr to fix
        Severity
        Category
        Status
        Source
        Language