From 5ced196fcb1bad9de1d79b6ce257350ff2ee2dad Mon Sep 17 00:00:00 2001
From: DIEGO MICHELOTTO <diego.michelotto@cnaf.infn.it>
Date: Thu, 17 Jun 2021 10:26:38 +0000
Subject: [PATCH 01/11] Code review

---
 .fixtures.yml                 |  1 +
 example/site.pp               |  6 +--
 manifests/init.pp             | 42 +++++++-------------
 manifests/params.pp           | 24 ++++++++++--
 manifests/setup/debian.pp     | 74 +++++++++++++++++------------------
 manifests/setup/redhat.pp     | 72 ++++++++++++++++------------------
 metadata.json                 | 32 ++++++---------
 spec/classes/collectd_spec.rb | 25 +++++++++++-
 8 files changed, 145 insertions(+), 131 deletions(-)

diff --git a/.fixtures.yml b/.fixtures.yml
index 2296adb..deb263b 100644
--- a/.fixtures.yml
+++ b/.fixtures.yml
@@ -4,3 +4,4 @@
 fixtures:
   forge_modules:
 #     stdlib: "puppetlabs/stdlib"
+     cron_core: "puppetlabs/cron_core"
diff --git a/example/site.pp b/example/site.pp
index 3fcb492..afdcac4 100644
--- a/example/site.pp
+++ b/example/site.pp
@@ -1,5 +1,5 @@
 node default {
- class { 'collectd' :
-   influxdb_collectd_host => 'accounting.novalocal'
- }
+  class { 'collectd' :
+    influxdb_collectd_host => 'accounting.novalocal'
+  }
 }
diff --git a/manifests/init.pp b/manifests/init.pp
index 172f5fa..f090c91 100644
--- a/manifests/init.pp
+++ b/manifests/init.pp
@@ -19,42 +19,28 @@
 # for accounting puroposes of INFN-CLOUD and Federated sites
 # === Parameters:
 #
-# [*influxdb_collectd_host*] Host for influxdb, usually local accounting server.
-#   Mandatory.
-# [*influxdb_collectd_port*] Port related to the influxdb host, usually 25826.
-#   Mandatory.
+# [*influxdb_collectd_host*] String: Host for influxdb, usually local accounting server.
+#   Mandatory. Default undef
+# [*influxdb_collectd_port*] String: Port related to the influxdb host, usually 25826.
+#   Mandatory. Default 25826
 # 
 #   include collectd
 class collectd (
-  $influxdb_collectd_host        = undef,
-  $influxdb_collectd_port        = "25826",
- ) inherits collectd::params {
+  String $influxdb_collectd_host = $::collectd::params::influxdb_collectd_host,
+  String $influxdb_collectd_port = $::collectd::params::influxdb_collectd_port,
+) inherits collectd::params {
 
-if defined('$influxdb_collectd_host') {
-   notify {"Variable influxdb_collectd_host is: $influxdb_collectd_host":}
-} else {
-   fail("Variable influxdb_collectd_host is unset.")
-}
-
-case $::osfamily {
+  case $::osfamily {
     'RedHat', 'CentOS':  {
-         notify {'You are using CentOS': }
-         class { 'collectd::setup::redhat' :
-           influxdb_collectd_host => $influxdb_collectd_host,
-           influxdb_collectd_port => $influxdb_collectd_port
-         }
-
+      notify {'You are using CentOS': }
+      class { 'collectd::setup::redhat': }
     }
     'Debian', 'Ubuntu':  {
-         notify {'You are using Ubuntu': }
-         class { 'collectd::setup::debian' :
-           influxdb_collectd_host => $influxdb_collectd_host,
-           influxdb_collectd_port => $influxdb_collectd_port
-         }
+      notify {'You are using Ubuntu': }
+      class { 'collectd::setup::debian': }
     }
     default:  {
-         fail("No suitable OS found for this Class:  ${::osfamily}/${::operatingsystem}")
+      fail("No suitable OS found for this Class:  ${::osfamily}/${::operatingsystem}")
     }
-}
-
+  }
 }
diff --git a/manifests/params.pp b/manifests/params.pp
index c6a80ee..ab7777c 100644
--- a/manifests/params.pp
+++ b/manifests/params.pp
@@ -1,4 +1,22 @@
+# @License
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+#
+# Author: Alessandro Costatnini <acostantini@infn.it>
+# 
+# == Class: collectd:params
+#
+# include params defaults
 class collectd::params {
-    $influxdb_collectd_host = ""
-    $influxdb_collectd_port = "25826"
-}  
+    $influxdb_collectd_host = undef
+    $influxdb_collectd_port = '25826'
+}
diff --git a/manifests/setup/debian.pp b/manifests/setup/debian.pp
index b44ec38..b92c40a 100644
--- a/manifests/setup/debian.pp
+++ b/manifests/setup/debian.pp
@@ -19,53 +19,49 @@
 # for accounting puroposes for Debian OS
 # === Parameters:
 #
