# PluginTools

# agents



# Global variables

**Descripción**

Las siguientes variables pueden modificarse de modo global.

<table border="1" id="bkmrk-transfer_mode-modo-d" style="height: 87px; width: 607px;"><tbody><tr style="height: 29px;"><td style="width: 108px; height: 29px;">**Nombre**</td><td style="width: 308px; height: 29px;">**Descripción**</td><td style="width: 191px; height: 29px;">**Valor por defecto**</td></tr><tr style="height: 29px;"><td style="width: 108px; height: 29px;"><div><div>agents_group_name</div></div></td><td style="width: 308px; height: 29px;">Grupo de destino de Pandora FMS</td><td style="width: 191px; height: 29px;">''</td></tr><tr style="height: 29px;"><td style="width: 108px; height: 29px;"><div><div>interval</div></div></td><td style="width: 308px;">Intervalo de monitorización del agente</td><td style="width: 191px; height: 29px;">300</td></tr></tbody></table>

Para modificar las variables globales use la función :

[set\_global\_variable](https://pandorafms.com/guides/public/books/plugintools/page/set-global-variable)

**Versión**

- 1.0.0

# class Agent

**Descripción**

Clase básica de agente. Requiere parámetros de agente (config {diccionario}) y definición de módulo (modules\_def \[lista de diccionarios\])

**Ejemplo**

```
import pandoraPlugintools as pt

# Create an instance of the Agent class
agent_instance = pt.agents.Agent()
```

### **Funciones**

##### **update\_config**

<div id="bkmrk-"><div>  
</div></div>**Descripción**

Actualiza los ajustes de configuración con nuevos valores.

**Parámetros**

<div id="bkmrk-nombre-tipo-requerid"><table border="1" id="bkmrk-module-acepta-el-tip" style="height: 58px;"><tbody><tr style="height: 29px;"><td style="width: 97.7344px; height: 29px;">**Nombre**</td><td style="width: 45.4062px; height: 29px;">**Tipo**</td><td style="width: 83.0938px; height: 29px;">**Requerido**</td><td style="width: 334.297px; height: 29px;">**Descripción**</td></tr><tr style="height: 29px;"><td style="width: 97.7344px; height: 29px;">config</td><td style="width: 45.4062px; height: 29px;">dict</td><td style="width: 83.0938px; height: 29px;">Si</td><td style="width: 334.297px; height: 29px;">Un diccionario que contiene las claves de configuración y sus nuevos valores</td></tr></tbody></table>

</div>**Versión**

<div id="bkmrk-1.0.0"><div><div>- 1.0.0

</div></div></div>**Ejemplo**

```
# Update agent configuration
new_config = {
    "agent_name": "UpdatedAgentName",
    "description": "Updated agent description"
}
agent_instance.update_config(new_config)
```

##### **get\_config**

**Descripción**

Recupera los ajustes de configuración actuales.

**Return**

<div id="bkmrk-tipo-descripci%C3%B3n-dic"><div><div><div><table border="1" id="bkmrk-module_xml-m%C3%B3dulo-en" style="width: 558px;"><tbody><tr><td style="width: 56px;">**Tipo**</td><td style="width: 502px;">**Descripción**</td></tr><tr><td style="width: 56px;">dict</td><td style="width: 502px;">Un diccionario que contiene los ajustes de configuración actuales</td></tr></tbody></table>

</div></div></div></div>**Versión**

<div id="bkmrk-1.0.0-0"><div><div><div><div>- 1.0.0

</div></div></div></div></div>**Ejemplo**

```
# Get current agent configuration
current_config = agent_instance.get_config()
print("Current Agent Configuration:", current_config)
```

##### **add\_module**

**Descripción**

Añade un nuevo módulo a la lista de módulos.

**Parámetros**

<div id="bkmrk-nombre-tipo-requerid-0"><div><div><div><div><table border="1" id="bkmrk-nombre-tipo-requerid-6" style="height: 87px;"><tbody><tr style="height: 29px;"><td style="width: 97.7344px; height: 29px;">**Nombre**</td><td style="width: 45.4062px; height: 29px;">**Tipo**</td><td style="width: 83.0938px; height: 29px;">**Requerido**</td><td style="width: 334.297px; height: 29px;">**Descripción**</td></tr><tr style="height: 29px;"><td style="width: 97.7344px; height: 29px;">module</td><td style="width: 45.4062px; height: 29px;">dict</td><td style="width: 83.0938px; height: 29px;">Si</td><td style="width: 334.297px; height: 29px;">Un diccionario que contiene información sobre el módulo</td></tr></tbody></table>

</div></div></div></div></div>**Return**

<table border="1" id="bkmrk-tipo-none" style="border-collapse: collapse; width: 100%;"><tbody><tr><td style="width: 100%;">**Tipo**</td></tr><tr><td style="width: 100%;">None</td></tr></tbody></table>

**Versión**

<div id="bkmrk-1.0.0-1"><div><div><div><div>- 1.0.0

</div></div></div></div></div>**Ejemplo**

```
# Define a module and add it to the agent
module_data = {
    "name": "HostAlive",
    "type": "generic_proc",
    "value": 1
}
agent_instance.add_module(module_data)
```

##### **del\_module**

**Descripción**

Elimina un módulo basándose en su nombre

**Parámetros**

<div id="bkmrk-nombre-tipo-requerid-1"><div><table border="1" id="bkmrk-nombre-tipo-requerid-7" style="height: 87px;"><tbody><tr style="height: 29px;"><td style="width: 97.7344px; height: 29px;">**Nombre**</td><td style="width: 45.4062px; height: 29px;">**Tipo**</td><td style="width: 83.0938px; height: 29px;">**Requerido**</td><td style="width: 334.297px; height: 29px;">**Descripción**</td></tr><tr style="height: 29px;"><td style="width: 97.7344px; height: 29px;">module\_name</td><td style="width: 45.4062px; height: 29px;">str</td><td style="width: 83.0938px; height: 29px;">Si</td><td style="width: 334.297px; height: 29px;">El nombre del módulo a eliminar</td></tr></tbody></table>

</div></div>**Return**

<table border="1" id="bkmrk-tipo-none-0" style="border-collapse: collapse; width: 100%;"><tbody><tr><td style="width: 100%;">**Tipo**</td></tr><tr><td style="width: 100%;">None</td></tr></tbody></table>

<div id="bkmrk--0"><div><div><div><div><div>  
</div></div></div></div></div></div>**Versión**

<div id="bkmrk-1.0.0-2"><div><div><div>- 1.0.0

</div></div></div></div>**Ejemplo**

```
# Delete a module based on its name
module_name_to_delete = "HostAlive"
agent_instance.del_module(module_name_to_delete)
```

**update\_module**

**Descripción**

Actualiza un módulo basándose en su nombre

**Parámetros**

<div id="bkmrk-nombre-tipo-requerid-2"><div><div><div><div><table border="1" id="bkmrk-nombre-tipo-requerid-8" style="height: 87px;"><tbody><tr style="height: 29px;"><td style="width: 97.7344px; height: 29px;">**Nombre**</td><td style="width: 45.4062px; height: 29px;">**Tipo**</td><td style="width: 83.0938px; height: 29px;">**Requerido**</td><td style="width: 334.297px; height: 29px;">**Descripción**</td></tr><tr style="height: 29px;"><td style="width: 97.7344px; height: 29px;">module\_name</td><td style="width: 45.4062px; height: 29px;">str</td><td style="width: 83.0938px; height: 29px;">Si</td><td style="width: 334.297px; height: 29px;">El nombre del módulo a actualizar</td></tr><tr style="height: 29px;"><td style="width: 97.7344px; height: 29px;">module</td><td style="width: 45.4062px; height: 29px;">dict</td><td style="width: 83.0938px; height: 29px;">Si</td><td style="width: 334.297px; height: 29px;">Un diccionario que contiene la información actualizada del módulo</td></tr></tbody></table>

</div></div></div></div></div>**Return**

<table border="1" id="bkmrk-tipo-none-1" style="border-collapse: collapse; width: 100%;"><tbody><tr><td style="width: 100%;">**Tipo**</td></tr><tr><td style="width: 100%;">None</td></tr></tbody></table>

<div id="bkmrk--1"><div><div><div><div><div>  
</div></div></div></div></div></div>**Versión**

<div id="bkmrk-1.0.0-3"><div><div><div><div>- 1.0.0

</div></div></div></div></div>**Ejemplo**

```
# Update a module based on its name
module_name_to_update = "HostAlive"
updated_module_data = {
    "type": "generic_data",
    "value": 1
}
agent_instance.update_module(module_name_to_update, updated_module_data)
```

##### **get\_module**

**Descripción**

Recupera información del módulo en base a su nombre

**Parámetros**

<div id="bkmrk-nombre-tipo-requerid-3"><div><div><div><table border="1" id="bkmrk-nombre-tipo-requerid-9" style="height: 87px;"><tbody><tr style="height: 29px;"><td style="width: 97.7344px; height: 29px;">**Nombre**</td><td style="width: 45.4062px; height: 29px;">**Tipo**</td><td style="width: 83.0938px; height: 29px;">**Requerido**</td><td style="width: 334.297px; height: 29px;">**Descripción**</td></tr><tr style="height: 29px;"><td style="width: 97.7344px; height: 29px;">module\_name</td><td style="width: 45.4062px; height: 29px;">str</td><td style="width: 83.0938px; height: 29px;">SI</td><td style="width: 334.297px; height: 29px;">El nombre del módulo a recuperar</td></tr></tbody></table>

</div></div></div></div>**Return**

<div id="bkmrk-tipo-descripci%C3%B3n-dic-0"><div><div><div><table border="1" id="bkmrk-tipo-descripci%C3%B3n-dic-3" style="width: 558px;"><tbody><tr><td style="width: 56px;">**Tipo**</td><td style="width: 502px;">**Descripción**</td></tr><tr><td style="width: 56px;">dict</td><td style="width: 502px;">Un diccionario que contiene información del módulo si se encuentra, de lo contrario un diccionario vacío</td></tr></tbody></table>

</div><div><div><div>  
</div></div></div></div></div></div>**Versión**

<div id="bkmrk-1.0.0-4"><div><div><div><div>- 1.0.0

</div></div></div></div></div>**Ejemplo**

```
# Get module information by name
module_info = agent_instance.get_module("HostAlive")
print("Module Information:", module_info)
```

##### **get\_modules\_def**

**Descripción**

Recupera las definiciones de todos los módulos añadidos.

**Return**

<div id="bkmrk-tipo-descripci%C3%B3n-dic-1"><div><div><div><table border="1" id="bkmrk-tipo-descripci%C3%B3n-dic-4" style="width: 558px;"><tbody><tr><td style="width: 56px;">**Tipo**</td><td style="width: 502px;">**Descripción**</td></tr><tr><td style="width: 56px;">dict</td><td style="width: 502px;">Un diccionario que contiene las definiciones de todos los módulos añadidos</td></tr></tbody></table>

</div><div><div><div>  
</div></div></div></div></div></div>**Versión**

<div id="bkmrk-1.0.0-5"><div><div><div><div>- 1.0.0

</div></div></div></div></div>**Ejemplo**

```
# Get definitions of all added modules
all_module_defs = agent_instance.get_modules_def()
print("All Module Definitions:", all_module_defs)
```

##### **add\_log\_module**

**Descripción**

Añade un nuevo módulo de registro a la lista de módulos de registro.

**Parámetros**

<div id="bkmrk-nombre-tipo-requerid-4"><div><div><div><table border="1" id="bkmrk-nombre-tipo-requerid-10" style="height: 87px;"><tbody><tr style="height: 29px;"><td style="width: 97.7344px; height: 29px;">**Nombre**</td><td style="width: 45.4062px; height: 29px;">**Tipo**</td><td style="width: 83.0938px; height: 29px;">**Requerido**</td><td style="width: 334.297px; height: 29px;">**Descripción**</td></tr><tr style="height: 29px;"><td style="width: 97.7344px; height: 29px;">log\_module</td><td style="width: 45.4062px; height: 29px;">dict</td><td style="width: 83.0938px; height: 29px;">Si</td><td style="width: 334.297px; height: 29px;">Un diccionario que contiene información sobre el módulo de registro</td></tr></tbody></table>

</div></div></div></div>**Return**

<div id="bkmrk-tipo-none-2"><div><div><div><div><div><table border="1" style="border-collapse: collapse; width: 100%;"><tbody><tr><td style="width: 100%;">**Tipo**</td></tr><tr><td style="width: 100%;">None</td></tr></tbody></table>

</div></div></div></div></div></div>**Versión**

<div id="bkmrk-1.0.0-6"><div><div><div><div>- 1.0.0

</div></div></div></div></div>**Ejemplo**

```
# Define a log module and add it to the agent
log_module_data = {
    "source": "LogSource",
    "type": "log",
    "value": "El host no es accesible"
}
agent_instance.add_log_module(log_module_data)
```

##### **get\_log\_modules\_def**

**Descripción**

<div id="bkmrk-recupera-las-definic-0"><div><div><div>Recupera las definiciones de todos los módulos de registro añadidos</div><div>  
</div></div></div></div>**Return**

<div id="bkmrk-tipo-descripci%C3%B3n-dic-2"><div><table border="1" id="bkmrk-tipo-descripci%C3%B3n-dic-5" style="width: 558px;"><tbody><tr><td style="width: 56px;">**Tipo**</td><td style="width: 502px;">**Descripción**</td></tr><tr><td style="width: 56px;">dict</td><td style="width: 502px;"> Un diccionario que contiene las definiciones de todos los módulos de registro añadidos</td></tr></tbody></table>

</div></div>**Versión**

<div id="bkmrk-1.0.0-7"><div><div><div><div>- 1.0.0

</div></div></div></div></div>**Ejemplo**

```
# Get definitions of all added log modules
all_log_module_defs = agent_instance.get_log_modules_def()
print("All Log Module Definitions:", all_log_module_defs)
```

##### **print\_xml**

**Descripción**

Genera y opcionalmente imprime la representación XML del agente.

**Parámetros**

<div id="bkmrk-nombre-tipo-requerid-5"><div><div><div><table border="1" id="bkmrk-nombre-tipo-requerid-11" style="height: 87px;"><tbody><tr style="height: 29px;"><td style="width: 97.7344px; height: 29px;">**Nombre**</td><td style="width: 45.4062px; height: 29px;">**Tipo**</td><td style="width: 83.0938px; height: 29px;">**Requerido**</td><td style="width: 334.297px; height: 29px;">**Descripción**</td></tr><tr style="height: 29px;"><td style="width: 97.7344px; height: 29px;">print\_flag</td><td style="width: 45.4062px; height: 29px;">bool</td><td style="width: 83.0938px; height: 29px;">SI</td><td style="width: 334.297px; height: 29px;">Una bandera que indica si imprimir la representación XML</td></tr></tbody></table>

</div></div></div></div>**Return**

<div id="bkmrk-tipo-descripci%C3%B3n-str"><div><div><div><table border="1" id="bkmrk-tipo-descripci%C3%B3n-str-0" style="width: 558px;"><tbody><tr><td style="width: 56px;">**Tipo**</td><td style="width: 502px;">**Descripción**</td></tr><tr><td style="width: 56px;">str</td><td style="width: 502px;">La representación XML del agente</td></tr></tbody></table>

</div></div></div></div>**Versión**

<div id="bkmrk-1.0.0-8"><div><div><div><div>- 1.0.0

</div></div></div></div></div>**Ejemplo**

```
# Generate and optionally print the XML representation of the agent
xml_representation = agent_instance.print_xml(print_flag=True)
print("Agent XML Representation:\n", xml_representation)
```

# set_global_variable

**Descripción**

Establece el valor de una variable global en el diccionario 'global\_variables'.

**Parámetros**

<table border="1" id="bkmrk-module-acepta-el-tip" style="border-collapse: collapse; width: 100%;"><tbody><tr><td style="width: 6.86728%;">**Nombre** </td><td style="width: 5.63272%;">**Tipo**</td><td style="width: 12.5%;">**Requerido**</td><td style="width: 50%;">**Descripción**</td></tr><tr><td style="width: 6.86728%;">variable\_name</td><td style="width: 5.63272%;">str</td><td style="width: 12.5%;">Si</td><td style="width: 50%;">Nombre de la variable a establecer</td></tr><tr><td style="width: 6.86728%;">value</td><td style="width: 5.63272%;">None</td><td style="width: 12.5%;">Si</td><td style="width: 50%;">Valor a asignar a la variable</td></tr></tbody></table>

**Return**

<table border="1" id="bkmrk-tipo-none" style="border-collapse: collapse; width: 100%;"><tbody><tr><td style="width: 100%;">**Tipo**</td></tr><tr><td style="width: 100%;">None</td></tr></tbody></table>

**Versión**

- 1.0.0

**Ejemplo**

```
import pandoraPlugintools as pt

variable_name = "agents_group_name"
value = "Servers"

pt.agents.set_global_variable(variable_name, value)

print(pt.agents._GLOBAL_VARIABLES)
```

# get_global_variable

**Descripción**

Establece el valor de una variable global en el diccionario 'global\_variables'.

**Parámetros**

<table border="1" id="bkmrk-module-acepta-el-tip" style="border-collapse: collapse; width: 100%;"><tbody><tr><td style="width: 6.86728%;">**Nombre** </td><td style="width: 5.63272%;">**Tipo**</td><td style="width: 12.5%;">**Requerido**</td><td style="width: 50%;">**Descripción**</td></tr><tr><td style="width: 6.86728%;">variable\_name</td><td style="width: 5.63272%;">str</td><td style="width: 12.5%;">Si</td><td style="width: 50%;">Nombre de la variable a establecer</td></tr></tbody></table>

**Return**

<table border="1" id="bkmrk-tipo-none" style="border-collapse: collapse; width: 100%;"><tbody><tr><td style="width: 100%;">**Tipo**</td></tr><tr><td style="width: 100%;">None</td></tr></tbody></table>

**Versión**

- 1.0.0

**Ejemplo**

```
import pandoraPlugintools as pt

variable_name = "agents_group_name"
value = pt.agents.get_global_variable(variable_name)
print(f"{variable_name}: {value}")
```

# get_os

**Descripción**

Detecta el sistema operativo del sistema.

**Return**

<table border="1" id="bkmrk-str-sistema-operativ" style="border-collapse: collapse; width: 100%;"><tbody><tr><td style="width: 50%;">**Tipo**</td><td style="width: 50%;">**Descripción**</td></tr><tr><td style="width: 50%;">str</td><td style="width: 50%;">Sistema operativo del sistema</td></tr></tbody></table>

**Requisitos**

- os

**Versión**

- 1.0.0

**Ejemplo**

```
import pandoraPlugintools as pt

os_name = pt.agents.get_os()
print("Operating System:", os_name)
```

# init_agent

**Descripción**

Inicializa una plantilla de agente con valores por defecto.

**Return**

<table border="1" id="bkmrk-module_xml-m%C3%B3dulo-en" style="border-collapse: collapse; width: 100%;"><tbody><tr><td style="width: 25%;">**Nombre**</td><td style="width: 12.5%;">**Tipo**</td><td style="width: 12.5%;">**Requerido**</td><td style="width: 50%;">**Descripción**</td></tr><tr><td style="width: 25%;">dict</td><td style="width: 12.5%;">dict</td><td style="width: 12.5%;">No</td><td style="width: 50%;">Diccionario que representa la plantilla de agente con valores por defecto</td></tr></tbody></table>

**Requisitos**

- datetime.datetime

**Versión**

- 1.0.0

**Ejemplo**

```
import pandoraPlugintools as pt

# Example: Initializing an agent template with default values and custom values
custom_defaults = {
    "agent_name": "RockyLinux",
    "description": "Linux system",
    "address": "192.168.1.100"
}

agent_template = pt.agents.init_agent(default_values=custom_defaults)
print("Agent Template:", agent_template)
```

# print_agent

**Descripción**

Imprime el XML del agente.

**Parámetros**

<table border="1" id="bkmrk-module-acepta-el-tip" style="border-collapse: collapse; width: 100%; height: 145px;"><tbody><tr style="height: 29px;"><td style="width: 12.5%; height: 29px;">**Nombre**</td><td style="width: 6.25%; height: 29px;">**Tipo**</td><td style="width: 9.0895%; height: 29px;">**Requerido**</td><td style="width: 47.1605%; height: 29px;">**Descripción**</td></tr><tr style="height: 29px;"><td style="width: 12.5%; height: 29px;">agent</td><td style="width: 6.25%; height: 29px;">dict</td><td style="width: 9.0895%; height: 29px;">Si</td><td style="width: 47.1605%; height: 29px;">Diccionario con la configuración del agente</td></tr><tr style="height: 29px;"><td style="width: 12.5%; height: 29px;">modules</td><td style="width: 6.25%; height: 29px;">list</td><td style="width: 9.0895%; height: 29px;">Si</td><td style="width: 47.1605%; height: 29px;">Lista de módulos</td></tr><tr style="height: 29px;"><td style="width: 12.5%; height: 29px;">log\_modules</td><td style="width: 6.25%; height: 29px;">list</td><td style="width: 9.0895%; height: 29px;">No</td><td style="width: 47.1605%; height: 29px;">Sirve para añadir módulos de log. Por defecto None</td></tr><tr><td style="width: 12.5%;"><div><div>log_encoding</div></div></td><td style="width: 6.25%;"><div><div>str</div></div></td><td style="width: 9.0895%;"><div><div>No</div></div></td><td style="width: 47.1605%;">Sirve para añadir encoding a los modulos de log</td></tr><tr style="height: 29px;"><td style="width: 12.5%; height: 29px;"><div><div>print_flag</div></div></td><td style="width: 6.25%; height: 29px;"><div><div>bool</div></div></td><td style="width: 9.0895%; height: 29px;"><div><div>No</div></div></td><td style="width: 47.1605%; height: 29px;">Sirve para mostrar el XML de los módulos en STDOUT. Por defecto None</td></tr></tbody></table>

**Return**

<table border="1" id="bkmrk-module_xml-m%C3%B3dulo-en" style="border-collapse: collapse; width: 100%;"><tbody><tr><td style="width: 50%;">**Tipo**</td><td style="width: 50%;">**Descripción**</td></tr><tr><td style="width: 50%;">str</td><td style="width: 50%;">Devuelve una cadena en formato XML</td></tr></tbody></table>

**Requisitos**

- modules.print\_module
- modules.print\_log\_module

**Versión**

- 1.0.0

**Ejemplo**

```
import pandoraPlugintools as pt

# Example: Creating agent and module data
agent_data = {
    "agent_name": "Debian10",
    "description": "Linux system",
    "address": "192.168.1.100"
}

module_data = {
    "name": "Ping",
    "type": "generic_proc",
    "value": 1,
    "desc": "Check host alive",
}


agent_xml_representation = pt.agents.print_agent(
    agent=agent_data,
    modules=[module_data],
    print_flag=True
)

print("Agent XML Representation:\n", agent_xml_representation)
```

# modules



# init_module

**Descripción**

Inicializa una plantilla de módulo con valores por defecto.

**Parámetros**

<table border="1" id="bkmrk-module-acepta-el-tip" style="width: 642px; height: 58px;"><tbody><tr style="height: 29px;"><td style="width: 117px; height: 29px;">**Nombre**</td><td style="width: 53px; height: 29px;"><div><div>**Tipo**</div></div></td><td style="width: 93px; height: 29px;"><div><div>**Requerido**</div></div></td><td style="width: 379px; height: 29px;">**Descripción**</td></tr><tr style="height: 29px;"><td style="width: 117px; height: 29px;"><div><div>default_values</div></div></td><td style="width: 53px; height: 29px;"><div><div>dict</div></div></td><td style="width: 93px; height: 29px;"><div><div>Si</div></div></td><td style="width: 379px; height: 29px;">Módulo en formato dict</td></tr></tbody></table>

**Return**

<table border="1" id="bkmrk-module_xml-m%C3%B3dulo-en" style="width: 641px;"><tbody><tr><td style="width: 75px;">**Tipo**</td><td style="width: 566px;">**Descripción**</td></tr><tr><td style="width: 75px;">dict</td><td style="width: 566px;">Módulo en formato XML</td></tr></tbody></table>

**Versión**

- 1.0.0

**Ejemplo**

```
import pandoraPlugintools as pt

# Define default values to override the template values
default_module_values = {
    "name": "HostAlive",
    "type": "generic_proc",
    "value": 1,
}

# Initialize a module template with default values
module_template = pt.modules.init_module(default_module_values)

# Print the initialized module template
print("Initialized Module Template:", module_template)
```

# print_module

**Descripción**

Devuelve el módulo en formato XML.

**Parámetros**

<table border="1" id="bkmrk-module-acepta-el-tip" style="width: 642px;"><tbody><tr><td style="width: 78px;">**Nombre**</td><td style="width: 57px;"><div><div>**Tipo**</div></div></td><td style="width: 105px;"><div><div>**Requerido**</div></div></td><td style="width: 402px;">**Descripción**</td></tr><tr><td style="width: 78px;"><div><div>module</div></div></td><td style="width: 57px;"><div><div>dict</div></div></td><td style="width: 105px;"><div><div>Si</div></div></td><td style="width: 402px;">Módulo en formato dict</td></tr><tr><td style="width: 78px;"><div><div>print_flag</div></div></td><td style="width: 57px;"><div><div>bool</div></div></td><td style="width: 105px;"><div><div>No</div></div></td><td style="width: 402px;">Con True muestra el XML del módulo en STDOUT</td></tr></tbody></table>

**Return**

<table border="1" id="bkmrk-module_xml-m%C3%B3dulo-en" style="width: 529px;"><tbody><tr><td style="width: 75px;">**Tipo**</td><td style="width: 454px;">**Descripción**</td></tr><tr><td style="width: 75px;">str</td><td style="width: 454px;">Módulo en formato XML</td></tr></tbody></table>

**Versión**

- 1.0.0

**Ejemplo**

```
import pandoraPlugintools as pt

# Define module data
module_data = {
    "name": "HostAlive",
    "type": "generic_proc",
    "value": 1,
    "desc": "Check if the host is alive",
}

# Print module data in XML format without printing to STDOUT
module_xml = pt.modules.print_module(module_data, print_flag=False)
print("Module XML:\n", module_xml)
```

# init_log_module

**Descripción**

Inicializa una plantilla de módulo de logs con valores por defecto.

**Parámetros**

<table border="1" id="bkmrk-module-acepta-el-tip" style="width: 642px; height: 58px;"><tbody><tr style="height: 29px;"><td style="width: 117px; height: 29px;">**Nombre**</td><td style="width: 53px; height: 29px;"><div><div>**Tipo**</div></div></td><td style="width: 93px; height: 29px;"><div><div>**Requerido**</div></div></td><td style="width: 379px; height: 29px;">**Descripción**</td></tr><tr style="height: 29px;"><td style="width: 117px; height: 29px;"><div><div>default_values</div></div></td><td style="width: 53px; height: 29px;"><div><div>dict</div></div></td><td style="width: 93px; height: 29px;"><div><div>Si</div></div></td><td style="width: 379px; height: 29px;">Módulo en formato dict</td></tr></tbody></table>

**Return**

<table border="1" id="bkmrk-module_xml-m%C3%B3dulo-en" style="width: 641px;"><tbody><tr><td style="width: 75px;">**Tipo**</td><td style="width: 566px;">**Descripción**</td></tr><tr><td style="width: 75px;">dict</td><td style="width: 566px;">Módulo de logs en formato XML</td></tr></tbody></table>

**Versión**

- 1.0.0

**Ejemplo**

```
import pandoraPlugintools as pt

# Define default values for the log module template
default_log_module_values = {
    "source": "System",
    "value": "The host is not accessible",
}

# Initialize a log module template with default values
log_module_template = pt.modules.init_log_module(default_log_module_values)

# Print the initialized log module template
print("Initialized Log Module Template:", log_module_template)
```

# print_log_module

**Descripción**

Devuelve el módulo de logs en formato XML.

**Parámetros**

<table border="1" id="bkmrk-module-acepta-el-tip" style="height: 58px; width: 532px;"><tbody><tr><td style="width: 94px;">**nombre**</td><td style="width: 94px;"><div><div>**tipo**</div></div></td><td style="width: 344px;">**descripción**</td></tr><tr style="height: 29px;"><td style="height: 29px; width: 94px;"><div><div>module</div></div></td><td style="width: 94px;"><div><div>dict</div></div></td><td style="height: 29px; width: 344px;">Módulo en formato dict</td></tr><tr><td style="width: 94px;"><div><div>encoding</div></div></td><td style="width: 94px;"><div><div>str</div></div></td><td style="width: 344px;">Formato de encoding</td></tr><tr style="height: 29px;"><td style="height: 29px; width: 94px;"><div><div>print_flag</div></div></td><td style="width: 94px;"><div><div>bool</div></div></td><td style="height: 29px; width: 344px;">Si se utiliza muestra el XML de los módulos en STDOUT</td></tr></tbody></table>

**Return**

<table border="1" id="bkmrk-module_xml-m%C3%B3dulo-en" style="width: 430px;"><tbody><tr><td style="width: 88px;">**tipo**</td><td style="width: 342px;">**descripción**</td></tr><tr><td style="width: 88px;">str</td><td style="width: 342px;">Módulo en formato XML</td></tr></tbody></table>

**Versión**

- 1.0.0

**Ejemplo**

```
import pandoraPlugintools as pt

# Define log module data
log_module_data = {
    "source": "System",
    "value": "The host is not accessible",
}

# Print the log module in XML format
log_module_xml = pt.modules.print_log_module(log_module_data,encoding="base64", print_flag=True)

# Print the generated log module XML
print("Log Module XML:\n", log_module_xml)
```

# transfer



# Global variables

Es un diccionario de variables con valores por defecto. Las variables que contiene son las siguientes:

<table border="1" id="bkmrk-transfer_mode-modo-d" style="border-collapse: collapse; width: 100%;"><tbody><tr><td style="width: 33.3333%;"><div><div>**Nombre**</div></div></td><td style="width: 33.3333%;">**Descripción**</td><td style="width: 33.3333%;"><div><div>**Valor por defecto**</div></div></td></tr><tr><td style="width: 33.3333%;"><div><div>transfer_mode</div></div></td><td style="width: 33.3333%;">Modo de transferencia, local o tentacle</td><td style="width: 33.3333%;"><div><div>tentacle</div></div></td></tr><tr><td style="width: 33.3333%;">temporal</td><td style="width: 33.3333%;">Ruta para ficheros temporales</td><td style="width: 33.3333%;"><div><div>/tmp</div></div></td></tr><tr><td style="width: 33.3333%;">data\_dir</td><td style="width: 33.3333%;">Directorio de datos de Pandora FMS</td><td style="width: 33.3333%;"><div><div>/var/spool/pandora/data_in/</div></div></td></tr><tr><td style="width: 33.3333%;">tentacle\_client</td><td style="width: 33.3333%;">Ruta del cliente de tentacle</td><td style="width: 33.3333%;"><div><div>tentacle</div></div></td></tr><tr><td style="width: 33.3333%;">tentacle\_ip</td><td style="width: 33.3333%;">Ip del servidor tentacle al que mandar los datos</td><td style="width: 33.3333%;"><div><div>127.0.0.1</div></div></td></tr><tr><td style="width: 33.3333%;">tentacle\_port</td><td style="width: 33.3333%;">Puerto de tentacle</td><td style="width: 33.3333%;"><div><div>41121</div></div></td></tr><tr><td style="width: 33.3333%;"><div><div>tentacle_extra_opts</div></div></td><td style="width: 33.3333%;">Opciones extras de tentacle</td><td style="width: 33.3333%;"><div><div>''</div></div></td></tr></tbody></table>

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

<table border="1" id="bkmrk-module-acepta-el-tip" style="border-collapse: collapse; width: 100%; height: 104px;"><tbody><tr style="height: 46px;"><td style="width: 12.5%; height: 46px;">**Nombre**</td><td style="width: 6.25%; height: 46px;">**Tipo**</td><td style="width: 6.25%; height: 46px;">**Requerido**</td><td style="width: 50%; height: 46px;">**Descripción**</td></tr><tr style="height: 29px;"><td style="width: 12.5%; height: 29px;">variable\_name</td><td style="width: 6.25%; height: 29px;">str</td><td style="width: 6.25%; height: 29px;">SI</td><td style="width: 50%; height: 29px;">Nombre de la variable a establecer</td></tr><tr style="height: 29px;"><td style="width: 12.5%; height: 29px;">value</td><td style="width: 6.25%; height: 29px;">None</td><td style="width: 6.25%; height: 29px;">Si</td><td style="width: 50%; height: 29px;">Valor a asignar a la variable</td></tr></tbody></table>

**Return**

<table border="1" id="bkmrk-tipo-none" style="border-collapse: collapse; width: 100%;"><tbody><tr><td style="width: 100%;">**Tipo**</td></tr><tr><td style="width: 100%;">None</td></tr></tbody></table>

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

<table border="1" id="bkmrk-module-acepta-el-tip" style="border-collapse: collapse; width: 100%;"><tbody><tr><td style="width: 12.5%;">**Nombre**</td><td style="width: 6.25%;">**Tipo**</td><td style="width: 6.25%;">**Requerido**</td><td style="width: 50%;">**Descripción**</td></tr><tr><td style="width: 12.5%;">variable\_name</td><td style="width: 6.25%;">str</td><td style="width: 6.25%;">Si</td><td style="width: 50%;">Nombre de la variable a establecer</td></tr></tbody></table>

**Return**

<table border="1" id="bkmrk-tipo-none" style="border-collapse: collapse; width: 100%;"><tbody><tr><td style="width: 100%;">**Tipo**</td></tr><tr><td style="width: 100%;">None</td></tr></tbody></table>

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

<table border="1" id="bkmrk-module-acepta-el-tip" style="border-collapse: collapse; width: 100%; height: 169px;"><tbody><tr style="height: 29px;"><td style="width: 12.5%; height: 29px;"><div><div>**Nombre**</div></div></td><td style="width: 6.25%; height: 29px;"><div><div>**Tipo**</div></div></td><td style="width: 8.47222%;"><div><div>**Requerido**</div></div></td><td style="width: 47.7778%; height: 29px;">**Descripción**</td></tr><tr style="height: 24px;"><td style="width: 12.5%; height: 24px;"><div><div>data_file</div></div></td><td style="width: 6.25%; height: 24px;"><div><div>str</div></div></td><td style="width: 8.47222%;"><div><div>Si</div></div></td><td style="width: 47.7778%; height: 24px;">Archivo a enviar. Se necesita la ruta completa del archivo</td></tr><tr style="height: 29px;"><td style="width: 12.5%; height: 29px;"><div><div>tentacle_ops</div></div></td><td style="width: 6.25%; height: 29px;"><div><div>dict</div></div></td><td style="width: 8.47222%;"><div><div>No</div></div></td><td style="width: 47.7778%; height: 29px;">Debe ser un dict con las opciones de tentacle (dirección \[contraseña\] \[puerto\])</td></tr><tr style="height: 29px;"><td style="width: 12.5%; height: 29px;"><div><div>tentacle_path</div></div></td><td style="width: 6.25%; height: 29px;"><div><div>str</div></div></td><td style="width: 8.47222%;">No</td><td style="width: 47.7778%; height: 29px;">Permite definir una ruta personalizada para el cliente tentacle en caso de que no esté en sys path)</td></tr><tr style="height: 29px;"><td style="width: 12.5%; height: 29px;">debug</td><td style="width: 6.25%; height: 29px;">int</td><td style="width: 8.47222%;">No</td><td style="width: 47.7778%; height: 29px;">Si está habilitado, el fichero de datos no será eliminado después de ser enviado</td></tr><tr style="height: 29px;"><td style="width: 12.5%; height: 29px;">print\_errors</td><td style="width: 6.25%; height: 29px;">bool</td><td style="width: 8.47222%;">No</td><td style="width: 47.7778%; height: 29px;">Si se habilita con True, imprimirá todos los mensajes de error</td></tr></tbody></table>

