Skip to content

Commit 0226140

Browse files
tsvanduyntrvanduy
authored andcommitted
[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: sonic-net/SONiC#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 <[email protected]>
1 parent 8836b6b commit 0226140

File tree

2 files changed

+39
-6
lines changed

2 files changed

+39
-6
lines changed

dockers/docker-snmp/snmpd.conf.j2

+39-5
Original file line numberDiff line numberDiff line change
@@ -34,25 +34,59 @@ view systemonly included .1.3.6.1.2.1.1
3434
view systemonly included .1.3.6.1.2.1.25.1
3535

3636
# Default access to basic system info
37-
{% if snmp_rocommunities %}
38-
{% for community in snmp_rocommunities %}
37+
38+
39+
{% if SNMP_COMMUNITY is defined %}
40+
{% for community in SNMP_COMMUNITY %}
41+
{% if SNMP_COMMUNITY[community]['TYPE'] == 'RO' %}
3942
rocommunity {{ community }}
4043
rocommunity6 {{ community }}
44+
{% endif %}
45+
{% endfor %}
46+
{% endif %}
47+
48+
{% if SNMP_COMMUNITY is defined %}
49+
{% for community in SNMP_COMMUNITY %}
50+
{% if SNMP_COMMUNITY[community]['TYPE'] == 'RW' %}
51+
rwcommunity {{ community }}
52+
rwcommunity6 {{ community }}
53+
{% endif %}
54+
{% endfor %}
55+
{% endif %}
56+
57+
{% if SNMP_USER is defined %}
58+
{% for user in SNMP_USER %}
59+
{% if SNMP_USER[user]['SNMP_USER_PERMISSION'] == 'RO' %}
60+
rouser {{ user }} {{ SNMP_USER[user]['SNMP_USER_TYPE'] }}
61+
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'] }}
62+
{% elif SNMP_USER[user]['SNMP_USER_PERMISSION'] == 'RW' %}
63+
rwuser {{ user }} {{ SNMP_USER[user]['SNMP_USER_TYPE'] }}
64+
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'] }}
65+
{% endif %}
4166
{% endfor %}
4267
{% else %}
43-
rocommunity {{ snmp_rocommunity }}
44-
rocommunity6 {{ snmp_rocommunity }}
4568
{% endif %}
4669

70+
4771
###############################################################################
4872
#
4973
# SYSTEM INFORMATION
5074
#
5175

5276
# Note that setting these values here, results in the corresponding MIB objects being 'read-only'
5377
# See snmpd.conf(5) for more details
54-
sysLocation {{ snmp_location }}
78+
79+
{% if SNMP is defined and SNMP.LOCATION is defined %}
80+
sysLocation {{ SNMP.LOCATION.Location }}
81+
{% else %}
82+
sysLocation public
83+
{% endif %}
84+
{% if SNMP is defined and SNMP.CONTACT is defined %}
85+
sysContact {{ SNMP.CONTACT.keys()[0] }} {{ SNMP.CONTACT.values()[0] }}
86+
{% else %}
5587
sysContact Azure Cloud Switch vteam <linuxnetdev@microsoft.com>
88+
{% endif %}
89+
5690
# Application + End-to-End layers
5791
sysServices 72
5892

dockers/docker-snmp/start.sh

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ SONIC_CFGGEN_ARGS=" \
2020
-d \
2121
-y /etc/sonic/sonic_version.yml \
2222
-t /usr/share/sonic/templates/sysDescription.j2,/etc/ssw/sysDescription \
23-
-y /etc/sonic/snmp.yml \
2423
-t /usr/share/sonic/templates/snmpd.conf.j2,/etc/snmp/snmpd.conf \
2524
"
2625

0 commit comments

Comments
 (0)