-# [*influxdb_collectd_host*] Host for influxdb, usually local accounting server.
-#   Mandatory.
-# [*influxdb_collectd_port*] Port related to the influxdb host, usually 25826.
-#   Mandatory.
+# [*influxdb_collectd_host*] String: Host for influxdb, usually local accounting server.
+#   Mandatory. Default undef
+# [*influxdb_collectd_port*] String: Port related to the influxdb host, usually 25826.
+#   Mandatory. Default 25826
 #
 #   include collectd
 
 class collectd::setup::debian (
-  $influxdb_collectd_host        = undef,
-  $influxdb_collectd_port        = "25826",
+  String $influxdb_collectd_host = $::collectd::influxdb_collectd_host,
+  String $influxdb_collectd_port = $::collectd::influxdb_collectd_port,
 ) {
 
-    $collectdpackages= [ 'collectd', 'collectd-core', 'collectd-dbg', 'collectd-utils', 'libcollectdclient1']
-  
-    package { $collectdpackages :
-              ensure => 'installed',
-              install_options => ['--no-install-recommends'],
-                   }
-                   
-
-   file { "/etc/collectd/collectd.conf":
-         ensure   => file,
-         owner    => "root",
-         group    => "root",
-         mode     => '0644',
-         content  => template('collectd/collectd.conf-deb.erb'),
-         require => Package[$collectdpackages],
-       }
+  $collectdpackages= [ 'collectd', 'collectd-core', 'collectd-dbg', 'collectd-utils', 'libcollectdclient1']
 
+  package { $collectdpackages :
+    ensure          => 'installed',
+    install_options => ['--no-install-recommends'],
+  }
 
-#    cron {'collectd_flush_cache':
-#             ensure      => present,
-#             command     => "/usr/bin/killall -SIGUSR1 collectd",
-#             user        => root,
-#             minute      => '0',
-#             hour        => '*/2'
-#          }
+  file { '/etc/collectd/collectd.conf':
+    ensure  => file,
+    owner   => 'root',
+    group   => 'root',
+    mode    => '0644',
+    content => template('collectd/collectd.conf-deb.erb'),
+    require => Package[$collectdpackages],
+  }
 
+  #cron {'collectd_flush_cache':
+  #  ensure  => present,
+  #  command => "/usr/bin/killall -SIGUSR1 collectd",
+  #  user    => root,
+  #  minute  => '0',
+  #  hour    => '*/2'
+  #}
 
-   service { "collectd":
-                             ensure      => running,
-                             enable      => true,
-                             hasstatus   => true,
-                             hasrestart  => true,
-                             require     => Package[$collectdpackages],
-                             subscribe   => File['/etc/collectd/collectd.conf'],
-                    }
-                    
-       
+  service { 'collectd':
+    ensure     => running,
+    enable     => true,
+    hasstatus  => true,
+    hasrestart => true,
+    require    => Package[$collectdpackages],
+    subscribe  => File['/etc/collectd/collectd.conf'],
   }
+
+}
diff --git a/manifests/setup/redhat.pp b/manifests/setup/redhat.pp
index ab1f003..e1d581f 100644
--- a/manifests/setup/redhat.pp
+++ b/manifests/setup/redhat.pp
@@ -19,52 +19,48 @@
 # for accounting puroposes for RedHat OS
 # === Parameters:
 #
-# [*influxdb_collectd_host*] Host for influxdb, usually local accounting server.
-#   Mandatory.
-# [*influxdb_collectd_port*] Port related to the influxdb host, usually 25826.
-#   Mandatory.
+# [*influxdb_collectd_host*] String: Host for influxdb, usually local accounting server.
+#   Mandatory. Default undef
+# [*influxdb_collectd_port*] String: Port related to the influxdb host, usually 25826.
+#   Mandatory. Default 25826
 #
 #   include collectd
 
 class collectd::setup::redhat (
-  $influxdb_collectd_host        = undef,
-  $influxdb_collectd_port        = "25826",
+  String $influxdb_collectd_host = $::collectd::influxdb_collectd_host,
+  String $influxdb_collectd_port = $::collectd::influxdb_collectd_port,
 ) {
 
-    $collectdpackages= [ 'collectd', 'collectd-virt']
-  
-    package { $collectdpackages :
-              ensure => 'installed',
-                   }
-                   
-
-   file { "/etc/collectd.conf":
-         ensure   => file,
-         owner    => "root",
-         group    => "root",
-         mode     => '0644',
-         content  => template('collectd/collectd.conf-rh.erb'),
-         require => Package[$collectdpackages],
-       }
+  $collectdpackages= [ 'collectd', 'collectd-virt']
 
+  package { $collectdpackages :
+    ensure => 'installed',
+  }
 
-    cron {'collectd_flush_cache':
-             ensure      => present,
-             command     => "/usr/bin/killall -SIGUSR1 collectd",
-             user        => root,
-             minute      => '0',
-             hour        => '*/2'
-          }
+  file { '/etc/collectd.conf':
+    ensure  => file,
+    owner   => 'root',
+    group   => 'root',
+    mode    => '0644',
+    content => template('collectd/collectd.conf-rh.erb'),
+    require => Package[$collectdpackages],
+  }
 
+  cron { 'collectd_flush_cache':
+    ensure  => present,
+    command => '/usr/bin/killall -SIGUSR1 collectd',
+    user    => root,
+    minute  => '0',
+    hour    => '*/2'
+  }
 
-   service { "collectd":
-                             ensure      => running,
-                             enable      => true,
-                             hasstatus   => true,
-                             hasrestart  => true,
-                             require     => Package[$collectdpackages],
-                             subscribe   => File['/etc/collectd.conf'],
-                    }
-                    
-       
+  service { 'collectd':
+    ensure     => running,
+    enable     => true,
+    hasstatus  => true,
+    hasrestart => true,
+    require    => Package[$collectdpackages],
+    subscribe  => File['/etc/collectd.conf'],
   }
+
+}
diff --git a/metadata.json b/metadata.json
index a83be1f..b679898 100644
--- a/metadata.json
+++ b/metadata.json
@@ -2,35 +2,35 @@
   "name": "infncloud-collectd",
   "version": "0.1.0",
   "author": "Alessandro Costantini",
-  "summary": "",
+  "summary": "Collectd for INFN-CLOUD",
   "license": "Apache-2.0",
-  "source": "",
+  "source": "https://baltig.infn.it/infn-cloud/collectd",
   "dependencies": [
-
+    {
+      "name": "puppetlabs/cron_core",
+      "version_requirement": ">=1.0.5 <2.0.0"
+    }
   ],
   "operatingsystem_support": [
     {
       "operatingsystem": "CentOS",
       "operatingsystemrelease": [
-        "7"
-      ]
-    },
-    {
-      "operatingsystem": "OracleLinux",
-      "operatingsystemrelease": [
-        "7"
+        "7",
+        "8"
       ]
     },
     {
       "operatingsystem": "RedHat",
       "operatingsystemrelease": [
+        "7",
         "8"
       ]
     },
     {
-      "operatingsystem": "Scientific",
+      "operatingsystem": "Ubuntu",
       "operatingsystemrelease": [
-        "7"
+        "18.04",
+        "20.04"
       ]
     },
     {
@@ -38,18 +38,12 @@
       "operatingsystemrelease": [
         "10"
       ]
-    },
-    {
-      "operatingsystem": "Ubuntu",
-      "operatingsystemrelease": [
-        "18.04"
-      ]
     }
   ],
   "requirements": [
     {
       "name": "puppet",
-      "version_requirement": ">= 6.21.0 < 8.0.0"
+      "version_requirement": ">= 5.5.0 < 8.0.0"
     }
   ],
   "pdk-version": "2.1.0",