**Return**

<table border="1" id="bkmrk-module_xml-m%C3%B3dulo-en" style="border-collapse: collapse; width: 100%;"><tbody><tr><td style="width: 50%;">bool</td><td style="width: 50%;">Devuelve 0 para OK y 1 para errores</td></tr></tbody></table>

**Requisitos**

- sys
- os
- datetime.datetime
- <div><div>subprocess.Popen</div></div><div>  
    </div><div>  
    </div>

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

<table border="1" id="bkmrk-module-acepta-el-tip" style="border-collapse: collapse; width: 100%; height: 174px;"><tbody><tr><td style="width: 13.3642%;">**Nombre**</td><td style="width: 6.86729%;">**Tipo**</td><td style="width: 6.86729%;">**Requerido**</td><td style="width: 47.9012%;">**Descripción**</td></tr><tr style="height: 29px;"><td style="width: 13.3642%; height: 29px;">file</td><td style="width: 6.86729%;">str</td><td style="width: 6.86729%;">Si</td><td style="width: 47.9012%; height: 29px;">Diccionario con la configuración del agente</td></tr><tr style="height: 29px;"><td style="width: 13.3642%; height: 29px;">transfer\_mode</td><td style="width: 6.86729%;">str</td><td style="width: 6.86729%;">Si</td><td style="width: 47.9012%; height: 29px;">Modo de transferencia. Por defecto es global\_variables\['transfer\_mode'\]</td></tr><tr style="height: 29px;"><td style="width: 13.3642%; height: 29px;">tentacle\_ip</td><td style="width: 6.86729%;">str</td><td style="width: 6.86729%;">Si</td><td style="width: 47.9012%; height: 29px;">Dirección IP para Tentacle. Por defecto es global\_variables\['tentacle\_ip'\]</td></tr><tr style="height: 29px;"><td style="width: 13.3642%; height: 29px;">tentacle\_port</td><td style="width: 6.86729%;">int</td><td style="width: 6.86729%;">Si</td><td style="width: 47.9012%; height: 29px;">Puerto para Tentacle. Por defecto es global\_variables\['tentacle\_port'\]</td></tr><tr style="height: 29px;"><td style="width: 13.3642%; height: 29px;">tentacle\_extra\_opts</td><td style="width: 6.86729%;">str</td><td style="width: 6.86729%;">Si</td><td style="width: 47.9012%; height: 29px;">Opciones extra para Tentacle. Por defecto es global\_variables\[' <div><div>tentacle_extra_opts']</div></div></td></tr><tr><td style="width: 13.3642%;">data\_dir</td><td style="width: 6.86729%;">str</td><td style="width: 6.86729%;">Si</td><td style="width: 47.9012%;">Ruta de la carpeta data\_dir. Por defecto es global\_variables\[' <div><div>data_dir']</div></div></td></tr></tbody></table>

