From 32df1bb7979eee86b03d573756ae58c1d892062b Mon Sep 17 00:00:00 2001 From: Dmitry Luhtionov Date: Thu, 18 Nov 2021 11:34:36 +0200 Subject: [PATCH 1/3] Update SKS.SKS profile --- sa/profiles/SKS/SKS/profile.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sa/profiles/SKS/SKS/profile.py b/sa/profiles/SKS/SKS/profile.py index 658945c87d..1e92a5c11a 100644 --- a/sa/profiles/SKS/SKS/profile.py +++ b/sa/profiles/SKS/SKS/profile.py @@ -2,7 +2,7 @@ # Vendor: SKS (SVYAZKOMPLEKTSERVICE, LLC. - https://www.nposkss.ru) # OS: SKS # --------------------------------------------------------------------- -# Copyright (C) 2007-2019 The NOC Project +# Copyright (C) 2007-2021 The NOC Project # See LICENSE for details # --------------------------------------------------------------------- @@ -22,6 +22,9 @@ class Profile(BaseProfile): r"% Unrecognized host or address|" r"Unknown command|Incomplete command|Too many parameters" ) + pattern_operation_error = ( + r"%LCLI-W-E1MESSAGE: E1 units are not yet updated, cannot show running config. Please wait." + ) command_super = "enable" command_disable_pager = "terminal datadump" rogue_chars = [re.compile(rb"\r\n##+#\r\n"), "\r"] -- GitLab From ad7a11a1cef82fbf05d5f8496aa87dc4800323d6 Mon Sep 17 00:00:00 2001 From: Andrey Vertiprahov Date: Thu, 2 Dec 2021 21:38:26 +0500 Subject: [PATCH 2/3] Add cleaned_config. --- sa/profiles/SKS/SKS/get_config.py | 30 ++++++++++++++++++------------ sa/profiles/SKS/SKS/profile.py | 11 ++++++++++- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/sa/profiles/SKS/SKS/get_config.py b/sa/profiles/SKS/SKS/get_config.py index 1e89b36482..666bbb91cd 100644 --- a/sa/profiles/SKS/SKS/get_config.py +++ b/sa/profiles/SKS/SKS/get_config.py @@ -16,19 +16,25 @@ class Script(BaseScript): def execute_cli(self, policy="r"): assert policy in ("r", "s") - if policy == "s": + + config, e1_error = None, False + if policy == "r": + try: + config = self.cli("show running-config") + except self.CLIOperationError: + e1_error = True + if policy == "s" or not config: try: config = self.cli("show startup-config") except self.CLISyntaxError: config = self.cli("show configuration") - else: - config = self.cli("show running-config") - try: - i = config.index("e1 unit-1") - except ValueError: - try: - i = config.index("!") - config = config[i:] - except ValueError: - pass - return self.cleaned_config(config) + r = [{"name": "main", "config": self.cleaned_config(config)}] + if e1_error: + r += [ + { + "name": "error", + "config": "%LCLI-W-E1MESSAGE: E1 units are not yet updated, cannot show running config", + } + ] + + return r diff --git a/sa/profiles/SKS/SKS/profile.py b/sa/profiles/SKS/SKS/profile.py index 1e92a5c11a..e475419f4a 100644 --- a/sa/profiles/SKS/SKS/profile.py +++ b/sa/profiles/SKS/SKS/profile.py @@ -23,7 +23,7 @@ class Profile(BaseProfile): r"Unknown command|Incomplete command|Too many parameters" ) pattern_operation_error = ( - r"%LCLI-W-E1MESSAGE: E1 units are not yet updated, cannot show running config. Please wait." + r"%LCLI-W-E1MESSAGE: E1 units are not yet updated, cannot show running config." ) command_super = "enable" command_disable_pager = "terminal datadump" @@ -125,3 +125,12 @@ class Profile(BaseProfile): # Vlan on SNMP return "SVI" return cls.INTERFACE_TYPES.get(name[:2].lower()) + + rx_e1 = re.compile(r"e1 unit-1|!") + + def cleaned_config(self, cfg): + cfg = super().cleaned_config(cfg) + search = self.rx_e1.search(cfg) + if search: + cfg = cfg[search.span()[0] :] + return cfg -- GitLab From 1027cb4125c6932d67f135818b975180ef98146d Mon Sep 17 00:00:00 2001 From: Andrey Vertiprahov Date: Thu, 2 Dec 2021 21:58:29 +0500 Subject: [PATCH 3/3] Add config tokenizer. --- sa/profiles/SKS/SKS/profile.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sa/profiles/SKS/SKS/profile.py b/sa/profiles/SKS/SKS/profile.py index e475419f4a..a03bc20c5e 100644 --- a/sa/profiles/SKS/SKS/profile.py +++ b/sa/profiles/SKS/SKS/profile.py @@ -38,6 +38,8 @@ class Profile(BaseProfile): r"radius(-server | accounting-server )(encrypt-key|key) \d+ \S+\n", r"tacacs(-server | accounting-server )(encrypt-key|key) \d+ \S+\n", ] + config_tokenizer = "indent" + config_tokenizer_settings = {"line_comment": "!"} matchers = {"is_sks_achtung": {"version": {"$regex": r"^2(\.\d+)+\w"}}} # 2.2.0C, 2.0.2H -- GitLab