From b99f949363e929fb5c7beb8464c63aa4c1a464b8 Mon Sep 17 00:00:00 2001 From: jokob-sk Date: Sat, 15 Mar 2025 08:13:14 +1100 Subject: [PATCH] MQTT #1019 --- front/php/templates/language/pt_br.json | 0 front/plugins/README.md | 113 +----------------------- front/plugins/_publisher_mqtt/mqtt.py | 13 +-- 3 files changed, 9 insertions(+), 117 deletions(-) mode change 100644 => 100755 front/php/templates/language/pt_br.json diff --git a/front/php/templates/language/pt_br.json b/front/php/templates/language/pt_br.json old mode 100644 new mode 100755 diff --git a/front/plugins/README.md b/front/plugins/README.md index 278e4ac2..8ca76057 100755 --- a/front/plugins/README.md +++ b/front/plugins/README.md @@ -1,112 +1 @@ -# πŸ”Œ Plugins - -NetAlertX supports additional plugins to extend its functionality, each with its own settings and options. Plugins can be loaded via the General -> `LOADED_PLUGINS` setting. For custom plugin development, refer to the [Plugin development guide](/docs/PLUGINS_DEV.md). - ->[!NOTE] -> Please check this [Plugins debugging guide](https://github.com/jokob-sk/NetAlertX/blob/main/docs/DEBUG_PLUGINS.md) and the corresponding Plugin documentation in the below table if you are facing issues. - -## ⚑ Quick start - -> [!TIP] -> You can load additional Plugins via the General -> `LOADED_PLUGINS` setting. - -1. Pick your `πŸ” dev scanner` plugin (e.g. `ARPSCAN` or `NMAPDEV`), or import devices into the application with an `πŸ“₯ importer` plugin. (See **βœ…Enabling plugins** below) -2. Pick a `▢️ publisher` plugin, if you want to send notifications. If you don't see a publisher you'd like to use, look at the [πŸ“š_publisher_apprise](/front/plugins/_publisher_apprise/) plugin which is a proxy for over 80 notification services. -3. Setup your [Network topology diagram](/docs/NETWORK_TREE.md) -4. Fine-tune [Notifications](/docs/NOTIFICATIONS.md) -5. [Backup your setup](/docs/BACKUPS.md) -6. Contribute and [Create custom plugins](/docs/PLUGINS_DEV.md) - - -## πŸ“‘ Available Plugins - -Device-detecting plugins insert values into the `CurrentScan` database table. The plugins that are not required are safe to ignore, however, it makes sense to have at least some device-detecting plugins enabled, such as `ARPSCAN` or `NMAPDEV`. - - -| ID | Type | Description | Features | Required | Data source | Detailed docs | -|---------------|---------|--------------------------------------------|----------|----------|--------------|---------------------------------------------------------------------| -| `APPRISE` | ▢️ | Apprise notification proxy | | | Script | [_publisher_apprise](/front/plugins/_publisher_apprise/) | -| `ARPSCAN` | πŸ” | ARP-scan on current network | | | Script | [arp_scan](/front/plugins/arp_scan/) | -| `AVAHISCAN` | πŸ†Ž | Avahi (mDNS-based) name resolution | | | Script | [avahi_scan](/front/plugins/avahi_scan/) | -| `ASUSWRT` | πŸ” | Import connected devices from AsusWRT | | | Script | [asuswrt_import](/front/plugins/asuswrt_import/) | -| `CSVBCKP` | βš™ | CSV devices backup | | | Script | [csv_backup](/front/plugins/csv_backup/) | -| `CUSTPROP` | βš™ | Managing custom device properties values | | Yes | Template | [custom_props](/front/plugins/custom_props/) | -| `DBCLNP` | βš™ | Database cleanup | | Yes* | Script | [db_cleanup](/front/plugins/db_cleanup/) | -| `DDNS` | βš™ | DDNS update | | | Script | [ddns_update](/front/plugins/ddns_update/) | -| `DHCPLSS` | πŸ”/πŸ“₯/πŸ†Ž| Import devices from DHCP leases | | | Script | [dhcp_leases](/front/plugins/dhcp_leases/) | -| `DHCPSRVS` | β™» | DHCP servers | | | Script | [dhcp_servers](/front/plugins/dhcp_servers/) | -| `FREEBOX` | πŸ”/β™»/πŸ†Ž| Pull data and names from Freebox/Iliadbox | | | Script | [freebox](/front/plugins/freebox/) | -| `ICMP` | πŸ” | ICMP (ping) status checker | | | Script | [icmp_scan](/front/plugins/icmp_scan/) | -| `INTRNT` | πŸ” | Internet IP scanner | | | Script | [internet_ip](/front/plugins/internet_ip/) | -| `INTRSPD` | β™» | Internet speed test | | | Script | [internet_speedtest](/front/plugins/internet_speedtest/) | -| `IPNEIGH` | πŸ” | Scan ARP (IPv4) and NDP (IPv6) tables | | | Script | [ipneigh](/front/plugins/ipneigh/) | -| `LUCIRPC` | πŸ” | Import connected devices from OpenWRT | | | Script | [luci_import](/front/plugins/luci_import/) | -| `MAINT` | βš™ | Maintenance of logs, etc. | | | Script | [maintenance](/front/plugins/maintenance/) | -| `MQTT` | ▢️ | MQTT for synching to Home Assistant | | | Script | [_publisher_mqtt](/front/plugins/_publisher_mqtt/) | -| `NBTSCAN` | πŸ†Ž | Nbtscan (NetBIOS-based) name resolution | | | Script | [nbtscan_scan](/front/plugins/nbtscan_scan/) | -| `NEWDEV` | βš™ | New device template | | Yes | Template | [newdev_template](/front/plugins/newdev_template/) | -| `NMAP` | β™» | Nmap port scanning & discovery | | | Script | [nmap_scan](/front/plugins/nmap_scan/) | -| `NMAPDEV` | πŸ” | Nmap dev scan on current network | | | Script | [nmap_dev_scan](/front/plugins/nmap_dev_scan/) | -| `NSLOOKUP` | πŸ†Ž | NSLookup (DNS-based) name resolution | | | Script | [nslookup_scan](/front/plugins/nslookup_scan/) | -| `NTFPRCS` | βš™ | Notification processing | | Yes | Template | [notification_processing](/front/plugins/notification_processing/)| -| `NTFY` | ▢️ | NTFY notifications | | | Script | [_publisher_ntfy](/front/plugins/_publisher_ntfy/) | -| `OMDSDN` | πŸ“₯/πŸ†Ž | OMADA TP-Link import | πŸ–§ πŸ”„ | | Script | [omada_sdn_imp](/front/plugins/omada_sdn_imp/) | -| `PIHOLE` | πŸ”/πŸ†Ž/πŸ“₯| Pi-hole device import & sync | | | SQLite DB | [pihole_scan](/front/plugins/pihole_scan/) | -| `PUSHSAFER` | ▢️ | Pushsafer notifications | | | Script | [_publisher_pushsafer](/front/plugins/_publisher_pushsafer/) | -| `PUSHOVER` | ▢️ | Pushover notifications | | | Script | [_publisher_pushover](/front/plugins/_publisher_pushover/) | -| `SETPWD` | βš™ | Set password | | Yes | Template | [set_password](/front/plugins/set_password/) | -| `SMTP` | ▢️ | Email notifications | | | Script | [_publisher_email](/front/plugins/_publisher_email/) | -| `SNMPDSC` | πŸ”/πŸ“₯ | SNMP device import & sync | | | Script | [snmp_discovery](/front/plugins/snmp_discovery/) | -| `SYNC` | πŸ”/βš™/πŸ“₯| Sync & import from NetAlertX instances | πŸ–§ πŸ”„ | Yes | Script | [sync](/front/plugins/sync/) | -| `TELEGRAM` | ▢️ | Telegram notifications | | | Script | [_publisher_telegram](/front/plugins/_publisher_telegram/) | -| `UI` | β™» | UI specific settings | | Yes | Template | [ui_settings](/front/plugins/ui_settings/) | -| `UNFIMP` | πŸ”/πŸ“₯/πŸ†Ž| UniFi device import & sync | πŸ–§ | | Script | [unifi_import](/front/plugins/unifi_import/) | -| `VNDRPDT` | βš™ | Vendor database update | | | Script | [vendor_update](/front/plugins/vendor_update/) | -| `WEBHOOK` | ▢️ | Webhook notifications | | | Script | [_publisher_webhook](/front/plugins/_publisher_webhook/) | -| `WEBMON` | β™» | Website down monitoring | | | Script | [website_monitor](/front/plugins/website_monitor/) | -| `WOL` | β™» | Automatic wake-on-lan | | | Script | [wake_on_lan](/front/plugins/wake_on_lan/) | - - -> \* The database cleanup plugin (`DBCLNP`) is not _required_ but the app will become unusable after a while if not executed. -> ❌ marked for removal -> ⌚It's recommended to use the same schedule interval for all plugins responsible for discovering new devices. - -## Plugin types - - -| Plugin type | Icon | Description | When to run | Required | Data source [?](/docs/PLUGINS_DEV.md) | -| -------------- | ---- | ---------------------------------------------------------------- | ----------------------------------- | -------- | ------------------------------------- | -| publisher | ▢️ | Sending notifications to services. | `on_notification` | βœ– | Script | -| dev scanner | πŸ” | Create devices in the app, manages online/offline device status. | `schedule` | βœ– | Script / SQLite DB | -| name discovery | πŸ†Ž | Discovers names of devices via various protocols. | `before_name_updates`, `schedule` | βœ– | Script | -| importer | πŸ“₯ | Importing devices from another service. | `schedule` | βœ– | Script / SQLite DB | -| system | βš™ | Providing core system functionality. | `schedule` / always on | βœ–/βœ” | Script / Template | -| other | β™» | Other plugins | misc | βœ– | Script / Template | - -## Features - -| Icon | Description | -| ---- | ------------------------------------------------------------ | -| πŸ–§ | Auto-imports the network topology diagram | -| πŸ”„ | Has the option to sync some data back into the plugin source | - - -## βœ…Enabling plugins - -Plugins can be enabled via Settings, and can be disabled as needed. - -1. Research which plugin you'd like to use, enable `DISCOVER_PLUGINS` and load the required plugins in Settings via the `LOADED_PLUGINS` setting. -1. Save the changes and review the Settings of the newly loaded plugins. -1. Change the `_RUN` Setting to the recommended or custom value as per the documentation of the given setting - - If using `schedule` on a `πŸ” dev scanner` plugin, make sure the schedules are the same across all `πŸ” dev scanner` plugins - -### Disabling, Unloading and Ignoring plugins - -1. Change the `_RUN` Setting to `disabled` if you want to disable the plugin, but keep the settings -1. If you want to speed up the application, you can unload the plugin by unselecting it in the `LOADED_PLUGINS` setting. - - Careful, once you save the Settings Unloaded plugin settings will be lost (old `app.conf` files are kept in the `/config` folder) -1. You can completely ignore plugins by placing a `ignore_plugin` file into the plugin directory. Ignored plugins won't show up in the `LOADED_PLUGINS` setting. - -## πŸ†• Developing new custom plugins - -If you want to develop a custom plugin, please read this [Plugin development guide](/docs/PLUGINS_DEV.md). \ No newline at end of file +Plugins docs have been relocated. Check the new [Plugins Overview location](/docs/PLUGINS.md). \ No newline at end of file diff --git a/front/plugins/_publisher_mqtt/mqtt.py b/front/plugins/_publisher_mqtt/mqtt.py index 4a84153a..2e1b1691 100755 --- a/front/plugins/_publisher_mqtt/mqtt.py +++ b/front/plugins/_publisher_mqtt/mqtt.py @@ -447,10 +447,10 @@ def mqtt_start(db): for device in devices: - # # debug statement START πŸ”» - # if 'Moto' not in device["devName"]: - # continue - # # debug statement END πŸ”Ί + # debug statement START πŸ”» + if 'Moto' not in device["devName"]: + continue + # debug statement END πŸ”Ί # Create devices in Home Assistant - send config messages deviceId = 'mac_' + device["devMac"].replace(" ", "").replace(":", "_").lower() @@ -465,7 +465,7 @@ def mqtt_start(db): sensorConfig = create_sensor(mqtt_client, deviceId, devDisplayName, 'sensor', 'last_connection', 'calendar-end', device["devMac"]) # handle device_tracker - # device_tracker attributes + # IMPORTANT: shared payload - device_tracker attributes and individual sensors devJson = { "last_ip": device["devLastIP"], "is_new": str(device["devIsNew"]), @@ -480,6 +480,9 @@ def mqtt_start(db): "network_parent_mac": device["devParentMAC"], "network_parent_name": next((dev["devName"] for dev in devices if dev["devMAC"] == device["devParentMAC"]), "") } + + # bulk update device sensors in home assistant + publish_mqtt(mqtt_client, sensorConfig.state_topic, devJson) # REQUIRED, DON'T DELETE # create and update is_present sensor sensorConfig = create_sensor(mqtt_client, deviceId, devDisplayName, 'binary_sensor', 'is_present', 'wifi', device["devMac"])