**Return**

<table border="1" id="bkmrk-tipo-none" style="border-collapse: collapse; width: 100%;"><tbody><tr><td style="width: 100%;">**Tipo**</td></tr><tr><td style="width: 100%;">None</td></tr></tbody></table>

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

<table border="1" id="bkmrk-module-acepta-el-tip" style="border-collapse: collapse; width: 100%; height: 145px;"><tbody><tr style="height: 29px;"><td style="width: 12.5%; height: 29px;"><div><div>**Nombre**</div></div></td><td style="width: 6.25%; height: 29px;"><div><div>**Tipo**</div></div></td><td style="width: 7.85494%; height: 29px;"><div><div>**Requerido**</div></div></td><td style="width: 48.3951%; height: 29px;">**Descripción**</td></tr><tr style="height: 29px;"><td style="width: 12.5%; height: 29px;"><div><div>xml</div></div></td><td style="width: 6.25%; height: 29px;"><div><div>str</div></div></td><td style="width: 7.85494%; height: 29px;">Si</td><td style="width: 48.3951%; height: 29px;">Cadena XML que se escribirá en el fichero</td></tr><tr style="height: 29px;"><td style="width: 12.5%; height: 29px;"><div><div>agent_name</div></div></td><td style="width: 6.25%; height: 29px;"><div><div>str</div></div></td><td style="width: 7.85494%; height: 29px;"><div><div>Si</div></div></td><td style="width: 48.3951%; height: 29px;">Nombre del agente para el xml y nombre del fichero</td></tr><tr style="height: 29px;"><td style="width: 12.5%; height: 29px;"><div><div>data_dir</div></div></td><td style="width: 6.25%; height: 29px;"><div><div>str</div></div></td><td style="width: 7.85494%; height: 29px;"><div><div>Si</div></div></td><td style="width: 48.3951%; height: 29px;">Carpeta en la que se creará el fichero</td></tr><tr style="height: 29px;"><td style="width: 12.5%; height: 29px;"><div><div>print_errors</div></div></td><td style="width: 6.25%; height: 29px;"><div><div>bool</div></div></td><td style="width: 7.85494%; height: 29px;"><div><div>No</div></div></td><td style="width: 48.3951%; height: 29px;">Si desea imprimir mensajes de error</td></tr></tbody></table>

**Return**

<table border="1" id="bkmrk-module_xml-m%C3%B3dulo-en" style="border-collapse: collapse; width: 100%;"><tbody><tr><td style="width: 50%;">file</td><td style="width: 50%;">Fichero del agente</td></tr></tbody></table>

**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)
```

# general



# _print_debug

**Descripción**

Imprime cualquier lista, dict, string, float o integer como un json

**Parámetros**

<table border="1" id="bkmrk-module-acepta-el-tip"><tbody><tr><td>**Nombre** </td><td>**Tipo**</td><td>**Requerido**</td><td>**Descripción**</td></tr><tr><td><div><div>var</div></div></td><td>str</td><td>Si</td><td>Elemento que será imprimido</td></tr><tr><td><div><div>print_errors</div></div></td><td>bool</td><td>No</td><td>Chequeo para pintar errores.</td></tr></tbody></table>

**Versión**

- 1.0.0

**Ejemplo**

```
import pandoraPlugintools as pt

device_name = "Router"
device_status = "Active"
device_data = {
    "cpu_usage": 80,
    "memory_usage": 60
}

information = {
    "name": device_name,
    "status": device_status,
    "data": device_data
}

pt.agents._print_debug(information, print_errors=True)
```

2

# safe_input

**Descripción**

Convierte una cadena de entrada codificada en entidades HTML en una cadena de caracteres claros.

**Parámetros**

<table border="1" id="bkmrk-module-acepta-el-tip"><tbody><tr><td>**Nombre** </td><td>**Tipo**</td><td>**Requerido**</td><td>**Descripción**</td></tr><tr><td><div><div>input_string</div></div></td><td>str</td><td>Si</td><td>La cadena de entrada codificada en entidades HTML</td></tr></tbody></table>

**Return**

<table border="1" id="bkmrk-str-la-cadena-de-car" style="border-collapse: collapse; width: 100%;"><tbody><tr><td style="width: 50%;">str</td><td style="width: 50%;">La cadena de caracteres claros descodificada</td></tr></tbody></table>

**Versión**

- 1.0.0

**Ejemplo**

```
import pandoraPlugintools as pt

# Define an input string with HTML entities
input_string = "&lt;p&gt;Hello, &lt;b&gt;world&lt;/b&gt;!&lt;/p&gt;"

# Use the safe_input function to decode the HTML entities
decoded_string = pt.general.safe_input(input_string)

# Print the decoded string
print("Decoded string:", decoded_string)
```

# safe_output

**Descripción**

Convierte las entidades HTML a sus caracteres correspondientes en la cadena de entrada.

**Parámetros**

<table border="1" id="bkmrk-module-acepta-el-tip" style="height: 58px; width: 532px;"><tbody><tr style="height: 29px;"><td style="height: 29px; width: 102px;">**Nombre** </td><td style="height: 29px; width: 49px;">**Tipo**</td><td style="height: 29px; width: 92px;">**Requerido**</td><td style="height: 29px; width: 289px;">**Descripción**</td></tr><tr style="height: 29px;"><td style="height: 29px; width: 102px;">input\_string</td><td style="height: 29px; width: 49px;">str</td><td style="height: 29px; width: 92px;">Si</td><td style="height: 29px; width: 289px;">La cadena de caracteres claros descodificada</td></tr></tbody></table>

**Return**

<table border="1" id="bkmrk-tipo-none" style="border-collapse: collapse; width: 100%;"><tbody><tr><td style="width: 100%;">**Tipo**</td></tr><tr><td style="width: 100%;">None</td></tr></tbody></table>

**Versión**

- 1.0.0

**Ejemplo**

```
import pandoraPlugintools as pt

# Define an input string with HTML entities
input_string = "&lt;p&gt;Hello, &lt;b&gt;world&lt;/b&gt;!&lt;/p&gt;"

# Use the safe_output function to convert HTML entities back to characters
decoded_string = pt.general.safe_output(input_string)

# Print the decoded string
print("Decoded string:", decoded_string)
```

# set_dict_key_value

**Descripción**

Asignar a una clave de un dict un valor determinado

**Parámetros**

<table border="1" id="bkmrk-module-acepta-el-tip" style="border-collapse: collapse; width: 100%; height: 58px;"><tbody><tr style="height: 29px;"><td style="width: 12.5%; height: 29px;">**Nombre**</td><td style="width: 6.25%; height: 29px;">**Tipo**</td><td style="width: 7.9784%; height: 29px;">**Requerido**</td><td style="width: 48.2716%; height: 29px;">**Descripción**</td></tr><tr style="height: 29px;"><td style="width: 12.5%; height: 29px;">input\_dict</td><td style="width: 6.25%; height: 29px;">dict</td><td style="width: 7.9784%; height: 29px;">Si</td><td style="width: 48.2716%; height: 29px;">Diccionario </td></tr><tr><td style="width: 12.5%;">input\_key</td><td style="width: 6.25%;">str</td><td style="width: 7.9784%;">Si</td><td style="width: 48.2716%;">Clave del diccionario</td></tr><tr><td style="width: 12.5%;">input\_value</td><td style="width: 6.25%;">None</td><td style="width: 7.9784%;">Si</td><td style="width: 48.2716%;">Valor del diccionario</td></tr></tbody></table>

**Return**

<table border="1" id="bkmrk-tipo-none" style="border-collapse: collapse; width: 100%;"><tbody><tr><td style="width: 100%;">**Tipo**</td></tr><tr><td style="width: 100%;">None</td></tr></tbody></table>

**Versión**

- 1.0.0

**Ejemplo**

```
import pandoraPlugintools as pt

# Define the dictionary of monitored devices
devices = {
    'device1': {
        'status': 'online',
        'temperature': 25.0,
        'humidity': 60.0
    },
    'device2': {
        'status': 'offline',
        'temperature': 0.0,
        'humidity': 0.0
    }
}

# Update the status of a device
pt.general.set_dict_key_value(devices['device1'], 'status', 'offline')

# Update the temperature of another device
pt.general.set_dict_key_value(devices['device2'], 'temperature', 22.5)

# Display the updated dictionary
print("Monitored devices dictionary:", devices)
```

# get_dict_key_value

**Descripción**

Devuelve el valor de una clave en un dict dado.

**Versión**

- 1.0.0

**Ejemplo**

```
import pandoraPlugintools as pt

# Sample device monitoring data
device_data = {
    'device_id': '12345',
    'temperature': 28.5,
    'status': 'online'
}

# Get the temperature reading from the device data
temperature = pt.general.get_dict_key_value(device_data, 'temperature')
if temperature is not None:
    print("Temperature:", temperature, "C")

# Get the status of the device
status = pt.general.get_dict_key_value(device_data, 'status')
if status is not None:
    print("Status:", status)
```

# generate_md5

**Descripción**

Genera un hash MD5 para la cadena de entrada dada

**Parámetros**

<table border="1" id="bkmrk-module-acepta-el-tip" style="border-collapse: collapse; width: 100%;"><tbody><tr><td style="width: 12.5%;">**Nombre**</td><td style="width: 6.25%;">**Tipo**</td><td style="width: 7.9784%;">**Requerido**</td><td style="width: 48.2716%;">**Descripción**</td></tr><tr><td style="width: 12.5%;">input\_string</td><td style="width: 6.25%;">str</td><td style="width: 7.9784%;">Si</td><td style="width: 48.2716%;">La cadena para la que se generará el hash MD5.</td></tr></tbody></table>

**Return**

<table border="1" id="bkmrk-module_xml-m%C3%B3dulo-en" style="border-collapse: collapse; width: 100%;"><tbody><tr><td style="width: 33.2099%;">str</td><td style="width: 66.7901%;">El hash MD5 de la cadena de entrada como cadena hexadecimal.</td></tr></tbody></table>

**Requisitos**

- hashlib <div>  
    </div>

**Versión**

- 1.0.0

**Ejemplo**

```
import pandoraPlugintools as pt

# Sample monitoring data for a Linux system agent
name_agent = "Rocky-linux-master"

# Convert the monitoring data dictionary to a string
data_string = str(linux_system_data)

# Generate MD5 hash for the monitoring data
md5_hash = pt.general.generate_md5(data_string)

print("Linux System Monitoring Data:")
print(linux_system_data)
print("MD5 Hash:", md5_hash)
```

# now

**Descripción**

Devuelve la hora en formato aaaa/mm/dd HH:MM:SS por defecto.

**Parámetros**

<table border="1" id="bkmrk-module-acepta-el-tip" style="border-collapse: collapse; width: 100%;"><tbody><tr><td style="width: 12.5%;"><div><div>**Nombre**</div></div></td><td style="width: 6.25%;"><div><div>**Tipo**</div></div></td><td style="width: 6.25%;"><div><div>**Requerido**</div></div></td><td style="width: 50%;">**Descripción**</td></tr><tr><td style="width: 12.5%;"><div><div>print_flag</div></div></td><td style="width: 6.25%;"><div><div>int</div></div></td><td style="width: 6.25%;"><div><div>No</div></div></td><td style="width: 50%;">Sirve para imprimir la hora, de no utilizarse la hora se devolverá. Por defecto None</td></tr><tr><td style="width: 12.5%;"><div><div>utimestamp</div></div></td><td style="width: 6.25%;"><div><div>int</div></div></td><td style="width: 6.25%;"><div><div>No</div></div></td><td style="width: 50%;">Sirve para introducir un utimestamp, por defecto utilizará el actual.</td></tr></tbody></table>

**Return**

<table border="1" id="bkmrk-module_xml-m%C3%B3dulo-en" style="border-collapse: collapse; width: 100%;"><tbody><tr><td style="width: 50%;">**Nombre**</td><td style="width: 50%;">**Descripción**</td></tr><tr><td style="width: 50%;">str</td><td style="width: 50%;">Hora en formato aaaa/mm/dd HH:MM:SS</td></tr><tr><td style="width: 50%;">float</td><td style="width: 50%;">Hora en formato epoch time</td></tr></tbody></table>

**Requisitos**

- datetime.datetime

**Versión**

- 1.0.0

**Ejemplo**

```
import pandoraPlugintools as pt

# Get the current time in the default format
current_time_default = pt.general.now()
print("Current Time (Default Format):", current_time_default)

# Get the current time in Unix timestamp format
current_time_unix = pt.general.now(utimestamp=True)
print("Current Time (Unix Timestamp):", current_time_unix)

