Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace create_resources with resource types #874

Merged
merged 1 commit into from Mar 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion manifests/plugin/aggregation.pp
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,9 @@
'ensure' => $ensure,
}

create_resources(collectd::plugin::aggregation::aggregator, $aggregators, $defaults)
$aggregators.each |String $resource, Hash $attributes| {
collectd::plugin::aggregation::aggregator { $resource:
* => $defaults + $attributes,
}
}
}
6 changes: 5 additions & 1 deletion manifests/plugin/curl.pp
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,9 @@
'ensure' => $ensure,
}

create_resources(collectd::plugin::curl::page, $pages, $defaults)
$pages.each |String $resource, Hash $attributes| {
collectd::plugin::curl::page { $resource:
* => $defaults + $attributes,
}
}
}
23 changes: 18 additions & 5 deletions manifests/plugin/dbi.pp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@

include ::collectd

$_manage_package = pick($manage_package, $::collectd::manage_package)
$_manage_package = pick($manage_package, $::collectd::manage_package)

$_databases_defaults = {
'ensure' => $ensure,
}

$_queries_defaults = {
'ensure' => $ensure,
}

if $facts['os']['family'] == 'RedHat' {
if $_manage_package {
Expand Down Expand Up @@ -53,10 +61,15 @@
target => "${collectd::plugin_conf_dir}/dbi-config.conf",
}

$defaults = {
'ensure' => $ensure,
$databases.each |String $resource, Hash $attributes| {
collectd::plugin::dbi::database { $resource:
* => $_databases_defaults + $attributes,
}
}

create_resources(collectd::plugin::dbi::database, $databases, $defaults)
create_resources(collectd::plugin::dbi::query, $queries, $defaults)
$queries.each |String $resource, Hash $attributes| {
collectd::plugin::dbi::query { $resource:
* => $_queries_defaults + $attributes,
}
}
}
15 changes: 10 additions & 5 deletions manifests/plugin/exec.pp
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# See http://collectd.org/documentation/manpages/collectd.conf.5.shtml#plugin_exec
class collectd::plugin::exec (
Hash $commands = {},
$interval = undef,
$ensure = 'present',
Boolean $globals = false,
Hash $commands = {},
Hash $commands_defaults = {},
$interval = undef,
$ensure = 'present',
Boolean $globals = false,
) {

include ::collectd
Expand Down Expand Up @@ -38,5 +39,9 @@
target => $exec_conf,
}

create_resources(collectd::plugin::exec::cmd, $commands)
$commands.each |String $resource, Hash $attributes| {
collectd::plugin::exec::cmd { $resource:
* => $commands_defaults + $attributes,
}
}
}
6 changes: 5 additions & 1 deletion manifests/plugin/filecount.pp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@
$values = values($directories)
if size($values) > 0 and is_hash($values[0]) {
$content = undef
create_resources(collectd::plugin::filecount::directory, $directories, {ensure => $ensure})
$directories.each |String $resource, Hash $attributes| {
collectd::plugin::filecount::directory { $resource:
* => { ensure => $ensure } + $attributes,
}
}
} else {
$content = template('collectd/plugin/filecount.conf.erb')
}
Expand Down
23 changes: 19 additions & 4 deletions manifests/plugin/network.pp
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,29 @@

include ::collectd

$listeners_defaults = {
'ensure' => $ensure,
}

$servers_defaults = {
'ensure' => $ensure,
}

collectd::plugin { 'network':
ensure => $ensure,
content => template('collectd/plugin/network.conf.erb'),
interval => $interval,
}
$defaults = {
'ensure' => $ensure,

$listeners.each |String $resource, Hash $attributes| {
collectd::plugin::network::listener { $resource:
* => $listeners_defaults + $attributes,
}
}

$servers.each |String $resource, Hash $attributes| {
collectd::plugin::network::server { $resource:
* => $servers_defaults + $attributes,
}
}
create_resources(collectd::plugin::network::listener, $listeners, $defaults)
create_resources(collectd::plugin::network::server, $servers, $defaults)
}
25 changes: 19 additions & 6 deletions manifests/plugin/postgresql.pp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@

include ::collectd

$_manage_package = pick($manage_package, $::collectd::manage_package)
$_manage_package = pick($manage_package, $::collectd::manage_package)
$databases_defaults = { 'ensure' => $ensure }
$queries_defaults = { 'ensure' => $ensure }
$writers_defaults = { 'ensure' => $ensure }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why create all these identical hashes?

@bastelfreak Did you not like #874 (comment) ?

Copy link
Contributor Author

@zoojar zoojar Mar 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looool i thought this too. It's one way of separating defaults for each resource

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    collectd::plugin::postgresql::writer { $resource:
      * => { 'ensure' => $ensure } + $attributes,
    }

