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
|
temporal | Ruta para ficheros temporales |
/tmp
|
data_dir | Directorio de datos de Pandora FMS |
/var/spool/pandora/data_in/
|
tentacle_client | Ruta del cliente de tentacle |
tentacle
|
tentacle_ip | Ip del servidor tentacle al que mandar los datos |
127.0.0.1
|
tentacle_port | Puerto de tentacle |
41121
|
tentacle_extra_opts
|
Opciones extras de tentacle |
''
|
Para modificar las variables globales use la función :
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_name | str | SI | Nombre de la variable a establecer |
value | None | Si | Valor 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_name | str | Si | Nombre 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
|
No | Permite definir una ruta personalizada para el cliente tentacle en caso de que no esté en sys path) |
debug | int | No | Si está habilitado, el fichero de datos no será eliminado después de ser enviado |
print_errors | bool | No | Si se habilita con True, imprimirá todos los mensajes de error |
Return
bool | Devuelve 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 |
file | str | Si | Diccionario con la configuración del agente |
transfer_mode | str | Si | Modo de transferencia. Por defecto es global_variables['transfer_mode'] |
tentacle_ip | str | Si | Dirección IP para Tentacle. Por defecto es global_variables['tentacle_ip'] |
tentacle_port | int | Si | Puerto para Tentacle. Por defecto es global_variables['tentacle_port'] |
tentacle_extra_opts | str | Si | Opciones extra para Tentacle. Por defecto es global_variables['
tentacle_extra_opts']
|
data_dir | str | Si | Ruta 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
|
Si | Cadena 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
file | Fichero 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 = """
<agent>
<name>RockyLinux</name>
<module>
<name>HostAlive</name>
<type>generic_proc</type>
<value>1</value>
</module>
</agent>
"""
# 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)