Puppet Class: splunk::forwarder

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

Overview

Class: splunk

This class deploys the Splunk Universal Forwarder on Linux, Windows, Solaris platforms.

Parameters:

server

The address of a server to send logs to.

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.

logging_port

The port to send splunktcp logs to.

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.

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:

  • server (Any) (defaults to: $splunk::params::server)
  • package_source (Any) (defaults to: $splunk::params::forwarder_pkg_src)
  • package_name (Any) (defaults to: $splunk::params::forwarder_pkg_name)
  • logging_port (Any) (defaults to: $splunk::params::logging_port)
  • splunkd_port (Any) (defaults to: $splunk::params::splunkd_port)
  • splunkd_listen (Any) (defaults to: '127.0.0.1')
  • purge_inputs (Any) (defaults to: false)
  • purge_outputs (Any) (defaults to: false)
  • pkg_provider (Any) (defaults to: undef)
  • forwarder_confdir (Any) (defaults to: $splunk::params::forwarder_confdir)
  • forwarder_output (Any) (defaults to: $splunk::params::forwarder_output)
  • forwarder_input (Any) (defaults to: $splunk::params::forwarder_input)
  • create_password (Any) (defaults to: $splunk::params::create_password)


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
# File 'manifests/forwarder.pp', line 43

class splunk::forwarder (
  $server            = $splunk::params::server,
  $package_source    = $splunk::params::forwarder_pkg_src,
  $package_name      = $splunk::params::forwarder_pkg_name,
  $logging_port      = $splunk::params::logging_port,
  $splunkd_port      = $splunk::params::splunkd_port,
  $splunkd_listen    = '127.0.0.1',
  $purge_inputs      = false,
  $purge_outputs     = false,
  $pkg_provider      = undef,
  $forwarder_confdir = $splunk::params::forwarder_confdir,
  $forwarder_output  = $splunk::params::forwarder_output,
  $forwarder_input   = $splunk::params::forwarder_input,
  $create_password   = $splunk::params::create_password,
) inherits splunk::params {

  $virtual_service = $splunk::params::forwarder_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
    $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
    $staged_package  = staging_parse($package_source)
    staging::file { $staged_package:
      source => $package_source,
      subdir => $staging_subdir,
      before => Package[$package_name],
    }
  }
  package { $package_name:
    ensure          => installed,
    provider        => $pkg_provider,
    source          => $pkg_source,
    before          => Service[$virtual_service],
    install_options => $splunk::params::forwarder_install_options,
    tag             => 'splunk_forwarder',
  }
  # Declare inputs and outputs specific to the forwarder profile
  create_resources( 'splunkforwarder_input',$forwarder_input)
  create_resources( 'splunkforwarder_output',$forwarder_output)
  # this is default
  ini_setting { 'forwarder_splunkd_port':
    path    => "${splunk::params::forwarder_confdir}/web.conf",
    section => 'settings',
    setting => 'mgmtHostPort',
    value   => "${splunkd_listen}:${splunkd_port}",
    require => Package[$package_name],
    notify  => Service[$virtual_service],
  }

  # If the purge parameters have been set, remove all unmanaged entries from
  # the inputs.conf and outputs.conf files, respectively.
  if $purge_inputs  {
    resources { 'splunkforwarder_input':  purge => true; }
  }
  if $purge_outputs {
    resources { 'splunkforwarder_output': 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': { class { 'splunk::platform::posix': splunkd_port => $splunkd_port, } }
    '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

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

  Package               <| title  == $package_name      |> ->
  Splunkforwarder_input <| tag    == 'splunk_forwarder' |> ~>
  Service               <| title  == $virtual_service   |>

  Package                <| title == $package_name      |> ->
  Splunkforwarder_output <| tag   == 'splunk_forwarder' |> ~>
  Service                <| title == $virtual_service   |>

  # 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')
      )
    }
  }

}