# Get and print the current time with the specified format
current_time_custom_format = pt.general.now(print_flag=True)
```

# translate_macros

**Descripción**

Espera un diccionario de macros clave:valor (nombre\_macro:valor\_macro) y una cadena para reemplazar la macro.

**Parámetros**

<table border="1" id="bkmrk-module-acepta-el-tip" style="border-collapse: collapse; width: 100%; height: 58px;"><tbody><tr><td style="width: 12.5%;"><div><div>**Nombre**</div></div></td><td style="width: 6.25%;"><div><div>**Tipo**</div></div></td><td style="width: 8.22531%;"><div><div>**Requerido**</div></div></td><td style="width: 48.0247%;">**Descripción**</td></tr><tr style="height: 29px;"><td style="width: 12.5%; height: 29px;"><div><div>macro_dic</div></div></td><td style="width: 6.25%;"><div><div>dict</div></div></td><td style="width: 8.22531%;"><div><div>Si</div></div></td><td style="width: 48.0247%; height: 29px;">Diccionario de macros clave:valor (nombre\_macro:valor\_macro)</td></tr><tr style="height: 29px;"><td style="width: 12.5%; height: 29px;"><div><div>data</div></div></td><td style="width: 6.25%;"><div><div>str</div></div></td><td style="width: 8.22531%;"><div><div>Si</div></div></td><td style="width: 48.0247%; height: 29px;">String para reemplazar la macro.</td></tr></tbody></table>

**Return**

<table border="1" id="bkmrk-module_xml-m%C3%B3dulo-en" style="border-collapse: collapse; width: 100%;"><tbody><tr><td style="width: 50%;">str</td><td style="width: 50%;">Devuelve el string parseado</td></tr></tbody></table>

**Versión**

- 1.0.0

**Ejemplo**

```
import pandoraPlugintools as pt

# Define a dictionary of macros and their corresponding values
macros = {
    "{DATE}": "2023-08-16",
    "{TIME}": "15:30:00",
    "{DEVICE}": "Linux Server",
    "{USER}": "admin"
}

# Input string with macros
input_data = "The {DEVICE} is operational since {TIME}."

# Replace macros in the input string
translated_data = pt.general.translate_macros(macro_dic=macros, data=input_data)

# Print the translated input string
print("Translated input string:", translated_data)
```

# parse_configuration

**Descripción**

Analiza la configuración. Lee el fichero de configuración y almacena sus datos como dict.

**Parámetros**

<table border="1" id="bkmrk-module-acepta-el-tip" style="border-collapse: collapse; width: 100%; height: 116px;"><tbody><tr style="height: 29px;"><td style="width: 12.5%; height: 29px;">**Nombre**</td><td style="width: 6.25%;">**Tipo**</td><td style="width: 8.34877%;">**Requerido**</td><td style="width: 47.9012%; height: 29px;">**Descripción**</td></tr><tr style="height: 29px;"><td style="width: 12.5%; height: 29px;">file</td><td style="width: 6.25%;"> </td><td style="width: 8.34877%;">si</td><td style="width: 47.9012%; height: 29px;">Ruta del fichero de configuración. Por defecto es "/etc/pandora/pandora\_server.conf"</td></tr><tr style="height: 29px;"><td style="width: 12.5%; height: 29px;">separator</td><td style="width: 6.25%;"> </td><td style="width: 8.34877%;">no</td><td style="width: 47.9012%; height: 29px;">Separador para la opción y el valor. Por defecto es " "</td></tr><tr style="height: 29px;"><td style="width: 12.5%; height: 29px;">default\_values</td><td style="width: 6.25%;"> </td><td style="width: 8.34877%;">no</td><td style="width: 47.9012%; height: 29px;">Diccionario de valores por defecto</td></tr></tbody></table>

**Return**

<table border="1" id="bkmrk-module_xml-m%C3%B3dulo-en" style="border-collapse: collapse; width: 100%;"><tbody><tr><td style="width: 50%;">dict</td><td style="width: 50%;">Diccionario que contiene todas las claves y valores del fichero</td></tr></tbody></table>

**Versión**

- 1.0.0

**Ejemplo**

```
import pandoraPlugintools as pt

# Specify the path to the configuration file
config_file = "/etc/pandora/pandora_server.conf"

# Specify the separator used in the configuration file
separator = "="

# Define default values for configuration options
default_config = {
    "server_port": "8080",
    "debug_mode": "false",
    "log_file": "/var/log/pandora.log"
}

# Parse the configuration file and get the configuration data
parsed_config = pt.general.parse_configuration(file=config_file, separator=separator, default_values=default_config)

# Print the parsed configuration data
print("Parsed configuration:", parsed_config)
```

# parse_csv_file

**Descripción**

Lee el fichero de configuración y almacena sus datos en un array.

**Parámetros**

<table border="1" id="bkmrk-module-acepta-el-tip" style="border-collapse: collapse; width: 100%; height: 145px;"><tbody><tr style="height: 29px;"><td style="width: 12.5%; height: 29px;">**Nombre**</td><td style="width: 6.25%; height: 29px;">**Tipo**</td><td style="width: 8.59568%; height: 29px;">**Requerido**</td><td style="width: 47.6543%; height: 29px;">**Descripción**</td></tr><tr style="height: 29px;"><td style="width: 12.5%; height: 29px;">file</td><td style="width: 6.25%; height: 29px;">str</td><td style="width: 8.59568%; height: 29px;">Si</td><td style="width: 47.6543%; height: 29px;">Ruta del fichero csv de configuración</td></tr><tr style="height: 29px;"><td style="width: 12.5%; height: 29px;">separator</td><td style="width: 6.25%; height: 29px;">str</td><td style="width: 8.59568%; height: 29px;">No</td><td style="width: 47.6543%; height: 29px;">Separador para la opción y el valor. Por defecto es ";"</td></tr><tr style="height: 29px;"><td style="width: 12.5%; height: 29px;"><div><div>coun_parameters</div></div></td><td style="width: 6.25%; height: 29px;"><div><div>int</div></div></td><td style="width: 8.59568%; height: 29px;"><div><div>No</div></div></td><td style="width: 47.6543%; height: 29px;">Número mínimo de parámetros que debe tener cada línea. Por defecto Ninguno</td></tr><tr style="height: 29px;"><td style="width: 12.5%; height: 29px;">debug</td><td style="width: 6.25%; height: 29px;">bool</td><td style="width: 8.59568%; height: 29px;">No</td><td style="width: 47.6543%; height: 29px;">Para imprimir errores en las líneas</td></tr></tbody></table>

**Return**

<table border="1" id="bkmrk-module_xml-m%C3%B3dulo-en" style="border-collapse: collapse; width: 100%;"><tbody><tr><td style="width: 50%;">list</td><td style="width: 50%;">Contiene una lista de valores para cada línea csv</td></tr></tbody></table>

**Requisitos**

- sys

**Versión**

- 1.0.0

**Ejemplo**

```
import pandoraPlugintools as pt

# Specify the path to the CSV configuration file
csv_file = "data.csv"

# Specify the separator used in the CSV file
separator = ","

# Specify the minimum number of parameters each line should have
min_parameters = 3

# Parse the CSV configuration file and get the data in a list
parsed_csv_data = pt.general.parse_csv_file(file=csv_file, separator=separator, count_parameters=min_parameters, print_errors=True)

# Print the parsed CSV data
print("Parsed CSV data:", parsed_csv_data)
```

# parse_int

**Descripción**

Convierte una variable dada en una cadena.

**Parámetros**

<table border="1" id="bkmrk-module-acepta-el-tip" style="border-collapse: collapse; width: 100%; height: 58px;"><tbody><tr style="height: 29px;"><td style="width: 12.5%; height: 29px;">**Nombre**</td><td style="width: 6.25%; height: 29px;">**Tipo**</td><td style="width: 7.9784%; height: 29px;">**Requerido**</td><td style="width: 48.2716%; height: 29px;">**Descripción**</td></tr><tr style="height: 29px;"><td style="width: 12.5%; height: 29px;">var</td><td style="width: 6.25%; height: 29px;">None</td><td style="width: 7.9784%; height: 29px;">Si</td><td style="width: 48.2716%; height: 29px;">La variable a analizar como cadena.</td></tr></tbody></table>

**Return**

<table border="1" id="bkmrk-module_xml-m%C3%B3dulo-en" style="border-collapse: collapse; width: 100%;"><tbody><tr><td style="width: 33.2099%;">str</td><td style="width: 66.7901%;">El valor de la cadena analizada. Si el análisis falla, devuelve "".</td></tr></tbody></table>

<div id="bkmrk-"></div>**Versión**

- 1.0.0

**Ejemplo**

```
import pandoraPlugintools as pt

# Sample variables to be parsed as integers
var1 = "123"
var2 = "45.67"
var3 = "invalid"

# Parse the variables as integers using the parse_int function
parsed_var1 = pt.general.parse_int(var1)
parsed_var2 = pt.general.parse_int(var2)
parsed_var3 = pt.general.parse_int(var3)

# Print the parsed integer values
print("Parsed var1:", parsed_var1)  # Should print: Parsed var1: 123
print("Parsed var2:", parsed_var2)  # Should print: Parsed var2: 0 (parsing fails for decimal value)
print("Parsed var3:", parsed_var3)  # Should print: Parsed var3: 0 (parsing fails for invalid value)
```

# parse_float

**Descripción**

Convierte una variable dada a float.

**Parámetros**

<table border="1" id="bkmrk-module-acepta-el-tip" style="border-collapse: collapse; width: 100%; height: 58px;"><tbody><tr style="height: 29px;"><td style="width: 12.5%; height: 29px;">**Nombre**</td><td style="width: 6.25%; height: 29px;">**Tipo**</td><td style="width: 7.9784%; height: 29px;">**Requerido**</td><td style="width: 48.2716%; height: 29px;">**Descripción**</td></tr><tr style="height: 29px;"><td style="width: 12.5%; height: 29px;">var</td><td style="width: 6.25%; height: 29px;">None</td><td style="width: 7.9784%; height: 29px;">SI</td><td style="width: 48.2716%; height: 29px;">La variable a convertir en float.</td></tr></tbody></table>

**Return**

<table border="1" id="bkmrk-module_xml-m%C3%B3dulo-en" style="border-collapse: collapse; width: 100%;"><tbody><tr><td style="width: 33.2099%;">float</td><td style="width: 66.7901%;">El valor de float analizado. Si el análisis falla, devuelve 0.</td></tr></tbody></table>

<div id="bkmrk-"></div>**Versión**

- 1.0.0

**Ejemplo**

```
import pandoraPlugintools as pt

# Sample variables to be parsed as floats
var1 = "123.45"
var2 = "invalid"
var3 = 67

# Parse the variables as floats using the parse_float function
parsed_var1 = pt.general.parse_float(var1)
parsed_var2 = pt.general.parse_float(var2)
parsed_var3 = pt.general.parse_float(var3)

# Print the parsed float values
print("Parsed var1:", parsed_var1)  # Should print: Parsed var1: 123.45
print("Parsed var2:", parsed_var2)  # Should print: Parsed var2: 0.0 (parsing fails for invalid value)
print("Parsed var3:", parsed_var3)  # Should print: Parsed var3: 67.0
```

# parse_str

**Descripción**

Convierte una variable dada en una cadena.

**Parámetros**

<table border="1" id="bkmrk-module-acepta-el-tip" style="border-collapse: collapse; width: 100%; height: 58px;"><tbody><tr style="height: 29px;"><td style="width: 12.5%; height: 29px;">**Nombre**</td><td style="width: 6.25%; height: 29px;">**Tipo**</td><td style="width: 7.9784%; height: 29px;">**Requerido**</td><td style="width: 48.2716%; height: 29px;">**Descripción**</td></tr><tr style="height: 29px;"><td style="width: 12.5%; height: 29px;">var</td><td style="width: 6.25%; height: 29px;">None</td><td style="width: 7.9784%; height: 29px;">Si</td><td style="width: 48.2716%; height: 29px;">La variable a analizar como cadena.</td></tr></tbody></table>

**Return**

<table border="1" id="bkmrk-module_xml-m%C3%B3dulo-en" style="border-collapse: collapse; width: 100%;"><tbody><tr><td style="width: 33.2099%;">str</td><td style="width: 66.7901%;">El valor de la cadena analizada. Si el análisis falla, devuelve "".s</td></tr></tbody></table>

<div id="bkmrk-"></div>**Versión**

- 1.0.0

**Ejemplo**

```
import pandoraPlugintools as pt

# Sample variables to be parsed as strings
var1 = 12345
var2 = 3.14159
var3 = True

# Parse the variables as strings using the parse_str function
parsed_var1 = pt.general.parse_str(var1)
parsed_var2 = pt.general.parse_str(var2)
parsed_var3 = pt.general.parse_str(var3)

# Print the parsed string values
print("Parsed var1:", parsed_var1)  # Should print: Parsed var1: 12345
print("Parsed var2:", parsed_var2)  # Should print: Parsed var2: 3.14159
print("Parsed var3:", parsed_var3)  # Should print: Parsed var3: True
```

# parse_bool

**Descripción**

Convierte una variable dada en bool.

**Parámetros**

<table border="1" id="bkmrk-module-acepta-el-tip" style="border-collapse: collapse; width: 100%; height: 58px;"><tbody><tr style="height: 29px;"><td style="width: 12.5%; height: 29px;">**Nombre**</td><td style="width: 6.25%; height: 29px;">**Tipo**</td><td style="width: 7.9784%; height: 29px;">**Requerido**</td><td style="width: 48.2716%; height: 29px;">**Descripción**</td></tr><tr style="height: 29px;"><td style="width: 12.5%; height: 29px;">var</td><td style="width: 6.25%; height: 29px;">None</td><td style="width: 7.9784%; height: 29px;">Si</td><td style="width: 48.2716%; height: 29px;">La variable a convertir en bool.</td></tr></tbody></table>

**Return**

<table border="1" id="bkmrk-module_xml-m%C3%B3dulo-en" style="border-collapse: collapse; width: 100%;"><tbody><tr><td style="width: 33.2099%;">bool</td><td style="width: 66.7901%;">El valor bool analizado. Si el análisis falla, devuelve False.</td></tr></tbody></table>

<div id="bkmrk-"></div>**Versión**

- 1.0.0

**Ejemplo**

```
import pandoraPlugintools as pt

# Sample variables to be parsed as booleans
var1 = "True"
var2 = 1
var3 = "false"

# Parse the variables as booleans using the parse_bool function
parsed_var1 = pt.general.parse_bool(var1)
parsed_var2 = pt.general.parse_bool(var2)
parsed_var3 = pt.general.parse_bool(var3)

# Print the parsed boolean values
print("Parsed var1:", parsed_var1)  # Should print: Parsed var1: True
print("Parsed var2:", parsed_var2)  # Should print: Parsed var2: True
print("Parsed var3:", parsed_var3)  # Should print: Parsed var3: False
```

# discovery



# Global variables

**Descripción**

Las siguientes variables pueden modificarse de modo global.

<table border="1" id="bkmrk-transfer_mode-modo-d"><tbody><tr><td>**Nombre**</td><td>**Descripción**</td><td>**Valor por defecto**</td></tr><tr><td><div><div>_ERROR_LEVEL</div></div></td><td>Esta variable se utiliza para controlar el nivel de error.</td><td>0</td></tr><tr><td><div><div>_SUMMARY</div></div></td><td>Este diccionario se utiliza para almacenar un sumario de elementos</td><td>{}</td></tr><tr><td><div><div>_INFO</div></div></td><td>Esta variable se utiliza para almacenar posibles errores en la ejecución</td><td>""</td></tr><tr><td><div><div>_MONITORING_DATA</div></div></td><td>Esta lista se utiliza para almacenar elementos</td><td>\[\]</td></tr></tbody></table>

Para modificar las variables globales use la función :

[set\_disco\_error\_level](https://pandorafms.com/guides/public/books/plugintools/page/set-disco-error-level)

[set\_disco\_summary](https://pandorafms.com/guides/public/books/plugintools/page/set-disco-summary)

[set\_disco\_info\_value](https://pandorafms.com/guides/public/books/plugintools/page/set-disco-info-value)

[set\_disco\_monitoring\_data](https://pandorafms.com/guides/public/books/plugintools/page/set-disco-monitoring-data)

**Versión**

- 1.0.0

# set_disco_error_level

**Descripción**

Establece el nivel de error al valor especificado.

**Parámetros**

<table border="1" id="bkmrk-module-acepta-el-tip" style="border-collapse: collapse; width: 100%; height: 58px;"><tbody><tr style="height: 29px;"><td style="width: 12.5%; height: 29px;">**Nombre**</td><td style="width: 6.25%; height: 29px;">**Tipo**</td><td style="width: 7.73148%; height: 29px;">**Requerido**</td><td style="width: 48.5185%; height: 29px;">**Descripción**</td></tr><tr style="height: 29px;"><td style="width: 12.5%; height: 29px;">value</td><td style="width: 6.25%; height: 29px;">int</td><td style="width: 7.73148%; height: 29px;">Si</td><td style="width: 48.5185%; height: 29px;">El valor del nivel de error. Por defecto es 0</td></tr></tbody></table>

**Return**

<table border="1" id="bkmrk-tipo-none" style="border-collapse: collapse; width: 100%;"><tbody><tr><td style="width: 100%;">**Tipo**</td></tr><tr><td style="width: 100%;">None</td></tr></tbody></table>

**Versión**

- 1.0.0

**Ejemplo**

```
import pandoraPlugintools as pt

# Set the error level to 1
pt.discovery.set_disco_error_level(1)

# Your code continues here without error level checking
print("Error level has been set to 1. Continue processing...")
```

# set_disco_summary

**Descripción**

Establecer valor fijo en el diccionario '\_SUMMARY'.

**Versión**

- 1.0.0

**Ejemplo**

```
import pandoraPlugintools as pt

