sensu-plugins/sensu-plugins-aws

View on GitHub

Showing 152 of 152 total issues

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

  def run
    event_instances = []
    aws_config = {}

    aws_regions = ec2_regions
Severity: Minor
Found in bin/check-instance-events.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

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

class AsgScaler < Sensu::Handler
  option :json_config,
         description: 'Name of the json config file',
         short: '-j JSONCONFIG',
         long: '--json JSONCONFIG',
Severity: Major
Found in bin/handler-scale-asg-up.rb and 1 other location - About 6 hrs to fix
bin/handler-scale-asg-down.rb on lines 44..128

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

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

class AsgScaler < Sensu::Handler
  option :json_config,
         description: 'Name of the json config file',
         short: '-j JSONCONFIG',
         long: '--json JSONCONFIG',
Severity: Major
Found in bin/handler-scale-asg-down.rb and 1 other location - About 6 hrs to fix
bin/handler-scale-asg-up.rb on lines 44..128

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

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

  def run
    Aws.config.update(aws_config)
    sqs = Aws::SQS::Resource.new

    if config[:prefix].empty?
Severity: Minor
Found in bin/check-sqs-messages.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
    warning = 3
    critical = 4
    result_launched = ''
    result_terminated = ''
Severity: Minor
Found in bin/check-asg-instances-created.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 maint_clusters has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
Open

  def maint_clusters
    maint_clusters = []
    aws_regions = rds_regions

    unless config[:aws_region].casecmp('all').zero?
Severity: Minor
Found in bin/check-rds-events.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 83 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def run
    # Subnets that meet the threshold criteria will store info hashes in this array
    consumption_alert = []

    begin
Severity: Major
Found in bin/check-subnet-ip-consumption.rb - About 3 hrs to fix

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

      def run
        aws_config = {}
    
        if (config[:key_name].nil? && config[:key_prefix].nil?) || (!config[:key_name].nil? && !config[:key_prefix].nil?)
          critical 'Need one option between "key_name" and "key_prefix"'
    Severity: Minor
    Found in bin/check-s3-object.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
        warning = 0
        critical = 0
        result = ''
        if config[:load_balancer].nil?
    Severity: Minor
    Found in bin/check-elb-instances-inservice.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
        ses = Aws::SES::Client.new(aws_config)
        begin
          response = ses.get_send_statistics
    
    
    Severity: Minor
    Found in bin/check-ses-statistics.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 22 (exceeds 5 allowed). Consider refactoring.
    Open

      def run
        errors = []
        warnings = []
        buckets = if config[:all_buckets]
                    list_buckets
    Severity: Minor
    Found in bin/check-s3-bucket-visibility.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 22 (exceeds 5 allowed). Consider refactoring.
    Open

      def run
        filters = Filter.parse(config[:filter])
        filters.push(
          name: 'instance-state-name',
          values: ['running']
    Severity: Minor
    Found in bin/check-ec2-cpu_balance.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 21 (exceeds 5 allowed). Consider refactoring.
    Open

      def run
        warning = 0
        critical = 0
        instance_in_service = 0
        result = ''
    Severity: Minor
    Found in bin/check-asg-instances-inservice.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 21 (exceeds 5 allowed). Consider refactoring.
    Open

      def run
        ok_message = []
        warning_message = []
        critical_message = []
    
    
    Severity: Minor
    Found in bin/check-elb-certs.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

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

    require 'sensu-plugin/check/cli'
    require 'aws-sdk'
    require 'time'
    
    class CheckRDS < Sensu::Plugin::Check::CLI
    Severity: Minor
    Found in bin/check-rds.rb - About 2 hrs to fix

      Method memory_total_bytes has 65 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def memory_total_bytes(instance_class)
          memory_total_gigabytes = {
            'db.cr1.8xlarge'  => 244.0,
            'db.m1.small'     => 1.7,
            'db.m1.medium'    => 3.75,
      Severity: Major
      Found in bin/check-rds.rb - About 2 hrs to fix

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

          def run
            service_healths = services_by_health(config[:cluster_name], config[:services], config[:primary_status])
        
            unhealthy = []
            unhealthy.concat(service_healths[:critical]) if service_healths.key? :critical
        Severity: Minor
        Found in bin/check-ecs-service-health.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
            aws_regions = ec2_regions
            @message = ''
            critical = false
        
        
        Severity: Minor
        Found in bin/check-elb-health-sdk.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 62 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def run
            Aws.config.update(aws_config)
            sqs = Aws::SQS::Resource.new
        
            if config[:prefix].empty?
        Severity: Major
        Found in bin/check-sqs-messages.rb - About 2 hrs to fix

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

            def run
              # Converting the string into a hash.
              filter_list = config[:exclude_tags].split(/}\s?{/).map do |x|
                x.gsub(/[{}]/, '')
              end
          Severity: Major
          Found in bin/check-sensu-client.rb - About 2 hrs to fix
            Severity
            Category
            Status
            Source
            Language