# MQTT

# Introduction

**The purpose of this plugin is to be able to receive messages from an MQTT topic**, having the possibility to apply filters such as words or the text format of the expected messages.

The plugin performs all these actions through a client with which it connects.

# Compatibility matrix

<table border="1" id="bkmrk-sistemas-donde-se-ha-1" style="width: 88.3951%;"><tbody><tr><td style="width: 42.8064%;">**Systems where tested**</td><td style="width: 57.1966%;">Rocky linux, Fedora 34</td></tr><tr><td style="width: 42.8064%;">**Systems where it works**</td><td style="width: 57.1966%;">Any linux system  
</td></tr></tbody></table>

# Prerrequisites

- Connectivity to the host and topic from which messages are to be received is required.

# Parameters

**Connectivity parameters**

<table border="1" id="bkmrk--i%2C---host-direcci%C3%B3n" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 50%;"></col><col style="width: 50%;"></col></colgroup><tbody><tr><td>-i, --host  
</td><td>MQTT' server address</td></tr><tr><td>-p, --port  
</td><td>MQTT' port address</td></tr></tbody></table>

**Parameters for posting message in topic**

<table border="1" id="bkmrk--m%2C---message-mensaj" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 50%;"></col><col style="width: 50%;"></col></colgroup><tbody><tr><td>-m, --message  
</td><td>MQTT message to be sent</td></tr><tr><td>-s, --publish\_topic  
</td><td>MQTT publication topic</td></tr></tbody></table>

**Parameters for receiving messages and filtering**

<table border="1" id="bkmrk--r%2C---suscribe_topic" style="border-collapse: collapse; width: 100%; height: 149px;"><colgroup><col style="width: 50%;"></col><col style="width: 50%;"></col></colgroup><tbody><tr style="height: 29.8px;"><td style="height: 29.8px;">-r, --suscribe\_topic  
</td><td style="height: 29.8px;">MQTT subscription topic</td></tr><tr style="height: 29.8px;"><td style="height: 29.8px;">-t, --time  
</td><td style="height: 29.8px;">Duration of run time in seconds</td></tr><tr style="height: 29.8px;"><td style="height: 29.8px;">-f, --filter  
</td><td style="height: 29.8px;">Filter (word) to apply. Only messages containing the word will be received.  
</td></tr><tr style="height: 29.8px;"><td style="height: 29.8px;">-k, --format  
</td><td style="height: 29.8px;">Text format of the expected messages to be received  
</td></tr><tr style="height: 29.8px;"><td style="height: 29.8px;">-l, --limit  
</td><td style="height: 29.8px;">Message limit</td></tr></tbody></table>

**Pandora configuration parameters**

<table border="1" id="bkmrk---agent_name-nombre-" style="border-collapse: collapse; width: 100%; height: 314.8px;"><colgroup><col style="width: 50%;"></col><col style="width: 50%;"></col></colgroup><tbody><tr style="height: 46.6px;"><td style="height: 46.6px;">--agent\_name  
</td><td style="height: 46.6px;">Name of the agent to be created or in which the module is to be created  
</td></tr><tr style="height: 29.8px;"><td style="height: 29.8px;">--interval</td><td style="height: 29.8px;">Agent monitoring interval</td></tr><tr style="height: 29.8px;"><td style="height: 29.8px;">--temporal</td><td style="height: 29.8px;">PandoraFMS temporary directory</td></tr><tr style="height: 29.8px;"><td style="height: 29.8px;">--data\_dir  
</td><td style="height: 29.8px;">PandoraFMS Data Directory</td></tr><tr style="height: 29.8px;"><td style="height: 29.8px;">--group  
</td><td style="height: 29.8px;">PandoraFMS Target Group</td></tr><tr style="height: 29.8px;"><td style="height: 29.8px;">--transfer\_mode  
</td><td style="height: 29.8px;">Data transfer mode, local or tentacle</td></tr><tr style="height: 29.8px;"><td style="height: 29.8px;">--tentacle\_client  
</td><td style="height: 29.8px;">Tentacle client path, by default "tentacle\_client".</td></tr><tr style="height: 29.8px;"><td style="height: 29.8px;">--tentacle\_opts  
</td><td style="height: 29.8px;">Tentacle extra options  
</td></tr><tr style="height: 29.8px;"><td style="height: 29.8px;">--tentacle\_port  
</td><td style="height: 29.8px;">Tentacle port  
</td></tr><tr style="height: 29.8px;"><td style="height: 29.8px;">--tentacle\_address  
</td><td style="height: 29.8px;">Tentacle IP  
</td></tr></tbody></table>

