Defined Type: logstash::plugin

Defined in:
modules/logstash/manifests/plugin.pp

Overview

Manage the installation of a Logstash plugin. github.com/elastic/puppet-logstash

By default, plugins are downloaded from RubyGems, but it is also possible to install from a local Gem, or one stored in Puppet.

Offline plugin packs can be generated from a staging host with internet access using bin/logstash-plugin prepare-offline-pack like so:

* From a staging host with logstash installed prepare an offline pack, e.g. /usr/share/logstash/bin/logstash-plugin prepare-offline-pack logstash-output-statsd
* This creates file /usr/share/logstash/logstash-offline-plugins-7.4.2.zip (or pass argument to bin/logstash-plugin to specify output file)
* Upload offline plugin zip to puppet volatile
* Specify location of plugin pack as source param to logstash::plugin like so logstash::plugin{ 'logstash-output-statsd': source => 'puppet:///volatile/logstash/plugins/logstash-output-statsd-1.2.3.zip' }

Examples:

Install a plugin.

logstash::plugin { 'logstash-input-stdin': }

Remove a plugin.

logstash::plugin { 'logstash-input-stout':
  ensure => absent,
}

Install a plugin from a local file.

logstash::plugin { 'logstash-input-custom':
  source => 'file:///tmp/logstash-input-custom.gem',
}

Install a plugin from a Puppet module.

logstash::plugin { 'logstash-input-custom':
  source => 'puppet:///modules/logstash-site-plugins/logstash-input-custom.gem',
}

Install a plugin, overriding JVM options via the environment.

logstash::plugin { 'logstash-input-jmx':
  environment => ['LS_JAVA_OPTS=-Xms1g -Xmx1g']
}

Install plugin pack generated by bin/logstash-plugin prepare-offline-pack

logstash::plugin { 'logstash-output-statsd':
   source => 'puppet:///volatile/logstash/plugins/logstash-output-statsd-1.2.3.zip',
}

Parameters:

  • ensure (String) (defaults to: present)

    Install or remove with `present` or `absent`.

  • source (String) (defaults to: undef)

    Install from this file, not from RubyGems.

  • environment (String) (defaults to: [])

    Environment used when running 'logstash-plugin'



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
# File 'modules/logstash/manifests/plugin.pp', line 48

define logstash::plugin (
  $source = undef,
  $ensure = present,
  $environment = [],
)
{
  $exe = '/usr/share/logstash/bin/logstash-plugin'

  case $source { # Where should we get the plugin from?
    undef: {
      # No explict source, so search Rubygems for the plugin, by name.
      # ie. "logstash-plugin install logstash-output-elasticsearch"
      $plugin = $title
    }

    /^(\/|file:)/: {
      # A gem file that is already available on the local filesystem.
      # Install from the local path.
      # ie. "logstash-plugin install /tmp/logtash-filter-custom.gem" or
      # "logstash-plugin install file:///tmp/logtash-filter-custom.gem" or
      $plugin = $source
    }

    /^puppet:/: {
      # A 'puppet:///' URL. Download the gem from Puppet, then install
      # the plugin from the downloaded file.
      $downloaded_file = sprintf('/tmp/%s', basename($source))
      file { $downloaded_file:
        source => $source,
        before => Exec["logstash-plugin-${title}: ${ensure}"],
      }

      case $source {
        /\.zip$/: {
          $plugin = "file://${downloaded_file}"
        }
        default: {
          $plugin = $downloaded_file
        }
      }
    }

    default: {
      fail('"source" should be a local path, a "puppet:///" url, or undef.')
    }
  }

  case $ensure {
    'present': {
      $command = "${exe} install ${plugin}"
      $unless  = "${exe} list ^${title}$"
      $onlyif  = undef
    }
    /\d+\.\d+\.\d+\./: {
      $command = "${exe} install --version ${ensure} ${plugin}"
      $unless  = "${exe} list --verbose ^${title}$ | grep --fixed-strings --quiet '(${ensure})'"
      $onlyif  = undef
    }
    'absent': {
      $command = "${exe} remove ${title}"
      $onlyif  = "${exe} list | grep -q ^${title}$"
      $unless  = undef
    }
    default: {
      fail "'ensure' should be 'present', 'absent', or a version like '1.3.4'."
    }
  }

  exec {"logstash-plugin-${title}: ${ensure}":
    path        => '/bin:/usr/bin',
    cwd         => '/tmp',
    user        => 'logstash',
    timeout     => 1800,
    environment => $environment,
    command     => $command,
    unless      => $unless,
    onlyif      => $onlyif,
  }

}