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