# Create a sample data dictionary
sample_data = {
    'total_devices': 50,
    'active_devices': 30,
    'inactive_devices': 20
}

# Set the discovery summary using the sample data
pt.set_disco_summary(sample_data)

# Verify by printing the updated _SUMMARY
print(pt._SUMMARY)
```

# set_disco_summary_value

**Descripción**

Establece un valor fijo para una clave del diccionario '\_SUMMARY'.

**Parámetros**

<table border="1" id="bkmrk-module-acepta-el-tip" style="height: 87px; width: 477px;"><tbody><tr style="height: 29px;"><td style="height: 29px; width: 72px;">**Nombre** </td><td style="height: 29px; width: 45px;">**Tipo**</td><td style="height: 29px; width: 83px;">**Requerido**</td><td style="height: 29px; width: 277px;">**Descripción**</td></tr><tr style="height: 29px;"><td style="height: 29px; width: 72px;">key</td><td style="height: 29px; width: 45px;">str</td><td style="height: 29px; width: 83px;">Si</td><td style="height: 29px; width: 277px;">Clave para la que se establece el valor</td></tr><tr style="height: 29px;"><td style="height: 29px; width: 72px;">value</td><td style="height: 29px; width: 45px;">any</td><td style="height: 29px; width: 83px;">Si</td><td style="height: 29px; width: 277px;">Valor a asignar a la clave</td></tr></tbody></table>

**Return**

<table border="1" id="bkmrk-tipo-none" style="border-collapse: collapse; width: 100%;"><tbody><tr><td style="width: 100%;">**Tipo**</td></tr><tr><td style="width: 100%;">None</td></tr></tbody></table>

**Versión**

- 1.0.0

**Ejemplo**

```
import pandoraPlugintools as pt

# Set a fixed value for a specific key in the discovery summary
pt.set_disco_summary_value('total_devices', 100)
pt.set_disco_summary_value('active_devices', 75)
pt.set_disco_summary_value('inactive_devices', 25)

# Verify by printing the updated _SUMMARY
print(pt._SUMMARY)
```

# add_disco_summary_value

**Descripción**

Añade un valor a una clave del diccionario 'resumen'.

Si la clave ya existe, se incrementará el valor. En caso contrario, se creará una nueva clave.

**Parámetros**

<table border="1" id="bkmrk-module-acepta-el-tip" style="border-collapse: collapse; width: 100%; height: 87px;"><tbody><tr style="height: 29px;"><td style="width: 12.5%; height: 29px;">**Nombre**</td><td style="width: 6.25%; height: 29px;">**Tipo**</td><td style="width: 8.84259%; height: 29px;">**Requerido**</td><td style="width: 47.4074%; height: 29px;">**Descripción**</td></tr><tr style="height: 29px;"><td style="width: 12.5%; height: 29px;">key</td><td style="width: 6.25%; height: 29px;">str</td><td style="width: 8.84259%; height: 29px;">SI</td><td style="width: 47.4074%; height: 29px;">Clave a la que añadir el valor</td></tr><tr style="height: 29px;"><td style="width: 12.5%; height: 29px;">value</td><td style="width: 6.25%; height: 29px;">None</td><td style="width: 8.84259%; height: 29px;">SI</td><td style="width: 47.4074%; height: 29px;">Valor a añadir a la clave</td></tr></tbody></table>

**Return**

<table border="1" id="bkmrk-tipo-none" style="border-collapse: collapse; width: 100%;"><tbody><tr><td style="width: 100%;">**Tipo**</td></tr><tr><td style="width: 100%;">None</td></tr></tbody></table>

**Versión**

- 1.0.0

**Ejemplo**

```
import pandoraPlugintools as pt

# Add values to existing keys in the discovery summary
pt.set_disco_summary_value('total_devices', 100)
pt.set_disco_summary_value('active_devices', 75)
pt.set_disco_summary_value('inactive_devices', 25)

# Add values to existing keys using add_disco_summary_value function
pt.add_disco_summary_value('total_devices', 10)
pt.add_disco_summary_value('active_devices', 5)
pt.add_disco_summary_value('inactive_devices', 5)

# Add values to new keys using add_disco_summary_value function
pt.add_disco_summary_value('new_key', 50)

# Verify by printing the updated _SUMMARY
print(pt._SUMMARY)
```

# set_disco_info_value

**Descripción**

Establece un valor fijo en la variable 'info'.

**Parámetros**

<table border="1" id="bkmrk-module-acepta-el-tip" style="border-collapse: collapse; width: 100%;"><tbody><tr><td style="width: 12.5%;">**Nombre**</td><td style="width: 6.25%;">**Tipo**</td><td style="width: 9.21296%;">**Requerido**</td><td style="width: 47.037%;">**Descripción**</td></tr><tr><td style="width: 12.5%;">value</td><td style="width: 6.25%;">str</td><td style="width: 9.21296%;">Si</td><td style="width: 47.037%;">El valor a establecer en la variable 'info'. Por defecto es una cadena vacía.</td></tr></tbody></table>

**Return**

<table border="1" id="bkmrk-tipo-none" style="border-collapse: collapse; width: 100%;"><tbody><tr><td style="width: 100%;">**Tipo**</td></tr><tr><td style="width: 100%;">None</td></tr></tbody></table>

**Versión**

- 1.0.0

**Ejemplo**

```
import pandoraPlugintools as pt

# Set a value to the _INFO variable
pt.set_disco_info_value("This is some information about the discovery.")

# Verify by printing the updated _INFO
print(discovery._INFO)
```

# add_disco_info_value

**Descripción**

Añade datos a la variable 'info'.

**Parámetros**

<table border="1" id="bkmrk-module-acepta-el-tip" style="border-collapse: collapse; width: 100%;"><tbody><tr><td style="width: 12.5%;">**Nombre**</td><td style="width: 6.25%;">**Tipo**</td><td style="width: 8.10185%;">**Requerido**</td><td style="width: 48.1481%;">**Descripción**</td></tr><tr><td style="width: 12.5%;">value</td><td style="width: 6.25%;">str</td><td style="width: 8.10185%;">Si</td><td style="width: 48.1481%;">Los datos a añadir a la variable 'info'. Por defecto es una cadena vacía</td></tr></tbody></table>

**Return**

<table border="1" id="bkmrk-tipo-none" style="border-collapse: collapse; width: 100%;"><tbody><tr><td style="width: 100%;">**Tipo**</td></tr><tr><td style="width: 100%;">None</td></tr></tbody></table>

**Versión**

- 1.0.0

**Ejemplo**

```
import pandoraPlugintools as pt

# Add data to the _INFO variable
pt.add_disco_info_value("Additional information: ")
pt.add_disco_info_value("System status: OK")

# Verify by printing the updated _INFO variable
print(pt._INFO)
```

# set_disco_monitoring_data

**Descripción**

Establecer un valor fijo en los datos de seguimiento

**Parámetros**

<table border="1" id="bkmrk-module-acepta-el-tip" style="border-collapse: collapse; width: 100%; height: 58px;"><tbody><tr style="height: 29px;"><td style="width: 12.5%; height: 29px;">**Nombre**</td><td style="width: 6.25%; height: 29px;">**Tipo**</td><td style="width: 9.21296%; height: 29px;">**Requerido**</td><td style="width: 47.037%; height: 29px;">**Descripción**</td></tr><tr style="height: 29px;"><td style="width: 12.5%; height: 29px;">data</td><td style="width: 6.25%; height: 29px;">list</td><td style="width: 9.21296%; height: 29px;">Si</td><td style="width: 47.037%; height: 29px;">Lista con los datos</td></tr></tbody></table>

**Return**

<table border="1" id="bkmrk-tipo-none" style="border-collapse: collapse; width: 100%;"><tbody><tr><td style="width: 100%;">**Tipo**</td></tr><tr><td style="width: 100%;">None</td></tr></tbody></table>

**Versión**

- 1.0.0

**Ejemplo**

```
import pandoraPlugintools as pt

# Example data for disk monitoring
disk_monitoring_data = [
    {'path': '/dev/sda1', 'usage': '75%'},
    {'path': '/dev/sdb1', 'usage': '42%'},
    {'path': '/dev/sdc1', 'usage': '90%'}
]

# Set the monitoring data for disk usage
pt.set_disco_monitoring_data(disk_monitoring_data)

# Verify by printing the updated _MONITORING_DATA variable
print(pt._MONITORING_DATA)
```

# add_disco_monitoring_data

**Descripción**

Añadir valor a los datos de seguimiento

**Parámetros**

<table border="1" id="bkmrk-module-acepta-el-tip" style="border-collapse: collapse; width: 100%; height: 58px;"><tbody><tr style="height: 29px;"><td style="width: 12.5%; height: 29px;">**Nombre**</td><td style="width: 6.25%; height: 29px;">**Tipo**</td><td style="width: 9.21296%; height: 29px;">**Requerido**</td><td style="width: 47.037%; height: 29px;">**Descripción**</td></tr><tr style="height: 29px;"><td style="width: 12.5%; height: 29px;">data</td><td style="width: 6.25%; height: 29px;">dict</td><td style="width: 9.21296%; height: 29px;">Si</td><td style="width: 47.037%; height: 29px;">Diccionario con los datos</td></tr></tbody></table>

**Return**

<table border="1" id="bkmrk-tipo-none" style="border-collapse: collapse; width: 100%;"><tbody><tr><td style="width: 100%;">**Tipo**</td></tr><tr><td style="width: 100%;">None</td></tr></tbody></table>

**Versión**

- 1.0.0

**Ejemplo**

```
import pandoraPlugintools as pt

# Example data for disk monitoring to be added
new_disk_data = {'path': '/dev/sdd1', 'usage': '60%'}

# Add the new disk monitoring data to the global monitoring dataset
pt.add_disco_monitoring_data(new_disk_data)

# Verify by printing the updated _MONITORING_DATA variable
print(pt._MONITORING_DATA)
```

# disco_output

**Descripción**

Imprime la salida JSON y sale del script.

**Requisitos**

- json
- sys

**Ejemplo**

```
import pandoraPlugintools as pt
import sys  # Don't forget to import the sys module for the sys.exit() function

# Set values for _SUMMARY, _INFO, and _MONITORING_DATA (for demonstration purposes)
pt.set_disco_summary({'disk_usage': '80%'})
pt.set_disco_info_value('Disk usage information')
pt.add_disco_monitoring_data({'path': '/dev/sda1', 'usage': '70%'})

# Call the disco_output function to print JSON output and exit with a specific error level
pt.disco_output()
```

# http



# auth_call

**Descripción**

Autenticación para petición url. Requiere el objeto request.sessions.Session().

**Parámetros**

<table border="1" id="bkmrk-module-acepta-el-tip" style="height: 162px; width: 515px;"><tbody><tr style="height: 29px;"><td style="width: 77px; height: 29px;">**Nombre**</td><td style="width: 77px; height: 29px;">**Tipo**</td><td style="width: 361px; height: 29px;">**Descripción**</td></tr><tr style="height: 29px;"><td style="height: 29px; width: 77px;">session </td><td style="width: 77px; height: 29px;">None</td><td style="height: 29px; width: 361px;">objeto Session() de request</td></tr><tr style="height: 29px;"><td style="height: 29px; width: 77px;">authtype </td><td style="width: 77px; height: 29px;">str</td><td style="height: 29px; width: 361px;">'ntlm', 'basic' o 'digest'</td></tr><tr style="height: 46px;"><td style="width: 77px; height: 46px;"><div><div>user </div></div></td><td style="width: 77px; height: 46px;"><div><div>str</div></div></td><td style="width: 361px; height: 46px;">Usuario de autenticación</td></tr><tr style="height: 29px;"><td style="width: 77px; height: 29px;"><div><div>passw </div></div></td><td style="width: 77px; height: 29px;"><div><div>str</div></div></td><td style="width: 361px; height: 29px;">Contraseña de autenticación</td></tr></tbody></table>

**Return**

<table border="1" id="bkmrk-tipo-none" style="border-collapse: collapse; width: 100%;"><tbody><tr><td style="width: 100%;">**Tipo**</td></tr><tr><td style="width: 100%;">None</td></tr></tbody></table>

 **Requisitos**

- <div><div>requests_ntlm.HttpNtlmAuth</div></div>
- <div><div>requests.auth.HTTPBasicAuth</div></div>
- <div><div><div>requests.auth.HTTPDigestAuth</div></div></div><div>  
    </div>

**Versión**

- 1.0.0

**Ejemplo**

```
import pandoraPlugintools as pt

# Create a request session
session = pt.requests.Session()

# Define authentication details
authtype = 'basic'
user = 'admin'
passw = 'S4n3tk!'

# Call the authentication function
pt._auth_call(session, authtype, user, passw)

# Now you can use the authenticated session to make URL requests
url = 'https://api.com/api/data'
response = session.get(url)

# Print the response
print(response.text)
```

# call_url

**Descripción**

Utiliza el módulo request para obtener el contenido de la URL.

**Parámetros**

<table border="1" id="bkmrk-module-acepta-el-tip" style="height: 191px; width: 515px;"><tbody><tr style="height: 29px;"><td style="width: 77px; height: 29px;"><div><div>**Nombre**</div></div></td><td style="width: 77px;"><div><div>**Tipo**</div></div></td><td style="width: 361px; height: 29px;">**Descripción**</td></tr><tr style="height: 29px;"><td style="height: 29px; width: 77px;"><div><div>url</div></div></td><td style="width: 77px;"><div><div>str</div></div></td><td style="height: 29px; width: 361px;">Url objetivo.</td></tr><tr style="height: 29px;"><td style="height: 29px; width: 77px;"><div><div>authtype</div></div></td><td style="width: 77px;"><div><div>str</div></div></td><td style="height: 29px; width: 361px;">ntlm', 'basic', 'digest'. Opcional.</td></tr><tr style="height: 46px;"><td style="width: 77px; height: 46px;"><div><div><div><div>user</div></div></div></div></td><td style="width: 77px;"><div><div><div><div>str</div></div></div></div></td><td style="width: 361px; height: 46px;">Usuario de autenticación. Opcional.</td></tr><tr style="height: 29px;"><td style="width: 77px; height: 29px;"><div><div><div><div>passw</div></div></div></div></td><td style="width: 77px;"><div><div><div><div>str</div></div></div></div></td><td style="width: 361px; height: 29px;">Contraseña de autenticación. Opcional.</td></tr><tr style="height: 29px;"><td style="width: 77px; height: 29px;"><div><div>time_out</div></div></td><td style="width: 77px;"><div><div>int</div></div></td><td style="width: 361px; height: 29px;">Time out para la llamada.</td></tr></tbody></table>

**Return**

<table border="1" id="bkmrk-output-salida-de-la-" style="border-collapse: collapse; width: 100%;"><tbody><tr><td style="width: 50%;">**Tipo**</td><td style="width: 50%;">**Descripción**</td></tr><tr><td style="width: 50%;">str</td><td style="width: 50%;">Salida de la petición request.</td></tr></tbody></table>

**Requisitos**

- <div><div><div>requests.sessions.Session</div></div></div><div>  
    </div>

**Versión**

- 1.0.0

**Ejemplo**

```
import pandoraPlugintools as pt

# Define URL and authentication details
url = 'https://api.com/api/data'
authtype = 'basic'
user = 'admin'
passw = 'S4!jdKm'

# Call the URL and get the contents
response = pt.call_url(url, authtype=authtype, user=user, passw=passw, timeout=5, verify=True, print_errors=True)

# Print the response content
if response is not None:
    print(response.decode('utf-8'))
else:
    print("Error occurred during URL call.")
```

# threads



# _single_thread

**Descripción**

Sólo para uso interno: Ejecuta una función dada en un hilo.

**Parámetros**

<table border="1" id="bkmrk-module-acepta-el-tip" style="width: 426px;"><tbody><tr><td style="width: 73px;">**Nombre** </td><td style="width: 61px;">**Tipo**</td><td style="width: 95px;">**Requerido**</td><td style="width: 197px;">**Descripción**</td></tr><tr><td style="width: 73px;">q</td><td style="width: 61px;">None</td><td style="width: 95px;">Si</td><td style="width: 197px;">Una cola de la que obtener parámetros para la función</td></tr><tr><td style="width: 73px;">function</td><td style="width: 61px;">callable</td><td style="width: 95px;">Si</td><td style="width: 197px;">La función a ejecutar en el hilo</td></tr><tr><td style="width: 73px;">errors</td><td style="width: 61px;">list</td><td style="width: 95px;">No</td><td style="width: 197px;">Una lista para almacenar cualquier error encontrado durante la ejecución</td></tr></tbody></table>

**Versión**

- 1.0.0

# run_threads

**Descripción**

Ejecutar una función dada para una lista de elementos dada en un número dado de hilos

**Parámetros**

<table border="1" id="bkmrk-module-acepta-el-tip" style="width: 562px; height: 162px;"><tbody><tr style="height: 29px;"><td style="width: 112px; height: 29px;">**Nombre**</td><td style="width: 70px; height: 29px;">**Tipo**</td><td style="width: 88px; height: 29px;">**Requerido**</td><td style="width: 292px; height: 29px;">**Descripción**</td></tr><tr style="height: 46px;"><td style="width: 112px; height: 46px;"><div><div>max_threads</div></div></td><td style="width: 70px; height: 46px;">int</td><td style="width: 88px; height: 46px;">SI</td><td style="width: 292px; height: 46px;">Número de hilos </td></tr><tr style="height: 29px;"><td style="width: 112px; height: 29px;">function</td><td style="width: 70px; height: 29px;">callable</td><td style="width: 88px; height: 29px;">Si</td><td style="width: 292px; height: 29px;">Función a ejecutar</td></tr><tr style="height: 29px;"><td style="width: 112px; height: 29px;">items</td><td style="width: 70px; height: 29px;">list</td><td style="width: 88px; height: 29px;">Si</td><td style="width: 292px; height: 29px;">Lista con los items que se asignaran a cada hilo</td></tr><tr style="height: 29px;"><td style="width: 112px; height: 29px;"><div><div>print_errors</div></div></td><td style="width: 70px; height: 29px;">bool</td><td style="width: 88px; height: 29px;">No</td><td style="width: 292px; height: 29px;">Para pintar error por salida</td></tr></tbody></table>

**Return**

<table border="1" id="bkmrk-module_xml-m%C3%B3dulo-en" style="width: 557px;"><tbody><tr><td style="width: 66px;">bool</td><td style="width: 491px;">Devuelve True si no ha habido errores en la ejecución y 0 de suceder lo contrario.</td></tr></tbody></table>

<div id="bkmrk-"></div>**Versión**

- 1.0.0

**Ejemplo**

```
import pandoraPlugintools as pt

