OpServ-Monitoring/opserv-backend

View on GitHub

Showing 66 of 66 total issues

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

def get_queue(component, metric, args=None):
    """ Returns either the requested queue or creates a new one """
    args = check_comp_args(realtime_queues, component, args)

    create_queue_if_not_exists(component, metric, args)
Severity: Major
Found in app/misc/queue_manager.py and 1 other location - About 4 hrs to fix
app/misc/data_manager.py on lines 35..44

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

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 get_measurement(component, metric, args=None):
    """ Returns the currently saved realtime data of the specified component """
    args = check_comp_args(realtime_data, component, args)

    create_measurement_if_not_exists(component, metric, args)
Severity: Major
Found in app/misc/data_manager.py and 1 other location - About 4 hrs to fix
app/misc/queue_manager.py on lines 41..50

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

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

Function get_measurement has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
Open

    def get_measurement(self, component, metric, args):
        '''
            Retrieves a measurement from the measuring source
            given the component, metric and optionally arguments
        '''
Severity: Minor
Found in app/gathering/measuring/psutil_source.py - 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

File ohm_source.py has 313 lines of code (exceeds 250 allowed). Consider refactoring.
Open

'''
    This module is pretty experimental and uses pythonnet to laod a C#-DLL
    The OpenHardwareMonitorLib is a pretty sophisticated library to get system metrics
    For more information about the project/code visit the GitHub Repository
    https://github.com/openhardwaremonitor/openhardwaremonitor
Severity: Minor
Found in app/gathering/measuring/ohm_source.py - About 3 hrs to fix

    Endpoint has 27 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class Endpoint(metaclass=ABCMeta):
        _outbound_gate = DefaultDataGate
    
        _request_holder = None
        _response_holder = None
    Severity: Minor
    Found in app/server/restful_api/general/endpoint.py - About 3 hrs to fix

      File psutil_source.py has 294 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      '''
          This module contains a wrapper class to create a nice fitting interface to the psutil module
      '''
      
      import logging
      Severity: Minor
      Found in app/gathering/measuring/psutil_source.py - About 3 hrs to fix

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

                        try:
                            network_info += str(self.psutil.net_if_addrs()[args])
                        except KeyError as err:
                            log.error(err)
                            log.error("Network Info couldnt be fetched with net_if_addrs")
        Severity: Major
        Found in app/gathering/measuring/psutil_source.py and 1 other location - About 2 hrs to fix
        app/gathering/measuring/psutil_source.py on lines 203..207

        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

                        try:
                            network_info += str(self.psutil.net_if_stats()[args])
                        except KeyError as err:
                            log.error(err)
                            log.error("Network Info couldnt be fetched with net_if_stats")
        Severity: Major
        Found in app/gathering/measuring/psutil_source.py and 1 other location - About 2 hrs to fix
        app/gathering/measuring/psutil_source.py on lines 208..212

        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

        Function is_pathname_valid has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
        Open

        def is_pathname_valid(pathname: str) -> bool:
            '''
            `True` if the passed pathname is a valid pathname for the current OS;
            `False` otherwise.
            SRC: http://stackoverflow.com/questions/9532499
        Severity: Minor
        Found in app/misc/standalone_helper.py - 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

        Function __init_endpoint has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
        Open

            def __init_endpoint(self, endpoints_prefix, endpoint_class, version, is_current):
                basic_auth = self.__basic_auth  # read basic_auth from wrapper class
        
                class CustomResource(Resource):
                    if basic_auth is not None:
        Severity: Minor
        Found in app/server/restful_api/flask_restful_wrapper.py - 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

        Function add_cpu has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

            def add_cpu(self, hardware):
                '''
                    Adds the given CPU (as OHM Hardware Object) to the cpu list
                    Also adds all its cores and updates the supported metrics
                '''
        Severity: Minor
        Found in app/gathering/measuring/ohm_source.py - 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

                elif component == "memory":
                    result = self.get_memory_measurement(metric)
                elif component == "disk":
                    result = self.get_disk_measurement(metric, args)
                elif component == "system":
        Severity: Major
        Found in app/gathering/measuring/ohm_source.py and 1 other location - About 1 hr to fix
        app/gathering/measuring/psutil_source.py on lines 144..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 44.

        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

                elif component == "partition":
                    result = self.measure_partition(metric, args)
                elif component == "network":
                    result = self.measure_network(metric, args)
        
        
        Severity: Major
        Found in app/gathering/measuring/psutil_source.py and 1 other location - About 1 hr to fix
        app/gathering/measuring/ohm_source.py on lines 156..161

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

        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

        Function __get_all_component_metrics has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

            def __get_all_component_metrics(cls) -> dict:
                from misc.constants import implemented_hardware, component_needs_arg
        
                component_metrics = {}
                for component_type in implemented_hardware:
        Severity: Minor
        Found in app/server/restful_api/data/v1/endpoints/gatheringrates.py - 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

        Function get_measurement has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

            def get_measurement(cls, component, metric, args):
                """
                    Given the component and metric this function uses the libraries to make a measurement
                    Returns: The value of the measurement
                """
        Severity: Minor
        Found in app/gathering/measurement_manager.py - 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

        Function get_measurement has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

            def get_measurement(self, component, metric, args):
                '''
                    Retrieves a measurement from the measuring source
                    given the component, metric and optionally arguments
                '''
        Severity: Minor
        Found in app/gathering/measuring/cpuinfo_source.py - 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

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

            def run(self):
                """
                    Starts the whole gathering process by manually
                    starting the queue_listener and then waiting for updates
                """
        Severity: Minor
        Found in app/gathering/gather_main.py - 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

        Consider simplifying this complex logical expression.
        Open

                if "component_type" not in request_body or request_body["component_type"] not in component_metrics_dict:
                    # TODO Future version: Log and return error message
        
                    return self.STOP_PROCESSING()
                elif "component_arg" not in request_body \
        Severity: Major
        Found in app/server/restful_api/data/v1/endpoints/gatheringrates.py - About 1 hr to fix

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

              def __init__(self):
                  self._init_complete = False
                  self.cpuinfo = import_if_exists("cpuinfo")
          
                  if self.cpuinfo:
          Severity: Minor
          Found in app/gathering/measuring/cpuinfo_source.py and 1 other location - About 55 mins to fix
          app/gathering/measuring/pyspectator_source.py on lines 26..33

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

          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 __init__(self):
          
                  self._init_complete = False
          
                  self.pyspectator = import_if_exists("pyspectator.processor")
          Severity: Minor
          Found in app/gathering/measuring/pyspectator_source.py and 1 other location - About 55 mins to fix
          app/gathering/measuring/cpuinfo_source.py on lines 44..49

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

          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

          Severity
          Category
          Status
          Source
          Language