diff --git a/manifests/config.pp b/manifests/config.pp new file mode 100644 index 0000000..e075ff9 --- /dev/null +++ b/manifests/config.pp @@ -0,0 +1,7 @@ +class stackdriver::config{ + # OS Family specific configuration + class { $::stackdriver::cclass: + apikey => $::stackdriver::apikey, + } + contain $::stackdriver::cclass +} diff --git a/manifests/config/debian.pp b/manifests/config/debian.pp index 2e3a5bf..1b86437 100644 --- a/manifests/config/debian.pp +++ b/manifests/config/debian.pp @@ -15,10 +15,9 @@ # - Stackdriver configuration file # class stackdriver::config::debian( - + $apikey, $sysconfig = '/etc/default/stackdriver-agent', - -) inherits stackdriver { +) { validate_string ( $sysconfig ) @@ -28,7 +27,6 @@ group => 'root', mode => '0440', # secure API key content => template("stackdriver/${::kernel}/${sysconfig}.erb"), - notify => Service[$svc], } } diff --git a/manifests/config/redhat.pp b/manifests/config/redhat.pp index 62ea6f6..253c326 100644 --- a/manifests/config/redhat.pp +++ b/manifests/config/redhat.pp @@ -15,11 +15,9 @@ # - Stackdriver configuration file # class stackdriver::config::redhat( - + $apikey, $sysconfig = '/etc/sysconfig/stackdriver', - -) inherits stackdriver { - +) { validate_string ( $sysconfig ) file { $sysconfig: @@ -28,8 +26,6 @@ group => 'root', mode => '0440', # secure API key content => template("stackdriver/${::kernel}/${sysconfig}.erb"), - notify => Service[$svc], } - } diff --git a/manifests/init.pp b/manifests/init.pp index 2743bf1..37984f0 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -23,57 +23,35 @@ # apikey => "OMGBECKYLOOKATHERBUTTITSJUSTSOROUND" # } # -class stackdriver ( - - $apikey = undef, - $ensure = 'present', +class stackdriver( + $apikey = undef, + $ensure = 'present', $service_ensure = 'running', $service_enable = true, - + $plugins = [], $svc = $::osfamily ? { 'RedHat' => [ 'stackdriver-agent', 'stackdriver-extractor' ], 'Debian' => [ 'stackdriver-agent', 'stackdriver-extractor' ], default => undef, }, - + $iclass = "::stackdriver::install::${::osfamily}", + $cclass = "::stackdriver::config::${::osfamily}", ) { - validate_string ( $apikey ) validate_array ( $svc ) - # Runtime class definitions - $iclass = "${name}::install::${::osfamily}" - $cclass = "${name}::config::${::osfamily}" - $sclass = "${name}::service" - - - # OS Family specific installation - class { "::${iclass}": - ensure => $ensure, - notify => Class[$sclass], - } - contain $iclass + contain stackdriver::install + contain stackdriver::config + contain stackdriver::service - - # OS Family specific configuration - class { "::${cclass}": require => Class[$iclass]; } - contain $cclass - - - # Service - class { "::${sclass}": - service_ensure => $service_ensure, - service_enable => $service_enable, - require => Class[$cclass], - } - include $sclass - - # Array of Plugins to load (optional) - $plugins = hiera_array("${name}::plugins", []) + Class['::stackdriver::install'] -> Class['::stackdriver::config'] + Class['::stackdriver::install'] ~> Class['::stackdriver::service'] + Class['::stackdriver::config'] ~> Class['::stackdriver::service'] if ! empty($plugins) { stackdriver::plugin { $plugins: } } + } diff --git a/manifests/install.pp b/manifests/install.pp new file mode 100644 index 0000000..5301aa2 --- /dev/null +++ b/manifests/install.pp @@ -0,0 +1,7 @@ +class stackdriver::install{ + # OS Family specific installation + class { $::stackdriver::iclass: + ensure => $stackdriver::ensure, + } + contain $::stackdriver::iclass +} diff --git a/manifests/install/redhat.pp b/manifests/install/redhat.pp index da31632..4a736eb 100644 --- a/manifests/install/redhat.pp +++ b/manifests/install/redhat.pp @@ -31,7 +31,7 @@ # class stackdriver::install::redhat( - $pkg = [ 'stackdriver-agent', 'stackdriver-extractor' ], + $pkg = [ 'stackdriver-extractor','stackdriver-agent'], $ensure = 'present', $repo = { diff --git a/manifests/plugin.pp b/manifests/plugin.pp index 9aace1b..480696e 100644 --- a/manifests/plugin.pp +++ b/manifests/plugin.pp @@ -1,31 +1,10 @@ -# vim: tabstop=2 expandtab shiftwidth=2 softtabstop=2 foldmethod=marker -# -# == Define: stackdriver::plugin -# -# Loads a Plugin for the Stackdriver Agent -# -# NOTE: plugin configuration parameters should be defined via Hiera -# -# === Parameters -# --- -# -# [*name*] -# - Default - NONE (REQUIRED) -# - Stackdriver plugin name -# -# == Examples: -# -# stackdriver::plugin { 'elasticsearch': } -# -define stackdriver::plugin() { - +define stackdriver::plugin(){ $pclass = "::stackdriver::plugin::${name}" if ! defined($pclass) { fail("Unknown Stackdriver Agent plugin ${name}") - } - - include $pclass + } else { + contain $pclass + } } - diff --git a/manifests/plugin/apache.pp b/manifests/plugin/apache.pp index 982ff2f..54bc928 100644 --- a/manifests/plugin/apache.pp +++ b/manifests/plugin/apache.pp @@ -40,26 +40,22 @@ # - 'apache' # class stackdriver::plugin::apache( - $config = '/opt/stackdriver/collectd/etc/collectd.d/apache.conf', - $url = 'http://127.0.0.1/mod_status?auto', $user = undef, $password = undef, - ) { - Class['stackdriver'] -> Class[$name] - validate_string ( $config ) validate_string ( $url ) if $user { validate_string ( $user ) } if $password { validate_string ( $password ) } - #contain "${name}::install" - - #class { "::${name}::config": require => Class["::${name}::install"] } contain "${name}::config" + Class['::stackdriver::config'] -> + Class["::${name}::config"] ~> + Class['::stackdriver::service'] + } diff --git a/manifests/plugin/elasticsearch.pp b/manifests/plugin/elasticsearch.pp index 4f2d892..e2ccc9d 100644 --- a/manifests/plugin/elasticsearch.pp +++ b/manifests/plugin/elasticsearch.pp @@ -42,30 +42,24 @@ # - 'elasticsearch' # class stackdriver::plugin::elasticsearch( - $pkg = $::osfamily ? { /(?i:Debian)/ => 'libyajl1', /(?i:RedHat)/ => 'yajl', default => undef, }, - $config = '/opt/stackdriver/collectd/etc/collectd.d/elasticsearch.conf', - $host = 'localhost', $port = 9200, - ) { - - Class['stackdriver'] -> Class[$name] - if $pkg { validate_string ( $pkg ) } validate_string ( $config ) - contain "${name}::install" - - class { "::${name}::config": require => Class["::${name}::install"] } contain "${name}::config" + Class['::stackdriver::config'] -> + Class["::${name}::install"] -> + Class["::${name}::config"] ~> + Class['::stackdriver::service'] } diff --git a/manifests/plugin/memcached.pp b/manifests/plugin/memcached.pp index 041c290..edba0f8 100644 --- a/manifests/plugin/memcached.pp +++ b/manifests/plugin/memcached.pp @@ -44,12 +44,14 @@ ) { - Class['stackdriver'] -> Class[$name] - validate_string ( $config ) validate_string ( $host ) contain "${name}::config" + Class['::stackdriver::config'] -> + Class["::${name}::config"] ~> + Class['::stackdriver::service'] + } diff --git a/manifests/plugin/mongo.pp b/manifests/plugin/mongo.pp index 4e9fcae..79d9f38 100644 --- a/manifests/plugin/mongo.pp +++ b/manifests/plugin/mongo.pp @@ -44,27 +44,23 @@ # - 'mongo' # class stackdriver::plugin::mongo( - $config = '/opt/stackdriver/collectd/etc/collectd.d/mongo.conf', - $host = 'localhost', $port = 27017, $user = 'stackdriver', $password = 'ahzae8aiLiKoe', - ) { - Class['stackdriver'] -> Class[$name] - validate_string ( $config ) validate_string ( $host ) validate_string ( $user ) validate_string ( $password ) - #contain "${name}::install" - - #class { "::${name}::config": require => Class["::${name}::install"] } contain "${name}::config" + Class['::stackdriver::config'] -> + Class["::${name}::config"] ~> + Class['::stackdriver::service'] + } diff --git a/manifests/plugin/nginx.pp b/manifests/plugin/nginx.pp index b01dc4b..4a0f048 100644 --- a/manifests/plugin/nginx.pp +++ b/manifests/plugin/nginx.pp @@ -64,8 +64,6 @@ ) { - Class['stackdriver'] -> Class[$name] - validate_absolute_path ( $config ) validate_string ( $url ) @@ -75,10 +73,11 @@ if $verifyhost != undef { validate_bool ( $verifyhost ) } if $cacert != undef { validate_absolute_path ( $cacert ) } - #contain "${name}::install" - - #class { "::${name}::config": require => Class["::${name}::install"] } contain "${name}::config" + Class['::stackdriver::config'] -> + Class["::${name}::config"] ~> + Class['::stackdriver::service'] + } diff --git a/manifests/plugin/nginx/config.pp b/manifests/plugin/nginx/config.pp index 420fd69..90c984a 100644 --- a/manifests/plugin/nginx/config.pp +++ b/manifests/plugin/nginx/config.pp @@ -5,8 +5,6 @@ # Configures Nginx Agent Plugin for Stackdriver Agent # class stackdriver::plugin::nginx::config( - - ) inherits stackdriver::plugin::nginx { file { $config: @@ -15,7 +13,6 @@ owner => 'root', group => 'root', mode => '0440', # secure - notify => Service[$::stackdriver::svc], } } diff --git a/manifests/plugin/postgres.pp b/manifests/plugin/postgres.pp index b47dfa2..ea7e2e3 100644 --- a/manifests/plugin/postgres.pp +++ b/manifests/plugin/postgres.pp @@ -40,26 +40,22 @@ # - 'postgres' # class stackdriver::plugin::postgres( - $config = '/opt/stackdriver/collectd/etc/collectd.d/postgres.conf', - $dbname = undef, # REQUIRED Param $user = 'stackdriver', $password = 'xoiboov9Pai5e', - ) { - Class['stackdriver'] -> Class[$name] - validate_string ( $config ) validate_string ( $dbname ) validate_string ( $user ) validate_string ( $password ) - #contain "${name}::install" - - #class { "::${name}::config": require => Class["::${name}::install"] } contain "${name}::config" + Class['::stackdriver::config'] -> + Class["::${name}::config"] ~> + Class['::stackdriver::service'] + } diff --git a/manifests/plugin/rabbitmq.pp b/manifests/plugin/rabbitmq.pp index 0c743f0..16f412e 100644 --- a/manifests/plugin/rabbitmq.pp +++ b/manifests/plugin/rabbitmq.pp @@ -60,7 +60,6 @@ ) { - Class['stackdriver'] -> Class[$name] validate_array ( $queues ) @@ -71,5 +70,9 @@ 'ensure' => 'present', }) + Class['::stackdriver::config'] -> + Class["::${name}::config"] ~> + Class['::stackdriver::service'] + } diff --git a/manifests/plugin/rabbitmq/config.pp b/manifests/plugin/rabbitmq/config.pp index ac6bb7c..31879f3 100644 --- a/manifests/plugin/rabbitmq/config.pp +++ b/manifests/plugin/rabbitmq/config.pp @@ -5,8 +5,6 @@ # Configures RabbitMQ Agent Plugin for Stackdriver Agent # class stackdriver::plugin::rabbitmq::config( - - ) inherits stackdriver::plugin::rabbitmq { file { $config: diff --git a/manifests/plugin/redis.pp b/manifests/plugin/redis.pp index d40c1d5..d476bca 100644 --- a/manifests/plugin/redis.pp +++ b/manifests/plugin/redis.pp @@ -45,27 +45,23 @@ # - 'redis' # class stackdriver::plugin::redis( - $pkg = 'hiredis-devel', - $config = '/opt/stackdriver/collectd/etc/collectd.d/redis.conf', - $host = 'localhost', $port = 6379, $timeout = 2000, ) { - Class['stackdriver'] -> Class[$name] - validate_string ( $pkg ) validate_string ( $config ) validate_string ( $host ) contain "${name}::install" - - class { "::${name}::config": require => Class["::${name}::install"] } contain "${name}::config" + Class['::stackdriver::config'] -> + Class["::${name}::install"] -> + Class["::${name}::config"] ~> + Class['::stackdriver::service'] } - diff --git a/manifests/plugin/tomcat.pp b/manifests/plugin/tomcat.pp index 9ddd788..48590dc 100644 --- a/manifests/plugin/tomcat.pp +++ b/manifests/plugin/tomcat.pp @@ -57,8 +57,6 @@ $apikey = hiera('stackdriver::apikey'), ) { - Class['stackdriver'] -> Class[$name] - validate_string ( $ensure ) validate_string ( $host ) validate_string ( $port ) @@ -73,4 +71,8 @@ contain "${name}::config" + Class['::stackdriver::config'] -> + Class["::${name}::config"] ~> + Class['::stackdriver::service'] + } diff --git a/manifests/plugin/zookeeper.pp b/manifests/plugin/zookeeper.pp index d54964b..01193a3 100644 --- a/manifests/plugin/zookeeper.pp +++ b/manifests/plugin/zookeeper.pp @@ -43,13 +43,15 @@ ) { - Class['stackdriver'] -> Class[$name] - validate_string ( $config ) validate_string ( $host ) validate_string ( $port ) contain "${name}::config" + Class['::stackdriver::config'] -> + Class["::${name}::config"] ~> + Class['::stackdriver::service'] + } diff --git a/manifests/service.pp b/manifests/service.pp index 738d232..69802ee 100644 --- a/manifests/service.pp +++ b/manifests/service.pp @@ -1,18 +1,6 @@ -# vim: tabstop=2 expandtab shiftwidth=2 softtabstop=2 foldmethod=marker -# -# == Class: stackdriver::service -# -# Manages Stackdriver Agent Service -# -class stackdriver::service( - $service_ensure = 'running', - $service_enable = true, - ) inherits stackdriver { - - service { $svc: - ensure => $service_ensure, - enable => $service_enable, +class stackdriver::service{ + service { $stackdriver::svc: + ensure => $stackdriver::service_ensure, + enable => $stackdriver::service_enable, } - } -