# Define a function to be executed in each thread
def process_item(item):
    # Perform some processing on the item
    print(f"Processing item: {item}")

# List of items to process
items = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

# Number of threads to use
max_threads = 3

# Run the function for each item using multiple threads
success = pt.run_threads(max_threads=max_threads, function=process_item, items=items, print_errors=True)

if success:
    print("All threads executed successfully.")
else:
    print("Errors occurred during thread execution.")
```

# set_shared_dict_value

**Descripción**

Establece un valor para una clave en el diccionario interno compartido. Esta función es utilizada por todos los procesos paralelos.

**Parámetros**

<table border="1" id="bkmrk-module-acepta-el-tip" style="width: 562px;"><tbody><tr><td style="width: 70px;">**Nombre**</td><td style="width: 54px;">**Tipo**</td><td style="width: 90px;">**Requerido**</td><td style="width: 348px;">**Descripción**</td></tr><tr><td style="width: 70px;">key</td><td style="width: 54px;">str</td><td style="width: 90px;">SI</td><td style="width: 348px;">La clave en el diccionario compartido</td></tr><tr><td style="width: 70px;">value</td><td style="width: 54px;">None</td><td style="width: 90px;">Si</td><td style="width: 348px;">El valor a asignar a la clave</td></tr></tbody></table>

<div id="bkmrk-"></div>**Return**

<div id="bkmrk-tipo-none"><table border="1" style="border-collapse: collapse; width: 100%;"><tbody><tr><td style="width: 100%;">**Tipo**</td></tr><tr><td style="width: 100%;">None</td></tr></tbody></table>

</div>**Versión**

- 1.0.0

Ejemplo

```
import pandoraPlugintools as pt

# Define a function to be executed by parallel processes
def process_data(item):
    # Process the data and set a value in the shared dictionary
    result = item * 2
    pt.set_shared_dict_value(key=str(item), value=result)

# List of items to process
data_list = [1, 2, 3, 4, 5]

# Create a shared dictionary and lock for synchronization
shared_dict = multiprocessing.Manager().dict()
shared_dict_lock = multiprocessing.Manager().Lock()

# Set the shared dictionary and lock in the module
pt._SHARED_DICT = shared_dict
pt._SHARED_DICT_LOCK = shared_dict_lock

# Number of parallel processes to use
num_processes = 2

# Run the function for each item using parallel processes
success = pt.run_parallel(num_processes=num_processes, function=process_data, data_list=data_list, print_errors=True)

if success:
    print("All processes executed successfully.")
else:
    print("Errors occurred during process execution.")
```

# add_shared_dict_value

**Descripción**

Añade un valor a una clave del diccionario interno compartido. Esta función es utilizada por todos los procesos paralelos.

**Parámetros**

<table border="1" id="bkmrk-module-acepta-el-tip" style="width: 562px; height: 87px;"><tbody><tr style="height: 29px;"><td style="width: 70px; height: 29px;">**Nombre**</td><td style="width: 54px; height: 29px;">**Tipo**</td><td style="width: 90px; height: 29px;">**Requerido**</td><td style="width: 348px; height: 29px;">**Descripción**</td></tr><tr style="height: 29px;"><td style="width: 70px; height: 29px;">key</td><td style="width: 54px; height: 29px;">str</td><td style="width: 90px; height: 29px;">Si</td><td style="width: 348px; height: 29px;">La clave en el diccionario compartido</td></tr><tr style="height: 29px;"><td style="width: 70px; height: 29px;">value</td><td style="width: 54px; height: 29px;">None</td><td style="width: 90px; height: 29px;">SI</td><td style="width: 348px; height: 29px;">El valor a añadir a la clave</td></tr></tbody></table>

<div id="bkmrk-"></div>**Return**

<div id="bkmrk-tipo-none"><table border="1" style="border-collapse: collapse; width: 100%;"><tbody><tr><td style="width: 100%;">**Tipo**</td></tr><tr><td style="width: 100%;">None</td></tr></tbody></table>

</div>**Versión**

- 1.0.0

**Ejemplo**

```
import pandoraPlugintools as pt

# Define a function to be executed by parallel processes
def process_data(item):
    # Process the data and add a value to the shared dictionary
    result = item * 2
    pt.add_shared_dict_value(key=str(item), value=result)

# List of items to process
data_list = [1, 2, 3, 4, 5]

# Create a shared dictionary and lock for synchronization
shared_dict = multiprocessing.Manager().dict()
shared_dict_lock = multiprocessing.Manager().Lock()

# Set the shared dictionary and lock in the module
pt._SHARED_DICT = shared_dict
pt._SHARED_DICT_LOCK = shared_dict_lock

# Number of parallel processes to use
num_processes = 2

# Run the function for each item using parallel processes
success = pt.run_parallel(num_processes=num_processes, function=process_data, data_list=data_list, print_errors=True)

if success:
    print("All processes executed successfully.")
else:
    print("Errors occurred during process execution.")
In this example, the process_data function processes each item and adds a value to the shared dictionary using the add_shared_dict_value function. The run_parallel function is used to execute the process_data function in parallel processes for the given list of items. The shared dictionary and lock are created using the multiprocessing.Manager() and then assigned to the corresponding module variables _SHARED_DICT and _SHARED_DICT_LOCK in the pandoraPluginTools module.






```

# get_shared_dict_value

**Descripción**

Obtener el valor de una clave en el diccionario interno compartido. Esta función es utilizada por todos los procesos paralelos.

**Parámetros**

<table border="1" id="bkmrk-module-acepta-el-tip" style="width: 562px;"><tbody><tr><td style="width: 70px;">**Nombre**</td><td style="width: 54px;">**Tipo**</td><td style="width: 90px;">**Requerido**</td><td style="width: 348px;">**Descripción**</td></tr><tr><td style="width: 70px;">key</td><td style="width: 54px;">str</td><td style="width: 90px;">Si</td><td style="width: 348px;">La clave en el diccionario compartido</td></tr></tbody></table>

<div id="bkmrk-"></div>**Return**

<div id="bkmrk-tipo-none"><table border="1" style="border-collapse: collapse; width: 100%;"><tbody><tr><td style="width: 100%;">**Tipo**</td></tr><tr><td style="width: 100%;">None</td></tr></tbody></table>

</div>**Versión**

- 1.0.0

**Ejemplo**

```
import pandoraPlugintools as pt

# Define a function to be executed by parallel processes
def process_data(item):
    # Process the data and get the value from the shared dictionary
    result = item * 2
    value = pt.get_shared_dict_value(key=str(item))
    print(f"Item: {item}, Processed Value: {result}, Shared Value: {value}")

# List of items to process
data_list = [1, 2, 3, 4, 5]

# Create a shared dictionary and lock for synchronization
shared_dict = multiprocessing.Manager().dict()
shared_dict_lock = multiprocessing.Manager().Lock()

# Set the shared dictionary and lock in the module
pt._SHARED_DICT = shared_dict
pt._SHARED_DICT_LOCK = shared_dict_lock

# Number of parallel processes to use
num_processes = 2

# Run the function for each item using parallel processes
success = pt.run_parallel(num_processes=num_processes, function=process_data, data_list=data_list, print_errors=True)

if success:
    print("All processes executed successfully.")
else:
    print("Errors occurred during process execution.")
```

# run_processes

**Descripción**

Ejecuta una función dada para una lista de elementos dada en un número dado de procesos

**Parámetros**

<table border="1" id="bkmrk-module-acepta-el-tip" style="width: 562px;"><tbody><tr><td style="width: 70px;">**Nombre**</td><td style="width: 54px;">**Tipo**</td><td style="width: 90px;">**Requerido**</td><td style="width: 348px;">**Descripción**</td></tr><tr><td style="width: 70px;"><div><div>max_processes</div></div></td><td style="width: 54px;">int</td><td style="width: 90px;">Si</td><td style="width: 348px;">El número máximo de procesos a ejecutar en paralelo</td></tr><tr><td style="width: 70px;"><div><div>function</div></div></td><td style="width: 54px;">callable</td><td style="width: 90px;">SI</td><td style="width: 348px;">La función a ejecutar para cada ítem</td></tr><tr><td style="width: 70px;"><div><div>items</div></div></td><td style="width: 54px;">list</td><td style="width: 90px;">Si</td><td style="width: 348px;">Lista de ítems a procesar</td></tr><tr><td style="width: 70px;"><div><div>print_errors</div></div></td><td style="width: 54px;">bool</td><td style="width: 90px;">No</td><td style="width: 348px;">Si se van a imprimir los errores</td></tr></tbody></table>

**Return**

<table border="1" id="bkmrk-module_xml-m%C3%B3dulo-en" style="width: 558px;"><tbody><tr><td style="width: 52px;">**Tipo**</td><td style="width: 506px;">**Descripción**</td></tr><tr><td style="width: 52px;">bool</td><td style="width: 506px;">True si todos los procesos se completaron con éxito, False en caso contrario</td></tr></tbody></table>

<div id="bkmrk-"></div>**Versión**

- 1.0.0

```
import pandoraPlugintools as pt

# Define a function to be executed by parallel processes
def process_data(item):
    result = item * 2
    print(f"Item: {item}, Processed Value: {result}")

# List of items to process
data_list = [1, 2, 3, 4, 5]

# Number of parallel processes to use
num_processes = 2

# Run the function for each item using parallel processes
success = pt.run_processes(max_processes=num_processes, function=process_data, items=data_list, print_errors=True)

if success:
    print("All processes completed successfully.")
else:
    print("Errors occurred during process execution.")
```

# encryption



# _get_cipher_AES

**Descripción**

Sólo para uso interno: Obtiene el cifrado AES para encriptación y desencriptación.

**Parámetros**

<table border="1" id="bkmrk-module-acepta-el-tip"><tbody><tr><td>**Nombre** </td><td>**Tipo**</td><td>**Requerido**</td><td>**Descripción**</td></tr><tr><td>password</td><td>str</td><td>Si</td><td>La contraseña utilizada para obtener la clave de cifrado</td></tr></tbody></table>

**Return**

<table border="1" id="bkmrk-tipo-descripci%C3%B3n-aes" style="border-collapse: collapse; width: 100%;"><tbody><tr><td style="width: 50%;">**Tipo**</td><td style="width: 50%;">**Descripción**</td></tr><tr><td style="width: 50%;">AES</td><td style="width: 50%;">Una instancia de cifrado AES para cifrar y descifrar</td></tr></tbody></table>

**Requisitos**

- base64
- hmac
- hashlib

**Versión**

- 1.0.0

# encrypt_AES

**Descripción**

Cifra una cadena utilizando el cifrado AES.

**Parámetros**

<table border="1" id="bkmrk-module-acepta-el-tip"><tbody><tr><td>**Nombre** </td><td>**Tipo**</td><td>**Requerido**</td><td>**Descripción**</td></tr><tr><td>str\_to\_encrypt</td><td>str</td><td>Si</td><td>La cadena a cifrar</td></tr><tr><td>password</td><td>str</td><td>No</td><td>La contraseña utilizada para obtener la clave de cifrado</td></tr></tbody></table>

**Return**

<table border="1" id="bkmrk-tipo-none" style="border-collapse: collapse; width: 100%;"><tbody><tr><td style="width: 100%;">**Tipo**</td></tr><tr><td style="width: 100%;">None</td></tr></tbody></table>

**Requisitos**

- base64

**Versión**

- 1.0.0

**Ejemplo**

```
import pandoraPlugintools as pt

# Define a password for encryption
encryption_password = "S4!DHhsd"

# String to be encrypted
data_to_encrypt = "This is a confidential message."

# Encrypt the string using AES encryption
encrypted_data = pt.encrypt_AES(str_to_encrypt=data_to_encrypt, password=encryption_password)

print(f"Original String: {data_to_encrypt}")
print(f"Encrypted String: {encrypted_data}")
```

# decrypt_AES

**Descripción**

Descifra una cadena encriptada utilizando el descifrado AES.

**Parámetros**

<table border="1" id="bkmrk-module-acepta-el-tip"><tbody><tr><td>**Nombre** </td><td>**Tipo**</td><td>**Requerido**</td><td>**Descripción**</td></tr><tr><td><div><div>str_to_decrypt</div></div></td><td>str</td><td>Si</td><td>La cadena cifrada que se va a descifrar</td></tr><tr><td>password</td><td>str</td><td>No</td><td>La contraseña utilizada para obtener la clave de cifrado base64</td></tr></tbody></table>

**Return**

<table border="1" id="bkmrk-tipo-none" style="border-collapse: collapse; width: 100%;"><tbody><tr><td style="width: 100%;">**Tipo**</td></tr><tr><td style="width: 100%;">None</td></tr></tbody></table>

**Requisitos**

- base64

**Versión**

- 1.0.0

**Ejemplo**

```
import pandoraPlugintools as pt

# Define a password for encryption
encryption_password = "S4snDH!"

# Encrypted string to be decrypted
encrypted_string = "2S1Ps52+qUQ45b5uK2od2w=="

# Decrypt the encrypted string
decrypted_string = pt.decrypt_AES(str_to_decrypt=encrypted_string, password=encryption_password)

print(f"Decrypted String: {decrypted_string}")
```

# _get_cipher_Rijndael

**Descripción**

Sólo para uso interno: Obtén el cifrado Rijndael para encriptar y desencriptar.

**Parámetros**

<table border="1" id="bkmrk-module-acepta-el-tip"><tbody><tr><td>**Nombre** </td><td>**Tipo**</td><td>**Requerido**</td><td>**Descripción**</td></tr><tr><td>password</td><td>str</td><td>Si</td><td>La contraseña utilizada para obtener la clave de cifrado</td></tr></tbody></table>

**Return**

<table border="1" id="bkmrk-tipo-descripci%C3%B3n-aes"><tbody><tr><td>**Tipo**</td><td>**Descripción**</td></tr><tr><td>AES</td><td>Una instancia de cifrado AES para cifrar y descifrar</td></tr></tbody></table>

**Requisitos**

- base64
- hmac
- hashlib

**Versión**

- 1.0.6

# encrypt_Rijndael

**Descripción**

Cifra una cadena utilizando el cifrado Rijndael.

**Parámetros**

<table border="1" id="bkmrk-module-acepta-el-tip"><tbody><tr><td>**Nombre** </td><td>**Tipo**</td><td>**Requerido**</td><td>**Descripción**</td></tr><tr><td>str\_to\_encrypt</td><td>str</td><td>Si</td><td>La cadena a cifrar</td></tr><tr><td>password</td><td>str</td><td>No</td><td>La contraseña utilizada para obtener la clave de cifrado</td></tr></tbody></table>

**Return**

<table border="1" id="bkmrk-tipo-none"><tbody><tr><td>**Tipo**</td></tr><tr><td>None</td></tr></tbody></table>

**Requisitos**

- base64

**Versión**

- 1.0.6

**Ejemplo**

```
import pandoraPlugintools as pt

# Define a password for encryption
encryption_password = "S4!DHhsd"

# String to be encrypted
data_to_encrypt = "This is a confidential message."

# Encrypt the string using AES encryption
encrypted_data = pt.encrypt_Rijndael(str_to_encrypt=data_to_encrypt, password=encryption_password)

print(f"Original String: {data_to_encrypt}")
print(f"Encrypted String: {encrypted_data}")
```

# decrypt_Rijndael

**Descripción**

Descifra una cadena cifrada utilizando el descifrado Rijndael.

**Parámetros**

<table border="1" id="bkmrk-module-acepta-el-tip"><tbody><tr><td>**Nombre** </td><td>**Tipo**</td><td>**Requerido**</td><td>**Descripción**</td></tr><tr><td>str\_to\_encrypt</td><td>str</td><td>Si</td><td>La cadena a cifrar</td></tr><tr><td>password</td><td>str</td><td>No</td><td>La contraseña utilizada para obtener la clave de cifrado</td></tr></tbody></table>

**Return**

<table border="1" id="bkmrk-tipo-none"><tbody><tr><td>**Tipo**</td></tr><tr><td>None</td></tr></tbody></table>

**Requisitos**

- base64

**Versión**

- 1.0.6

**Ejemplo**

```
import pandoraPlugintools as pt

