Skip to content

Commit 72df3d8

Browse files
author
Beau Bilyeu
committed
style(*): correcting to appease the lint masters
* pillar.example - corrected to match yamllint guidelines * snmp/conf.sls - exploded into variables to stay below 160 char * snmp/macros.jinja - corrected style issues * config.rb - fixed to snake_cake
1 parent 8ea4f03 commit 72df3d8

File tree

4 files changed

+74
-64
lines changed

4 files changed

+74
-64
lines changed

pillar.example

Lines changed: 58 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ snmp:
66
lookup:
77
snmpdargs: '-Lsd -Lf /dev/null -p /var/run/snmpd.pid -a'
88
trapdargs: '-Lsd -p /var/run/snmptrapd.pid'
9-
trapdrun: 'no' # Single quote wrap to avoid boolean behavior
9+
trapdrun: 'no' # Single quote wrap to avoid boolean behavior
1010

1111
conf:
1212
## Config reference: http://www.net-snmp.org/docs/man/snmpd.conf.html
@@ -19,8 +19,8 @@ snmp:
1919
### Disk Usage Monitoring ###
2020
#################################
2121
# ref: http://www.net-snmp.org/docs/man/snmpd.conf.html#lbAS
22-
#disks:
23-
# (path): (min-space-in-kB)
22+
# disks:
23+
# (path): (min-space-in-kB)
2424
disks:
2525
'/': 1000000
2626
'/nfs/apache': 250000
@@ -29,14 +29,14 @@ snmp:
2929
### VACM Configuration ###
3030
##############################
3131
# ref: http://www.net-snmp.org/docs/man/snmpd.conf.html#lbAL
32-
# `com2sec` : map an SNMPv1 or SNMPv2c community string to a
33-
# security name - either from a particular range of
32+
# `com2sec` : map an SNMPv1 or SNMPv2c community string to a
33+
# security name - either from a particular range of
3434
# source addresses, or globally ("default")
3535
# (SALT: multiple entries allowed, list syntax)
36-
#com2sec:
37-
# - name: (helpful label)
38-
# source: {hostname|IP+Mask|IP+Subnet}
39-
# community: (community string)
36+
# com2sec:
37+
# - name: (helpful label)
38+
# source: {hostname|IP+Mask|IP+Subnet}
39+
# community: (community string)
4040
com2Sec:
4141
- name: localSec
4242
source: 10.20.30.0/24
@@ -48,10 +48,10 @@ snmp:
4848
# `group` : maps a security name (in the specified security model)
4949
# into a named group
5050
# (SALT: multiple entries allowed, list syntax)
51-
#groups:
52-
# - name: (helpful label)
53-
# version: {v1|v2c|usm|tsm|ksm}
54-
# secname: (any valid `com2Sec` entry defined)
51+
# groups:
52+
# - name: (helpful label)
53+
# version: {v1|v2c|usm|tsm|ksm}
54+
# secname: (any valid `com2Sec` entry defined)
5555
groups:
5656
- name: ROwers1
5757
version: v1
@@ -64,11 +64,11 @@ snmp:
6464
#
6565
# `view` : defines a named "view" - a subset of the overall OID tree
6666
# (SALT: multiple entries allowed, list syntax)
67-
#views:
68-
# - name: (helpful label)
69-
# type: {included|excluded}
70-
# oid: (oid string)
71-
# mask: (list of hex octets to match against) ## OPTIONAL
67+
# views:
68+
# - name: (helpful label)
69+
# type: {included|excluded}
70+
# oid: (oid string)
71+
# mask: (list of hex octets to match against) ## OPTIONAL
7272
views:
7373
- name: all
7474
type: included
@@ -80,21 +80,21 @@ snmp:
8080
- name: iso3
8181
type: included
8282
oid: '.iso.org.dod.mgmt'
83-
#
84-
# `access` : maps from a group of users/communities (with a particular
85-
# security model and minimum security level, and in a
83+
#
84+
# `access` : maps from a group of users/communities (with a particular
85+
# security model and minimum security level, and in a
8686
# specific context) to one of three views, depending on the
8787
# request being processed
8888
# (SALT: multiple entries allowed, list syntax)
89-
#access:
90-
# - name: (any valid `group` entry defined)
91-
# context: (incoming request context) # can be leftout to assume 'blank'
92-
# match: {any|v1|v2c|usm|tsm|ksm}
93-
# level: {noauth|auth|priv} # v1 & v2c require 'noauth'
94-
# prefix: {exact|prefix}
95-
# read: {all|none} # omitting selects 'none'
96-
# write: {all|none} # omitting selects 'none'
97-
# notify: {all|none} # omitting selects 'none'
89+
# access:
90+
# - name: (any valid `group` entry defined)
91+
# context: (incoming request context) # can be leftout to assume 'blank'
92+
# match: {any|v1|v2c|usm|tsm|ksm}
93+
# level: {noauth|auth|priv} # v1 & v2c require 'noauth'
94+
# prefix: {exact|prefix}
95+
# read: {all|none} # omitting selects 'none'
96+
# write: {all|none} # omitting selects 'none'
97+
# notify: {all|none} # omitting selects 'none'
9898
access:
9999
- name: ROwers1
100100
match: any
@@ -107,31 +107,32 @@ snmp:
107107
prefix: exact
108108
read: all
109109
write: all
110-
110+
111111
######################################
112112
### Traditional Access Control ###
113113
######################################
114114
# ref: http://www.net-snmp.org/docs/man/snmpd.conf.html#lbAK
115115
## v1/v2c ##
116-
# rXcommunity - specify an SNMPv1 or SNMPv2c community that will be
116+
# rXcommunity - specify an SNMPv1 or SNMPv2c community that will be
117117
# allowed read-only (if `rocommunity`) or be allowed
118118
# read-write (if `rwcommunity`) access
119119
# (SALT: suffix '6' for ipv6 version of the communities,
120120
# such as 'rocommunities6' or 'rwcommunities6')
121+
# (SALT: source, if used, accepts list format or single entry)
121122
# SYNTAX WITH SOURCE
122-
#rXcommunities:
123-
# (community string):
124-
# source: {hostname|IP+Mask|IP+Subnet} or [{hostname|IP+Mask|IP+Subnet}, ...] # list format or single entry
125-
rocommunities:
126-
public:
127-
source: [localhost, 192.168.0.0/24, 2001:DB8::1]
128-
rwcommunities:
129-
private:
130-
source: 192.168.1.0/24
131-
# SYNTAX WITHOUT SOURCE
132-
#rXcommunities:
133-
# - (community string)
134-
# - (another community string)
123+
# rXcommunities:
124+
# (community string):
125+
# source: {hostname|IP+Mask|IP+Subnet} or [{hostname|IP+Mask|IP+Subnet}, ...]
126+
# rocommunities:
127+
# public:
128+
# source: [localhost, 192.168.0.0/24, 2001:DB8::1]
129+
# rwcommunities:
130+
# private:
131+
# source: 192.168.1.0/24
132+
# SYNTAX WITHOUT SOURCE
133+
# rXcommunities:
134+
# - (community string)
135+
# - (another community string)
135136
rocommunities:
136137
- monitoring
137138
- dontbreakit
@@ -142,20 +143,21 @@ snmp:
142143
# and the default privproto will be AES, instead of
143144
# DES, for the sake of security.
144145
# `securitylevel` = 'priv' enforces encryption, in
145-
# addition to auth, which *requires* privpassphrase
146+
# addition to auth, which *requires* privpassphrase
146147
# to be defined.
147-
#rXusers:
148-
# - username: (snmpv3 user name)
149-
# authpassphrase: (authentication password)
150-
# privpassphrase: (encryption password) ## optional only if `securitylevel` = 'auth'
151-
# securitylevel: {auth|priv} # omitting selects 'auth'
152-
# authproto: {MD5|SHA} # omitting selects 'SHA'
153-
# privproto: {DES|AES} # omitting selects 'AES'
154-
# view: (any valid `view` entry defined) ## OPTIONAL
148+
# (SALT: `privpassphrase` is optional only if `securitylevel` = 'auth')
149+
# rXusers:
150+
# - username: (snmpv3 user name)
151+
# authpassphrase: (authentication password)
152+
# privpassphrase: (encryption password)
153+
# securitylevel: {auth|priv} # omitting selects 'auth'
154+
# authproto: {MD5|SHA} # omitting selects 'SHA'
155+
# privproto: {DES|AES} # omitting selects 'AES'
156+
# view: (any valid `view` entry defined) ## OPTIONAL
155157
rousers:
156158
- username: 'someNewUser'
157159
authpassphrase: 'tklhgKipJF1nNY'
158-
view: all
160+
view: all
159161
rwusers:
160162
- username: 'somethingCICD'
161163
authpassphrase: 'VPluOBhwmnFB6z'
@@ -170,7 +172,7 @@ snmp:
170172
# should be acceptable here.)
171173
settings:
172174
# ref: http://www.net-snmp.org/docs/man/snmpd.conf.html#lbAD
173-
#agentAddress: [<transport-specifier>:]<transport-address>
175+
# agentAddress: [<transport-specifier>:]<transport-address>
174176
agentAddress: 'udp:161,udp6:[::1]:161'
175177
sysServices: 72
176178
master: ['agentx']

