From 27f1b14ec4f3939683f0ab8492050b39cde20b1e Mon Sep 17 00:00:00 2001 From: tomaae <23486452+tomaae@users.noreply.github.com> Date: Mon, 12 Apr 2021 13:23:05 +0200 Subject: [PATCH] Added support for DNS comments #86 Remove everything after hash in comments for device tracking #86 --- .../mikrotik_router/mikrotik_controller.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/custom_components/mikrotik_router/mikrotik_controller.py b/custom_components/mikrotik_router/mikrotik_controller.py index 95c8c1e..6df211b 100644 --- a/custom_components/mikrotik_router/mikrotik_controller.py +++ b/custom_components/mikrotik_router/mikrotik_controller.py @@ -1436,7 +1436,7 @@ class MikrotikControllerData: data=self.data["dns"], source=self.api.path("/ip/dns/static"), key="name", - vals=[{"name": "name"}, {"name": "address"}], + vals=[{"name": "name"}, {"name": "address"}, {"name": "comment"}], ) # --------------------------- @@ -1719,9 +1719,14 @@ class MikrotikControllerData: if vals["address"] != "unknown": for dns_uid, dns_vals in self.data["dns"].items(): if dns_vals["address"] == vals["address"]: - self.data["host"][uid]["host-name"] = dns_vals[ - "name" - ].split(".")[0] + if dns_vals["comment"] != "": + self.data["host"][uid]["host-name"] = dns_vals[ + "comment" + ].split("#", 1)[0] + else: + self.data["host"][uid]["host-name"] = dns_vals[ + "name" + ].split(".")[0] break # Resolve hostname from DHCP comment if ( @@ -1731,7 +1736,7 @@ class MikrotikControllerData: ): self.data["host"][uid]["host-name"] = self.data["dhcp"][uid][ "comment" - ] + ].split("#", 1)[0] # Resolve hostname from DHCP hostname elif ( self.data["host"][uid]["host-name"] == "unknown"