# Define a password for encryption
encryption_password = "S4snDH!"

# Encrypted string to be decrypted
encrypted_string = "2S1Ps52+qUQ45b5uK2od2w=="

# Decrypt the encrypted string
decrypted_string = pt.decrypt_Rijndael(str_to_decrypt=encrypted_string, password=encryption_password)

print(f"Decrypted String: {decrypted_string}")
```

# output



# print_stdout

**Descripción**

Imprime el mensaje en stdout

**Parámetros**

<table border="1" id="bkmrk-module-acepta-el-tip"><tbody><tr><td>**Nombre** </td><td>**Tipo**</td><td>**Requerido**</td><td>**Descripción**</td></tr><tr><td>message</td><td>str</td><td>No</td><td>Mensaje a imprimir. Por defecto es ""</td></tr></tbody></table>

**Return**

<table border="1" id="bkmrk-tipo-none" style="border-collapse: collapse; width: 100%;"><tbody><tr><td style="width: 100%;">**Tipo**</td></tr><tr><td style="width: 100%;">None</td></tr></tbody></table>

**Versión**

- 1.0.0

**Ejemplo**

```
import pandoraPlugintools as pt

# Message to be printed
message = "Disk usage exceeded threshold: 90%."

# Print the message using the print_stdout function
pt.print_stdout(message)
```

# print_stderr

**Descripción**

Imprime el mensaje en stdout

**Parámetros**

<table border="1" id="bkmrk-module-acepta-el-tip"><tbody><tr><td>**Nombre** </td><td>**Tipo**</td><td>**Requerido**</td><td>**Descripción**</td></tr><tr><td>message</td><td>str</td><td>No</td><td>Mensaje a imprimir. Por defecto es ""</td></tr></tbody></table>

**Return**

<table border="1" id="bkmrk-tipo-none" style="border-collapse: collapse; width: 100%;"><tbody><tr><td style="width: 100%;">**Tipo**</td></tr><tr><td style="width: 100%;">None</td></tr></tbody></table>

**Versión**

- 1.0.0

**Ejemplo**

```
import pandoraPlugintools as pt

# Monitoring error message to be printed
monitoring_error = "Error: Disk space running low!"

# Print the monitoring error message using the print_stderr function
pt.print_stderr(monitoring_error)
```

# print_debug

**Descripción**

Imprime cualquier lista, dict, string, float o integer como un json

**Parámetros**

<table border="1" id="bkmrk-module-acepta-el-tip"><tbody><tr><td>**Nombre** </td><td>**Tipo**</td><td>**Requerido**</td><td>**Descripción**</td></tr><tr><td><div><div>var</div></div></td><td>str</td><td>Si</td><td>Variable a imprimir</td></tr><tr><td><div><div>print_errors</div></div></td><td>bool</td><td>No</td><td>Imprime o no los errores. Por defecto es False.</td></tr></tbody></table>

**Return**

<table border="1" id="bkmrk-tipo-none" style="border-collapse: collapse; width: 100%;"><tbody><tr><td style="width: 100%;">**Tipo**</td></tr><tr><td style="width: 100%;">None</td></tr></tbody></table>

**Versión**

- 1.0.0

**Ejemplo**

```
import pandoraPlugintools as pt

# Monitoring data in dictionary format
monitoring_data = {
    "disk_usage": {
        "drive": "/dev/sda1",
        "usage": "85%"
    },
    "cpu_usage": {
        "core_1": "50%",
        "core_2": "45%"
    }
}

# Print the monitoring data using the print_debug function
pt.print_debug(monitoring_data)
```

# logger

**Descripción**

Añadir una nueva línea al archivo de registro

**Parámetros**

<table border="1" id="bkmrk-module-acepta-el-tip" style="height: 174px; width: 778px;"><tbody><tr style="height: 29px;"><td style="height: 29px; width: 91px;">**Nombre** </td><td style="height: 29px; width: 45px;">**Tipo**</td><td style="height: 29px; width: 83px;">**Requerido**</td><td style="height: 29px; width: 559px;">**Descripción**</td></tr><tr style="height: 29px;"><td style="height: 29px; width: 91px;"><div><div>log_file</div></div></td><td style="height: 29px; width: 45px;">str</td><td style="height: 29px; width: 83px;">Si</td><td style="height: 29px; width: 559px;">Ruta al archivo de registro</td></tr><tr style="height: 29px;"><td style="height: 29px; width: 91px;">message</td><td style="height: 29px; width: 45px;">str</td><td style="height: 29px; width: 83px;">Si</td><td style="height: 29px; width: 559px;">Mensaje a añadir al registro</td></tr><tr style="height: 29px;"><td style="height: 29px; width: 91px;"><div><div>log_level</div></div></td><td style="height: 29px; width: 45px;">str</td><td style="height: 29px; width: 83px;">No</td><td style="height: 29px; width: 559px;">Nivel de registro, si procede. Por defecto es una cadena vacía</td></tr><tr style="height: 29px;"><td style="height: 29px; width: 91px;">add\_date</td><td style="height: 29px; width: 45px;">bool</td><td style="height: 29px; width: 83px;">No</td><td style="height: 29px; width: 559px;">Si desea añadir la fecha y hora actuales a la entrada del registro. Por defecto es True</td></tr><tr style="height: 29px;"><td style="height: 29px; width: 91px;"><div><div>print_errors</div></div></td><td style="height: 29px; width: 45px;">bool</td><td style="height: 29px; width: 83px;">No</td><td style="height: 29px; width: 559px;">Si se imprimen los errores. Por defecto es False</td></tr></tbody></table>

**Return**

<table border="1" id="bkmrk-tipo-descripci%C3%B3n-boo" style="border-collapse: collapse; width: 100%;"><tbody><tr><td style="width: 50%;">**Tipo**</td><td style="width: 50%;">**Descripción**</td></tr><tr><td style="width: 50%;">bool</td><td style="width: 50%;">True si la entrada de registro se ha añadido correctamente, False en caso contrario</td></tr></tbody></table>

**Versión**

- 1.0.0

**Ejemplo**

```
import pandoraPlugintools as pt

# Path to the log file
log_file = "/tmp/log_file.txt"

# Log message to be added
log_message = "Disk space usage exceeded threshold."

# Log level (optional)
log_level = "WARNING"

# Add the log entry using the logger function
pt.logger(log_file, log_message, log_level)
```

# snmp



# Global variables

**Descripción**

Las siguientes variables pueden modificarse de modo global.

<table border="1" id="bkmrk-transfer_mode-modo-d" style="height: 377px;"><tbody><tr style="height: 29px;"><td style="height: 29px; width: 144.938px;">**Nombre**</td><td style="height: 29px; width: 254.969px;">**Descripción**</td><td style="height: 29px; width: 128.047px;">**Valor por defecto**</td></tr><tr style="height: 29px;"><td style="height: 29px; width: 144.938px;"><div><div>hostname</div></div></td><td style="height: 29px; width: 254.969px;">El nombre del host o dirección IP del dispositivo SNMP que deseas consultar</td><td style="height: 29px; width: 128.047px;">""</td></tr><tr style="height: 29px;"><td style="height: 29px; width: 144.938px;"><div><div>version</div></div></td><td style="height: 29px; width: 254.969px;">La versión del protocolo SNMP que se utilizará para la comunicación. Puede ser 1, 2 o 3</td><td style="height: 29px; width: 128.047px;">1</td></tr><tr style="height: 29px;"><td style="width: 144.938px; height: 29px;"><div><div>community</div></div></td><td style="width: 254.969px; height: 29px;">La cadena de comunidad utilizada en SNMPv1 y SNMPv2c para autenticar el acceso. Es como una contraseña simple que permite la lectura de información</td><td style="width: 128.047px; height: 29px;">public</td></tr><tr style="height: 29px;"><td style="width: 144.938px; height: 29px;"><div><div>user</div></div></td><td style="width: 254.969px; height: 29px;">El nombre de usuario utilizado en SNMPv3 para autenticación y autorización</td><td style="width: 128.047px; height: 29px;">""</td></tr><tr style="height: 29px;"><td style="width: 144.938px; height: 29px;"><div><div>auth_protocol</div></div></td><td style="width: 254.969px; height: 29px;">El protocolo de autenticación utilizado en SNMPv3, como "MD5" o "SHA". Debe coincidir con el protocolo configurado en el dispositivo SNMP</td><td style="width: 128.047px; height: 29px;">""</td></tr><tr style="height: 29px;"><td style="width: 144.938px; height: 29px;"><div><div>auth_password</div></div></td><td style="width: 254.969px; height: 29px;">La contraseña utilizada para autenticación en SNMPv3. Debe coincidir con la configuración del dispositivo SNMP</td><td style="width: 128.047px; height: 29px;">""</td></tr><tr style="height: 29px;"><td style="width: 144.938px; height: 29px;"><div><div>privacy_protocol</div></div></td><td style="width: 254.969px; height: 29px;">El protocolo de privacidad utilizado en SNMPv3 para cifrar los datos, como "DES" o "AES". Debe coincidir con la configuración del dispositivo SNMP</td><td style="width: 128.047px; height: 29px;">""</td></tr><tr style="height: 29px;"><td style="width: 144.938px; height: 29px;"><div><div>privacy_password</div></div></td><td style="width: 254.969px; height: 29px;">La contraseña utilizada para cifrar los datos en SNMPv3. Debe coincidir con la configuración del dispositivo SNMP</td><td style="width: 128.047px; height: 29px;">""</td></tr><tr style="height: 29px;"><td style="width: 144.938px; height: 29px;"><div><div>security_level</div></div></td><td style="width: 254.969px; height: 29px;">El nivel de seguridad utilizado en SNMPv3, que puede ser "noAuthNoPriv" (sin autenticación ni privacidad), "authNoPriv" (autenticación sin privacidad) o "authPriv" (autenticación y privacidad)</td><td style="width: 128.047px; height: 29px;"><div><div>noAuthNoPriv</div></div></td></tr><tr style="height: 29px;"><td style="width: 144.938px; height: 29px;"><div><div>timeout</div></div></td><td style="width: 254.969px; height: 29px;">El tiempo máximo en segundos que se esperará por una respuesta del dispositivo SNMP antes de que se agote el tiempo de espera</td><td style="width: 128.047px; height: 29px;">2</td></tr><tr style="height: 29px;"><td style="width: 144.938px; height: 29px;"><div><div>retries</div></div></td><td style="width: 254.969px; height: 29px;">El número de veces que se reintentará la operación SNMP en caso de que no se reciba una respuesta o se produzca un error</td><td style="width: 128.047px; height: 29px;">1</td></tr><tr style="height: 29px;"><td style="width: 144.938px; height: 29px;"><div><div>remote_port</div></div></td><td style="width: 254.969px; height: 29px;">El número de puerto remoto utilizado para la comunicación SNMP</td><td style="width: 128.047px; height: 29px;"><div><div>161</div></div></td></tr></tbody></table>

Para modificar las variables globales use la función :

[set\_global\_variable](https://pandorafms.com/guides/public/books/plugintools/page/set-global-variable-821)

**Versión**

- 1.0.0

# set_global_variable

**Descripción**

Establece el valor de una variable global en el diccionario '\_GLOBAL\_VARIABLES'.

**Parámetros**

<table border="1" id="bkmrk-module-acepta-el-tip" style="border-collapse: collapse; width: 100%;"><tbody><tr><td style="width: 12.5%;">**Nombre**</td><td style="width: 6.25%;">**Tipo**</td><td style="width: 6.25%;">**Requerido**</td><td style="width: 50%;">**Descripción**</td></tr><tr><td style="width: 12.5%;">variable\_name</td><td style="width: 6.25%;">str</td><td style="width: 6.25%;">SI</td><td style="width: 50%;">Nombre de la variable a establecer</td></tr><tr><td style="width: 12.5%;">value</td><td style="width: 6.25%;">None</td><td style="width: 6.25%;">Si</td><td style="width: 50%;">Valor a asignar a la variable</td></tr></tbody></table>

**Return**

<table border="1" id="bkmrk-tipo-none" style="border-collapse: collapse; width: 100%;"><tbody><tr><td style="width: 100%;">**Tipo**</td></tr><tr><td style="width: 100%;">None</td></tr></tbody></table>

 **Versión**

- 1.0.0

**Ejemplo**

```
import pandoraPlugintools as pt

# Define the variable name and value to set
variable_name = 'security_level'
new_value = 'auth_without_privacy'

# Set the value of the global variable
pt.snmp.set_global_variable(variable_name, new_value)

# Print the updated value of the global variable
print(f"Updated value of '{variable_name}': {pt.snmp._GLOBAL_VARIABLES[variable_name]}")
```

# get_global_variable

**Descripción**

Obtiene el valor de una variable global del diccionario '\_GLOBAL\_VARIABLES'.

**Parámetros**

<table border="1" id="bkmrk-module-acepta-el-tip" style="border-collapse: collapse; width: 100%;"><tbody><tr><td style="width: 12.5%;">**Nombre**</td><td style="width: 6.25%;">**Tipo**</td><td style="width: 6.25%;">**Requerido**</td><td style="width: 50%;">**Descripción**</td></tr><tr><td style="width: 12.5%;">variable\_name</td><td style="width: 6.25%;">str</td><td style="width: 6.25%;">Si</td><td style="width: 50%;">Nombre de la variable a establecer</td></tr></tbody></table>

**Return**

<table border="1" id="bkmrk-tipo-none" style="border-collapse: collapse; width: 100%;"><tbody><tr><td style="width: 100%;">**Tipo**</td></tr><tr><td style="width: 100%;">None</td></tr></tbody></table>

 **Versión**

- 1.0.0

**Ejemplo**

```
import pandoraPlugintools as pt

# Define the variable name to retrieve
variable_name = 'community'

# Get the value of the global variable
value = pt.snmp.get_global_variable(variable_name)

# Print the value of the global variable
print(f"The value of '{variable_name}' is: {value}")
```

# create_snmp_session

**Descripción**

Crea una sesión SNMP basada en las variables de configuración global.

**Argumentos**

<table border="1" id="bkmrk-nombre-tipo-requerid" style="border-collapse: collapse; width: 100%; height: 377px;"><tbody><tr style="height: 29px;"><td style="width: 25%; height: 29px;">**Nombre**</td><td style="width: 25%; height: 29px;">**Tipo**</td><td style="width: 25%; height: 29px;">**Requerido**</td><td style="width: 25%; height: 29px;">**Descripción**</td></tr><tr style="height: 29px;"><td style="width: 25%; height: 29px;">host</td><td style="width: 25%; height: 29px;">str</td><td style="width: 25%; height: 29px;">Si</td><td style="width: 25%; height: 29px;">Dirección IP o nombre del dispositivo SNMP</td></tr><tr style="height: 29px;"><td style="width: 25%; height: 29px;">version</td><td style="width: 25%; height: 29px;">int</td><td style="width: 25%; height: 29px;">No</td><td style="width: 25%; height: 29px;">Versión del protocolo SNMP (1, 2 o 3)</td></tr><tr style="height: 29px;"><td style="width: 25%; height: 29px;">community</td><td style="width: 25%; height: 29px;">str</td><td style="width: 25%; height: 29px;">No</td><td style="width: 25%; height: 29px;">Contraseña simple para acceso en SNMPv1/v2c</td></tr><tr style="height: 29px;"><td style="width: 25%; height: 29px;">user</td><td style="width: 25%; height: 29px;">str</td><td style="width: 25%; height: 29px;">Si</td><td style="width: 25%; height: 29px;">Nombre de usuario en SNMPv3</td></tr><tr style="height: 29px;"><td style="width: 25%; height: 29px;">auth\_protocol</td><td style="width: 25%; height: 29px;">str</td><td style="width: 25%; height: 29px;">No</td><td style="width: 25%; height: 29px;">Protocolo de autenticación en SNMPv3 (MD5, SHA, etc.)</td></tr><tr style="height: 29px;"><td style="width: 25%; height: 29px;">auth\_password</td><td style="width: 25%; height: 29px;">str</td><td style="width: 25%; height: 29px;">No</td><td style="width: 25%; height: 29px;">Contraseña de autenticación en SNMPv3</td></tr><tr style="height: 29px;"><td style="width: 25%; height: 29px;">privacy\_protocol</td><td style="width: 25%; height: 29px;">str</td><td style="width: 25%; height: 29px;">No</td><td style="width: 25%; height: 29px;">Protocolo de cifrado en SNMPv3 (DES, AES, etc.)</td></tr><tr style="height: 29px;"><td style="width: 25%; height: 29px;">privacy\_password</td><td style="width: 25%; height: 29px;">str</td><td style="width: 25%; height: 29px;">No</td><td style="width: 25%; height: 29px;">Contraseña de cifrado en SNMPv3</td></tr><tr style="height: 29px;"><td style="width: 25%; height: 29px;">security\_level</td><td style="width: 25%; height: 29px;">str</td><td style="width: 25%; height: 29px;">No</td><td style="width: 25%; height: 29px;">Nivel de seguridad en SNMPv3</td></tr><tr style="height: 29px;"><td style="width: 25%; height: 29px;">timeout</td><td style="width: 25%; height: 29px;">int</td><td style="width: 25%; height: 29px;">No</td><td style="width: 25%; height: 29px;">Tiempo máximo de espera para respuestas SNMP</td></tr><tr style="height: 29px;"><td style="width: 25%; height: 29px;">retries</td><td style="width: 25%; height: 29px;">int</td><td style="width: 25%; height: 29px;">No</td><td style="width: 25%; height: 29px;">Número de intentos en caso de fallo</td></tr><tr style="height: 29px;"><td style="width: 25%; height: 29px;">remote\_port</td><td style="width: 25%; height: 29px;">int</td><td style="width: 25%; height: 29px;">No</td><td style="width: 25%; height: 29px;">Puerto remoto para comunicación SNMP</td></tr></tbody></table>

**Return**

<table border="1" id="bkmrk-tipo-none" style="border-collapse: collapse; width: 100%;"><tbody><tr><td style="width: 50%;">**Tipo**</td><td style="width: 50%;">**Descripción**</td></tr><tr><td style="width: 50%;">Session</td><td style="width: 50%;">Una sesión SNMP configurada en base a las variables globales</td></tr></tbody></table>

 **Versión**

- 1.0.0

**Ejemplo**

```
import PandoraPlugintools as pt