snmp/conf.sls

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,18 @@ snmp_conf:
2222
{% if 'persistentconfig' in snmp %}
2323
{% for groups in ['rousers', 'rwusers'] %}
2424
{% for user in conf.get(groups, []) %}
25-
{% set securitylevel = 'authPriv' if user.get('securitylevel') == 'priv' else 'authNoPriv' %}
25+
{% set seclevel = 'authPriv' if user.get('securitylevel') == 'priv' else 'authNoPriv' %}
26+
{% set uname = user.username %}
27+
{% set authproto = user.get('authproto', 'SHA') %}
28+
{% set authpass = user.authpassphrase %}
29+
{% set privproto = user.get('privproto', 'AES') %}
30+
{% set privpass = '-X ' ~ user.privpassphrase if seclevel == 'authPriv' else '' %}
2631
{# if test fails, stop snmpd, add user to persistent config file, restart snmpd #}
2732
snmpv3 creating {{ user.username }} step 1 of 3:
2833
service.dead:
2934
- name: {{ snmp.service }}
3035
- unless:
31-
- "snmpget -v3 -l {{ securitylevel }} -u {{ user.username }} -a {{ user.get('authproto', 'SHA') }} -A {{ user.authpassphrase }} -x {{ user.get('privproto', 'AES') }} {% if securitylevel == "authPriv" %}-X {{ user.privpassphrase }}{% endif %} 127.0.0.1 1.3.6.1.2.1.1.5.0 -On"
36+
- "snmpget -v3 -l {{ seclevel }} -u {{ uname }} -a {{ authproto }} -A {{ authpass }} -x {{ privproto }} {{ privpass }} 127.0.0.1 1.3.6.1.2.1.1.5.0 -On"
3237
3338
snmpv3 creating {{ user.username }} step 2 of 3:
3439
file.line:

snmp/macros.jinja

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,15 @@
1515
{%- set source = [source] %}
1616
{%- endif %}
1717
{%- for src in source -%}
18-
{{ mode }}community {{ community }} {{ src }}{{' -V ' ~ view if view else ''}}
18+
{{ mode~'community' }} {{ community }} {{ src }} {{ ' -V ' ~ view if view else '' }}
1919
{% endfor %}
2020
{%- endfor -%}
21-
{% endmacro-%}
21+
{% endmacro -%}
2222

2323
{%- macro v3_createUser_string(user) -%}
2424
{% set seclevel = user.get('securitylevel', 'auth') -%}
25-
createUser {{ user.username }} {{ user.get('authproto', 'SHA') }} {{ user.authpassphrase }} {{ user.get('privproto', 'AES') }} {% if seclevel == "priv" %}{{ user.privpassphrase }}{% else %}{{ user.get('privpassphrase', '') }}{% endif %}
25+
{% set authproto = user.get('authproto', 'SHA') -%}
26+
{% set privproto = user.get('privproto', 'AES') %}
27+
{% set privpass = user.get('privpassphrase', '') %}
28+
createUser {{ user.username }} {{ authproto }} {{ user.authpassphrase }} {{ privproto }} {{ privpass }}
2629
{%- endmacro -%}

test/integration/default/controls/config.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
else
1212
%w[/etc/snmp/snmpd.conf root]
1313
end
14-
14+
1515
# Override for persistent config file
16-
createUser_str =
16+
create_user_str =
1717
case platform[:family]
1818
when 'debian'
1919
'createUser string will be added to /var/lib/snmp/snmpd.conf'
@@ -38,7 +38,7 @@
3838
its('content') { should include 'rwcommunity private 192.168.1.0/24' }
3939
its('content') { should include 'rouser myv3user auth -V all' }
4040
its('content') do
41-
should include createUser_str
41+
should include create_user_str
4242
end
4343
end
4444
end

0 commit comments

Comments
 (0)