Puppet Class: snmpd

Defined in:
manifests/init.pp

Overview

Class: snmpd

Configure the SNMP Daemon.

This class, and the associated defines, should provide relatively comprehensive coverage of the snmpd features.

See snmpd(8) and snmpd.conf(5) for additional details.

Parameters

rsync_server
rsync_timeout

Authors

Parameters:

  • rsync_server (Any) (defaults to: hiera('rsync::server'))
  • rsync_timeout (Any) (defaults to: hiera('rsync::timeout','2'))
  • agentgid (Any) (defaults to: '333')
  • agentuid (Any) (defaults to: '333')
  • leave_pidfile (Any) (defaults to: 'no')
  • max_get_bulk_repeats (Any) (defaults to: '1024')
  • max_get_bulk_responses (Any) (defaults to: '100')
  • engine_id (Any) (defaults to: '')
  • engine_id_type (Any) (defaults to: '')
  • engine_id_nic (Any) (defaults to: '')
  • dont_log_tcp_wrappers_connects (Any) (defaults to: false)


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'manifests/init.pp', line 19

class snmpd (
  $rsync_server = hiera('rsync::server'),
  $rsync_timeout = hiera('rsync::timeout','2'),
  $agentgid = '333',
  $agentuid = '333',
  $leave_pidfile = 'no',
  $max_get_bulk_repeats = '1024',
  $max_get_bulk_responses = '100',
  $engine_id = '',
  $engine_id_type = '',
  $engine_id_nic = '',
  $dont_log_tcp_wrappers_connects = false
){
  include 'rsync'
  include 'tcpwrappers'
  include 'snmpd::utils'


  validate_bool($dont_log_tcp_wrappers_connects)
  validate_integer($agentgid)
  validate_integer($agentuid)

  $l_fragdir = fragmentdir('snmpd')
  $l_outdir = concat_output('snmpd')

  concat_build { 'snmpd':
    target => '/etc/snmp/snmpd.conf',
    order  => [
        '*.all',
        'main.conf',
        '*.auth',
        '*.comm',
        '*.com2sec',
        '*.group',
        '*.view',
        '*.tview',
        '*.access',
        '*.authc',
        '*.authu',
        '*.authg',
        '*.autha',
        '*.seta',
        '*.system',
        '*.iface',
        '*.host_resources',
        '*.proc',
        '*.procfix',
        '*.disks',
        '*.load',
        '*.logmon',
        '*.logmatch',
        '*.comstr',
        '*.sink',
        '*.trapsess',
        'all.authtrapenable',
        'all.v1trapaddress',
        'disman.*',
        'ext.*',
        '*.module',
        '*.proxy',
        '*.smux',
        '*.agentX',
        '*.other',
        '*.inject',
        '*.user' ],
    notify => File['/etc/snmp/snmpd.conf']
  }

  concat_build { 'snmpd_agentaddress':
    clean_whitespace => 'all',
    target           => "${l_fragdir}/agentaddress.all",
    parent_build     => 'snmpd',
    file_delimiter   => ',',
    quiet            => true
  }

  file { '/etc/snmp/snmpd.conf':
    owner   => 'root',
    group   => 'root',
    mode    => '0640',
    notify  => [ Service['snmpd'], Exec['set_snmp_perms'] ],
    audit   => content,
    require => [
      Package['net-snmp'],
      Package['net-snmp-libs']
    ]
  }

  file { '/etc/snmp/snmpd.local.conf':
    owner   => 'root',
    group   => 'root',
    mode    => '0640',
    notify  => [ Service['snmpd'], Exec['set_snmp_perms'] ],
    require => [
      Package['net-snmp'],
      Package['net-snmp-libs']
    ]
  }

  package { [
      'net-snmp',
      'net-snmp-libs',
    ]:
      ensure => 'latest'
  }

  # This pulls any global dynamically loadable modules for later inclusion in
  # the configuration file.
  #
  # If this does not succeed, then the entire build chain will fail.
  rsync { 'snmp_dlmod':
    source       => 'snmp/dlmod',
    target       => '/usr/local/share/snmp',
    server       => $rsync_server,
    timeout      => $rsync_timeout,
    delete       => true,
    preserve_acl => false,
    notify       => [
      Service['snmpd'],
      Exec['set_snmp_perms']
    ]
  }

  service { 'snmpd':
    ensure    => 'running',
    enable    => true,
    start     =>
      'process=`/bin/ps -C snmpd > /dev/null; /bin/echo $?`; if [ $process -eq 0 ]; then /sbin/service snmpd reload; else /sbin/service snmpd start; fi',
    restart   =>
      '/sbin/service snmpd stop; /bin/sed -i /usmUser/d /var/net-snmp/snmpd.conf; /sbin/service snmpd start',
    subscribe => File['/etc/snmp/snmpd.conf'],
    require   => [
      Package['net-snmp'],
      Package['net-snmp-libs']
    ]
  }

  tcpwrappers::allow { 'snmpd':
    pattern => 'ALL'
  }

  concat_fragment { 'snmpd+main.conf':
    content => template('snmpd/main.conf.erb')
  }

  if !empty($agentgid) {
    group { 'snmp':
      ensure    => 'present',
      gid       => $agentgid,
      allowdupe => false,
      notify    => Service['snmpd']
    }
  }

  if !empty($agentuid) {
    user { 'snmp':
      ensure     => 'present',
      uid        => $agentuid,
      comment    => 'SNMP User',
      gid        => 'snmp',
      home       => '/var/run/snmpd',
      managehome => false,
      shell      => '/sbin/nologin',
      notify     => Service['snmpd']
    }
  }
}