From 0364d44b4ffbcde647807c31e42c3662cc87e2e3 Mon Sep 17 00:00:00 2001 From: Nataliia Solomko Date: Mon, 11 Mar 2024 12:32:46 +0200 Subject: snmp: T2998: SNMP v3 oid "exclude" option fix --- data/templates/snmp/etc.snmpd.conf.tmpl | 5 +++++ interface-definitions/snmp.xml.in | 1 + smoketest/scripts/cli/test_service_snmp.py | 20 ++++++++++++++++++++ src/conf_mode/snmp.py | 4 ++++ 4 files changed, 30 insertions(+) diff --git a/data/templates/snmp/etc.snmpd.conf.tmpl b/data/templates/snmp/etc.snmpd.conf.tmpl index 30806ce8a..ca9b4d617 100644 --- a/data/templates/snmp/etc.snmpd.conf.tmpl +++ b/data/templates/snmp/etc.snmpd.conf.tmpl @@ -91,6 +91,11 @@ trap2sink {{ trap.target }}{{ ":" + trap.port if trap.port is defined }} {{ trap {% for view in v3_views %} {% for oid in view.oids %} view {{ view.name }} included .{{ oid.oid }} +{% if oid.exclude %} +{% for excl in oid.exclude %} +view {{ view.name }} excluded .{{ excl }} +{% endfor %} +{% endif %} {% endfor %} {% endfor %} diff --git a/interface-definitions/snmp.xml.in b/interface-definitions/snmp.xml.in index 1067aa8a8..48aee7c9a 100644 --- a/interface-definitions/snmp.xml.in +++ b/interface-definitions/snmp.xml.in @@ -599,6 +599,7 @@ Exclude is an optional argument + diff --git a/smoketest/scripts/cli/test_service_snmp.py b/smoketest/scripts/cli/test_service_snmp.py index 864097771..5066b7942 100755 --- a/smoketest/scripts/cli/test_service_snmp.py +++ b/smoketest/scripts/cli/test_service_snmp.py @@ -225,5 +225,25 @@ class TestSNMPService(VyOSUnitTestSHIM.TestCase): # Check for running process self.assertTrue(process_named_running(PROCESS_NAME)) + def test_snmpv3_view_exclude(self): + snmpv3_group = 'default_group' + snmpv3_view = 'default_view' + snmpv3_view_oid = '1' + snmpv3_view_oid_exclude = ['1.3.6.1.2.1.4.21', '1.3.6.1.2.1.4.24'] + + self.cli_set(base_path + ['v3', 'group', snmpv3_group, 'view', snmpv3_view]) + self.cli_set(base_path + ['v3', 'view', snmpv3_view, 'oid', snmpv3_view_oid]) + + for excluded in snmpv3_view_oid_exclude: + self.cli_set(base_path + ['v3', 'view', snmpv3_view, 'oid', snmpv3_view_oid, 'exclude', excluded]) + + self.cli_commit() + + tmp = read_file(SNMPD_CONF) + # views + self.assertIn(f'view {snmpv3_view} included .{snmpv3_view_oid}', tmp) + for excluded in snmpv3_view_oid_exclude: + self.assertIn(f'view {snmpv3_view} excluded .{excluded}', tmp) + if __name__ == '__main__': unittest.main(verbosity=2) diff --git a/src/conf_mode/snmp.py b/src/conf_mode/snmp.py index 0be0da3d1..b300961ff 100755 --- a/src/conf_mode/snmp.py +++ b/src/conf_mode/snmp.py @@ -383,6 +383,10 @@ def get_config(): oid_cfg = { 'oid': oid } + if conf.exists('v3 view {0} oid {1} exclude'.format(view, oid)): + oid_cfg['exclude'] = [] + for exclude in conf.return_values('v3 view {0} oid {1} exclude'.format(view, oid)): + oid_cfg['exclude'].append(exclude) view_cfg['oids'].append(oid_cfg) snmp['v3_views'].append(view_cfg) -- cgit v1.2.3 From 1fb746332602fd53eb5412c8f3c7fc38c09b7d26 Mon Sep 17 00:00:00 2001 From: Nataliia Solomko Date: Thu, 14 Mar 2024 15:12:08 +0200 Subject: snmp: T2998: updated snmp.py --- src/conf_mode/snmp.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/conf_mode/snmp.py b/src/conf_mode/snmp.py index b300961ff..7b3f9cbb7 100755 --- a/src/conf_mode/snmp.py +++ b/src/conf_mode/snmp.py @@ -384,9 +384,7 @@ def get_config(): 'oid': oid } if conf.exists('v3 view {0} oid {1} exclude'.format(view, oid)): - oid_cfg['exclude'] = [] - for exclude in conf.return_values('v3 view {0} oid {1} exclude'.format(view, oid)): - oid_cfg['exclude'].append(exclude) + oid_cfg['exclude'] = conf.return_values('v3 view {0} oid {1} exclude'.format(view, oid)) view_cfg['oids'].append(oid_cfg) snmp['v3_views'].append(view_cfg) -- cgit v1.2.3