diff --git a/spec/classes/collectd_spec.rb b/spec/classes/collectd_spec.rb
index a7c1436..9216d48 100644
--- a/spec/classes/collectd_spec.rb
+++ b/spec/classes/collectd_spec.rb
@@ -7,7 +7,30 @@ describe 'collectd' do
     context "on #{os}" do
       let(:facts) { os_facts }
 
-      it { is_expected.to compile }
+      describe 'with params' do
+        let(:params) do
+          {
+            influxdb_collectd_host: 'influx.host',
+          }
+        end
+
+        it { is_expected.to compile.with_all_deps }
+
+        if :operatingsystem == 'CentOS' || :operatingsystem == 'RedHat'
+          it { is_expected.to contain_class('collectd::setup::redhat') }
+          it { is_expected.to contain_package([ 'collectd', 'collectd-virt']) }
+          it { is_expected.to contain_file('/etc/collectd.conf').with_content(%r{\nServer "influx.host" "25826"\n}) }
+          it { is_expected.to contain_cron('collectd_flush_cache') }
+        end
+
+        if :operatingsystem == 'Ubuntu' || :operatingsystem == 'Debian'
+          it { is_expected.to contain_class('collectd::setup::debian') }
+          it { is_expected.to contain_package([ 'collectd', 'collectd-core', 'collectd-dbg', 'collectd-utils', 'libcollectdclient1' ]) }
+          it { is_expected.to contain_file('/etc/collectd/collectd.conf').with_content(%r{\nServer "influx.host" "25826"\n}) }
+        end
+
+        it { is_expected.to contain_service('collectd') }
+      end
     end
   end
 end
-- 
GitLab


From a128548cb525614f5a49b3ccf4a5cf07043c5da5 Mon Sep 17 00:00:00 2001
From: Alessandro Costantini <alessandro.costantini@cnaf.infn.it>
Date: Thu, 17 Jun 2021 12:28:32 +0000
Subject: [PATCH 02/11] Updated manifest: cron removed

---
 .fixtures.yml               | 1 -
 manifests/setup/debian.pp   | 8 --------
 manifests/setup/redhat.pp   | 8 --------
 metadata.json               | 4 ----
 spec/classes/redhat_spec.rb | 1 -
 5 files changed, 22 deletions(-)

diff --git a/.fixtures.yml b/.fixtures.yml
index deb263b..2296adb 100644
--- a/.fixtures.yml
+++ b/.fixtures.yml
@@ -4,4 +4,3 @@
 fixtures:
   forge_modules:
 #     stdlib: "puppetlabs/stdlib"
-     cron_core: "puppetlabs/cron_core"
diff --git a/manifests/setup/debian.pp b/manifests/setup/debian.pp
index b92c40a..c141e99 100644
--- a/manifests/setup/debian.pp
+++ b/manifests/setup/debian.pp
@@ -47,14 +47,6 @@ class collectd::setup::debian (
     require => Package[$collectdpackages],
   }
 
