mirror of
https://github.com/tomaae/homeassistant-mikrotik_router.git
synced 2025-07-16 12:24:30 +02:00
Fix for naming of static DNS entries without host-name and static DNS entry. Fallback value is not mac-address
This commit is contained in:
parent
069897c32c
commit
3c44445cd1
2 changed files with 7 additions and 5 deletions
|
@ -51,7 +51,6 @@ You can add this integration several times for different devices.
|
||||||
* "Port" - Leave at 0 for defaults
|
* "Port" - Leave at 0 for defaults
|
||||||
* "Name of the integration" - Friendy name for this router
|
* "Name of the integration" - Friendy name for this router
|
||||||
* "Unit of measurement" - Traffic sensor measurement (bps, Kbps, Mbps, B/s, KB/s, MB/s)
|
* "Unit of measurement" - Traffic sensor measurement (bps, Kbps, Mbps, B/s, KB/s, MB/s)
|
||||||
* "Track accounting" - Determines if integration will track per-host throughput. Accounting must be enabled in Mikrotik first
|
|
||||||
|
|
||||||
# Configuration
|
# Configuration
|
||||||

|

|
||||||
|
@ -67,7 +66,7 @@ For per-IP throughput tracking Mikrotik's accounting feature is used.
|
||||||
|
|
||||||
[Mikrotik support page](https://wiki.mikrotik.com/wiki/Manual:IP/Accounting)
|
[Mikrotik support page](https://wiki.mikrotik.com/wiki/Manual:IP/Accounting)
|
||||||
|
|
||||||
Before setting up integration in HA, go in Winbox IP-Accounting and setup the feature. Make sure that threshold is set to resonable value to store all connections between user defined scan interval. Max value is 8192 so for piece of mind i recommend setting that value. Web Access is not needed, integration is using API access.
|
Feature will be automaticaly used if accounting is enabled in Mikrotik. Feature is present in Winbox IP-Accounting. Make sure that threshold is set to resonable value to store all connections between user defined scan interval. Max value is 8192 so for piece of mind i recommend setting that value. Web Access is not needed, integration is using API access.
|
||||||
|
|
||||||
Integration will scan DHCP Lease table and ARP table to generate all known hosts and create two sensors for WAN traffic (mikrotik-XXX-wan-rx and mikrotik-XXX-wan-tx). If the parameter *account-local-traffic* is set in Mikrotik's accounting configuration it will also create two sensors for LAN traffic (mikrotik-XXX-lan-rx and mikrotik-XXX-lan-tx).
|
Integration will scan DHCP Lease table and ARP table to generate all known hosts and create two sensors for WAN traffic (mikrotik-XXX-wan-rx and mikrotik-XXX-wan-tx). If the parameter *account-local-traffic* is set in Mikrotik's accounting configuration it will also create two sensors for LAN traffic (mikrotik-XXX-lan-rx and mikrotik-XXX-lan-tx).
|
||||||
|
|
||||||
|
@ -75,4 +74,4 @@ Device's name will be determined by first available string this order:
|
||||||
1. DHCP lease comment
|
1. DHCP lease comment
|
||||||
2. DNS static entry
|
2. DNS static entry
|
||||||
3. DHCP hostname
|
3. DHCP hostname
|
||||||
4. Device's IP address
|
4. Device's MAC address
|
||||||
|
|
|
@ -788,9 +788,12 @@ class MikrotikControllerData:
|
||||||
# Then static DNS entry
|
# Then static DNS entry
|
||||||
elif vals['address'] in dns_data and str(dns_data[vals['address']].get('name', '').strip()):
|
elif vals['address'] in dns_data and str(dns_data[vals['address']].get('name', '').strip()):
|
||||||
self.data["accounting"][mac]['name'] = dns_data[vals['address']]['name']
|
self.data["accounting"][mac]['name'] = dns_data[vals['address']]['name']
|
||||||
# If everything fails use hosts DHCP lease host-name
|
# Then DHCP lease host-name
|
||||||
else:
|
elif str(vals.get('host-name', '').strip()):
|
||||||
self.data["accounting"][mac]['name'] = vals['host-name']
|
self.data["accounting"][mac]['name'] = vals['host-name']
|
||||||
|
# If everything fails fallback to device's MAC address
|
||||||
|
else:
|
||||||
|
self.data["accounting"][mac]['name'] = vals['mac-address']
|
||||||
|
|
||||||
_LOGGER.debug(f"Generated {len(self.data['accounting'])} accounting devices")
|
_LOGGER.debug(f"Generated {len(self.data['accounting'])} accounting devices")
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue