Puppet Class: splunk

Inherits:
splunk::params
Defined in:
manifests/init.pp

Overview

Class: splunk

This class deploys Splunk on Linux, Windows, Solaris platforms.

Parameters:

package_source

The source URL for the splunk installation media (typically an RPM, MSI, etc). If a $src_root parameter is set in splunk::params, this will be automatically supplied. Otherwise it is required. The URL can be of any protocol supported by the nanliu/staging module.

package_name

The name of the package(s) as they will exist or be detected on the host.

*package_ensure

ensurance of the package

logging_port

The port to recieve splunktcp logs on.

splunkd_port

The splunkd port. Used as a default for both splunk and splunk::forwarder.

splunkd_listen

The address on which splunkd should listen. Defaults to localhost only.

web_port

The port on which to serve the Splunk Web interface.

purge_inputs

If set to true, will remove any inputs.conf configuration not supplied by Puppet from the target system. Defaults to false.

purge_outputs

If set to true, will remove any outputs.conf configuration not supplied by Puppet from the target system. Defaults to false.

Actions:

Declares parameters to be consumed by other classes in the splunk module.

Requires: nothing

Parameters:

  • package_source (Any) (defaults to: $splunk::params::server_pkg_src)
  • package_name (Any) (defaults to: $splunk::params::server_pkg_name)
  • package_ensure (Any) (defaults to: $splunk::params::server_pkg_ensure)
  • logging_port (Any) (defaults to: $splunk::params::logging_port)
  • splunkd_port (Any) (defaults to: $splunk::params::splunkd_port)
  • splunk_user (Any) (defaults to: $splunk::params::splunk_user)
  • pkg_provider (Any) (defaults to: $splunk::params::pkg_provider)
  • splunkd_listen (Any) (defaults to: '127.0.0.1')
  • web_port (Any) (defaults to: '8000')
  • purge_authentication (Any) (defaults to: false)
  • purge_authorize (Any) (defaults to: false)
  • purge_distsearch (Any) (defaults to: false)
  • purge_indexes (Any) (defaults to: false)
  • purge_inputs (Any) (defaults to: false)
  • purge_limits (Any) (defaults to: false)
  • purge_outputs (Any) (defaults to: false)
  • purge_props (Any) (defaults to: false)
  • purge_server (Any) (defaults to: false)
  • purge_transforms (Any) (defaults to: false)
  • purge_web (Any) (defaults to: false)


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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
# File 'manifests/init.pp', line 45

class splunk (
  $package_source       = $splunk::params::server_pkg_src,
  $package_name         = $splunk::params::server_pkg_name,
  $package_ensure       = $splunk::params::server_pkg_ensure,
  $logging_port         = $splunk::params::logging_port,
  $splunkd_port         = $splunk::params::splunkd_port,
  $splunk_user          = $splunk::params::splunk_user,
  $pkg_provider         = $splunk::params::pkg_provider,
  $splunkd_listen       = '127.0.0.1',
  $web_port             = '8000',
  $purge_authentication = false,
  $purge_authorize      = false,
  $purge_distsearch     = false,
  $purge_indexes        = false,
  $purge_inputs         = false,
  $purge_limits         = false,
  $purge_outputs        = false,
  $purge_props          = false,
  $purge_server         = false,
  $purge_transforms     = false,
  $purge_web            = false,
) inherits splunk::params {

  $virtual_service = $splunk::params::server_service
  $staging_subdir  = $splunk::params::staging_subdir

  $path_delimiter  = $splunk::params::path_delimiter

  if $pkg_provider != undef and $pkg_provider != 'yum' and  $pkg_provider != 'apt' {
    include staging

    $staged_package  = staging_parse($package_source)
    $pkg_path_parts  = [$staging::path, $staging_subdir, $staged_package]
    $pkg_source      = join($pkg_path_parts, $path_delimiter)

    #no need for staging the source if we have yum or apt
    staging::file { $staged_package:
      source => $package_source,
      subdir => $staging_subdir,
      before => Package[$package_name],
    }
  }

  package { $package_name:
    ensure   => $package_ensure,
    provider => $pkg_provider,
    source   => $pkg_source,
    before   => Service[$virtual_service],
    tag      => 'splunk_server',
  }

  splunk_input { 'default_host':
    section => 'default',
    setting => 'host',
    value   => $::clientcert,
    tag     => 'splunk_server',
  }
  splunk_input { 'default_splunktcp':
    section => "splunktcp://:${logging_port}",
    setting => 'connection_host',
    value   => 'dns',
    tag     => 'splunk_server',
  }
  splunk_web { 'splunk_server_splunkd_port':
    section => 'settings',
    setting => 'mgmtHostPort',
    value   => "${splunkd_listen}:${splunkd_port}",
    tag => 'splunk_server'
  }

  splunk_web { 'splunk_server_web_port':
    section => 'settings',
    setting => 'httpport',
    value   => $web_port,
    tag => 'splunk_server'
  }

  # If the purge parameters have been set, remove all unmanaged entries from
  # the inputs.conf and outputs.conf files, respectively.
  if $purge_authentication  {
    resources { 'splunk_authentication':  purge => true; }
  }

  if $purge_authorize  {
    resources { 'splunk_authorize':  purge => true; }
  }

  if $purge_distsearch  {
    resources { 'splunk_distsearch':  purge => true; }
  }

  if $purge_indexes  {
    resources { 'splunk_indexes':  purge => true; }
  }

  if $purge_inputs  {
    resources { 'splunk_input':  purge => true; 
                'splunkforwarder_input':  purge => true; }
  }

  if $purge_limits  {
    resources { 'splunk_limits':  purge => true; }
  }

  if $purge_outputs {
    resources { 'splunk_output': purge => true;
                'splunkforwarder_output': purge => true; }
  }

  if $purge_props  {
    resources { 'splunk_props':  purge => true; }
  }


  if $purge_server  {
    resources { 'splunk_server':  purge => true; }
  }


  if $purge_transforms  {
    resources { 'splunk_transforms':  purge => true; }
  }

  if $purge_web  {
    resources { 'splunk_web':  purge => true; }
  }

  # This is a module that supports multiple platforms. For some platforms
  # there is non-generic configuration that needs to be declared in addition
  # to the agnostic resources declared here.
  case $::kernel {
    'Linux': { include splunk::platform::posix   }
    'SunOS': { include splunk::platform::solaris }
    default: { } # no special configuration needed
  }

  # Realize resources shared between server and forwarder profiles, and set up
  # dependency chains.
  include splunk::virtual

  # This realize() call is because the collectors don't seem to work well with
  # arrays. They'll set the dependencies but not realize all Service resources
  realize(Service[$virtual_service])

  Package                <| title == $package_name    |> ->
  Exec                   <| tag   == 'splunk_server'  |> ->
  File                   <| tag   == 'splunk_server'  |> ->
  Service                <| title == $virtual_service |>

  Package                <| title == $package_name    |> ->
  File                   <| tag   == 'splunk_server'  |> ->
  Splunk_authentication  <| tag   == 'splunk_server'  |> ~>
  Service                <| title == $virtual_service |>

  Package                <| title == $package_name    |> ->
  File                   <| tag   == 'splunk_server'  |> ->
  Splunk_authorize       <| tag   == 'splunk_server'  |> ~>
  Service                <| title == $virtual_service |>

  Package                <| title == $package_name    |> ->
  File                   <| tag   == 'splunk_server'  |> ->
  Splunk_distsearch      <| tag   == 'splunk_server'  |> ~>
  Service                <| title == $virtual_service |>

  Package                <| title == $package_name    |> ->
  File                   <| tag   == 'splunk_server'  |> ->
  Splunk_indexes         <| tag   == 'splunk_server'  |> ~>
  Service                <| title == $virtual_service |>

  Package                <| title == $package_name    |> ->
  File                   <| tag   == 'splunk_server'  |> ->
  Splunk_input           <| tag   == 'splunk_server'  |> ~>
  Service                <| title == $virtual_service |>

  Package                <| title == $package_name    |> ->
  File                   <| tag   == 'splunk_server'  |> ->
  Splunk_limits          <| tag   == 'splunk_server'  |> ~>
  Service                <| title == $virtual_service |>

  Package                <| title == $package_name    |> ->
  File                   <| tag   == 'splunk_server'  |> ->
  Splunk_output          <| tag   == 'splunk_server'  |> ~>
  Service                <| title == $virtual_service |>

  Package                <| title == $package_name    |> ->
  File                   <| tag   == 'splunk_server'  |> ->
  Splunk_props           <| tag   == 'splunk_server'  |> ~>
  Service                <| title == $virtual_service |>

  Package                <| title == $package_name    |> ->
  File                   <| tag   == 'splunk_server'  |> ->
  Splunk_server          <| tag   == 'splunk_server'  |> ~>
  Service                <| title == $virtual_service |>

  Package                <| title == $package_name    |> ->
  File                   <| tag   == 'splunk_server'  |> ->
  Splunk_transforms      <| tag   == 'splunk_server'  |> ~>
  Service                <| title == $virtual_service |>

  Package                <| title == $package_name    |> ->
  File                   <| tag   == 'splunk_server'  |> ->
  Splunk_web             <| tag   == 'splunk_server'  |> ~>
  Service                <| title == $virtual_service |>

  File {
    owner => $splunk_user,
    group => $splunk_user,
    mode => '0600',
  }

  file { "/opt/splunk/etc/system/local/authentication.conf":
    ensure => present,
    tag => 'splunk_server'
  }

  file { "/opt/splunk/etc/system/local/authorize.conf":
    ensure => present,
    tag => 'splunk_server'
  }

  file { "/opt/splunk/etc/system/local/distsearch.conf":
    ensure => present,
    tag => 'splunk_server'
  }

  file { "/opt/splunk/etc/system/local/indexes.conf":
    ensure => present,
    tag => 'splunk_server'
  }

  file { "/opt/splunk/etc/system/local/inputs.conf":
    ensure => present,
    tag => 'splunk_server'
  }

  file { "/opt/splunk/etc/system/local/limits.conf":
    ensure => present,
    tag => 'splunk_server'
  }

  file { "/opt/splunk/etc/system/local/outputs.conf":
    ensure => present,
    tag => 'splunk_server'
  }

  file { "/opt/splunk/etc/system/local/props.conf":
    ensure => present,
    tag => 'splunk_server'
  }

  file { "/opt/splunk/etc/system/local/server.conf":
    ensure => present,
    tag => 'splunk_server'
  }

  file { "/opt/splunk/etc/system/local/transforms.conf":
    ensure => present,
    tag => 'splunk_server'
  }

  file { "/opt/splunk/etc/system/local/web.conf":
    ensure => present,
    tag => 'splunk_server'
  }

  # Validate: if both Splunk and Splunk Universal Forwarder are installed on
  # the same system, then they must use different admin ports.
  if (defined(Class['splunk']) and defined(Class['splunk::forwarder'])) {
    $s_port = $splunk::splunkd_port
    $f_port = $splunk::forwarder::splunkd_port
    if $s_port == $f_port {
      fail(regsubst("Both splunk and splunk::forwarder are included, but both
        are configured to use the same splunkd port (${s_port}). Please either
        include only one of splunk, splunk::forwarder, or else configure them
        to use non-conflicting splunkd ports.", '\s\s+', ' ', 'G')
      )
    }
  }

}