From b7174e53acd7b9f6cc024794b8e12490b23e6a51 Mon Sep 17 00:00:00 2001 From: Dmitry Luhtionov Date: Mon, 15 Jun 2020 11:39:36 +0300 Subject: [PATCH 1/3] Update Dlink.DxS_Smart profile to support DGS-1210 rev. F1 series --- sa/profiles/DLink/DxS_Smart/get_version.py | 9 +++-- sa/profiles/DLink/DxS_Smart/profile.py | 38 +++++++++------------- 2 files changed, 20 insertions(+), 27 deletions(-) diff --git a/sa/profiles/DLink/DxS_Smart/get_version.py b/sa/profiles/DLink/DxS_Smart/get_version.py index a52b4b152a..8fa74e2018 100644 --- a/sa/profiles/DLink/DxS_Smart/get_version.py +++ b/sa/profiles/DLink/DxS_Smart/get_version.py @@ -1,7 +1,7 @@ # --------------------------------------------------------------------- # DLink.DxS_Smart.get_version # --------------------------------------------------------------------- -# Copyright (C) 2007-2019 The NOC Project +# Copyright (C) 2007-2020 The NOC Project # See LICENSE for details # --------------------------------------------------------------------- @@ -11,7 +11,6 @@ import re # NOC modules from noc.core.script.base import BaseScript from noc.sa.interfaces.igetversion import IGetVersion -from noc.sa.profiles.DLink.DxS_Smart.profile import DES1210, DGS1210, DXS1210, DGS1500 class Script(BaseScript): @@ -27,7 +26,7 @@ class Script(BaseScript): r"system serial number\s+:\s*(?P\S+)", re.MULTILINE | re.DOTALL | re.I, ) - rx_snmp_ver = re.compile(r"^(?P\S+)\s*", re.DOTALL) + rx_snmp_ver = re.compile(r"^(?:WS6-)?(?P\S+)\s*") def execute(self): r = {"vendor": "DLink"} @@ -40,9 +39,9 @@ class Script(BaseScript): pass else: raise self.NotSupportedError() - if DES1210(r) or DGS1210(r) or DXS1210(r) or DGS1500(r): + if self.is_has_cli: s = self.cli("show switch", cached=True) - match = self.re_search(self.rx_ver, s) + match = self.rx_ver.search(s) r.update( { "version": match.group("version"), diff --git a/sa/profiles/DLink/DxS_Smart/profile.py b/sa/profiles/DLink/DxS_Smart/profile.py index 42ec04f4f6..2ccad899ce 100644 --- a/sa/profiles/DLink/DxS_Smart/profile.py +++ b/sa/profiles/DLink/DxS_Smart/profile.py @@ -1,14 +1,16 @@ # --------------------------------------------------------------------- # Vendor: D-Link # OS: DxS_Smart -# Compatible: # --------------------------------------------------------------------- -# Copyright (C) 2007-2019 The NOC Project +# Copyright (C) 2007-2020 The NOC Project # See LICENSE for details # --------------------------------------------------------------------- +# Python modules import re + +# NOC modules from noc.core.profile.base import BaseProfile from noc.core.script.error import NotSupportedError @@ -30,6 +32,11 @@ class Profile(BaseProfile): command_exit = "logout" command_save_config = "save" config_volatile = ["^%.*?$"] + + matchers = { + "is_has_cli": {"platform": {"$regex": r"^(D[EGX]S-1210|DGS-1500)"}}, + } + # # Version comparison # Version format: @@ -53,6 +60,13 @@ class Profile(BaseProfile): "DGS-1210-28P/C1": "1.3.6.1.4.1.171.10.76.21.1", "DGS-1210-52/C1": "1.3.6.1.4.1.171.10.76.22.1", "DGS-1210-52P/C1": "1.3.6.1.4.1.171.10.76.33.1", + "DGS-1210-10/F1": "1.3.6.1.4.1.171.10.153.3.1", + "DGS-1210-10P/F1": "1.3.6.1.4.1.171.10.153.1.1", + "DGS-1210-20/F1": "1.3.6.1.4.1.171.10.153.4.1", + "DGS-1210-26/F1": "1.3.6.1.4.1.171.10.153.6.1", + "DGS-1210-28/F1": "1.3.6.1.4.1.171.10.153.5.1", + "DGS-1210-28P/F1": "1.3.6.1.4.1.171.10.153.8.1", + "DGS-1210-52/F1": "1.3.6.1.4.1.171.10.153.7.1", "DGS-1500-20": "1.3.6.1.4.1.171.10.126.1.1", "DGS-1500-28": "1.3.6.1.4.1.171.10.126.2.1", "DGS-1500-28P": "1.3.6.1.4.1.171.10.126.3.1", @@ -223,23 +237,3 @@ class Profile(BaseProfile): } ] return vlans - - -# DES-1210-series -def DES1210(v): - return v["platform"].startswith("DES-1210") - - -# DGS-1210-series -def DGS1210(v): - return v["platform"].startswith("DGS-1210") - - -# DXS-1210-series -def DXS1210(v): - return v["platform"].startswith("DXS-1210") - - -# DGS-1500-series -def DGS1500(v): - return v["platform"].startswith("DGS-1500") -- GitLab From 5743830f55591204b2782a1f83184903c262d21b Mon Sep 17 00:00:00 2001 From: Dmitry Luhtionov Date: Mon, 15 Jun 2020 11:46:16 +0300 Subject: [PATCH 2/3] Add profile check rules --- .../DLink/DxS_Smart/DGS_1210_F1_Series.json | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 collections/sa.profilecheckrules/DLink/DxS_Smart/DGS_1210_F1_Series.json diff --git a/collections/sa.profilecheckrules/DLink/DxS_Smart/DGS_1210_F1_Series.json b/collections/sa.profilecheckrules/DLink/DxS_Smart/DGS_1210_F1_Series.json new file mode 100644 index 0000000000..1202ebe48a --- /dev/null +++ b/collections/sa.profilecheckrules/DLink/DxS_Smart/DGS_1210_F1_Series.json @@ -0,0 +1,13 @@ +{ + "name": "DLink | DxS_Smart | DGS-1210-F1-Series sysObjectID", + "$collection": "sa.profilecheckrules", + "uuid": "bd5a7c93-5d92-4a46-b2f8-4d071ad920e5", + "description": "", + "preference": 10, + "method": "snmp_v2c_get", + "param": "SNMPv2-MIB::sysObjectID.0", + "match_method": "contains", + "value": "1.3.6.1.4.1.171.10.153", + "action": "match", + "profile__name": "DLink.DxS_Smart" +} -- GitLab From 199033a1e9cb2e7ddaaeb5ce763dd5b427753ea1 Mon Sep 17 00:00:00 2001 From: Dmitry Luhtionov Date: Mon, 15 Jun 2020 13:18:01 +0300 Subject: [PATCH 3/3] Fix matchers --- sa/profiles/DLink/DxS_Smart/ping.py | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/sa/profiles/DLink/DxS_Smart/ping.py b/sa/profiles/DLink/DxS_Smart/ping.py index 1b9e6dd080..6629a6e056 100644 --- a/sa/profiles/DLink/DxS_Smart/ping.py +++ b/sa/profiles/DLink/DxS_Smart/ping.py @@ -1,7 +1,7 @@ # --------------------------------------------------------------------- # DLink.DxS_Smart.ping # --------------------------------------------------------------------- -# Copyright (C) 2007-2019 The NOC Project +# Copyright (C) 2007-2020 The NOC Project # See LICENSE for details # --------------------------------------------------------------------- @@ -11,7 +11,6 @@ import re # NOC modules from noc.core.script.base import BaseScript from noc.sa.interfaces.iping import IPing -from noc.sa.profiles.DLink.DxS_Smart.profile import DES1210 class Script(BaseScript): @@ -20,17 +19,15 @@ class Script(BaseScript): rx_result = re.compile( r"^\s*(?P\d+) Packets Transmitted, (?P\d+) " r"Packets Received, \d+% Packets Loss", - re.MULTILINE | re.DOTALL | re.IGNORECASE, + re.MULTILINE | re.IGNORECASE, ) - @BaseScript.match(DES1210) - def execute_ping(self, address): - cmd = "ping %s" % address - match = self.rx_result.search(self.cli(cmd)) - if not match: + def execute_cli(self, address): + if self.is_has_cli: + cmd = "ping %s" % address + match = self.rx_result.search(self.cli(cmd)) + if not match: + raise self.NotSupportedError() + return {"success": match.group("success"), "count": match.group("count")} + else: raise self.NotSupportedError() - return {"success": match.group("success"), "count": match.group("count")} - - @BaseScript.match() - def execute_ping_other(self, address): - raise self.NotSupportedError() -- GitLab