# Set global variables
pt.set_global_variable('hostname', '192.168.1.1')
pt.set_global_variable('version', 2)
pt.set_global_variable('community', 'public')
pt.set_global_variable('user', 'admin')
pt.set_global_variable('auth_protocol', 'md5')
pt.set_global_variable('auth_password', 'authpass')
pt.set_global_variable('privacy_protocol', 'des')
pt.set_global_variable('privacy_password', 'privpass')
pt.set_global_variable('security_level', 'authPriv')
pt.set_global_variable('timeout', 5)
pt.set_global_variable('retries', 2)
pt.set_global_variable('remote_port', 161)

# Create an SNMP session
session = pt.create_snmp_session()
print(session)
```

# snmp_get

**Descripción**

Realiza una operación SNMP GET para recuperar el valor de un OID especificado.

**Parámetros**

<table border="1" id="bkmrk-nombre-tipo-requerid" style="border-collapse: collapse; width: 100%; height: 377px;"><tbody><tr style="height: 29px;"><td style="width: 25%; height: 29px;">**Nombre**</td><td style="width: 25%; height: 29px;">**Tipo**</td><td style="width: 25%; height: 29px;">**Requerido**</td><td style="width: 25%; height: 29px;">**Descripción**</td></tr><tr><td style="width: 25%;">oid</td><td style="width: 25%;">str</td><td style="width: 25%;">Si</td><td style="width: 25%;">El OID para la operación SNMP GET</td></tr><tr style="height: 29px;"><td style="width: 25%; height: 29px;">host</td><td style="width: 25%; height: 29px;">str</td><td style="width: 25%; height: 29px;">Si</td><td style="width: 25%; height: 29px;">Dirección IP o nombre del dispositivo SNMP</td></tr><tr style="height: 29px;"><td style="width: 25%; height: 29px;">version</td><td style="width: 25%; height: 29px;">int</td><td style="width: 25%; height: 29px;">No</td><td style="width: 25%; height: 29px;">Versión del protocolo SNMP (1, 2 o 3)</td></tr><tr style="height: 29px;"><td style="width: 25%; height: 29px;">community</td><td style="width: 25%; height: 29px;">str</td><td style="width: 25%; height: 29px;">No</td><td style="width: 25%; height: 29px;">Contraseña simple para acceso en SNMPv1/v2c</td></tr><tr style="height: 29px;"><td style="width: 25%; height: 29px;">user</td><td style="width: 25%; height: 29px;">str</td><td style="width: 25%; height: 29px;">Si</td><td style="width: 25%; height: 29px;">Nombre de usuario en SNMPv3</td></tr><tr style="height: 29px;"><td style="width: 25%; height: 29px;">auth\_protocol</td><td style="width: 25%; height: 29px;">str</td><td style="width: 25%; height: 29px;">No</td><td style="width: 25%; height: 29px;">Protocolo de autenticación en SNMPv3 (MD5, SHA, etc.)</td></tr><tr style="height: 29px;"><td style="width: 25%; height: 29px;">auth\_password</td><td style="width: 25%; height: 29px;">str</td><td style="width: 25%; height: 29px;">No</td><td style="width: 25%; height: 29px;">Contraseña de autenticación en SNMPv3</td></tr><tr style="height: 29px;"><td style="width: 25%; height: 29px;">privacy\_protocol</td><td style="width: 25%; height: 29px;">str</td><td style="width: 25%; height: 29px;">No</td><td style="width: 25%; height: 29px;">Protocolo de cifrado en SNMPv3 (DES, AES, etc.)</td></tr><tr style="height: 29px;"><td style="width: 25%; height: 29px;">privacy\_password</td><td style="width: 25%; height: 29px;">str</td><td style="width: 25%; height: 29px;">No</td><td style="width: 25%; height: 29px;">Contraseña de cifrado en SNMPv3</td></tr><tr style="height: 29px;"><td style="width: 25%; height: 29px;">security\_level</td><td style="width: 25%; height: 29px;">str</td><td style="width: 25%; height: 29px;">No</td><td style="width: 25%; height: 29px;">Nivel de seguridad en SNMPv3</td></tr><tr style="height: 29px;"><td style="width: 25%; height: 29px;">timeout</td><td style="width: 25%; height: 29px;">int</td><td style="width: 25%; height: 29px;">No</td><td style="width: 25%; height: 29px;">Tiempo máximo de espera para respuestas SNMP</td></tr><tr style="height: 29px;"><td style="width: 25%; height: 29px;">retries</td><td style="width: 25%; height: 29px;">int</td><td style="width: 25%; height: 29px;">No</td><td style="width: 25%; height: 29px;">Número de intentos en caso de fallo</td></tr><tr style="height: 29px;"><td style="width: 25%; height: 29px;">remote\_port</td><td style="width: 25%; height: 29px;">int</td><td style="width: 25%; height: 29px;">No</td><td style="width: 25%; height: 29px;">Puerto remoto para comunicación SNMP</td></tr></tbody></table>

**Return**

<table border="1" id="bkmrk-tipo-none" style="border-collapse: collapse; width: 100%; height: 58px;"><tbody><tr style="height: 29px;"><td style="width: 50%; height: 29px;">**Tipo**</td><td style="width: 50%; height: 29px;">**Descripción**</td></tr><tr style="height: 29px;"><td style="width: 50%; height: 29px;">str</td><td style="width: 50%; height: 29px;">El valor recuperado del OID especificado</td></tr></tbody></table>

 **Versión**

- 1.0.0

**Ejemplo**

```
import PandoraPlugintools as pt

# Set global variables
pt.set_global_variable('hostname', '192.168.1.1')
pt.set_global_variable('version', 2)
pt.set_global_variable('community', 'public')
pt.set_global_variable('timeout', 5)
pt.set_global_variable('retries', 2)
pt.set_global_variable('remote_port', 161)

# Create an SNMP session
session = pt.create_snmp_session()

# Specify the OID for the SNMP GET operation
oid = '1.3.6.1.2.1.1.1.0'

# Perform an SNMP GET operation
value = pt.snmp_get(session, oid)
print('SNMP GET Value:', value)
```

# snmp_walk

**Descripción**

Realiza una operación SNMP WALK para recuperar una lista de valores de un subárbol de la MIB.

**Parámetros**

<table border="1" id="bkmrk-nombre-tipo-requerid"><tbody><tr><td>**Nombre**</td><td>**Tipo**</td><td>**Requerido**</td><td>**Descripción**</td></tr><tr><td>oid</td><td>str</td><td>Si</td><td>El OID para la operación SNMP GET</td></tr><tr><td>host</td><td>str</td><td>Si</td><td>Dirección IP o nombre del dispositivo SNMP</td></tr><tr><td>version</td><td>int</td><td>No</td><td>Versión del protocolo SNMP (1, 2 o 3)</td></tr><tr><td>community</td><td>str</td><td>No</td><td>Contraseña simple para acceso en SNMPv1/v2c</td></tr><tr><td>user</td><td>str</td><td>Si</td><td>Nombre de usuario en SNMPv3</td></tr><tr><td>auth\_protocol</td><td>str</td><td>No</td><td>Protocolo de autenticación en SNMPv3 (MD5, SHA, etc.)</td></tr><tr><td>auth\_password</td><td>str</td><td>No</td><td>Contraseña de autenticación en SNMPv3</td></tr><tr><td>privacy\_protocol</td><td>str</td><td>No</td><td>Protocolo de cifrado en SNMPv3 (DES, AES, etc.)</td></tr><tr><td>privacy\_password</td><td>str</td><td>No</td><td>Contraseña de cifrado en SNMPv3</td></tr><tr><td>security\_level</td><td>str</td><td>No</td><td>Nivel de seguridad en SNMPv3</td></tr><tr><td>timeout</td><td>int</td><td>No</td><td>Tiempo máximo de espera para respuestas SNMP</td></tr><tr><td>retries</td><td>int</td><td>No</td><td>Número de intentos en caso de fallo</td></tr><tr><td>remote\_port</td><td>int</td><td>No</td><td>Puerto remoto para comunicación SNMP</td></tr></tbody></table>

<table border="1" id="bkmrk-tipo-none" style="border-collapse: collapse; width: 100%; height: 58px;"><tbody><tr style="height: 29px;"><td style="width: 50%; height: 29px;">**Tipo**</td><td style="width: 50%; height: 29px;">**Descripción**</td></tr><tr style="height: 29px;"><td style="width: 50%; height: 29px;">dict</td><td style="width: 50%; height: 29px;">Diccionario con la OID y el valor de cada elemento.</td></tr></tbody></table>

- 1.0.0

**Ejemplo**

```
import PandoraPlugintools as pt

# Set global variables
pt.set_global_variable('hostname', '192.168.1.1')
pt.set_global_variable('version', 2)
pt.set_global_variable('community', 'public')
pt.set_global_variable('timeout', 5)
pt.set_global_variable('retries', 2)
pt.set_global_variable('remote_port', 161)

# Create an SNMP session
session = pt.create_snmp_session()

# Specify the OID for the SNMP WALK operation
oid = '1.3.6.1.2.1.2.2.1.2'  # Example OID for interface descriptions

# Perform an SNMP WALK operation
values = pt.snmp_walk(session, oid)
for value in values:
    print('SNMP WALK Value:', value)
```

# snmp_trap

**Descripción**

Envía un trap SNMP a la IP de destino especificada utilizando el OID, valor y comunidad dados.

**Parámetros**

<table border="1" id="bkmrk-module-acepta-el-tip" style="border-collapse: collapse; width: 100%; height: 162px;"><tbody><tr style="height: 46px;"><td style="width: 12.5%; height: 46px;">**Nombre**</td><td style="width: 6.25%; height: 46px;">**Tipo**</td><td style="width: 6.25%; height: 46px;">**Requerido**</td><td style="width: 50%; height: 46px;">**Descripción**</td></tr><tr style="height: 29px;"><td style="width: 12.5%; height: 29px;"><div><div>trap_oid</div></div></td><td style="width: 6.25%; height: 29px;"><div><div>str</div></div></td><td style="width: 6.25%; height: 29px;"><div><div>Si</div></div></td><td style="width: 50%; height: 29px;">El OID para el trap SNMP</td></tr><tr style="height: 29px;"><td style="width: 12.5%; height: 29px;"><div><div>trap_value</div></div></td><td style="width: 6.25%; height: 29px;"><div><div>str</div></div></td><td style="width: 6.25%; height: 29px;"><div><div>SI</div></div></td><td style="width: 50%; height: 29px;">El valor asociado a la trampa</td></tr><tr style="height: 29px;"><td style="width: 12.5%; height: 29px;"><div><div>destination_ip</div></div></td><td style="width: 6.25%; height: 29px;"><div><div>str</div></div></td><td style="width: 6.25%; height: 29px;"><div><div>Si</div></div></td><td style="width: 50%; height: 29px;">La dirección IP del destino de la trampa</td></tr><tr style="height: 29px;"><td style="width: 12.5%; height: 29px;"><div><div>community</div></div></td><td style="width: 6.25%; height: 29px;"><div><div>str</div></div></td><td style="width: 6.25%; height: 29px;"><div><div>Si</div></div></td><td style="width: 50%; height: 29px;">La cadena de comunidad SNMP para la autenticación</td></tr></tbody></table>

**Return**

<table border="1" id="bkmrk-tipo-none" style="border-collapse: collapse; width: 100%;"><tbody><tr><td style="width: 100%;">**Tipo**</td></tr><tr><td style="width: 100%;">None</td></tr></tbody></table>

 **Versión**

- 1.0.0

**Ejemplo**

```
import PandoraPlugintools as pt

# Specify the trap details
trap_oid = '1.3.6.1.4.1.12345.1.0'  # Example OID for custom trap
trap_value = 'Trap from my application'
destination_ip = '192.168.1.2'
community = 'public'

# Send an SNMP trap
pt.send_trap(trap_oid, trap_value, destination_ip, community)
print('SNMP Trap sent successfully.')
```

# class SNMPTarget

**Descripción**

Una clase que representa un objetivo SNMP, proporcionando métodos para establecer la configuración SNMP  
y realizar operaciones SNMP como GET y WALK.

**Ejemplo**

```
import pandoraPlugintools as pt

target = pt.SNMPTarget(
    host="192.168.1.1",
    community="public",
    version=2,
    timeout=5,
    retries=3
)
```

### **Funciones**

##### **snmp\_get**

<div id="bkmrk-"><div>  
</div></div>**Descripción**

**Parámetros**

<div id="bkmrk-nombre-tipo-requerid"><table border="1" id="bkmrk-module-acepta-el-tip" style="height: 58px;"><tbody><tr style="height: 29px;"><td style="width: 97.7344px; height: 29px;">**Nombre**</td><td style="width: 45.4062px; height: 29px;">**Tipo**</td><td style="width: 83.0938px; height: 29px;">**Requerido**</td><td style="width: 334.297px; height: 29px;">**Descripción**</td></tr><tr style="height: 29px;"><td style="width: 97.7344px; height: 29px;">oid</td><td style="width: 45.4062px; height: 29px;">str</td><td style="width: 83.0938px; height: 29px;">SI</td><td style="width: 334.297px; height: 29px;">El OID para la operación SNMP GET</td></tr></tbody></table>

</div>**Return**

<table border="1" id="bkmrk-tipo-none" style="border-collapse: collapse; width: 100%; height: 58px;"><tbody><tr style="height: 29px;"><td style="width: 50%; height: 29px;">**Tipo**</td><td style="width: 50%; height: 29px;">**Descripción**</td></tr><tr style="height: 29px;"><td style="width: 50%; height: 29px;">str</td><td style="width: 50%; height: 29px;">El valor recuperado del OID especificado</td></tr></tbody></table>

**Versión**

<div id="bkmrk-1.0.0"><div><div>- 1.0.0

</div></div></div>**Ejemplo**

```
import pandoraPlugintools as pt

target = pt.SNMPTarget(
    host="192.168.1.1",
    community="public",
    version=2,
    timeout=5,
    retries=3
)

oid_value = target.snmp_get("1.3.6.1.2.1.1.1.0")
print("Valor del OID 1.3.6.1.2.1.1.1.0:", oid_value)
```

##### **snmp\_walk**

<div id="bkmrk-descripci%C3%B3n-0"><div>**Descripción**</div></div>**Parámetros**

<div id="bkmrk-nombre-tipo-requerid-0"><div><table border="1" id="bkmrk-nombre-tipo-requerid-1" style="height: 58px;"><tbody><tr style="height: 29px;"><td style="width: 97.7344px; height: 29px;">**Nombre**</td><td style="width: 45.4062px; height: 29px;">**Tipo**</td><td style="width: 83.0938px; height: 29px;">**Requerido**</td><td style="width: 334.297px; height: 29px;">**Descripción**</td></tr><tr style="height: 29px;"><td style="width: 97.7344px; height: 29px;">oid</td><td style="width: 45.4062px; height: 29px;">str</td><td style="width: 83.0938px; height: 29px;">Si</td><td style="width: 334.297px; height: 29px;">El OID para la operación SNMP WALK</td></tr></tbody></table>

</div></div><table border="1" id="bkmrk-tipo-descripci%C3%B3n-dic" style="border-collapse: collapse; width: 100%; height: 58px;"><tbody><tr style="height: 29px;"><td style="width: 50%; height: 29px;">**Tipo**</td><td style="width: 50%; height: 29px;">**Descripción**</td></tr><tr style="height: 29px;"><td style="width: 50%; height: 29px;">dict</td><td style="width: 50%; height: 29px;">Diccionario con la OID y el valor de cada elemento.</td></tr></tbody></table>

**Versión**

<div id="bkmrk-1.0.0-0"><div><div>- 1.0.0

</div></div></div>**Ejemplo**

```
import pandoraPlugintools as pt

target = pt.SNMPTarget(
    host="192.168.1.1",
    community="public",
    version=2,
    timeout=5,
    retries=3
)

oid_values_dict = target.snmp_walk("1.3.6.1.2.1.2.2.1.2")
print("Valores del OID 1.3.6.1.2.1.2.2.1.2:", oid_values_dict)
```