summaryrefslogtreecommitdiff
path: root/src/conf_mode/snmp.py
diff options
context:
space:
mode:
authorhagbard <vyosdev@derith.de>2019-07-15 11:25:12 -0700
committerhagbard <vyosdev@derith.de>2019-07-15 11:37:20 -0700
commit334677572aef752b0bf2c893bd14bdf6f801bb4b (patch)
tree3ac962a6269799e43582943998aaaef2484a6eb0 /src/conf_mode/snmp.py
parent13b27148102d2e38202bcfecbab8830a8561abdc (diff)
downloadvyos-1x-334677572aef752b0bf2c893bd14bdf6f801bb4b.tar.gz
vyos-1x-334677572aef752b0bf2c893bd14bdf6f801bb4b.zip
[T1299] - SNMP extension with custom scripts
Diffstat (limited to 'src/conf_mode/snmp.py')
-rwxr-xr-xsrc/conf_mode/snmp.py27
1 files changed, 25 insertions, 2 deletions
diff --git a/src/conf_mode/snmp.py b/src/conf_mode/snmp.py
index 06d2e253a..0ddab2129 100755
--- a/src/conf_mode/snmp.py
+++ b/src/conf_mode/snmp.py
@@ -206,6 +206,13 @@ group {{ u.group }} usm {{ u.name }}
group {{ u.group }} tsm {{ u.name }}
{% endfor %}
{%- endif %}
+
+{% if script_ext %}
+# extension scripts
+{%- for ext in script_ext|sort %}
+extend\t{{ext}}\t{{script_ext[ext]}}
+{%- endfor %}
+{% endif %}
"""
# SNMP template (/etc/default/snmpd) - be careful if you edit the template.
@@ -240,7 +247,8 @@ default_config_data = {
'v3_tsm_key': '',
'v3_tsm_port': '10161',
'v3_users': [],
- 'v3_views': []
+ 'v3_views': [],
+ 'script_ext': {}
}
def rmfile(file):
@@ -345,6 +353,14 @@ def get_config():
snmp['trap_targets'].append(trap_tgt)
+ #
+ # 'set service snmp script-extensions'
+ #
+ if conf.exists('script-extensions'):
+ for extname in conf.list_nodes('script-extensions extension-name'):
+ snmp['script_ext'][extname] = '/config/user-data/' + conf.return_value('script-extensions extension-name ' + extname + ' script')
+
+
#########################################################################
# ____ _ _ __ __ ____ _____ #
# / ___|| \ | | \/ | _ \ __ _|___ / #
@@ -581,6 +597,14 @@ def verify(snmp):
if snmp is None:
return None
+ ### check if the configured script actually exist under /config/user-data
+ if snmp['script_ext']:
+ for ext in snmp['script_ext']:
+ if not os.path.isfile(snmp['script_ext'][ext]):
+ print ("WARNING: script: " + snmp['script_ext'][ext] + " doesn\'t exist")
+ else:
+ os.chmod(snmp['script_ext'][ext], 0o555)
+
# bail out early if SNMP v3 is not configured
if not snmp['v3_enabled']:
return None
@@ -633,7 +657,6 @@ def verify(snmp):
if not 'seclevel' in group.keys():
raise ConfigError('"seclevel" must be specified')
-
if 'v3_traps' in snmp.keys():
for trap in snmp['v3_traps']:
if trap['authPassword'] and trap['authMasterKey']: