mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-31 01:35:36 +02:00
Minor changes
This commit is contained in:
parent
a42a87dffe
commit
1a8c2f2a23
@ -46,13 +46,16 @@ def _print_debug(
|
|||||||
def set_global_variable(
|
def set_global_variable(
|
||||||
variable_name: str = "",
|
variable_name: str = "",
|
||||||
value = None
|
value = None
|
||||||
):
|
)-> None:
|
||||||
"""
|
"""
|
||||||
Sets the value of a global variable in the '_GLOBAL_VARIABLES' dictionary.
|
Sets the value of a global variable in the '_GLOBAL_VARIABLES' dictionary.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
variable_name (str): Name of the variable to set.
|
variable_name (str): Name of the variable to set.
|
||||||
value (any): Value to assign to the variable.
|
value (any): Value to assign to the variable.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
None
|
||||||
"""
|
"""
|
||||||
from .general import set_dict_key_value
|
from .general import set_dict_key_value
|
||||||
|
|
||||||
@ -63,12 +66,15 @@ def set_global_variable(
|
|||||||
#########################################################################################
|
#########################################################################################
|
||||||
def get_global_variable(
|
def get_global_variable(
|
||||||
variable_name: str = ""
|
variable_name: str = ""
|
||||||
):
|
)-> None:
|
||||||
"""
|
"""
|
||||||
Gets the value of a global variable in the '_GLOBAL_VARIABLES' dictionary.
|
Gets the value of a global variable in the '_GLOBAL_VARIABLES' dictionary.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
variable_name (str): Name of the variable to set.
|
variable_name (str): Name of the variable to set.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
None
|
||||||
"""
|
"""
|
||||||
from .general import get_dict_key_value
|
from .general import get_dict_key_value
|
||||||
|
|
||||||
@ -105,12 +111,15 @@ class Agent:
|
|||||||
def update_config(
|
def update_config(
|
||||||
self,
|
self,
|
||||||
config: dict = {}
|
config: dict = {}
|
||||||
):
|
)-> None:
|
||||||
'''
|
'''
|
||||||
Update the configuration settings with new values.
|
Update the configuration settings with new values.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
config (dict): A dictionary containing configuration keys and their new values.
|
config (dict): A dictionary containing configuration keys and their new values.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
None
|
||||||
'''
|
'''
|
||||||
for key, value in config.items():
|
for key, value in config.items():
|
||||||
if key in self.config:
|
if key in self.config:
|
||||||
@ -130,12 +139,15 @@ class Agent:
|
|||||||
def add_module(
|
def add_module(
|
||||||
self,
|
self,
|
||||||
module: dict = {}
|
module: dict = {}
|
||||||
):
|
)-> None:
|
||||||
'''
|
'''
|
||||||
Add a new module to the list of modules.
|
Add a new module to the list of modules.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
module (dict): A dictionary containing module information.
|
module (dict): A dictionary containing module information.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
None
|
||||||
'''
|
'''
|
||||||
from .general import generate_md5
|
from .general import generate_md5
|
||||||
from .modules import init_module
|
from .modules import init_module
|
||||||
@ -147,12 +159,15 @@ class Agent:
|
|||||||
def del_module(
|
def del_module(
|
||||||
self,
|
self,
|
||||||
module_name: str = ""
|
module_name: str = ""
|
||||||
):
|
)-> None:
|
||||||
'''
|
'''
|
||||||
Delete a module based on its name.
|
Delete a module based on its name.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
module_name (str): The name of the module to be deleted.
|
module_name (str): The name of the module to be deleted.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
None
|
||||||
'''
|
'''
|
||||||
from .general import generate_md5
|
from .general import generate_md5
|
||||||
|
|
||||||
@ -170,13 +185,16 @@ class Agent:
|
|||||||
self,
|
self,
|
||||||
module_name: str = "",
|
module_name: str = "",
|
||||||
module: dict = {}
|
module: dict = {}
|
||||||
):
|
)-> None:
|
||||||
'''
|
'''
|
||||||
Update a module based on its name.
|
Update a module based on its name.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
module_name (str): The name of the module to be updated.
|
module_name (str): The name of the module to be updated.
|
||||||
module (dict): A dictionary containing updated module information.
|
module (dict): A dictionary containing updated module information.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
None
|
||||||
'''
|
'''
|
||||||
module_def = self.get_module(module_name)
|
module_def = self.get_module(module_name)
|
||||||
|
|
||||||
@ -229,12 +247,15 @@ class Agent:
|
|||||||
def add_log_module(
|
def add_log_module(
|
||||||
self,
|
self,
|
||||||
log_module: dict = {}
|
log_module: dict = {}
|
||||||
):
|
)-> None:
|
||||||
'''
|
'''
|
||||||
Add a new log module to the list of log modules.
|
Add a new log module to the list of log modules.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
log_module (dict): A dictionary containing log module information.
|
log_module (dict): A dictionary containing log module information.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
None
|
||||||
'''
|
'''
|
||||||
from .modules import init_log_module
|
from .modules import init_log_module
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ def _print_debug(
|
|||||||
#########################################################################################
|
#########################################################################################
|
||||||
def set_disco_error_level(
|
def set_disco_error_level(
|
||||||
value: int = 0
|
value: int = 0
|
||||||
):
|
)-> None:
|
||||||
"""
|
"""
|
||||||
Sets the error level to the specified value.
|
Sets the error level to the specified value.
|
||||||
|
|
||||||
@ -49,9 +49,17 @@ def set_disco_error_level(
|
|||||||
#########################################################################################
|
#########################################################################################
|
||||||
def set_disco_summary(
|
def set_disco_summary(
|
||||||
data: dict = {}
|
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
|
global _SUMMARY
|
||||||
|
|
||||||
@ -63,13 +71,16 @@ def set_disco_summary(
|
|||||||
def set_disco_summary_value(
|
def set_disco_summary_value(
|
||||||
key: str = "",
|
key: str = "",
|
||||||
value = None
|
value = None
|
||||||
):
|
)-> None:
|
||||||
"""
|
"""
|
||||||
Sets a fixed value for a key in the '_SUMMARY' dictionary.
|
Sets a fixed value for a key in the '_SUMMARY' dictionary.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
key (str): Key to set the value for.
|
key (str): Key to set the value for.
|
||||||
value (any): Value to assign to the key.
|
value (any): Value to assign to the key.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
None
|
||||||
"""
|
"""
|
||||||
global _SUMMARY
|
global _SUMMARY
|
||||||
|
|
||||||
@ -81,7 +92,7 @@ def set_disco_summary_value(
|
|||||||
def add_disco_summary_value(
|
def add_disco_summary_value(
|
||||||
key: str = "",
|
key: str = "",
|
||||||
value = None
|
value = None
|
||||||
):
|
)-> None:
|
||||||
"""
|
"""
|
||||||
Adds a value to a key in the 'SUMMARY' dictionary.
|
Adds a value to a key in the 'SUMMARY' dictionary.
|
||||||
|
|
||||||
@ -90,6 +101,9 @@ def add_disco_summary_value(
|
|||||||
Args:
|
Args:
|
||||||
key (str): Key to add the value to.
|
key (str): Key to add the value to.
|
||||||
value (any): Value to add to the key.
|
value (any): Value to add to the key.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
None
|
||||||
"""
|
"""
|
||||||
global _SUMMARY
|
global _SUMMARY
|
||||||
|
|
||||||
@ -103,12 +117,15 @@ def add_disco_summary_value(
|
|||||||
#########################################################################################
|
#########################################################################################
|
||||||
def set_disco_info_value(
|
def set_disco_info_value(
|
||||||
value: str = ""
|
value: str = ""
|
||||||
):
|
)-> None:
|
||||||
"""
|
"""
|
||||||
Sets a fixed value to the '_INFO' variable.
|
Sets a fixed value to the '_INFO' variable.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
data (str, optional): The value to set in the '_INFO' variable. Default is an empty string.
|
data (str, optional): The value to set in the '_INFO' variable. Default is an empty string.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
None
|
||||||
"""
|
"""
|
||||||
global _INFO
|
global _INFO
|
||||||
|
|
||||||
@ -119,12 +136,15 @@ def set_disco_info_value(
|
|||||||
#########################################################################################
|
#########################################################################################
|
||||||
def add_disco_info_value(
|
def add_disco_info_value(
|
||||||
value: str = ""
|
value: str = ""
|
||||||
):
|
)-> None:
|
||||||
"""
|
"""
|
||||||
Adds data to the '_INFO' variable.
|
Adds data to the '_INFO' variable.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
data (str, optional): The data to add to the '_INFO' variable. Default is an empty string.
|
data (str, optional): The data to add to the '_INFO' variable. Default is an empty string.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
None
|
||||||
"""
|
"""
|
||||||
global _INFO
|
global _INFO
|
||||||
|
|
||||||
@ -135,12 +155,15 @@ def add_disco_info_value(
|
|||||||
#########################################################################################
|
#########################################################################################
|
||||||
def set_disco_monitoring_data(
|
def set_disco_monitoring_data(
|
||||||
data: list = []
|
data: list = []
|
||||||
):
|
)-> None:
|
||||||
"""
|
"""
|
||||||
Set the monitoring data for disk usage.
|
Set the monitoring data for disk usage.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
data (list): A list containing disk monitoring data.
|
data (list): A list containing disk monitoring data.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
None
|
||||||
"""
|
"""
|
||||||
global _MONITORING_DATA
|
global _MONITORING_DATA
|
||||||
|
|
||||||
@ -151,12 +174,15 @@ def set_disco_monitoring_data(
|
|||||||
#########################################################################################
|
#########################################################################################
|
||||||
def add_disco_monitoring_data(
|
def add_disco_monitoring_data(
|
||||||
data: dict = {}
|
data: dict = {}
|
||||||
):
|
)-> None:
|
||||||
"""
|
"""
|
||||||
Add disk monitoring data to the global monitoring dataset.
|
Add disk monitoring data to the global monitoring dataset.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
data (dict): A dictionary containing disk monitoring data.
|
data (dict): A dictionary containing disk monitoring data.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
None
|
||||||
"""
|
"""
|
||||||
global _MONITORING_DATA
|
global _MONITORING_DATA
|
||||||
|
|
||||||
@ -165,13 +191,16 @@ def add_disco_monitoring_data(
|
|||||||
####
|
####
|
||||||
# Print JSON output and exit script
|
# Print JSON output and exit script
|
||||||
#########################################################################################
|
#########################################################################################
|
||||||
def disco_output():
|
def disco_output()-> None:
|
||||||
"""
|
"""
|
||||||
Prints the JSON output and exits the script.
|
Prints the JSON output and exits the script.
|
||||||
|
|
||||||
The function uses the global variables '_ERROR_LEVEL', '_SUMMARY', '_INFO' and '_MONITORING_DATA'
|
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
|
to create the JSON output. It then prints the JSON string and exits the script with
|
||||||
the '_ERROR_LEVEL' as the exit code.
|
the '_ERROR_LEVEL' as the exit code.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
None
|
||||||
"""
|
"""
|
||||||
from .output import print_stdout
|
from .output import print_stdout
|
||||||
|
|
||||||
|
@ -360,7 +360,7 @@ def set_dict_key_value(
|
|||||||
input_dict: dict = {},
|
input_dict: dict = {},
|
||||||
input_key: str = "",
|
input_key: str = "",
|
||||||
input_value = None
|
input_value = None
|
||||||
):
|
)-> None:
|
||||||
"""
|
"""
|
||||||
Assign a given value to a specified key in a dictionary.
|
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_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_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.
|
input_value (any): The value to be assigned to the specified key.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
None
|
||||||
"""
|
"""
|
||||||
key = input_key.strip()
|
key = input_key.strip()
|
||||||
|
|
||||||
@ -381,9 +384,16 @@ def set_dict_key_value(
|
|||||||
def get_dict_key_value(
|
def get_dict_key_value(
|
||||||
input_dict: dict = {},
|
input_dict: dict = {},
|
||||||
input_key: str = ""
|
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()
|
key = input_key.strip()
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ def _auth_call(
|
|||||||
authtype: str = "basic",
|
authtype: str = "basic",
|
||||||
user: str = "",
|
user: str = "",
|
||||||
passw: str = ""
|
passw: str = ""
|
||||||
):
|
)-> None:
|
||||||
"""
|
"""
|
||||||
Perform authentication for URL requests using various authentication types.
|
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'.
|
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.
|
user (str, optional): The authentication user. Defaults to an empty string.
|
||||||
passw (str, optional): The authentication password. Defaults to an empty string.
|
passw (str, optional): The authentication password. Defaults to an empty string.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
None
|
||||||
"""
|
"""
|
||||||
if session is not None:
|
if session is not None:
|
||||||
if authtype == 'ntlm':
|
if authtype == 'ntlm':
|
||||||
|
@ -25,12 +25,15 @@ def _print_debug(
|
|||||||
|
|
||||||
def print_stdout(
|
def print_stdout(
|
||||||
message: str = ""
|
message: str = ""
|
||||||
):
|
)-> None:
|
||||||
"""
|
"""
|
||||||
Prints message in stdout
|
Prints message in stdout
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
message (str, optional): Message to be printed. Defaults to "".
|
message (str, optional): Message to be printed. Defaults to "".
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
None
|
||||||
"""
|
"""
|
||||||
print(message)
|
print(message)
|
||||||
|
|
||||||
@ -40,12 +43,15 @@ def print_stdout(
|
|||||||
|
|
||||||
def print_stderr(
|
def print_stderr(
|
||||||
message: str = ""
|
message: str = ""
|
||||||
):
|
)-> None:
|
||||||
"""
|
"""
|
||||||
Prints message in stderr
|
Prints message in stderr
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
message (str, optional): Message to be printed. Defaults to "".
|
message (str, optional): Message to be printed. Defaults to "".
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
None
|
||||||
"""
|
"""
|
||||||
print(message, file=sys.stderr)
|
print(message, file=sys.stderr)
|
||||||
|
|
||||||
@ -56,13 +62,16 @@ def print_stderr(
|
|||||||
def print_debug(
|
def print_debug(
|
||||||
var = "",
|
var = "",
|
||||||
print_errors: bool = False
|
print_errors: bool = False
|
||||||
):
|
)-> None:
|
||||||
"""
|
"""
|
||||||
Prints any list, dict, string, float or integer as a json
|
Prints any list, dict, string, float or integer as a json
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
var: Variable to be printed.
|
var: Variable to be printed.
|
||||||
print_errors (bool, optional): Whether to print errors. Defaults to False.
|
print_errors (bool, optional): Whether to print errors. Defaults to False.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
None
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
debug_json = json.dumps(var, indent=4)
|
debug_json = json.dumps(var, indent=4)
|
||||||
|
@ -138,7 +138,7 @@ def run_threads(
|
|||||||
def set_shared_dict_value(
|
def set_shared_dict_value(
|
||||||
key: str = None,
|
key: str = None,
|
||||||
value = None
|
value = None
|
||||||
):
|
)-> None:
|
||||||
"""
|
"""
|
||||||
Set a value for a key in the internal shared dictionary.
|
Set a value for a key in the internal shared dictionary.
|
||||||
This function is used by all parallel processes.
|
This function is used by all parallel processes.
|
||||||
@ -160,7 +160,7 @@ def set_shared_dict_value(
|
|||||||
def add_shared_dict_value(
|
def add_shared_dict_value(
|
||||||
key: str = None,
|
key: str = None,
|
||||||
value = None
|
value = None
|
||||||
):
|
)-> None:
|
||||||
"""
|
"""
|
||||||
Add a value to a key in the internal shared dictionary.
|
Add a value to a key in the internal shared dictionary.
|
||||||
This function is used by all parallel processes.
|
This function is used by all parallel processes.
|
||||||
|
@ -45,13 +45,16 @@ def _print_debug(
|
|||||||
def set_global_variable(
|
def set_global_variable(
|
||||||
variable_name: str = "",
|
variable_name: str = "",
|
||||||
value = None
|
value = None
|
||||||
):
|
)-> None:
|
||||||
"""
|
"""
|
||||||
Sets the value of a global variable in the '_GLOBAL_VARIABLES' dictionary.
|
Sets the value of a global variable in the '_GLOBAL_VARIABLES' dictionary.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
variable_name (str): Name of the variable to set.
|
variable_name (str): Name of the variable to set.
|
||||||
value (any): Value to assign to the variable.
|
value (any): Value to assign to the variable.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
None
|
||||||
"""
|
"""
|
||||||
from .general import set_dict_key_value
|
from .general import set_dict_key_value
|
||||||
|
|
||||||
@ -62,12 +65,15 @@ def set_global_variable(
|
|||||||
#########################################################################################
|
#########################################################################################
|
||||||
def get_global_variable(
|
def get_global_variable(
|
||||||
variable_name: str = ""
|
variable_name: str = ""
|
||||||
):
|
)-> None:
|
||||||
"""
|
"""
|
||||||
Gets the value of a global variable in the '_GLOBAL_VARIABLES' dictionary.
|
Gets the value of a global variable in the '_GLOBAL_VARIABLES' dictionary.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
variable_name (str): Name of the variable to set.
|
variable_name (str): Name of the variable to set.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
None
|
||||||
"""
|
"""
|
||||||
from .general import get_dict_key_value
|
from .general import get_dict_key_value
|
||||||
|
|
||||||
@ -185,7 +191,7 @@ def transfer_xml(
|
|||||||
tentacle_port: int = _GLOBAL_VARIABLES['tentacle_port'],
|
tentacle_port: int = _GLOBAL_VARIABLES['tentacle_port'],
|
||||||
tentacle_extra_opts: str = _GLOBAL_VARIABLES['tentacle_extra_opts'],
|
tentacle_extra_opts: str = _GLOBAL_VARIABLES['tentacle_extra_opts'],
|
||||||
data_dir: str = _GLOBAL_VARIABLES['data_dir']
|
data_dir: str = _GLOBAL_VARIABLES['data_dir']
|
||||||
):
|
)-> None:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Detects the transfer mode and calls the agentplugin() function to perform the transfer.
|
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_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'].
|
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'].
|
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 file is not None:
|
||||||
if transfer_mode != "local":
|
if transfer_mode != "local":
|
||||||
|
Loading…
x
Reference in New Issue
Block a user