better?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With create_resources we had to pass a hash for the defaults (although it didn't strictly need to be assigned to a variable first).

Since we just have a single default property (ensure), putting it directly in the resource declaration is probably cleaner??

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    collectd::plugin::postgresql::writer { $resource:
      * => { 'ensure' => $ensure } + $attributes,
    }

better?

No need to merge hashes. Just...

collectd::plugin::postgresql::writer { $resource:
  ensure => $ensure,
  *      => $attributes,
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That depends on $attributes not containing an override for ensure though. (which might be a perfectly reasonable assumption?)

Copy link
Contributor Author

@zoojar zoojar Mar 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually... I don't think that is a safe assumption.
* => { 'ensure' => $ensure } + $attributes, works for me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok. well, we still get one thing... replacement of create_resources :)


if $facts['os']['family'] == 'RedHat' {
if $_manage_package {
Expand Down Expand Up @@ -45,11 +48,21 @@
target => "${collectd::plugin_conf_dir}/postgresql-config.conf",
}

$defaults = {
'ensure' => $ensure,
$databases.each |String $resource, Hash $attributes| {
collectd::plugin::postgresql::database { $resource:
* => $databases_defaults + $attributes,
}
}

$queries.each |String $resource, Hash $attributes| {
collectd::plugin::postgresql::query { $resource:
* => $queries_defaults + $attributes,
}
}

create_resources(collectd::plugin::postgresql::database, $databases, $defaults)
create_resources(collectd::plugin::postgresql::query, $queries, $defaults)
create_resources(collectd::plugin::postgresql::writer, $writers, $defaults)
$writers.each |String $resource, Hash $attributes| {
collectd::plugin::postgresql::writer { $resource:
* => $writers_defaults + $attributes,
}
}
}
29 changes: 13 additions & 16 deletions manifests/plugin/powerdns.pp
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
Enum['present', 'absent'] $ensure = 'present',
Integer $order = 10,
Optional[Numeric] $interval = undef,
Optional[Hash[String, Hash]] $servers = undef,
Optional[Hash[String, Hash]] $recursors = undef,
Optional[Hash[String, Hash]] $servers = {},
zoojar marked this conversation as resolved.
Show resolved Hide resolved
Optional[Hash[String, Hash]] $recursors = {},
Optional[String] $local_socket = undef,
) {

include collectd

$servers_defaults = { 'ensure' => $ensure }
$recursors_defaults = { 'ensure' => $ensure }

collectd::plugin { 'powerdns':
ensure => $ensure,
order => $order,
Expand All @@ -36,21 +39,15 @@
target => "${collectd::plugin_conf_dir}/powerdns-config.conf",
}

$defaults = { 'ensure' => $ensure }

if $servers {
create_resources(
collectd::plugin::powerdns::server,
$servers,
$defaults,
)
$servers.each |String $resource, Hash $attributes| {
collectd::plugin::powerdns::server { $resource:
* => $servers_defaults + $attributes,
}
}

if $recursors {
create_resources(
collectd::plugin::powerdns::recursor,
$recursors,
$defaults
)
$recursors.each |String $resource, Hash $attributes| {
collectd::plugin::powerdns::recursor { $resource:
* => $recursors_defaults + $attributes,
}
}
}
27 changes: 14 additions & 13 deletions manifests/plugin/processes.pp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

include ::collectd

$processes_defaults = { 'ensure' => $ensure }
$process_matches_defaults = { 'ensure' => $ensure }

collectd::plugin { 'processes':
ensure => $ensure,
order => $order,
Expand All @@ -38,23 +41,21 @@
target => "${collectd::plugin_conf_dir}/processes-config.conf",
}

$defaults = { 'ensure' => $ensure }

if $processes {
$process_resources = collectd_convert_processes($processes)
create_resources(
collectd::plugin::processes::process,
$process_resources,
$defaults,
)

$process_resources.each |String $resource, Hash $attributes| {
collectd::plugin::processes::process { $resource:
* => $processes_defaults + $attributes,
}
}
}

if $process_matches {
$process_matches_resources = collectd_convert_processes($process_matches)
create_resources(
collectd::plugin::processes::processmatch,
$process_matches_resources,
$defaults
)
$process_matches_resources.each |String $resource, Hash $attributes| {
collectd::plugin::processes::processmatch { $resource:
* => $process_matches_defaults + $attributes,
}
}
}
}
7 changes: 6 additions & 1 deletion manifests/plugin/python.pp
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,10 @@
'ensure' => $ensure,
'modulepath' => $module_dirs[0],
}
create_resources(collectd::plugin::python::module, $modules, $defaults)

$modules.each |String $resource, Hash $attributes| {
collectd::plugin::python::module { $resource:
* => $defaults + $attributes,
}
}
}
10 changes: 7 additions & 3 deletions manifests/plugin/tail.pp
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@
# https://collectd.org/wiki/index.php/Plugin:Tail
class collectd::plugin::tail (
$interval = undef,
Optional[Hash] $files = undef,
Optional[Hash] $files = {},
) {

collectd::plugin { 'tail':
interval => $interval,
}

if $files {
create_resources(collectd::plugin::tail::file, $files)
$defaults = {}

$files.each |String $resource, Hash $attributes| {
collectd::plugin::tail::file { $resource:
* => $defaults + $attributes,
}
}
}
8 changes: 6 additions & 2 deletions manifests/plugin/write_graphite.pp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# https://collectd.org/wiki/index.php/Graphite
class collectd::plugin::write_graphite (
Hash $carbons = {},
Hash $carbons = {},
$carbon_defaults = {},
$ensure = 'present',
$globals = false,
Expand Down Expand Up @@ -38,7 +38,11 @@
target => $graphite_conf,
}

create_resources(collectd::plugin::write_graphite::carbon, $carbons, $carbon_defaults)
$carbons.each |String $resource, Hash $attributes| {
collectd::plugin::write_graphite::carbon { $resource:
* => $carbon_defaults + $attributes,
}
}
}
'absent': {
file { $graphite_conf:
Expand Down