**Extra parameters**

<table border="1" id="bkmrk---log_file-ruta-dond" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 50%;"></col><col style="width: 50%;"></col></colgroup><tbody><tr><td>--log\_file  
</td><td>Path where the log file will be generated</td></tr></tbody></table>

# Manual execution

The plugin execution format is as follows:

```
./pandora_mqtt --agent_name < agent name > --host < host > --port < port >  \
[ --message < message > ] [ --publish_topic < publish_topic > ] \
[ --subscribe_topic < subscribe_topic > ] [ --time < time > ] \
[ --filter < filter > ] [ --format < format > ] [ --limit < limit > ] \
[ --transfer_mode < local o tentacle > ] [ --tentacle_port < tentacle_port > ] \
[ --tentacle_address < tentacle_address > ] [ --tentacle_client < tentacle client path ] \
[ --tentacle_opts < tentacle extra options ][ -g < group > ] [ --data_dir < data dir > ] \
[ --temporal < temporary directory path > ] [ --interval < interval agent monitorings in seconds > ] \ 
[ --logfile < logfile path > ]
```

# Configuration in Pandora

To configure the plugin in PandoraFMS, the following steps must be followed:

**1.Upload the plugin to PandoraFMS, for example in the following path:**

```
/etc/pandora/plugin
```

**2. Go to the plugins section and create a new one:**

[![imagen.png](https://pandorafms.com/guides/public/uploads/images/gallery/2024-01/scaled-1680-/VNOimagen.png)](https://pandorafms.com/guides/public/uploads/images/gallery/2024-01/VNOimagen.png)

 **3. Name, description and timeout are added:**

[![imagen.png](https://pandorafms.com/guides/public/uploads/images/gallery/2024-01/scaled-1680-/ERUimagen.png)](https://pandorafms.com/guides/public/uploads/images/gallery/2024-01/ERUimagen.png)

**4. The path to the plugin is added to the command and the necessary parameters for the execution of the plugin are added.**

<p class="callout info">For each parameter a macro must be configured, being the syntax of this macro the following : \_fieldx\_, where x is the positional number of the parameter, for example in the following image we see the parameters that are necessary to use to subscribe to a topic and receive messages.</p>

[![imagen.png](https://pandorafms.com/guides/public/uploads/images/gallery/2024-01/scaled-1680-/HPnimagen.png)](https://pandorafms.com/guides/public/uploads/images/gallery/2024-01/HPnimagen.png)

**5. Configure the above macros, adding in each one the value of the parameter:**

[![imagen.png](https://pandorafms.com/guides/public/uploads/images/gallery/2024-01/scaled-1680-/sDmimagen.png)](https://pandorafms.com/guides/public/uploads/images/gallery/2024-01/sDmimagen.png)

**6.** **Once configured, you should create a module in an agent that executes the plugin. In the modules menu of an agent we create a new plugin type module:**

[![imagen.png](https://pandorafms.com/guides/public/uploads/images/gallery/2024-01/scaled-1680-/503imagen.png)](https://pandorafms.com/guides/public/uploads/images/gallery/2024-01/503imagen.png)

**7.In the module configuration menu, give it a name, select the previously configured plugin and click on "create".**

[![imagen.png](https://pandorafms.com/guides/public/uploads/images/gallery/2024-01/scaled-1680-/kZHimagen.png)](https://pandorafms.com/guides/public/uploads/images/gallery/2024-01/kZHimagen.png)

**8.In the agent selected with the --agent\_name parameter, a new module of list format will be created, which will contain the messages received by the plugin execution.**

[![imagen.png](https://pandorafms.com/guides/public/uploads/images/gallery/2024-01/scaled-1680-/3G0imagen.png)](https://pandorafms.com/guides/public/uploads/images/gallery/2024-01/3G0imagen.png)

# Agent and modules generated by the plugin

- The plugin will create an agent with the selected name with the --agent\_name parameter. Or in its defect it will insert the module in an agent that already exists with this name.
- The plugin will create a module:

<table border="1" id="bkmrk-mqtt.%3Ctopic-de-subsc" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 50%;"></col><col style="width: 50%;"></col></colgroup><tbody><tr><td>MQTT.&lt;suscribe topic&gt;.results  
</td><td>Results obtained in list format, i.e. the messages received that have passed the filters used.</td></tr></tbody></table>