# transfer # Global variables Es un diccionario de variables con valores por defecto. Las variables que contiene son las siguientes:
**Nombre**
**Descripción**
**Valor por defecto**
transfer_mode
Modo de transferencia, local o tentacle
tentacle
temporalRuta para ficheros temporales
/tmp
data\_dirDirectorio de datos de Pandora FMS
/var/spool/pandora/data_in/
tentacle\_clientRuta del cliente de tentacle
tentacle
tentacle\_ipIp del servidor tentacle al que mandar los datos
127.0.0.1
tentacle\_portPuerto de tentacle
41121
tentacle_extra_opts
Opciones extras de tentacle
''
Para modificar las variables globales use la función : [set\_global\_variable](https://pandorafms.com/guides/public/books/plugintools/page/set-global-variable-577) **Versión** - 1.0.0 # set_global_variable **Descripción** Establece el valor de una variable global en el diccionario '\_GLOBAL\_VARIABLES'. **Parámetros**
**Nombre****Tipo****Requerido****Descripción**
variable\_namestrSINombre de la variable a establecer
valueNoneSiValor a asignar a la variable
**Return**
**Tipo**
None
**Versión** - 1.0.0 **Ejemplo** ``` import pandoraPlugintools as pt # Define the variable name and value to set variable_name = 'transfer_mode' new_value = 'local' # Set the value of the global variable pt.transfer.set_global_variable(variable_name, new_value) # Print the updated value of the global variable print(f"Updated value of '{variable_name}': {pt.transfer._GLOBAL_VARIABLES[variable_name]}") ``` # get_global_variable **Descripción** Obtiene el valor de una variable global del diccionario '\_GLOBAL\_VARIABLES'. **Parámetros**
**Nombre****Tipo****Requerido****Descripción**
variable\_namestrSiNombre de la variable a establecer
**Return**
**Tipo**
None
**Versión** - 1.0.0 **Ejemplo** ``` import pandoraPlugintools as pt # Define the variable name to retrieve variable_name = 'tentacle_client' # Get the value of the global variable value = pt.transfer.get_global_variable(variable_name) # Print the value of the global variable print(f"The value of '{variable_name}' is: {value}") ``` # tentacle_xml **Descripción** Envía un archivo usando el protocolo tentacle. **Parámetros**
**Nombre**
**Tipo**
**Requerido**
**Descripción**
data_file
str
Si
Archivo a enviar. Se necesita la ruta completa del archivo
tentacle_ops
dict
No
Debe ser un dict con las opciones de tentacle (dirección \[contraseña\] \[puerto\])
tentacle_path
str
NoPermite definir una ruta personalizada para el cliente tentacle en caso de que no esté en sys path)
debugintNoSi está habilitado, el fichero de datos no será eliminado después de ser enviado
print\_errorsboolNoSi se habilita con True, imprimirá todos los mensajes de error
**Return**
boolDevuelve 0 para OK y 1 para errores
**Requisitos** - sys - os - datetime.datetime -
subprocess.Popen
**Versión** - 1.0.0 Ejemplo ``` import pandoraPlugintools as pt # Define the path to the data file to be sent data_file = '/tmp/agent.data' # Define tentacle options as a dictionary tentacle_ops = { 'address': '192.168.1.100', 'port': 41121 } # Send the file using the tentacle protocol success = pt.transfer.tentacle_xml(data_file, tentacle_ops, tentacle_path, debug, print_errors) # Check if the file was sent successfully if success: print("File sent successfully using tentacle protocol.") else: print("Failed to send file using tentacle protocol.") ``` # transfer_xml **Descripción** Detecta el modo de transferencia y llama a la función agentplugin() para realizar la transferencia. **Parámetros**
**Nombre****Tipo****Requerido****Descripción**
filestrSiDiccionario con la configuración del agente
transfer\_modestrSiModo de transferencia. Por defecto es global\_variables\['transfer\_mode'\]
tentacle\_ipstrSiDirección IP para Tentacle. Por defecto es global\_variables\['tentacle\_ip'\]
tentacle\_portintSiPuerto para Tentacle. Por defecto es global\_variables\['tentacle\_port'\]
tentacle\_extra\_optsstrSiOpciones extra para Tentacle. Por defecto es global\_variables\['
tentacle_extra_opts']
data\_dirstrSiRuta de la carpeta data\_dir. Por defecto es global\_variables\['
data_dir']
**Return**
**Tipo**
None
**Versión** - 1.0.0 **Ejemplo** ``` import pandoraPlugintools as pt # Define the path to the file to be transferred file_to_transfer = '/tmp/agent.data' # Define transfer mode (e.g., 'local' or 'tentacle') transfer_mode = 'tentacle' # Define Tentacle IP and port tentacle_ip = '192.168.1.100' tentacle_port = 41121 # Define data directory for local transfer mode data_dir = '/var/spool/pandora/data_in/' # Perform the file transfer based on the selected transfer mode pt.transfer.transfer_xml(file_to_transfer, transfer_mode, tentacle_ip, tentacle_port, tentacle_extra_opts, data_dir) # Print a message indicating the successful transfer print("File transfer completed.") ``` # write_xml **Descripción** Crea un archivo .data de agente en la carpeta data\_dir especificada **Parámetros**
**Nombre**
**Tipo**
**Requerido**
**Descripción**
xml
str
SiCadena XML que se escribirá en el fichero
agent_name
str
Si
Nombre del agente para el xml y nombre del fichero
data_dir
str
Si
Carpeta en la que se creará el fichero
print_errors
bool
No
Si desea imprimir mensajes de error
**Return**
fileFichero del agente
**Requisitos** - datetime.datetime - hashlib - sys **Versión** - 1.0.0 **Ejemplo** ``` import pandoraPlugintools as pt # Define the XML string to be written xml_data = """ RockyLinux HostAlive generic_proc 1 """ # Define the agent name and data directory agent_name = "RockyLinux" data_dir = '/tmp' # Write the XML data to a .data file data_file_path = pt.output.write_xml(xml_data, agent_name, data_dir) # Print the path to the created .data file print("Data file created:", data_file_path) ```