From 7e946dc26f628ac716a1d6a75664781e5685cb66 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Mon, 11 Apr 2022 20:57:16 +0200 Subject: snmp: T4333: migrate to new vyos_defined Jinja2 test --- data/templates/snmp/etc.snmp.conf.tmpl | 2 +- data/templates/snmp/etc.snmpd.conf.tmpl | 56 ++++++++++++++++----------------- data/templates/snmp/override.conf.tmpl | 6 ++-- data/templates/snmp/usr.snmpd.conf.tmpl | 2 +- data/templates/snmp/var.snmpd.conf.tmpl | 6 ++-- 5 files changed, 35 insertions(+), 37 deletions(-) (limited to 'data') diff --git a/data/templates/snmp/etc.snmp.conf.tmpl b/data/templates/snmp/etc.snmp.conf.tmpl index f7d9a3c17..8012cf6bb 100644 --- a/data/templates/snmp/etc.snmp.conf.tmpl +++ b/data/templates/snmp/etc.snmp.conf.tmpl @@ -1,4 +1,4 @@ ### Autogenerated by snmp.py ### -{% if trap_source is defined and trap_source is not none %} +{% if trap_source is vyos_defined %} clientaddr {{ trap_source }} {% endif %} diff --git a/data/templates/snmp/etc.snmpd.conf.tmpl b/data/templates/snmp/etc.snmpd.conf.tmpl index befea0122..510b35097 100644 --- a/data/templates/snmp/etc.snmpd.conf.tmpl +++ b/data/templates/snmp/etc.snmpd.conf.tmpl @@ -33,14 +33,14 @@ interface_replace_old yes # Default system description is VyOS version sysDescr VyOS {{ version }} -{% if description is defined and description is not none %} +{% if description is vyos_defined %} # Description SysDescr {{ description }} {% endif %} # Listen {% set options = [] %} -{% if listen_address is defined and listen_address is not none %} +{% if listen_address is vyos_defined %} {% for address, address_options in listen_address.items() %} {% if address | is_ipv6 %} {% set protocol = protocol ~ '6' %} @@ -49,16 +49,14 @@ SysDescr {{ description }} {% endfor %} {% else %} {% set _ = options.append(protocol ~ ':161') %} -{% if ipv6_disabled is not defined %} -{% set _ = options.append(protocol ~ '6:161') %} -{% endif %} +{% set _ = options.append(protocol ~ '6:161') %} {% endif %} -agentaddress unix:/run/snmpd.socket{{ ',' ~ options | join(',') if options is defined and options is not none }} +agentaddress unix:/run/snmpd.socket{{ ',' ~ options | join(',') if options is vyos_defined }} # SNMP communities -{% if community is defined and community is not none %} +{% if community is vyos_defined %} {% for comm, comm_config in community.items() %} -{% if comm_config.client is defined and comm_config.client is not none %} +{% if comm_config.client is vyos_defined %} {% for client in comm_config.client %} {% if client | is_ipv4 %} {{ comm_config.authorization }}community {{ comm }} {{ client }} @@ -67,7 +65,7 @@ agentaddress unix:/run/snmpd.socket{{ ',' ~ options | join(',') if options is de {% endif %} {% endfor %} {% endif %} -{% if comm_config.network is defined and comm_config.network is not none %} +{% if comm_config.network is vyos_defined %} {% for network in comm_config.network %} {% if network | is_ipv4 %} {{ comm_config.authorization }}community {{ comm }} {{ network }} @@ -76,44 +74,44 @@ agentaddress unix:/run/snmpd.socket{{ ',' ~ options | join(',') if options is de {% endif %} {% endfor %} {% endif %} -{% if comm_config.client is not defined and comm_config.network is not defined %} +{% if comm_config.client is not vyos_defined and comm_config.network is not vyos_defined %} {{ comm_config.authorization }}community {{ comm }} {% endif %} {% endfor %} {% endif %} -{% if contact is defined and contact is not none %} +{% if contact is vyos_defined %} # system contact information SysContact {{ contact }} {% endif %} -{% if location is defined and location is not none %} +{% if location is vyos_defined %} # system location information SysLocation {{ location }} {% endif %} -{% if smux_peer is defined and smux_peer is not none %} +{% if smux_peer is vyos_defined %} # additional smux peers {% for peer in smux_peer %} smuxpeer {{ peer }} {% endfor %} {% endif %} -{% if trap_target is defined and trap_target is not none %} +{% if trap_target is vyos_defined %} # if there is a problem - tell someone! {% for trap, trap_config in trap_target.items() %} trap2sink {{ trap }}:{{ trap_config.port }} {{ trap_config.community }} {% endfor %} {% endif %} -{% if v3 is defined and v3 is not none %} +{% if v3 is vyos_defined %} # # SNMPv3 stuff goes here # -{% if v3.view is defined and v3.view is not none %} +{% if v3.view is vyos_defined %} # views {% for view, view_config in v3.view.items() %} -{% if view_config.oid is defined and view_config.oid is not none %} +{% if view_config.oid is vyos_defined %} {% for oid in view_config.oid %} view {{ view }} included .{{ oid }} {% endfor %} @@ -122,7 +120,7 @@ view {{ view }} included .{{ oid }} {% endif %} # access -{% if v3.group is defined and v3.group is not none %} +{% if v3.group is vyos_defined %} # context sec.model sec.level match read write notif {% for group, group_config in v3.group.items() %} access {{ group }} "" usm {{ group_config.seclevel }} exact {{ group_config.view }} {% if group_config.mode == 'ro' %}none{% else %}{{ group_config.view }}{% endif %} none @@ -130,30 +128,30 @@ access {{ group }} "" usm {{ group_config.seclevel }} exact {{ group_config.view {% endif %} # trap-target -{% if v3.trap_target is defined and v3.trap_target is not none %} +{% if v3.trap_target is vyos_defined %} {% for trap, trap_config in v3.trap_target.items() %} {% set options = '' %} {% if trap_config.type == 'inform' %} {% set options = options ~ ' -Ci' %} {% endif %} -{% if v3.engineid is defined and v3.engineid is not none %} +{% if v3.engineid is vyos_defined %} {% set options = options ~ ' -e "' ~ v3.engineid ~ '"' %} {% endif %} -{% if trap_config.user is defined and trap_config.user is not none %} +{% if trap_config.user is vyos_defined %} {% set options = options ~ ' -u ' ~ trap_config.user %} {% endif %} -{% if trap_config.auth is defined and trap_config.auth.plaintext_password is defined or trap_config.auth.encrypted_password is defined %} +{% if trap_config.auth.plaintext_password is vyos_defined or trap_config.auth.encrypted_password is vyos_defined %} {% set options = options ~ ' -a ' ~ trap_config.auth.type %} -{% if trap_config.auth.plaintext_password is defined and trap_config.auth.plaintext_password is not none %} +{% if trap_config.auth.plaintext_password is vyos_defined %} {% set options = options ~ ' -A ' ~ trap_config.auth.plaintext_password %} -{% elif trap_config.auth.encrypted_password is defined and trap_config.auth.encrypted_password is not none %} +{% elif trap_config.auth.encrypted_password is vyos_defined %} {% set options = options ~ ' -3m ' ~ trap_config.auth.encrypted_password %} {% endif %} -{% if trap_config.privacy is defined and trap_config.privacy.plaintext_password is defined or trap_config.privacy.encrypted_password is defined %} +{% if trap_config.privacy.plaintext_password is vyos_defined or trap_config.privacy.encrypted_password is vyos_defined %} {% set options = options ~ ' -x ' ~ trap_config.privacy.type %} -{% if trap_config.privacy.plaintext_password is defined and trap_config.privacy.plaintext_password is not none %} +{% if trap_config.privacy.plaintext_password is vyos_defined %} {% set options = options ~ ' -X ' ~ trap_config.privacy.plaintext_password %} -{% elif trap_config.privacy.encrypted_password is defined and trap_config.privacy.encrypted_password is not none %} +{% elif trap_config.privacy.encrypted_password is vyos_defined %} {% set options = options ~ ' -3M ' ~ trap_config.privacy.encrypted_password %} {% endif %} {% set options = options ~ ' -l authPriv' %} @@ -168,7 +166,7 @@ trapsess -v 3 {{ options }} {{ trap }}:{{ trap_config.protocol }}:{{ trap_config {% endif %} # group -{% if v3.user is defined and v3.user is not none %} +{% if v3.user is vyos_defined %} {% for user, user_config in v3.user.items() %} group {{ user_config.group }} usm {{ user }} {% endfor %} @@ -176,7 +174,7 @@ group {{ user_config.group }} usm {{ user }} {# SNMPv3 end #} {% endif %} -{% if script_extensions is defined and script_extensions.extension_name is defined and script_extensions.extension_name is not none %} +{% if script_extensions.extension_name is vyos_defined %} # extension scripts {% for script, script_config in script_extensions.extension_name.items() | sort(attribute=script) %} extend {{ script }} {{ script_config.script }} diff --git a/data/templates/snmp/override.conf.tmpl b/data/templates/snmp/override.conf.tmpl index 3b00aab83..5d787de86 100644 --- a/data/templates/snmp/override.conf.tmpl +++ b/data/templates/snmp/override.conf.tmpl @@ -1,5 +1,5 @@ -{% set vrf_command = 'ip vrf exec ' + vrf + ' ' if vrf is defined else '' %} -{% set oid_route_table = ' ' if oid_enable is defined and oid_enable == 'route-table' else '-I -ipCidrRouteTable,inetCidrRouteTable' %} +{% set vrf_command = 'ip vrf exec ' ~ vrf ~ ' ' if vrf is vyos_defined else '' %} +{% set oid_route_table = ' ' if oid_enable is vyos_defined('route-table') else '-I -ipCidrRouteTable,inetCidrRouteTable' %} [Unit] StartLimitIntervalSec=0 After=vyos-router.service @@ -8,7 +8,7 @@ After=vyos-router.service Environment= Environment="MIBDIRS=/usr/share/snmp/mibs:/usr/share/snmp/mibs/iana:/usr/share/snmp/mibs/ietf:/usr/share/vyos/mibs" ExecStart= -ExecStart={{vrf_command}}/usr/sbin/snmpd -LS0-5d -Lf /dev/null -u Debian-snmp -g Debian-snmp {{oid_route_table}} -f -p /run/snmpd.pid +ExecStart={{ vrf_command }}/usr/sbin/snmpd -LS0-5d -Lf /dev/null -u Debian-snmp -g Debian-snmp {{ oid_route_table }} -f -p /run/snmpd.pid Restart=always RestartSec=10 diff --git a/data/templates/snmp/usr.snmpd.conf.tmpl b/data/templates/snmp/usr.snmpd.conf.tmpl index 1c688a61e..a46b3997f 100644 --- a/data/templates/snmp/usr.snmpd.conf.tmpl +++ b/data/templates/snmp/usr.snmpd.conf.tmpl @@ -1,5 +1,5 @@ ### Autogenerated by snmp.py ### -{% if v3 is defined and v3.user is defined and v3.user is not none %} +{% if v3.user is vyos_defined %} {% for user, user_config in v3.user.items() %} {{ user_config.mode }}user {{ user }} {% endfor %} diff --git a/data/templates/snmp/var.snmpd.conf.tmpl b/data/templates/snmp/var.snmpd.conf.tmpl index 5871a8234..16d39db89 100644 --- a/data/templates/snmp/var.snmpd.conf.tmpl +++ b/data/templates/snmp/var.snmpd.conf.tmpl @@ -1,7 +1,7 @@ ### Autogenerated by snmp.py ### # user -{% if v3 is defined and v3 is not none %} -{% if v3.user is defined and v3.user is not none %} +{% if v3 is vyos_defined %} +{% if v3.user is vyos_defined %} {% for user, user_config in v3.user.items() %} usmUser 1 3 0x{{ v3.engineid }} "{{ user }}" "{{ user }}" NULL {{ user_config.auth.type | snmp_auth_oid }} 0x{{ user_config.auth.encrypted_password }} {{ user_config.privacy.type | snmp_auth_oid }} 0x{{ user_config.privacy.encrypted_password }} 0x {% endfor %} @@ -10,7 +10,7 @@ usmUser 1 3 0x{{ v3.engineid }} "{{ user }}" "{{ user }}" NULL {{ user_config.au # VyOS default user createUser {{ vyos_user }} MD5 "{{ vyos_user_pass }}" DES -{% if v3.engineid is defined and v3.engineid is not none %} +{% if v3.engineid is vyos_defined %} oldEngineID 0x{{ v3.engineid }} {% endif %} {% endif %} -- cgit v1.2.3