From 1a8c2f2a233bcc5af1411384de869928a66b9ad7 Mon Sep 17 00:00:00 2001 From: alejandro Date: Fri, 18 Aug 2023 12:53:03 +0200 Subject: [PATCH] Minor changes --- .../extras/pandoraPlugintools/agents.py | 35 ++++++++++--- .../extras/pandoraPlugintools/discovery.py | 49 +++++++++++++++---- .../extras/pandoraPlugintools/general.py | 16 ++++-- .../extras/pandoraPlugintools/http.py | 5 +- .../extras/pandoraPlugintools/output.py | 15 ++++-- .../extras/pandoraPlugintools/threads.py | 4 +- .../extras/pandoraPlugintools/transfer.py | 15 ++++-- 7 files changed, 110 insertions(+), 29 deletions(-) diff --git a/pandora_server/extras/pandoraPlugintools/agents.py b/pandora_server/extras/pandoraPlugintools/agents.py index 18674bd012..dfd5eea788 100644 --- a/pandora_server/extras/pandoraPlugintools/agents.py +++ b/pandora_server/extras/pandoraPlugintools/agents.py @@ -46,13 +46,16 @@ def _print_debug( def set_global_variable( variable_name: str = "", value = None - ): + )-> None: """ Sets the value of a global variable in the '_GLOBAL_VARIABLES' dictionary. Args: variable_name (str): Name of the variable to set. value (any): Value to assign to the variable. + + Returns: + None """ from .general import set_dict_key_value @@ -63,12 +66,15 @@ def set_global_variable( ######################################################################################### def get_global_variable( variable_name: str = "" - ): + )-> None: """ Gets the value of a global variable in the '_GLOBAL_VARIABLES' dictionary. Args: variable_name (str): Name of the variable to set. + + Returns: + None """ from .general import get_dict_key_value @@ -105,12 +111,15 @@ class Agent: def update_config( self, config: dict = {} - ): + )-> None: ''' Update the configuration settings with new values. Args: config (dict): A dictionary containing configuration keys and their new values. + + Returns: + None ''' for key, value in config.items(): if key in self.config: @@ -130,12 +139,15 @@ class Agent: def add_module( self, module: dict = {} - ): + )-> None: ''' Add a new module to the list of modules. Args: module (dict): A dictionary containing module information. + + Returns: + None ''' from .general import generate_md5 from .modules import init_module @@ -147,12 +159,15 @@ class Agent: def del_module( self, module_name: str = "" - ): + )-> None: ''' Delete a module based on its name. Args: module_name (str): The name of the module to be deleted. + + Returns: + None ''' from .general import generate_md5 @@ -170,13 +185,16 @@ class Agent: self, module_name: str = "", module: dict = {} - ): + )-> None: ''' Update a module based on its name. Args: module_name (str): The name of the module to be updated. module (dict): A dictionary containing updated module information. + + Returns: + None ''' module_def = self.get_module(module_name) @@ -229,12 +247,15 @@ class Agent: def add_log_module( self, log_module: dict = {} - ): + )-> None: ''' Add a new log module to the list of log modules. Args: log_module (dict): A dictionary containing log module information. + + Returns: + None ''' from .modules import init_log_module diff --git a/pandora_server/extras/pandoraPlugintools/discovery.py b/pandora_server/extras/pandoraPlugintools/discovery.py index 229e963a8d..fc74144d35 100644 --- a/pandora_server/extras/pandoraPlugintools/discovery.py +++ b/pandora_server/extras/pandoraPlugintools/discovery.py @@ -33,7 +33,7 @@ def _print_debug( ######################################################################################### def set_disco_error_level( value: int = 0 - ): + )-> None: """ Sets the error level to the specified value. @@ -49,9 +49,17 @@ def set_disco_error_level( ######################################################################################### def set_disco_summary( data: dict = {} - ): + )-> None: """ - TODO: Add comments + Sets the disk summary data in the internal summary dictionary. + + This function updates the summary dictionary with the provided disk summary data. + + Args: + data (dict): A dictionary containing disk summary data. + + Returns: + None """ global _SUMMARY @@ -63,13 +71,16 @@ def set_disco_summary( def set_disco_summary_value( key: str = "", value = None - ): + )-> None: """ Sets a fixed value for a key in the '_SUMMARY' dictionary. Args: key (str): Key to set the value for. value (any): Value to assign to the key. + + Returns: + None """ global _SUMMARY @@ -81,7 +92,7 @@ def set_disco_summary_value( def add_disco_summary_value( key: str = "", value = None - ): + )-> None: """ Adds a value to a key in the 'SUMMARY' dictionary. @@ -90,6 +101,9 @@ def add_disco_summary_value( Args: key (str): Key to add the value to. value (any): Value to add to the key. + + Returns: + None """ global _SUMMARY @@ -103,12 +117,15 @@ def add_disco_summary_value( ######################################################################################### def set_disco_info_value( value: str = "" - ): + )-> None: """ Sets a fixed value to the '_INFO' variable. Args: data (str, optional): The value to set in the '_INFO' variable. Default is an empty string. + + Returns: + None """ global _INFO @@ -119,12 +136,15 @@ def set_disco_info_value( ######################################################################################### def add_disco_info_value( value: str = "" - ): + )-> None: """ Adds data to the '_INFO' variable. Args: data (str, optional): The data to add to the '_INFO' variable. Default is an empty string. + + Returns: + None """ global _INFO @@ -135,12 +155,15 @@ def add_disco_info_value( ######################################################################################### def set_disco_monitoring_data( data: list = [] - ): + )-> None: """ Set the monitoring data for disk usage. Args: data (list): A list containing disk monitoring data. + + Returns: + None """ global _MONITORING_DATA @@ -151,12 +174,15 @@ def set_disco_monitoring_data( ######################################################################################### def add_disco_monitoring_data( data: dict = {} - ): + )-> None: """ Add disk monitoring data to the global monitoring dataset. Args: data (dict): A dictionary containing disk monitoring data. + + Returns: + None """ global _MONITORING_DATA @@ -165,13 +191,16 @@ def add_disco_monitoring_data( #### # Print JSON output and exit script ######################################################################################### -def disco_output(): +def disco_output()-> None: """ Prints the JSON output and exits the script. The function uses the global variables '_ERROR_LEVEL', '_SUMMARY', '_INFO' and '_MONITORING_DATA' to create the JSON output. It then prints the JSON string and exits the script with the '_ERROR_LEVEL' as the exit code. + + Returns: + None """ from .output import print_stdout diff --git a/pandora_server/extras/pandoraPlugintools/general.py b/pandora_server/extras/pandoraPlugintools/general.py index a6c4c9a5ac..abf07221a2 100644 --- a/pandora_server/extras/pandoraPlugintools/general.py +++ b/pandora_server/extras/pandoraPlugintools/general.py @@ -360,7 +360,7 @@ def set_dict_key_value( input_dict: dict = {}, input_key: str = "", input_value = None - ): + )-> None: """ Assign a given value to a specified key in a dictionary. @@ -368,6 +368,9 @@ def set_dict_key_value( input_dict (dict): The dictionary to which the value will be assigned. input_key (str): The key in the dictionary to which the value will be assigned. input_value (any): The value to be assigned to the specified key. + + Returns: + None """ key = input_key.strip() @@ -381,9 +384,16 @@ def set_dict_key_value( def get_dict_key_value( input_dict: dict = {}, input_key: str = "" - ): + )-> None: """ - Return the value of a key in a given dict. + Return the value associated with a given key in a provided dictionary. + + Args: + input_dict (dict): The dictionary to search for the key-value pair. + input_key (str): The key to look up in the dictionary. + + Returns: + The value associated with the specified key, or None if the key is not found. """ key = input_key.strip() diff --git a/pandora_server/extras/pandoraPlugintools/http.py b/pandora_server/extras/pandoraPlugintools/http.py index e5bc1b1768..20e082537c 100644 --- a/pandora_server/extras/pandoraPlugintools/http.py +++ b/pandora_server/extras/pandoraPlugintools/http.py @@ -32,7 +32,7 @@ def _auth_call( authtype: str = "basic", user: str = "", passw: str = "" - ): + )-> None: """ Perform authentication for URL requests using various authentication types. @@ -41,6 +41,9 @@ def _auth_call( authtype (str, optional): The authentication type. Supported values: 'ntlm', 'basic', or 'digest'. Defaults to 'basic'. user (str, optional): The authentication user. Defaults to an empty string. passw (str, optional): The authentication password. Defaults to an empty string. + + Returns: + None """ if session is not None: if authtype == 'ntlm': diff --git a/pandora_server/extras/pandoraPlugintools/output.py b/pandora_server/extras/pandoraPlugintools/output.py index f9064c2abf..89b87dcdd6 100644 --- a/pandora_server/extras/pandoraPlugintools/output.py +++ b/pandora_server/extras/pandoraPlugintools/output.py @@ -25,12 +25,15 @@ def _print_debug( def print_stdout( message: str = "" - ): + )-> None: """ Prints message in stdout Args: message (str, optional): Message to be printed. Defaults to "". + + Returns: + None """ print(message) @@ -40,12 +43,15 @@ def print_stdout( def print_stderr( message: str = "" - ): + )-> None: """ Prints message in stderr Args: message (str, optional): Message to be printed. Defaults to "". + + Returns: + None """ print(message, file=sys.stderr) @@ -56,13 +62,16 @@ def print_stderr( def print_debug( var = "", print_errors: bool = False - ): + )-> None: """ Prints any list, dict, string, float or integer as a json Args: var: Variable to be printed. print_errors (bool, optional): Whether to print errors. Defaults to False. + + Returns: + None """ try: debug_json = json.dumps(var, indent=4) diff --git a/pandora_server/extras/pandoraPlugintools/threads.py b/pandora_server/extras/pandoraPlugintools/threads.py index f38c479eab..fe8e844df1 100644 --- a/pandora_server/extras/pandoraPlugintools/threads.py +++ b/pandora_server/extras/pandoraPlugintools/threads.py @@ -138,7 +138,7 @@ def run_threads( def set_shared_dict_value( key: str = None, value = None - ): + )-> None: """ Set a value for a key in the internal shared dictionary. This function is used by all parallel processes. @@ -160,7 +160,7 @@ def set_shared_dict_value( def add_shared_dict_value( key: str = None, value = None - ): + )-> None: """ Add a value to a key in the internal shared dictionary. This function is used by all parallel processes. diff --git a/pandora_server/extras/pandoraPlugintools/transfer.py b/pandora_server/extras/pandoraPlugintools/transfer.py index 9c8316c6c5..798b0511c4 100644 --- a/pandora_server/extras/pandoraPlugintools/transfer.py +++ b/pandora_server/extras/pandoraPlugintools/transfer.py @@ -45,13 +45,16 @@ def _print_debug( def set_global_variable( variable_name: str = "", value = None - ): + )-> None: """ Sets the value of a global variable in the '_GLOBAL_VARIABLES' dictionary. Args: variable_name (str): Name of the variable to set. value (any): Value to assign to the variable. + + Returns: + None """ from .general import set_dict_key_value @@ -62,12 +65,15 @@ def set_global_variable( ######################################################################################### def get_global_variable( variable_name: str = "" - ): + )-> None: """ Gets the value of a global variable in the '_GLOBAL_VARIABLES' dictionary. Args: variable_name (str): Name of the variable to set. + + Returns: + None """ from .general import get_dict_key_value @@ -185,7 +191,7 @@ def transfer_xml( tentacle_port: int = _GLOBAL_VARIABLES['tentacle_port'], tentacle_extra_opts: str = _GLOBAL_VARIABLES['tentacle_extra_opts'], data_dir: str = _GLOBAL_VARIABLES['data_dir'] - ): + )-> None: """ Detects the transfer mode and calls the agentplugin() function to perform the transfer. @@ -196,6 +202,9 @@ def transfer_xml( tentacle_ip (str, optional): IP address for Tentacle. Default is _GLOBAL_VARIABLES['tentacle_ip']. tentacle_port (str, optional): Port for Tentacle. Default is _GLOBAL_VARIABLES['tentacle_port']. data_dir (str, optional): Path to data dir with local transfer mode. Default is _GLOBAL_VARIABLES['data_dir']. + + Returns: + None """ if file is not None: if transfer_mode != "local":