2025-05-22 19:24:13 +00:00
# Existing Plugins
2025-06-28 03:08:09 +00:00
With the aMQTT plugins framework, one can add additional functionality without
having to rewrite core logic in the broker or client. Plugins can be loaded and configured using
the `plugins` section of the config file (or parameter passed to the class).
## Broker
By default, `EventLoggerPlugin` , `PacketLoggerPlugin` , `AnonymousAuthPlugin` and `BrokerSysPlugin` are activated
and configured for the broker:
2025-05-22 19:24:13 +00:00
2025-05-30 22:50:31 +00:00
```yaml
2025-06-28 03:08:09 +00:00
--8< -- " amqtt / scripts / default_broker . yaml "
2025-05-22 22:24:51 +00:00
```
2025-05-22 19:24:13 +00:00
2025-05-22 22:24:51 +00:00
2025-06-28 03:08:09 +00:00
??? warning "Loading plugins from EntryPoints in `pyproject.toml` has been deprecated"
Previously, all plugins were loaded from EntryPoints:
```toml
--8< -- " pyproject . toml:included "
```
2025-05-22 19:24:13 +00:00
2025-07-30 13:32:56 +00:00
But the previous default config only caused 4 plugins to be active:
2025-06-28 03:08:09 +00:00
```yaml
--8< -- " samples / legacy . yaml "
```
## Client
2025-08-05 15:56:05 +00:00
By default, the `PacketLoggerPlugin` is activated and configured for the client:
2025-06-28 03:08:09 +00:00
```yaml
--8< -- " amqtt / scripts / default_client . yaml "
```
## Plugins
### Anonymous (Auth Plugin)
`amqtt.plugins.authentication.AnonymousAuthPlugin`
2025-05-22 19:24:13 +00:00
2025-08-05 15:56:05 +00:00
Authentication plugin allowing anonymous access.
::: amqtt.plugins.authentication.AnonymousAuthPlugin.Config
options:
heading_level: 4
extra:
class_style: "simple"
2025-05-22 22:24:51 +00:00
2025-05-22 19:24:13 +00:00
2025-05-28 11:45:12 +00:00
!!! danger
2025-06-28 03:08:09 +00:00
even if `allow_anonymous` is set to `false` , the plugin will still allow access if a username is provided by the client
2025-05-28 11:45:12 +00:00
2025-06-28 03:08:09 +00:00
??? warning "EntryPoint-style configuration is deprecated"
2025-05-28 11:45:12 +00:00
2025-06-28 03:08:09 +00:00
```yaml
auth:
plugins:
- auth_anonymous
allow-anonymous: true # if false, providing a username will allow access
```
2025-05-22 22:24:51 +00:00
2025-06-28 03:08:09 +00:00
### Password File (Auth Plugin)
`amqtt.plugins.authentication.FileAuthPlugin`
2025-05-22 19:24:13 +00:00
2025-08-05 15:56:05 +00:00
Authentication plugin based on a file-stored user database.
2025-05-22 19:24:13 +00:00
2025-08-05 15:56:05 +00:00
::: amqtt.plugins.authentication.FileAuthPlugin.Config
options:
heading_level: 4
extra:
class_style: "simple"
2025-05-22 19:24:13 +00:00
2025-06-28 03:08:09 +00:00
??? warning "EntryPoint-style configuration is deprecated"
```yaml
auth:
plugins:
- auth_file
password-file: /path/to/password_file
```
2025-05-22 22:24:51 +00:00
**File Format**
2025-05-22 19:24:13 +00:00
The file includes `username:password` pairs, one per line.
The password should be encoded using sha-512 with `mkpasswd -m sha-512` or:
```python
import sys
from getpass import getpass
from passlib.hash import sha512_crypt
passwd = input() if not sys.stdin.isatty() else getpass()
print(sha512_crypt.hash(passwd))
```
2025-05-22 22:24:51 +00:00
2025-06-28 03:08:09 +00:00
### Taboo (Topic Plugin)
2025-05-22 22:24:51 +00:00
2025-06-28 03:08:09 +00:00
`amqtt.plugins.topic_checking.TopicTabooPlugin`
2025-05-28 11:45:12 +00:00
2025-05-22 22:24:51 +00:00
Prevents using topics named: `prohibited` , `top-secret` , and `data/classified`
**Configuration**
```yaml
2025-06-28 03:08:09 +00:00
plugins:
2025-07-04 20:05:55 +00:00
amqtt.plugins.topic_checking.TopicTabooPlugin:
2025-05-22 22:24:51 +00:00
```
2025-06-28 03:08:09 +00:00
??? warning "EntryPoint-style configuration is deprecated"
```yaml
topic-check:
enabled: true
plugins:
- topic_taboo
```
2025-05-22 22:24:51 +00:00
2025-06-28 03:08:09 +00:00
### ACL (Topic Plugin)
`amqtt.plugins.topic_checking.TopicAccessControlListPlugin`
2025-05-28 11:45:12 +00:00
2025-05-22 22:24:51 +00:00
**Configuration**
2025-07-26 19:47:49 +00:00
Each acl category are a list a key-value pair, where:
2025-05-30 22:50:31 +00:00
2025-07-26 19:47:49 +00:00
> `<username>:["<topic1>", "<topic2>", ...]` *(string, list[string])*: username of the client followed by a list of allowed topics (wildcards are supported: `#`, `+`).
2025-05-30 22:50:31 +00:00
2025-07-26 19:47:49 +00:00
!!! info "`#` and `$SYS` topics"
Per the MQTT 3.1.1 spec 4.7.2, a single `#` will not allow access to `$` broker
topics; need to additionally specify `$SYS/#` to allow a client full access subscribe & receive.
Also MQTT spec prevents clients from publishing to topics starting with `$` ; these will be ignored.
If set to `None` , no restrictions are placed on client subscriptions (legacy behavior). An empty list will block clients from using any topics.
- `subscribe-acl` *(mapping)* : determines subscription access.
- `acl` *(mapping)* : Deprecated and replaced by `subscribe-acl` .
- `publish-acl` *(mapping)* : determines publish access.
- `receive-acl` *(mapping)* : determines if a message can be sent to a client.
2025-05-30 22:50:31 +00:00
!!! info "Reserved usernames"
- The username `admin` is allowed access to all topics.
- The username `anonymous` will control allowed topics, if using the `auth_anonymous` plugin.
2025-05-22 22:24:51 +00:00
```yaml
2025-06-28 03:08:09 +00:00
plugins:
2025-07-04 20:05:55 +00:00
amqtt.plugins.topic_checking.TopicAccessControlListPlugin:
acl:
- username: ["list", "of", "allowed", "topics", "for", "subscribing"]
- .
publish_acl:
- username: ["list", "of", "allowed", "topics", "for", "publishing"]
- .
2025-05-22 22:24:51 +00:00
```
2025-06-28 03:08:09 +00:00
??? warning "EntryPoint-style configuration is deprecated"
```yaml
topic-check:
enabled: true
plugins:
- topic_acl
publish-acl:
- username: ["list", "of", "allowed", "topics", "for", "publishing"]
- .
acl:
- username: ["list", "of", "allowed", "topics", "for", "subscribing"]
- .
```
### $SYS topics
2025-05-22 17:20:49 +00:00
2025-06-28 03:08:09 +00:00
`amqtt.plugins.sys.broker.BrokerSysPlugin`
2025-05-30 22:50:31 +00:00
2025-05-22 17:20:49 +00:00
Publishes, on a periodic basis, statistics about the broker
2025-05-30 22:50:31 +00:00
**Configuration**
2025-05-22 17:20:49 +00:00
2025-07-04 20:08:24 +00:00
- `sys_interval` - int, seconds between updates (default: 20)
2025-07-04 20:05:55 +00:00
2025-06-28 03:08:09 +00:00
```yaml
plugins:
2025-07-04 20:05:55 +00:00
amqtt.plugins.sys.broker.BrokerSysPlugin:
sys_interval: 20 # int, seconds between updates
2025-06-28 03:08:09 +00:00
```
2025-05-22 17:20:49 +00:00
2025-05-30 22:50:31 +00:00
**Supported Topics**
2025-05-22 17:20:49 +00:00
2025-06-28 03:08:09 +00:00
- `$SYS/broker/version` *(string)*
- `$SYS/broker/load/bytes/received` *(int)*
- `$SYS/broker/load/bytes/sent` *(int)*
- `$SYS/broker/messages/received` *(int)*
- `$SYS/broker/messages/sent` *(int)*
- `$SYS/broker/time` *(int, current time in epoch seconds)*
- `$SYS/broker/uptime` *(int, seconds since broker start)*
- `$SYS/broker/uptime/formatted` *(string, start time of broker in UTC)*
- `$SYS/broker/clients/connected` *(int, number of currently connected clients)*
- `$SYS/broker/clients/disconnected` *(int, number of clients that have disconnected)*
- `$SYS/broker/clients/maximum` *(int, maximum number of clients connected)*
- `$SYS/broker/clients/total` *(int)*
- `$SYS/broker/messages/inflight` *(int)*
- `$SYS/broker/messages/inflight/in` *(int)*
- `$SYS/broker/messages/inflight/out` *(int)*
- `$SYS/broker/messages/inflight/stored` *(int)*
- `$SYS/broker/messages/publish/received` *(int)*
- `$SYS/broker/messages/publish/sent` *(int)*
- `$SYS/broker/messages/retained/count` *(int)*
- `$SYS/broker/messages/subscriptions/count` *(int)*
- `$SYS/broker/heap/size` *(float, MB)*
- `$SYS/broker/heap/maximum` *(float, MB)*
- `$SYS/broker/cpu/percent` *(float, %)*
- `$SYS/broker/cpu/maximum` *(float, %)*
### Event Logger
`amqtt.plugins.logging_amqtt.EventLoggerPlugin`
This plugin issues log messages when [broker and mqtt events ](custom_plugins.md#events ) are triggered:
- info level messages for `client connected` and `client disconnected`
- debug level for all others
2025-07-04 20:05:55 +00:00
```yaml
plugins:
amqtt.plugins.logging_amqtt.EventLoggerPlugin:
```
2025-06-28 03:08:09 +00:00
### Packet Logger
`amqtt.plugins.logging_amqtt.PacketLoggerPlugin`
2025-07-30 13:32:56 +00:00
This plugin issues debug-level messages for [mqtt events ](custom_plugins.md#events ): `on_mqtt_packet_sent`
2025-06-28 03:08:09 +00:00
and `on_mqtt_packet_received` .
2025-07-04 20:05:55 +00:00
```yaml
plugins:
amqtt.plugins.logging_amqtt.PacketLoggerPlugin:
```