Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

T6525: Add default dir for ext-scripts without absolute path (backport #3827) #4144

Merged
merged 1 commit into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions smoketest/scripts/cli/test_service_snmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,5 +246,19 @@ def test_snmpv3_view_exclude(self):
for excluded in snmpv3_view_oid_exclude:
self.assertIn(f'view {snmpv3_view} excluded .{excluded}', tmp)

def test_snmp_script_extensions(self):
extensions = {
'default': 'snmp_smoketest_extension_script.sh',
'external': '/run/external_snmp_smoketest_extension_script.sh'
}

for key, val in extensions.items():
self.cli_set(base_path + ['script-extensions', 'extension-name', key, 'script', val])
self.cli_commit()

self.assertEqual(get_config_value('extend default'), f'/config/user-data/{extensions["default"]}')
self.assertEqual(get_config_value('extend external'), extensions["external"])


if __name__ == '__main__':
unittest.main(verbosity=2)
13 changes: 13 additions & 0 deletions src/conf_mode/service_snmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
config_file_daemon = r'/etc/snmp/snmpd.conf'
config_file_access = r'/usr/share/snmp/snmpd.conf'
config_file_user = r'/var/lib/snmp/snmpd.conf'
default_script_dir = r'/config/user-data/'
systemd_override = r'/run/systemd/system/snmpd.service.d/override.conf'
systemd_service = 'snmpd.service'

Expand Down Expand Up @@ -85,8 +86,20 @@ def get_config(config=None):
tmp = {'::1': {'port': '161'}}
snmp['listen_address'] = dict_merge(tmp, snmp['listen_address'])

if 'script_extensions' in snmp and 'extension_name' in snmp['script_extensions']:
for key, val in snmp['script_extensions']['extension_name'].items():
if 'script' not in val:
continue
script_path = val['script']
# if script has not absolute path, use pre configured path
if not os.path.isabs(script_path):
script_path = os.path.join(default_script_dir, script_path)

snmp['script_extensions']['extension_name'][key]['script'] = script_path

return snmp


def verify(snmp):
if 'deleted' in snmp:
return None
Expand Down
Loading