Minor changes

This commit is contained in:
alejandro 2023-08-18 12:53:03 +02:00
parent a42a87dffe
commit 1a8c2f2a23
7 changed files with 110 additions and 29 deletions

View File

@ -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

View File

@ -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

View File

@ -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()

View File

@ -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':

View File

@ -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)

View File

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

View File

@ -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":