-  #cron {'collectd_flush_cache':
-  #  ensure  => present,
-  #  command => "/usr/bin/killall -SIGUSR1 collectd",
-  #  user    => root,
-  #  minute  => '0',
-  #  hour    => '*/2'
-  #}
-
   service { 'collectd':
     ensure     => running,
     enable     => true,
diff --git a/manifests/setup/redhat.pp b/manifests/setup/redhat.pp
index e1d581f..b072ad9 100644
--- a/manifests/setup/redhat.pp
+++ b/manifests/setup/redhat.pp
@@ -46,14 +46,6 @@ class collectd::setup::redhat (
     require => Package[$collectdpackages],
   }
 
-  cron { 'collectd_flush_cache':
-    ensure  => present,
-    command => '/usr/bin/killall -SIGUSR1 collectd',
-    user    => root,
-    minute  => '0',
-    hour    => '*/2'
-  }
-
   service { 'collectd':
     ensure     => running,
     enable     => true,
diff --git a/metadata.json b/metadata.json
index b679898..353663d 100644
--- a/metadata.json
+++ b/metadata.json
@@ -6,10 +6,6 @@
   "license": "Apache-2.0",
   "source": "https://baltig.infn.it/infn-cloud/collectd",
   "dependencies": [
-    {
-      "name": "puppetlabs/cron_core",
-      "version_requirement": ">=1.0.5 <2.0.0"
-    }
   ],
   "operatingsystem_support": [
     {
diff --git a/spec/classes/redhat_spec.rb b/spec/classes/redhat_spec.rb
index 72efbae..eab5a20 100644
--- a/spec/classes/redhat_spec.rb
+++ b/spec/classes/redhat_spec.rb
@@ -20,7 +20,6 @@ describe 'collectd::setup::redhat' do
           it { is_expected.to contain_package(pkg) }
         end
         it { is_expected.to contain_file('/etc/collectd.conf').with_content(%r{\nServer "influx.host" "25826"\n}) }
-        it { is_expected.to contain_cron('collectd_flush_cache') }
         it { is_expected.to contain_service('collectd') }
       end
     end
-- 
GitLab


From b94cb39ed9ee5c2297c8e529c0807069c9723e34 Mon Sep 17 00:00:00 2001
From: Alessandro Costantini <alessandro.costantini@cnaf.infn.it>
Date: Fri, 18 Jun 2021 15:43:10 +0200
Subject: [PATCH 03/11] addes encryption in transit

---
 manifests/init.pp               |  6 ++++++
 manifests/params.pp             |  2 ++
 manifests/setup/debian.pp       |  8 +++++++-
 manifests/setup/redhat.pp       |  6 ++++++
 spec/classes/redhat_spec.rb     |  2 ++
 templates/collectd.conf-deb.erb |  1 +
 templates/collectd.conf-rh.erb  | 10 ++++++++++
 7 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/manifests/init.pp b/manifests/init.pp
index 2fdd986..a638432 100644
--- a/manifests/init.pp
+++ b/manifests/init.pp
@@ -23,11 +23,17 @@
 #   Mandatory. Default undef
 # [*influxdb_collectd_port*] String: Port related to the influxdb host, usually 25826.
 #   Mandatory. Default 25826
+# [*encryption_username*] String: Username used to encrypt data in transit. If not set, no security is used.
+#   Optional. Default undef
+# [*encryption_password*] String: Password used to encrypt data in transit. If not set, no security is used.
+#   Optional. Default undef
 # 
 #   include collectd
 class collectd (
   String $influxdb_collectd_host = $::collectd::params::influxdb_collectd_host,
   String $influxdb_collectd_port = $::collectd::params::influxdb_collectd_port,
+  String $encryption_username = $::collectd::params::encryption_username,
+  String $encryption_password = $::collectd::params::encryption_password,
 ) inherits collectd::params {
 
   case $::osfamily {
diff --git a/manifests/params.pp b/manifests/params.pp
index ab7777c..24e2bff 100644
--- a/manifests/params.pp
+++ b/manifests/params.pp
@@ -19,4 +19,6 @@
 class collectd::params {
     $influxdb_collectd_host = undef
     $influxdb_collectd_port = '25826'
+    $encryption_username = undef
+    $encryption_password = undef
 }
diff --git a/manifests/setup/debian.pp b/manifests/setup/debian.pp
index c141e99..bb59d71 100644
--- a/manifests/setup/debian.pp
+++ b/manifests/setup/debian.pp
@@ -23,12 +23,18 @@
 #   Mandatory. Default undef
 # [*influxdb_collectd_port*] String: Port related to the influxdb host, usually 25826.
 #   Mandatory. Default 25826
+# [*encryption_username*] String: Username used to encrypt data in transit. If not set, no security is used.
+#   Optional. Default undef
+# [*encryption_password*] String: Password used to encrypt data in transit. If not set, no security is used.
+#   Optional. Default undef
 #
 #   include collectd
 
-class collectd::setup::debian (
+class collectd::setup::redhat (
   String $influxdb_collectd_host = $::collectd::influxdb_collectd_host,
   String $influxdb_collectd_port = $::collectd::influxdb_collectd_port,
+  String $encryption_username = $::collectd::params::encryption_username,
+  String $encryption_password = $::collectd::params::encryption_password,
 ) {
 
   $collectdpackages= [ 'collectd', 'collectd-core', 'collectd-dbg', 'collectd-utils', 'libcollectdclient1']
diff --git a/manifests/setup/redhat.pp b/manifests/setup/redhat.pp
index b072ad9..6739a21 100644
--- a/manifests/setup/redhat.pp
+++ b/manifests/setup/redhat.pp
@@ -23,12 +23,18 @@
 #   Mandatory. Default undef
 # [*influxdb_collectd_port*] String: Port related to the influxdb host, usually 25826.
 #   Mandatory. Default 25826
+# [*encryption_username*] String: Username used to encrypt data in transit. If not set, no security is used.
+#   Optional. Default undef
+# [*encryption_password*] String: Password used to encrypt data in transit. If not set, no security is used.
+#   Optional. Default undef
 #
 #   include collectd
 
 class collectd::setup::redhat (
   String $influxdb_collectd_host = $::collectd::influxdb_collectd_host,
   String $influxdb_collectd_port = $::collectd::influxdb_collectd_port,
+  String $encryption_username = $::collectd::params::encryption_username,
+  String $encryption_password = $::collectd::params::encryption_password,
 ) {
 
   $collectdpackages= [ 'collectd', 'collectd-virt']
diff --git a/spec/classes/redhat_spec.rb b/spec/classes/redhat_spec.rb
index eab5a20..a960269 100644
--- a/spec/classes/redhat_spec.rb
+++ b/spec/classes/redhat_spec.rb
@@ -12,6 +12,8 @@ describe 'collectd::setup::redhat' do
           {
             influxdb_collectd_host: 'influx.host',
             influxdb_collectd_port: '25826',
+            encryption_username: 'user0',
+            encryption_password: 'foo',
           }
         end
 
diff --git a/templates/collectd.conf-deb.erb b/templates/collectd.conf-deb.erb
index 5e1f064..5e40a4b 100644
--- a/templates/collectd.conf-deb.erb
+++ b/templates/collectd.conf-deb.erb
@@ -19,6 +19,7 @@ LoadPlugin rrdtool
         DataDir "/var/lib/collectd/rrd"
 </Plugin>
 
+
 <Plugin network>
 Server "<%=@influxdb_collectd_host-%>" "<%=@influxdb_collectd_port-%>"
 </Plugin>
diff --git a/templates/collectd.conf-rh.erb b/templates/collectd.conf-rh.erb
index 0abe95c..25cefa8 100644
--- a/templates/collectd.conf-rh.erb
+++ b/templates/collectd.conf-rh.erb
@@ -16,9 +16,19 @@ LoadPlugin syslog
 </Plugin>
 
 
+<% if defined?@encryption_username && defined?@encryption_password %>
+<Plugin network>
+  <Server "<%=@influxdb_collectd_host-%>" "<%=@influxdb_collectd_port-%>">
+    SecurityLevel "Encrypt"
+    Username "<%=@encryption_username-%>"
+    Password "<%=@encryption_password-%>"
+  </Server>
+</Plugin>
+<% else %>
 <Plugin network>
 Server "<%=@influxdb_collectd_host-%>" "<%=@influxdb_collectd_port-%>"
 </Plugin>
+<% end %>
 
 
 <Plugin virt>
-- 
GitLab


From b1c2ec21fe33cf4c56bf2e71a67c805e4dadb3c4 Mon Sep 17 00:00:00 2001
From: Alessandro Costantini <alessandro.costantini@cnaf.infn.it>
Date: Fri, 18 Jun 2021 13:54:39 +0000
Subject: [PATCH 04/11] String deleted and typo corrected

---
 manifests/init.pp         | 4 ++--
 manifests/setup/debian.pp | 6 +++---
 manifests/setup/redhat.pp | 4 ++--
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/manifests/init.pp b/manifests/init.pp
index a638432..7ecbf5c 100644
--- a/manifests/init.pp
+++ b/manifests/init.pp
@@ -32,8 +32,8 @@
 class collectd (
   String $influxdb_collectd_host = $::collectd::params::influxdb_collectd_host,
   String $influxdb_collectd_port = $::collectd::params::influxdb_collectd_port,
-  String $encryption_username = $::collectd::params::encryption_username,
-  String $encryption_password = $::collectd::params::encryption_password,
+  $encryption_username = $::collectd::params::encryption_username,
+  $encryption_password = $::collectd::params::encryption_password,
 ) inherits collectd::params {
 
   case $::osfamily {
diff --git a/manifests/setup/debian.pp b/manifests/setup/debian.pp
index bb59d71..f61c6b5 100644
--- a/manifests/setup/debian.pp
+++ b/manifests/setup/debian.pp
@@ -30,11 +30,11 @@
 #
 #   include collectd
 
-class collectd::setup::redhat (
+class collectd::setup::debian (
   String $influxdb_collectd_host = $::collectd::influxdb_collectd_host,
   String $influxdb_collectd_port = $::collectd::influxdb_collectd_port,
-  String $encryption_username = $::collectd::params::encryption_username,
-  String $encryption_password = $::collectd::params::encryption_password,
+  $encryption_username = $::collectd::params::encryption_username,
+  $encryption_password = $::collectd::params::encryption_password,
 ) {
 
   $collectdpackages= [ 'collectd', 'collectd-core', 'collectd-dbg', 'collectd-utils', 'libcollectdclient1']
diff --git a/manifests/setup/redhat.pp b/manifests/setup/redhat.pp
index 6739a21..f5b2eff 100644
--- a/manifests/setup/redhat.pp
+++ b/manifests/setup/redhat.pp
@@ -33,8 +33,8 @@
 class collectd::setup::redhat (
   String $influxdb_collectd_host = $::collectd::influxdb_collectd_host,
   String $influxdb_collectd_port = $::collectd::influxdb_collectd_port,
-  String $encryption_username = $::collectd::params::encryption_username,
-  String $encryption_password = $::collectd::params::encryption_password,
+  $encryption_username = $::collectd::params::encryption_username,
+  $encryption_password = $::collectd::params::encryption_password,
 ) {
 
   $collectdpackages= [ 'collectd', 'collectd-virt']
-- 
GitLab


From 1dd2cc8971cc05012b799168894a25cfc7168513 Mon Sep 17 00:00:00 2001
From: Alessandro Costantini <alessandro.costantini@cnaf.infn.it>
Date: Fri, 18 Jun 2021 15:24:54 +0000
Subject: [PATCH 05/11] revert to working

---
 manifests/init.pp         | 2 --
 manifests/params.pp       | 2 --
 manifests/setup/debian.pp | 2 --
 manifests/setup/redhat.pp | 2 --
 4 files changed, 8 deletions(-)

diff --git a/manifests/init.pp b/manifests/init.pp
index 7ecbf5c..d333109 100644
--- a/manifests/init.pp
+++ b/manifests/init.pp
@@ -32,8 +32,6 @@
 class collectd (
   String $influxdb_collectd_host = $::collectd::params::influxdb_collectd_host,
   String $influxdb_collectd_port = $::collectd::params::influxdb_collectd_port,
-  $encryption_username = $::collectd::params::encryption_username,
-  $encryption_password = $::collectd::params::encryption_password,
 ) inherits collectd::params {
 
   case $::osfamily {
diff --git a/manifests/params.pp b/manifests/params.pp
index 24e2bff..ab7777c 100644
--- a/manifests/params.pp
+++ b/manifests/params.pp
@@ -19,6 +19,4 @@
 class collectd::params {
     $influxdb_collectd_host = undef
     $influxdb_collectd_port = '25826'
-    $encryption_username = undef
-    $encryption_password = undef
 }
diff --git a/manifests/setup/debian.pp b/manifests/setup/debian.pp
index f61c6b5..c96b3bc 100644
--- a/manifests/setup/debian.pp
+++ b/manifests/setup/debian.pp
@@ -33,8 +33,6 @@
 class collectd::setup::debian (
   String $influxdb_collectd_host = $::collectd::influxdb_collectd_host,
   String $influxdb_collectd_port = $::collectd::influxdb_collectd_port,
-  $encryption_username = $::collectd::params::encryption_username,
-  $encryption_password = $::collectd::params::encryption_password,
 ) {
 
   $collectdpackages= [ 'collectd', 'collectd-core', 'collectd-dbg', 'collectd-utils', 'libcollectdclient1']
diff --git a/manifests/setup/redhat.pp b/manifests/setup/redhat.pp
index f5b2eff..38de2d3 100644
--- a/manifests/setup/redhat.pp
+++ b/manifests/setup/redhat.pp
@@ -33,8 +33,6 @@
 class collectd::setup::redhat (
   String $influxdb_collectd_host = $::collectd::influxdb_collectd_host,
   String $influxdb_collectd_port = $::collectd::influxdb_collectd_port,
-  $encryption_username = $::collectd::params::encryption_username,
-  $encryption_password = $::collectd::params::encryption_password,
 ) {
 
   $collectdpackages= [ 'collectd', 'collectd-virt']
-- 
GitLab


From 1ab867cbc42cb91abb998b6c75a2d9cbd9381fd7 Mon Sep 17 00:00:00 2001
From: Alessandro Costantini <alessandro.costantini@cnaf.infn.it>
Date: Fri, 18 Jun 2021 15:40:10 +0000
Subject: [PATCH 06/11] Updated: encryption

---
 manifests/init.pp               |  6 ++++--
 manifests/params.pp             |  2 ++
 manifests/setup/debian.pp       |  6 ++++--
 manifests/setup/redhat.pp       |  6 ++++--
 templates/collectd.conf-deb.erb | 11 ++++++++++-
 templates/collectd.conf-rh.erb  |  7 +++----
 6 files changed, 27 insertions(+), 11 deletions(-)

diff --git a/manifests/init.pp b/manifests/init.pp
index d333109..2d5610e 100644
--- a/manifests/init.pp
+++ b/manifests/init.pp
@@ -23,15 +23,17 @@
 #   Mandatory. Default undef
 # [*influxdb_collectd_port*] String: Port related to the influxdb host, usually 25826.
 #   Mandatory. Default 25826
-# [*encryption_username*] String: Username used to encrypt data in transit. If not set, no security is used.
+# [*encript_user*] String: Username used to encrypt data in transit. If not set, no security is used.
 #   Optional. Default undef
-# [*encryption_password*] String: Password used to encrypt data in transit. If not set, no security is used.
+# [*encript_password*] String: Password used to encrypt data in transit. If not set, no security is used.
 #   Optional. Default undef
 # 
 #   include collectd
 class collectd (
   String $influxdb_collectd_host = $::collectd::params::influxdb_collectd_host,
   String $influxdb_collectd_port = $::collectd::params::influxdb_collectd_port,
+  String $encript_user = $::collectd::params::encript_user,
+  String $encript_password = $::collectd::params::encript_password,
 ) inherits collectd::params {
 
   case $::osfamily {
diff --git a/manifests/params.pp b/manifests/params.pp
index ab7777c..1ad4b74 100644
--- a/manifests/params.pp
+++ b/manifests/params.pp
@@ -19,4 +19,6 @@
 class collectd::params {
     $influxdb_collectd_host = undef
     $influxdb_collectd_port = '25826'
+    $encript_user = undef
+    $encript_password = undef
 }
diff --git a/manifests/setup/debian.pp b/manifests/setup/debian.pp
index c96b3bc..6d409bf 100644
--- a/manifests/setup/debian.pp
+++ b/manifests/setup/debian.pp
@@ -23,9 +23,9 @@
 #   Mandatory. Default undef
 # [*influxdb_collectd_port*] String: Port related to the influxdb host, usually 25826.
 #   Mandatory. Default 25826
-# [*encryption_username*] String: Username used to encrypt data in transit. If not set, no security is used.
+# [*encript_user*] String: Username used to encrypt data in transit. If not set, no security is used.
 #   Optional. Default undef
-# [*encryption_password*] String: Password used to encrypt data in transit. If not set, no security is used.
+# [*encript_password*] String: Password used to encrypt data in transit. If not set, no security is used.
 #   Optional. Default undef
 #
 #   include collectd
@@ -33,6 +33,8 @@
 class collectd::setup::debian (
   String $influxdb_collectd_host = $::collectd::influxdb_collectd_host,
   String $influxdb_collectd_port = $::collectd::influxdb_collectd_port,
+  String $encript_user = $::collectd::encript_user,
+  String $encript_password = $::collectd::encript_password,
 ) {
 
   $collectdpackages= [ 'collectd', 'collectd-core', 'collectd-dbg', 'collectd-utils', 'libcollectdclient1']
diff --git a/manifests/setup/redhat.pp b/manifests/setup/redhat.pp
index 38de2d3..2a17ec2 100644
--- a/manifests/setup/redhat.pp
+++ b/manifests/setup/redhat.pp
@@ -23,9 +23,9 @@
 #   Mandatory. Default undef
 # [*influxdb_collectd_port*] String: Port related to the influxdb host, usually 25826.
 #   Mandatory. Default 25826
-# [*encryption_username*] String: Username used to encrypt data in transit. If not set, no security is used.
+# [*encript_user*] String: Username used to encrypt data in transit. If not set, no security is used.
 #   Optional. Default undef
-# [*encryption_password*] String: Password used to encrypt data in transit. If not set, no security is used.
+# [*encript_password*] String: Password used to encrypt data in transit. If not set, no security is used.
 #   Optional. Default undef
 #
 #   include collectd
@@ -33,6 +33,8 @@
 class collectd::setup::redhat (
   String $influxdb_collectd_host = $::collectd::influxdb_collectd_host,
   String $influxdb_collectd_port = $::collectd::influxdb_collectd_port,
+  String $encript_user = $::collectd::encript_user,
+  String $encript_password = $::collectd::encript_password,
 ) {
 
   $collectdpackages= [ 'collectd', 'collectd-virt']
diff --git a/templates/collectd.conf-deb.erb b/templates/collectd.conf-deb.erb
index 5e40a4b..a6a1c1d 100644
--- a/templates/collectd.conf-deb.erb
+++ b/templates/collectd.conf-deb.erb
@@ -19,10 +19,19 @@ LoadPlugin rrdtool
         DataDir "/var/lib/collectd/rrd"
 </Plugin>
 
-
+<% if defined?@encript_user && defined?@encript_password %>
+<Plugin network>
+  <Server "<%=@influxdb_collectd_host-%>" "<%=@influxdb_collectd_port-%>">
+    SecurityLevel "Encrypt"
+    Username "<%=@encript_user-%>"
+    Password "<%=@encript_password-%>"
+  </Server>
+</Plugin>
+<% else %>
 <Plugin network>
 Server "<%=@influxdb_collectd_host-%>" "<%=@influxdb_collectd_port-%>"
 </Plugin>
+<% end %>
 
 
 <Plugin virt>
diff --git a/templates/collectd.conf-rh.erb b/templates/collectd.conf-rh.erb
index 25cefa8..14d3c1f 100644
--- a/templates/collectd.conf-rh.erb
+++ b/templates/collectd.conf-rh.erb
@@ -15,13 +15,12 @@ LoadPlugin syslog
        LogLevel info
 </Plugin>
 
-
-<% if defined?@encryption_username && defined?@encryption_password %>
+<% if defined?@encript_user && defined?@encript_password %>
 <Plugin network>
   <Server "<%=@influxdb_collectd_host-%>" "<%=@influxdb_collectd_port-%>">
     SecurityLevel "Encrypt"
-    Username "<%=@encryption_username-%>"
-    Password "<%=@encryption_password-%>"
+    Username "<%=@encript_user-%>"
+    Password "<%=@encript_password-%>"
   </Server>
 </Plugin>
 <% else %>
-- 
GitLab


From 3166b9e6ff11eddfc854e221d72256377f3b25ce Mon Sep 17 00:00:00 2001
From: Alessandro Costantini <alessandro.costantini@cnaf.infn.it>
Date: Fri, 18 Jun 2021 15:53:34 +0000
Subject: [PATCH 07/11] Typo correction

---
 templates/collectd.conf-deb.erb | 2 --
 templates/collectd.conf-rh.erb  | 2 --
 2 files changed, 4 deletions(-)

diff --git a/templates/collectd.conf-deb.erb b/templates/collectd.conf-deb.erb
index a6a1c1d..55f26eb 100644
--- a/templates/collectd.conf-deb.erb
+++ b/templates/collectd.conf-deb.erb
@@ -5,7 +5,6 @@ PluginDir   "/usr/lib/collectd"
 TypesDB     "/usr/share/collectd/types.db"
 Interval    600
 
-
 LoadPlugin network
 LoadPlugin virt
 LoadPlugin syslog
@@ -33,7 +32,6 @@ Server "<%=@influxdb_collectd_host-%>" "<%=@influxdb_collectd_port-%>"
 </Plugin>
 <% end %>
 
-
 <Plugin virt>
         Connection "qemu:///system"
         RefreshInterval 60
diff --git a/templates/collectd.conf-rh.erb b/templates/collectd.conf-rh.erb
index 14d3c1f..6a7be42 100644
--- a/templates/collectd.conf-rh.erb
+++ b/templates/collectd.conf-rh.erb
@@ -6,7 +6,6 @@ PluginDir   "/usr/lib64/collectd"
 TypesDB     "/usr/share/collectd/types.db"
 Interval    600
 
-
 LoadPlugin network
 LoadPlugin virt
 LoadPlugin syslog
@@ -29,7 +28,6 @@ Server "<%=@influxdb_collectd_host-%>" "<%=@influxdb_collectd_port-%>"
 </Plugin>
 <% end %>
 
-
 <Plugin virt>
         Connection "qemu:///system"
         RefreshInterval 60
-- 
GitLab


From 27ce0aca8605cb59663391e080d7d0df7d9f575e Mon Sep 17 00:00:00 2001
From: Alessandro Costantini <alessandro.costantini@cnaf.infn.it>
Date: Fri, 18 Jun 2021 16:21:43 +0000
Subject: [PATCH 08/11] Encryption added

---
 manifests/init.pp               | 4 ++--
 manifests/setup/debian.pp       | 4 ++--
 manifests/setup/redhat.pp       | 4 ++--
 templates/collectd.conf-deb.erb | 2 +-
 templates/collectd.conf-rh.erb  | 2 +-
 5 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/manifests/init.pp b/manifests/init.pp
index 2d5610e..ee44c10 100644
--- a/manifests/init.pp
+++ b/manifests/init.pp
@@ -32,8 +32,8 @@
 class collectd (
   String $influxdb_collectd_host = $::collectd::params::influxdb_collectd_host,
   String $influxdb_collectd_port = $::collectd::params::influxdb_collectd_port,
-  String $encript_user = $::collectd::params::encript_user,
-  String $encript_password = $::collectd::params::encript_password,
+  $encript_user = $::collectd::params::encript_user,
+  $encript_password = $::collectd::params::encript_password,
 ) inherits collectd::params {
 
   case $::osfamily {
diff --git a/manifests/setup/debian.pp b/manifests/setup/debian.pp
index 6d409bf..02615a3 100644
--- a/manifests/setup/debian.pp
+++ b/manifests/setup/debian.pp
@@ -33,8 +33,8 @@
 class collectd::setup::debian (
   String $influxdb_collectd_host = $::collectd::influxdb_collectd_host,
   String $influxdb_collectd_port = $::collectd::influxdb_collectd_port,
-  String $encript_user = $::collectd::encript_user,
-  String $encript_password = $::collectd::encript_password,
+  $encript_user = $::collectd::encript_user,
+  $encript_password = $::collectd::encript_password,
 ) {
 
   $collectdpackages= [ 'collectd', 'collectd-core', 'collectd-dbg', 'collectd-utils', 'libcollectdclient1']
diff --git a/manifests/setup/redhat.pp b/manifests/setup/redhat.pp
index 2a17ec2..c00753d 100644
--- a/manifests/setup/redhat.pp
+++ b/manifests/setup/redhat.pp
@@ -33,8 +33,8 @@
 class collectd::setup::redhat (
   String $influxdb_collectd_host = $::collectd::influxdb_collectd_host,
   String $influxdb_collectd_port = $::collectd::influxdb_collectd_port,
-  String $encript_user = $::collectd::encript_user,
-  String $encript_password = $::collectd::encript_password,
+  $encript_user = $::collectd::encript_user,
+  $encript_password = $::collectd::encript_password,
 ) {
 
   $collectdpackages= [ 'collectd', 'collectd-virt']
diff --git a/templates/collectd.conf-deb.erb b/templates/collectd.conf-deb.erb
index 55f26eb..3cd496d 100644
--- a/templates/collectd.conf-deb.erb
+++ b/templates/collectd.conf-deb.erb
@@ -18,7 +18,7 @@ LoadPlugin rrdtool
         DataDir "/var/lib/collectd/rrd"
 </Plugin>
 
-<% if defined?@encript_user && defined?@encript_password %>
+<% if @encript_user && @encript_password %>
 <Plugin network>
   <Server "<%=@influxdb_collectd_host-%>" "<%=@influxdb_collectd_port-%>">
     SecurityLevel "Encrypt"
diff --git a/templates/collectd.conf-rh.erb b/templates/collectd.conf-rh.erb
index 6a7be42..ac937ce 100644
--- a/templates/collectd.conf-rh.erb
+++ b/templates/collectd.conf-rh.erb
@@ -14,7 +14,7 @@ LoadPlugin syslog
        LogLevel info
 </Plugin>
 
-<% if defined?@encript_user && defined?@encript_password %>
+<% if @encript_user && @encript_password %>
 <Plugin network>
   <Server "<%=@influxdb_collectd_host-%>" "<%=@influxdb_collectd_port-%>">
     SecurityLevel "Encrypt"
-- 
GitLab


From e157e69f53d8d860c697500509c7c807ab1a8ee1 Mon Sep 17 00:00:00 2001
From: Alessandro Costantini <alessandro.costantini@cnaf.infn.it>
Date: Sat, 19 Jun 2021 16:41:57 +0000
Subject: [PATCH 09/11] Update tests

---
 spec/classes/debian_spec.rb | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/spec/classes/debian_spec.rb b/spec/classes/debian_spec.rb
index cef2172..2653f50 100644
--- a/spec/classes/debian_spec.rb
+++ b/spec/classes/debian_spec.rb
@@ -12,6 +12,8 @@ describe 'collectd::setup::debian' do
           {
             influxdb_collectd_host: 'influx.host',
             influxdb_collectd_port: '25826',
+            encript_user: 'user0',
+            encript_password: 'foo',
           }
         end
 
-- 
GitLab


From 2bc53ed2be4b7eec0b0807e70ce7d2dd78ec8bd0 Mon Sep 17 00:00:00 2001
From: Alessandro Costantini <alessandro.costantini@cnaf.infn.it>
Date: Mon, 21 Jun 2021 05:09:37 +0000
Subject: [PATCH 10/11] Modify expected conted in tests

---
 spec/classes/debian_spec.rb | 2 +-
 spec/classes/redhat_spec.rb | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/spec/classes/debian_spec.rb b/spec/classes/debian_spec.rb
index 2653f50..10bb01a 100644
--- a/spec/classes/debian_spec.rb
+++ b/spec/classes/debian_spec.rb
@@ -21,7 +21,7 @@ describe 'collectd::setup::debian' do
         [ 'collectd', 'collectd-core', 'collectd-dbg', 'collectd-utils', 'libcollectdclient1' ].each do |pkg|
           it { is_expected.to contain_package(pkg) }
         end
-        it { is_expected.to contain_file('/etc/collectd/collectd.conf').with_content(%r{\nServer "influx.host" "25826"\n}) }
+        it { is_expected.to contain_file('/etc/collectd/collectd.conf').with_content(%r{\n<Server "influx.host" "25826">\n}) }
         it { is_expected.to contain_service('collectd') }
       end
     end
diff --git a/spec/classes/redhat_spec.rb b/spec/classes/redhat_spec.rb
index a960269..bb92727 100644
--- a/spec/classes/redhat_spec.rb
+++ b/spec/classes/redhat_spec.rb
@@ -21,7 +21,7 @@ describe 'collectd::setup::redhat' do
         [ 'collectd', 'collectd-virt'].each do |pkg|
           it { is_expected.to contain_package(pkg) }
         end
-        it { is_expected.to contain_file('/etc/collectd.conf').with_content(%r{\nServer "influx.host" "25826"\n}) }
+        it { is_expected.to contain_file('/etc/collectd.conf').with_content(%r{\n<Server "influx.host" "25826">\n}) }
         it { is_expected.to contain_service('collectd') }
       end
     end
-- 
GitLab


From 9a21a4f09fee1f5443415ce5b31d1cd841ef8954 Mon Sep 17 00:00:00 2001
From: DIEGO MICHELOTTO <diego.michelotto@cnaf.infn.it>
Date: Mon, 21 Jun 2021 07:19:25 +0000
Subject: [PATCH 11/11] Update spec/classes/redhat_spec.rb

---
 spec/classes/redhat_spec.rb | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/spec/classes/redhat_spec.rb b/spec/classes/redhat_spec.rb
index bb92727..2f73b2e 100644
--- a/spec/classes/redhat_spec.rb
+++ b/spec/classes/redhat_spec.rb
@@ -7,7 +7,7 @@ describe 'collectd::setup::redhat' do
     context "on #{os}" do
       let(:facts) { os_facts }
 
-      describe 'with params' do
+      describe 'with params and encryption enabled' do
         let(:params) do
           {
             influxdb_collectd_host: 'influx.host',
@@ -17,6 +17,27 @@ describe 'collectd::setup::redhat' do
           }
         end
 
+        it { is_expected.to compile.with_all_deps }
+        [ 'collectd', 'collectd-virt'].each do |pkg|
+          it { is_expected.to contain_package(pkg) }
+        end
+        it do
+          is_expected.to contain_file('/etc/collectd.conf') \
+          .with_content(%r{\n  <Server "influx.host" "25826">\n}) \
+          .with_content(%r{\n    Username "user0"\n}) \
+          .with_content(%r{\n    Password "foo"\n})
+        end
+        it { is_expected.to contain_file('/etc/collectd.conf').with_content(%r{\n  <Server "influx.host" "25826">\n}) }
+        it { is_expected.to contain_service('collectd') }
+      end
+      describe 'with params and encryption disabled' do
+        let(:params) do
+          {
+            influxdb_collectd_host: 'influx.host',
+            influxdb_collectd_port: '25826',
+          }
+        end
+
         it { is_expected.to compile.with_all_deps }
         [ 'collectd', 'collectd-virt'].each do |pkg|
           it { is_expected.to contain_package(pkg) }
-- 
GitLab