Puppet Class: splunk
Overview
Class: splunk
This is the main splunk class
Parameters
Specific class parameters
- license_file_source
-
Optional source for the license file, if provided it’s added to Splunk
- install
-
Splunk install type:
-
server - For complete installation (seacher, indexer…).
Use this on central server
-
forwarder - TO install only the universal forwarder package
Use this on all the other servers (Default option)
-
- install_source
-
Complete URL (http://.…) of the splunk or splunkforwarder package to install. If not defined you must be able to install these packages via your default provider (apt, yum…) so you should have them in a custom repo
- admin_password
-
Splunk admin password both for the forwarder management and the splunk web interface. Default is “changeme”
- forward_server
-
The central server(s) to forward messages to. MUST be in host:port format If you want to forward to more than one servers, use an array. Example: [ “splunk1.example42.com:9997” , “splunk2.example42.com:9997” ]
- deployment_server
-
The server to receieve apps from. MUST be in host:port format Example: “splunk1.example42.com:8089”
- monitor_path
-
The path of files or directories that you want to monitor with Splunk Either on the central server or the forwarders. May be an array. Example: [ “/var/log/tomcat6/catalina.out” , “/var/log/apache2” ]
- monitor_sourcetype
-
The source_type for the logs defined in monitor_path If you need a more granular management of sourcetype for different logs try splunk::input::monitor
- template_inputs
-
A custom template to use for a custom etc/system/local/inputs.conf file The value is used in: content => template($template_inputs), Note that splunk generates autonomously this file, overwrite if you know what you’re doing.
- template_outputs
-
A custom template to use for a custom etc/system/local/outputs.conf file The value is used in: content => template($template_outputs), Note that splunk generates autonomously this file and on the forwarder this is populated with the value of forward_server
- template_server
-
A custom template to use for a custom etc/system/local/server.conf file The value is used in: content => template($template_server), Note that splunk generates autonomously this file, overwrite if you know what you’re doing.
- template_web
-
A custom template to use for a custom etc/system/local/web.conf file The value is used in: content => template($template_web),
Standard class parameters Define the general class behaviour and customizations
- my_class
-
Name of a custom class to autoload to manage module’s customizations If defined, splunk class will automatically “include $my_class” Can be defined also by the (top scope) variable $splunk_myclass
- source_dir
-
If defined, the whole splunk configuration directory content is retrieved recursively from the specified source (source => $source_dir , recurse => true) Can be defined also by the (top scope) variable $splunk_source_dir
- source_dir_purge
-
If set to true (default false) the existing configuration directory is mirrored with the content retrieved from source_dir (source => $source_dir , recurse => true , purge => true) Can be defined also by the (top scope) variable $splunk_source_dir_purge
- options
-
An hash of custom options to be used in templates for arbitrary settings. Can be defined also by the (top scope) variable $splunk_options
- absent
-
Set to ‘true’ to remove package(s) installed by module Can be defined also by the (top scope) variable $splunk_absent
- disable
-
Set to ‘true’ to disable service(s) managed by module Can be defined also by the (top scope) variable $splunk_disable
- disableboot
-
Set to ‘true’ to disable service(s) at boot, without checks if it’s running Use this when the service is managed by a tool like a cluster software Can be defined also by the (top scope) variable $splunk_disableboot
- monitor
-
Set to ‘true’ to enable monitoring of the services provided by the module Can be defined also by the (top scope) variables $splunk_monitor and $monitor
- monitor_tool
-
Define which monitor tools (ad defined in Example42 monitor module) you want to use for splunk checks Can be defined also by the (top scope) variables $splunk_monitor_tool and $monitor_tool
- monitor_target
-
The Ip address or hostname to use as a target for monitoring tools. Default is the fact $ip_address Can be defined also by the (top scope) variables $splunk_monitor_target and $monitor_target
- puppi
-
Set to ‘true’ to enable creation of module data files that are used by puppi Can be defined also by the (top scope) variables $splunk_puppi and $puppi
- puppi_helper
-
Specify the helper to use for puppi commands. The default for this module is specified in params.pp and is generally a good choice. You can customize the output of puppi commands for this module using another puppi helper. Use the define puppi::helper to create a new custom helper Can be defined also by the (top scope) variables $splunk_puppi_helper and $puppi_helper
- firewall
-
Set to ‘true’ to enable firewalling of the services provided by the module Can be defined also by the (top scope) variables $splunk_firewall and $firewall
- firewall_tool
-
Define which firewall tool(s) (ad defined in Example42 firewall module) you want to use to open firewall for splunk port(s) Can be defined also by the (top scope) variables $splunk_firewall_tool and $firewall_tool
- firewall_src
-
Define which source ip/net allow for firewalling splunk. Default: 0.0.0.0/0 Can be defined also by the (top scope) variables $splunk_firewall_src and $firewall_src
- firewall_dst
-
Define which destination ip to use for firewalling. Default: $ipaddress Can be defined also by the (top scope) variables $splunk_firewall_dst and $firewall_dst
- debug
-
Set to ‘true’ to enable modules debugging Can be defined also by the (top scope) variables $splunk_debug and $debug
- audit_only
-
Set to ‘true’ if you don’t intend to override existing configuration files and want to audit the difference between existing files and the ones managed by Puppet. Can be defined also by the (top scope) variables $splunk_audit_only and $audit_only
- port
-
The listening port, if any, of the service. This is used by monitor, firewall and puppi (optional) components Note: This doesn’t necessarily affect the service configuration file Can be defined also by the (top scope) variable $splunk_port
- protocol
-
The protocol used by the the service. This is used by monitor, firewall and puppi (optional) components Can be defined also by the (top scope) variable $splunk_protocol
Examples
You can use this class in 2 ways:
-
Set variables (at top scope level on in a ENC) and “include splunk”
-
Call splunk as a parametrized class
See README for details.
Author
Alessandro Franceschi <al@lab42.it/>
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 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 |
# File 'manifests/init.pp', line 192
class splunk (
$license_file_source = params_lookup('license_file_source'),
$install = params_lookup('install'),
$install_source = params_lookup('install_source'),
$admin_password = params_lookup('admin_password'),
$forward_server = params_lookup('forward_server'),
$deployment_server = params_lookup('deployment_server'),
$monitor_path = params_lookup('monitor_path'),
$monitor_sourcetype = params_lookup('monitor_sourcetype'),
$template_inputs = params_lookup('template_inputs'),
$template_outputs = params_lookup('template_outputs'),
$template_server = params_lookup('template_server'),
$template_web = params_lookup('template_web'),
$my_class = params_lookup('my_class'),
$source_dir = params_lookup('source_dir'),
$source_dir_purge = params_lookup('source_dir_purge'),
$options = params_lookup('options'),
$absent = params_lookup('absent'),
$disable = params_lookup('disable'),
$disableboot = params_lookup('disableboot'),
$monitor = params_lookup( 'monitor' , 'global' ),
$monitor_tool = params_lookup( 'monitor_tool' , 'global' ),
$monitor_target = params_lookup( 'monitor_target' , 'global' ),
$puppi = params_lookup( 'puppi' , 'global' ),
$puppi_helper = params_lookup( 'puppi_helper' , 'global' ),
$firewall = params_lookup( 'firewall' , 'global' ),
$firewall_tool = params_lookup( 'firewall_tool' , 'global' ),
$firewall_src = params_lookup( 'firewall_src' , 'global' ),
$firewall_dst = params_lookup( 'firewall_dst' , 'global' ),
$debug = params_lookup( 'debug' , 'global' ),
$audit_only = params_lookup( 'audit_only' , 'global' ),
$port = params_lookup('port'),
$protocol = params_lookup('protocol')
) inherits splunk::params {
# Module's internal variables
$basename = $splunk::install ? {
server => 'splunk',
forwarder => 'splunkforwarder',
}
$basedir = $splunk::install ? {
server => '/opt/splunk',
forwarder => '/opt/splunkforwarder',
}
$package = $splunk::basename
$service = 'splunk'
$service_status = true
$process = 'splunkd'
$process_args = ''
$config_dir = "${splunk::basedir}/etc/"
$config_file_mode = '0644'
$config_file_owner = 'root'
$config_file_group = 'root'
$pid_file = "${splunk::basedir}/var/run/splunk/splunkd.pid"
$data_dir = "${splunk::basedir}/var/lib/splunk"
$log_dir = "${splunk::basedir}/var/log/splunk"
$log_file = "${splunk::basedir}/var/log/splunk/splunkd.log"
### Definition of some variables used in the module
$bool_absent=any2bool($absent)
$bool_disable=any2bool($disable)
$bool_disableboot=any2bool($disableboot)
$bool_puppi=any2bool($puppi)
$bool_monitor=any2bool($monitor)
$bool_firewall=any2bool($firewall)
$bool_audit_only=any2bool($audit_only)
$bool_source_dir_purge=any2bool($source_dir_purge)
$bool_debug=any2bool($debug)
$manage_package = $splunk::bool_absent ? {
true => 'absent',
false => 'present',
}
$manage_service_enable = $splunk::bool_disableboot ? {
true => false,
default => $splunk::bool_disable ? {
true => false,
default => $splunk::bool_absent ? {
true => false,
false => true,
},
},
}
$manage_service_ensure = $splunk::bool_disable ? {
true => 'stopped',
default => $splunk::bool_absent ? {
true => 'stopped',
default => 'running',
},
}
$manage_file = $splunk::bool_absent ? {
true => 'absent',
default => 'present',
}
# If $splunk::disable == true we dont check splunk on the local system
if $splunk::bool_absent == true or $splunk::bool_disable == true or $splunk::bool_disableboot == true {
$manage_monitor = false
} else {
$manage_monitor = true
}
if $splunk::bool_absent == true or $splunk::bool_disable == true {
$manage_firewall = false
} else {
$manage_firewall = true
}
$manage_audit = $splunk::bool_audit_only ? {
true => 'all',
false => undef,
}
$manage_file_replace = $splunk::bool_audit_only ? {
true => false,
false => true,
}
$real_monitor_sourcetype = $splunk::monitor_sourcetype ? {
'' => '',
default => "-sourcetype ${splunk::monitor_sourcetype}",
}
### Managed resources
# If install_source is defined installation is done retriving directly the defined source
if $splunk::install_source != '' {
$install_command = $::operatingsystem ? {
/(?i:Debian|Ubuntu|Mint)/ => "wget \'${splunk::install_source}\' -O /tmp/puppet-splunk.deb ; dpkg -i /tmp/puppet-splunk.deb ; rm -f /tmp/puppet-splunk.deb",
/(?i:RedHat|Centos|Scientific|Suse|OracleLinux|Amazon)/ => "rpm -U ${splunk::install_source}",
}
exec { 'splunk_manage_package':
command => "${splunk::basedir}/puppet_manage_package",
refreshonly => true,
before => Package['splunk'],
}
file { 'splunk_manage_package':
ensure => present,
path => "${splunk::basedir}/puppet_manage_package",
mode => '0700',
content => template('splunk/manage_package.erb'),
before => Package['splunk'] ,
notify => Exec['splunk_manage_package'],
}
file { $splunk::basedir:
ensure => directory
}
}
package { 'splunk':
ensure => $splunk::manage_package,
name => $splunk::package,
}
service { 'splunk':
ensure => $splunk::manage_service_ensure,
name => $splunk::service,
enable => $splunk::manage_service_enable,
hasstatus => $splunk::service_status,
pattern => $splunk::process,
require => Exec['splunk_create_service'],
}
exec { 'splunk_create_service':
command => "${splunk::basedir}/bin/splunk --accept-license enable boot-start --answer-yes --no-prompt",
creates => '/etc/init.d/splunk',
require => Package['splunk'],
}
# Setting of forward_server for forwarders
if $splunk::forward_server {
exec { 'splunk_add_forward_server':
command => "${splunk::basedir}/bin/puppet_add_forward_server",
refreshonly => true,
require => Exec['splunk_change_admin_password'],
}
file { 'splunk_add_forward_server':
ensure => present,
path => "${splunk::basedir}/bin/puppet_add_forward_server",
mode => '0700',
owner => $splunk::config_file_owner,
group => $splunk::config_file_group,
content => template('splunk/add_forward_server.erb'),
require => Package['splunk'],
notify => Exec['splunk_add_forward_server'],
}
}
# Setting of deployment server
if $splunk::deployment_server {
file { 'splunk_deployment_server' :
ensure => present,
path => "${splunk::basedir}/etc/system/local/deploymentclient.conf",
mode => '0700',
owner => $splunk::config_file_owner,
group => $splunk::config_file_group,
content => template('splunk/deploymentclient.erb'),
require => Package['splunk'],
notify => Service['splunk'],
}
}
# Setting of files or directories to be monitored
if $splunk::monitor_path {
exec { 'splunk_add_monitor':
command => "${splunk::basedir}/bin/puppet_add_monitor",
refreshonly => true,
require => Exec['splunk_change_admin_password'],
}
file { 'splunk_add_monitor':
ensure => present,
path => "${splunk::basedir}/bin/puppet_add_monitor",
mode => '0700',
owner => $splunk::config_file_owner,
group => $splunk::config_file_group,
content => template('splunk/add_monitor.erb'),
require => Package['splunk'],
notify => Exec['splunk_add_monitor'],
}
}
# Change of admin password
exec { 'splunk_change_admin_password':
command => "${splunk::basedir}/bin/puppet_change_admin_password",
refreshonly => true,
require => Service['splunk'],
}
file { 'splunk_change_admin_password':
ensure => present,
path => "${splunk::basedir}/bin/puppet_change_admin_password",
mode => '0700',
owner => $splunk::config_file_owner,
group => $splunk::config_file_group,
content => template('splunk/change_admin_password.erb'),
require => Package['splunk'],
notify => Exec['splunk_change_admin_password'],
}
# Local configuration files for which a template can be provided
if $splunk::template_inputs {
file { 'splunk_inputs.conf':
ensure => $splunk::manage_file,
path => "${splunk::basedir}/etc/system/local/inputs.conf",
mode => $splunk::config_file_mode,
owner => $splunk::config_file_owner,
group => $splunk::config_file_group,
require => Package['splunk'],
notify => Service['splunk'],
content => template($splunk::template_inputs),
replace => $splunk::manage_file_replace,
audit => $splunk::manage_audit,
}
}
if $splunk::template_outputs {
file { 'splunk_outputs.conf':
ensure => $splunk::manage_file,
path => "${splunk::basedir}/etc/system/local/outputs.conf",
mode => $splunk::config_file_mode,
owner => $splunk::config_file_owner,
group => $splunk::config_file_group,
require => Package['splunk'],
notify => Service['splunk'],
content => template($splunk::template_outputs),
replace => $splunk::manage_file_replace,
audit => $splunk::manage_audit,
}
}
if $splunk::template_server {
file { 'splunk_server.conf':
ensure => $splunk::manage_file,
path => "${splunk::basedir}/etc/system/local/server.conf",
mode => $splunk::config_file_mode,
owner => $splunk::config_file_owner,
group => $splunk::config_file_group,
require => Package['splunk'],
notify => Service['splunk'],
content => template($splunk::template_server),
replace => $splunk::manage_file_replace,
audit => $splunk::manage_audit,
}
}
if $splunk::template_web {
file { 'splunk_web.conf':
ensure => $splunk::manage_file,
path => "${splunk::basedir}/etc/system/local/web.conf",
mode => $splunk::config_file_mode,
owner => $splunk::config_file_owner,
group => $splunk::config_file_group,
require => Package['splunk'],
notify => Service['splunk'],
content => template($splunk::template_web),
replace => $splunk::manage_file_replace,
audit => $splunk::manage_audit,
}
}
# The whole local splunk configuration directory can be recursively overriden
if $splunk::source_dir {
file { 'splunk.dir':
ensure => directory,
path => $splunk::config_dir,
require => Package['splunk'],
source => $source_dir,
recurse => true,
purge => $splunk::bool_source_dir_purge,
replace => $splunk::manage_file_replace,
audit => $splunk::manage_audit,
}
}
if $license_file_source {
exec { 'splunk_add_license':
command => "${splunk::basedir}/bin/splunk add licenses /root/splunk.license",
refreshonly => true,
before => Service['splunk'],
require => Exec['splunk_create_service'],
}
file { 'splunk_license':
ensure => present,
path => '/root/splunk.license',
mode => '0755',
owner => 'root',
group => 'root',
source => $license_file_source,
before => Service['splunk'] ,
notify => Exec['splunk_add_license'],
}
}
### Include custom class if $my_class is set
if $splunk::my_class {
include $splunk::my_class
}
### Provide puppi data, if enabled ( puppi => true )
if $splunk::bool_puppi == true {
$classvars=get_class_args()
puppi::ze { 'splunk':
ensure => $splunk::manage_file,
variables => $classvars,
helper => $splunk::puppi_helper,
}
}
### Service monitoring, if enabled ( monitor => true )
if $splunk::bool_monitor == true {
monitor::port { "splunk_${splunk::protocol}_${splunk::port}":
protocol => $splunk::protocol,
port => $splunk::port,
target => $splunk::monitor_target,
tool => $splunk::monitor_tool,
enable => $splunk::manage_monitor,
}
monitor::process { 'splunk_process':
process => $splunk::process,
service => $splunk::service,
pidfile => $splunk::pid_file,
tool => $splunk::monitor_tool,
enable => $splunk::manage_monitor,
}
}
### Firewall management, if enabled ( firewall => true )
if $splunk::bool_firewall == true {
firewall { "splunk_${splunk::protocol}_${splunk::port}":
source => $splunk::firewall_src,
destination => $splunk::firewall_dst,
protocol => $splunk::protocol,
port => $splunk::port,
action => 'allow',
direction => 'input',
tool => $splunk::firewall_tool,
enable => $splunk::manage_firewall,
}
}
### Debugging, if enabled ( debug => true )
if $splunk::bool_debug == true {
file { 'debug_splunk':
ensure => $splunk::manage_file,
path => "${settings::vardir}/debug-splunk",
mode => '0640',
owner => 'root',
group => 'root',
content => inline_template('<%= scope.to_hash.reject { |k,v| k.to_s =~ /(uptime.*|path|timestamp|free|.*password.*|.*psk.*|.*key)/ }.to_yaml %>'),
}
}
}
|