From d769ef2abd75b2da48bef806b91b9a369b1ecbba Mon Sep 17 00:00:00 2001 From: Travis Van Duyn Date: Tue, 5 Jan 2021 13:43:29 -0800 Subject: [PATCH] [snmp]: updated to support snmp config from redis configdb (#6134) **- Why I did it** I'm updating the jinja2 template to support getting SNMP information from the redis configdb. I'm using the format approved here: https://github.com/Azure/SONiC/pull/718 This will pave the way for us to decrement using the snmp.yml in the future. Right now we will still be using both the snmp.yml and configdb to get variable information in order to create the snmpd.conf via the sonic-cfggen tool. **- How I did it** I first updated the SNMP Schema in PR #718 to get that approved as a standardized format. Then I verified I could add snmp configs to the configdb using this standard schema. Once the configs were added to the configdb then I updated the snmpd.conf.j2 file to support the updates via the configdb while still using the variables in the snmp.yml file in parallel. This way we will have backward compatibility until we can fully migrate to the configdb only. By updating the snmpd.conf.j2 template and running the sonic-cfggen tool the snmpd.conf gets generated with using the values in both the configdb and snmp.yml file. Co-authored-by: trvanduy --- dockers/docker-snmp/snmpd.conf.j2 | 44 +++++++++++++++++++++++++++---- dockers/docker-snmp/start.sh | 1 - 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/dockers/docker-snmp/snmpd.conf.j2 b/dockers/docker-snmp/snmpd.conf.j2 index 7d4022501fbb..b83fbffda025 100644 --- a/dockers/docker-snmp/snmpd.conf.j2 +++ b/dockers/docker-snmp/snmpd.conf.j2 @@ -34,16 +34,40 @@ view systemonly included .1.3.6.1.2.1.1 view systemonly included .1.3.6.1.2.1.25.1 # Default access to basic system info -{% if snmp_rocommunities %} -{% for community in snmp_rocommunities %} + + +{% if SNMP_COMMUNITY is defined %} +{% for community in SNMP_COMMUNITY %} +{% if SNMP_COMMUNITY[community]['TYPE'] == 'RO' %} rocommunity {{ community }} rocommunity6 {{ community }} +{% endif %} +{% endfor %} +{% endif %} + +{% if SNMP_COMMUNITY is defined %} +{% for community in SNMP_COMMUNITY %} +{% if SNMP_COMMUNITY[community]['TYPE'] == 'RW' %} +rwcommunity {{ community }} +rwcommunity6 {{ community }} +{% endif %} +{% endfor %} +{% endif %} + +{% if SNMP_USER is defined %} +{% for user in SNMP_USER %} +{% if SNMP_USER[user]['SNMP_USER_PERMISSION'] == 'RO' %} +rouser {{ user }} {{ SNMP_USER[user]['SNMP_USER_TYPE'] }} +CreateUser {{ user }} {{ SNMP_USER[user]['SNMP_USER_AUTH_TYPE'] }} {{ SNMP_USER[user]['SNMP_USER_AUTH_PASSWORD'] }} {{ SNMP_USER[user]['SNMP_USER_ENCRYPTION_TYPE'] }} {{ SNMP_USER[user]['SNMP_USER_ENCRYPTION_PASSWORD'] }} +{% elif SNMP_USER[user]['SNMP_USER_PERMISSION'] == 'RW' %} +rwuser {{ user }} {{ SNMP_USER[user]['SNMP_USER_TYPE'] }} +CreateUser {{ user }} {{ SNMP_USER[user]['SNMP_USER_AUTH_TYPE'] }} {{ SNMP_USER[user]['SNMP_USER_AUTH_PASSWORD'] }} {{ SNMP_USER[user]['SNMP_USER_ENCRYPTION_TYPE'] }} {{ SNMP_USER[user]['SNMP_USER_ENCRYPTION_PASSWORD'] }} +{% endif %} {% endfor %} {% else %} -rocommunity {{ snmp_rocommunity }} -rocommunity6 {{ snmp_rocommunity }} {% endif %} + ############################################################################### # # SYSTEM INFORMATION @@ -51,8 +75,18 @@ rocommunity6 {{ snmp_rocommunity }} # Note that setting these values here, results in the corresponding MIB objects being 'read-only' # See snmpd.conf(5) for more details -sysLocation {{ snmp_location }} + +{% if SNMP is defined and SNMP.LOCATION is defined %} +sysLocation {{ SNMP.LOCATION.Location }} +{% else %} +sysLocation public +{% endif %} +{% if SNMP is defined and SNMP.CONTACT is defined %} +sysContact {{ SNMP.CONTACT.keys()[0] }} {{ SNMP.CONTACT.values()[0] }} +{% else %} sysContact Azure Cloud Switch vteam +{% endif %} + # Application + End-to-End layers sysServices 72 diff --git a/dockers/docker-snmp/start.sh b/dockers/docker-snmp/start.sh index 70f139bec45e..aefd0bfc3db6 100755 --- a/dockers/docker-snmp/start.sh +++ b/dockers/docker-snmp/start.sh @@ -20,7 +20,6 @@ SONIC_CFGGEN_ARGS=" \ -d \ -y /etc/sonic/sonic_version.yml \ -t /usr/share/sonic/templates/sysDescription.j2,/etc/ssw/sysDescription \ - -y /etc/sonic/snmp.yml \ -t /usr/share/sonic/templates/snmpd.conf.j2,/etc/snmp/snmpd.conf \ "