sensu-plugins/sensu-plugins-aws

View on GitHub
bin/check-rds.rb

Summary

Maintainability
C
1 day
Test Coverage

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

        def run
          instances = []
          if config[:db_cluster_id]
            db_cluster_writer_id = find_db_cluster_writer(config[:db_cluster_id])
            instances << find_db_instance(db_cluster_writer_id)
      Severity: Minor
      Found in bin/check-rds.rb - About 1 hr to fix

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

          def run
            instances = []
            if config[:db_cluster_id]
              db_cluster_writer_id = find_db_cluster_writer(config[:db_cluster_id])
              instances << find_db_instance(db_cluster_writer_id)
        Severity: Minor
        Found in bin/check-rds.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 collect has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

          def collect(instance)
            message = "\n#{instance[:db_instance_identifier]}: "
            @severities = {
              critical: false,
              warning:  false
        Severity: Minor
        Found in bin/check-rds.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_iops has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

          def check_iops(severity, expected_lower_than)
            read_iops_metric ||= cloud_watch_metric 'ReadIOPS', 'Count/Second'
            read_iops_metric_value ||= latest_value read_iops_metric
            write_iops_metric ||= cloud_watch_metric 'WriteIOPS', 'Count/Second'
            write_iops_metric_value ||= latest_value write_iops_metric
        Severity: Minor
        Found in bin/check-rds.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

        Method check_memory has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

          def check_memory(severity, expected_lower_than)
            memory_metric ||= cloud_watch_metric 'FreeableMemory', 'Bytes'
            memory_metric_value ||= latest_value memory_metric
            memory_total_bytes ||= memory_total_bytes @db_instance.db_instance_class
            memory_usage_bytes ||= memory_total_bytes - memory_metric_value
        Severity: Minor
        Found in bin/check-rds.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

        Method check_disk has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

          def check_disk(severity, expected_lower_than)
            disk_metric ||= cloud_watch_metric 'FreeStorageSpace', 'Bytes'
            disk_metric_value ||= latest_value disk_metric
            disk_total_bytes ||= @db_instance.allocated_storage * 1024**3
            disk_usage_bytes ||= disk_total_bytes - disk_metric_value
        Severity: Minor
        Found in bin/check-rds.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

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

          def check_connections(severity, expected_lower_than)
            connections_metric ||= cloud_watch_metric 'DatabaseConnections', 'Count'
            connections_metric_value ||= latest_value connections_metric
            return if connections_metric_value < expected_lower_than
            @severities[severity] = true
        Severity: Minor
        Found in bin/check-rds.rb and 1 other location - About 25 mins to fix
        bin/check-rds.rb on lines 272..277

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

        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

          def check_cpu(severity, expected_lower_than)
            cpu_metric ||= cloud_watch_metric 'CPUUtilization', 'Percent'
            cpu_metric_value ||= latest_value cpu_metric
            return if cpu_metric_value < expected_lower_than
            @severities[severity] = true
        Severity: Minor
        Found in bin/check-rds.rb and 1 other location - About 25 mins to fix
        bin/check-rds.rb on lines 302..307

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

        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

          def cloud_watch
            @cloud_watch ||= config[:role_arn] ? Aws::CloudWatch::Client.new(credentials: role_credentials, region: aws_config[:region]) : Aws::CloudWatch::Client.new(aws_config)
          end
        Severity: Minor
        Found in bin/check-rds.rb and 1 other location - About 15 mins to fix
        bin/check-rds.rb on lines 148..150

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

        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

          def rds
            @rds ||= config[:role_arn] ? Aws::RDS::Client.new(credentials: role_credentials, region: aws_config[:region]) : Aws::RDS::Client.new(aws_config)
          end
        Severity: Minor
        Found in bin/check-rds.rb and 1 other location - About 15 mins to fix
        bin/check-rds.rb on lines 152..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 25.

        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

        There are no issues that match your filters.

        Category
        Status