From 0643cf990c02df03db7e8e95487d11ead671786c Mon Sep 17 00:00:00 2001 From: David Hartley Date: Wed, 1 May 2019 22:08:33 +1000 Subject: [PATCH 1/4] Added support for Ubuntu 18.04 and CentOS 7 --- README.md | 9 ++- manifests/init.pp | 52 ++++++------ manifests/install.pp | 154 +++++++++++++++++++++++++----------- manifests/remote_package.pp | 36 ++++++--- 4 files changed, 163 insertions(+), 88 deletions(-) diff --git a/README.md b/README.md index ca71604..fd87e25 100644 --- a/README.md +++ b/README.md @@ -20,11 +20,16 @@ It can install and configure the required packages and authentication as well as ### Setup Requirements **OPTIONAL** -This module has only been tested on Ubuntu Xenial (16.04) LTS. +This module has only been tested on Ubuntu Xenial (16.04) LTS, Bionic (18.04) and CentOS 7. ### Beginning with snmpcollector -No setup is required other than adding this module to your Puppetfile. +No setup is required other than adding a reference to this module to your Puppetfile. + +``` +mod 'ixaustralia/snmpcollector', + :git => 'https://github.com/ixaustralia/ixaustralia-snmpcollector.git' +``` ## Usage diff --git a/manifests/init.pp b/manifests/init.pp index 3a9abb8..3d8631d 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -28,13 +28,13 @@ # -------- # # @example - # class {'snmpcollector' : - # instance_name => 'instance01', - # web_port => 8090, - # admin_username => 'admin', - # admin_password => 'strongpassword', - # service_enabled => true, - # } + # class {'snmpcollector' : + # instance_name => 'instance01', + # web_port => 8090, + # admin_username => 'admin', + # admin_password => 'strongpassword', + # service_enabled => true, + # } # # Authors # ------- @@ -43,26 +43,26 @@ # # class snmpcollector ( - String $version, - String $instance_name, - Integer $web_port, - String $admin_username, - String $admin_password, - Boolean $service_enabled, + String $version = 'latest', + String $instance_name, + Integer $web_port, + String $admin_username, + String $admin_password, + Boolean $service_enabled, ) { - class {'snmpcollector::install': - version => $version - } -> - class {'snmpcollector::configure' : - instance_name => $instance_name, - web_port => $web_port, - admin_username => $admin_username, - admin_password => $admin_password, - service_enabled => $service_enabled - } ~> - class {'snmpcollector::service' : - enable => $service_enabled - } + class {'snmpcollector::install': + version => $version + } -> + class {'snmpcollector::configure' : + instance_name => $instance_name, + web_port => $web_port, + admin_username => $admin_username, + admin_password => $admin_password, + service_enabled => $service_enabled + } ~> + class {'snmpcollector::service' : + enable => $service_enabled + } } diff --git a/manifests/install.pp b/manifests/install.pp index 00e6fe8..322f8d5 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -1,50 +1,110 @@ class snmpcollector::install ( - String $version = 'latest' + String $version = 'latest' ) { - - $packages = [ - 'build-essential', - 'bison', - 'openssl', - 'libreadline6', - 'libreadline6-dev', - 'curl', - 'git-core', - 'zlib1g', - 'zlib1g-dev', - 'libssl-dev', - 'libyaml-dev', - 'libxml2-dev', - 'autoconf', - 'libc6-dev', - 'ncurses-dev', - 'automake', - 'libtool' - ] - - $puppet_gems = [ - 'rest-client', - 'json' - ] - - $package_name = "snmpcollector_${version}_amd64" - - # Dependency for Package install - package{ $packages : - ensure => latest, - } -> - - # Gem requirements - package { $puppet_gems: - ensure => 'installed', - provider => 'puppet_gem', - } -> - - # Pull down the required version deb and install. - snmpcollector::remote_package { $package_name : - url => "http://snmpcollector-rel.s3.amazonaws.com/builds/snmpcollector_${version}_amd64.deb", - creates => "/usr/sbin/snmpcollector", - } - -} \ No newline at end of file + # We can't reassign variables, so set it inside the right OS fact. + # Check for 16.04, otherwise assume 18.04 + if $osfamily == 'Debian' { + if $osrelease == '16.04' { + $packages = [ + 'build-essential', + 'bison', + 'openssl', + 'libreadline6', + 'libreadline6-dev', + 'curl', + 'git-core', + 'zlib1g', + 'zlib1g-dev', + 'libssl-dev', + 'libyaml-dev', + 'libxml2-dev', + 'autoconf', + 'libc6-dev', + 'ncurses-dev', + 'automake', + 'libtool' + ] + } + else { + $packages = [ + 'build-essential', + 'bison', + 'openssl', + 'libreadline7', + 'libreadline6-dev', + 'curl', + 'git-core', + 'zlib1g', + 'zlib1g-dev', + 'libssl-dev', + 'libyaml-dev', + 'libxml2-dev', + 'autoconf', + 'libc6-dev', + 'ncurses-dev', + 'automake', + 'libtool' + ] + } + } + # CentOS / RHEL + elsif $osfamily == 'RedHat' { + $packages = [ + 'gcc', + 'gcc-c++', + 'make', + 'bison', + 'openssl', + 'openssl-devel', + 'readline', + 'readline-devel', + 'curl', + 'git', + 'zlib', + 'zlib-devel', + 'libyaml-devel', + 'libxml2-devel', + 'autoconf', + 'glibc-devel', + 'ncurses-devel', + 'automake', + 'libtool' + ] + } + + $puppet_gems = [ + 'rest-client', + 'json' + ] + + # Same deal with the snmpcollector package - slight differences between Ubuntu & CentOS filenames. + # Note that the Debian version uses underscores whereas the Redhat version uses hyphens.. + # + # Debian + # http://snmpcollector-rel.s3.amazonaws.com/builds/snmpcollector_latest_amd64.deb + # Redhat + # http://snmpcollector-rel.s3.amazonaws.com/builds/snmpcollector-latest-1.x86_64.rpm + + if $osfamily == 'Debian' { + $package_path = "snmpcollector_${version}_amd64.deb" + } + elsif $osfamily == 'RedHat' { + $package_path = "snmpcollector-${version}-1.x86_64.rpm" + } + + # Dependency for Package install + package{ $packages : + ensure => latest, + } -> + # Gem requirements + package { $puppet_gems: + ensure => 'installed', + provider => 'puppet_gem', + } -> + # Pull down the required version and install. + snmpcollector::remote_package { $package_path : + url => "https://snmpcollector-rel.s3.amazonaws.com/builds/${package_path}", + creates => "/usr/sbin/snmpcollector", + } +} diff --git a/manifests/remote_package.pp b/manifests/remote_package.pp index 9f92712..246cf26 100644 --- a/manifests/remote_package.pp +++ b/manifests/remote_package.pp @@ -1,14 +1,24 @@ -define snmpcollector::remote_package($packagename=$title,$url,$creates){ - exec{"download-$packagename": - command=>"/usr/bin/curl -o /tmp/$packagename.deb $url", - creates=>"/tmp/$packagename.deb", - require=>Package['curl'] - } - - package{ 'snmpcollector' : - ensure=> 'latest', - require=>Exec["download-$packagename"], - source=>"/tmp/$packagename.deb", - provider=>"dpkg" - } +define snmpcollector::remote_package($packagename=$title,$url,$creates){ + if $osfamily == 'Debian' { + # Download and install + exec{"download-$packagename": + command=>"/usr/bin/curl -o /tmp/$packagename $url", + creates=>"/tmp/$packagename", + require=>Package['curl'] + } + package{ 'snmpcollector' : + ensure=> 'latest', + require=>Exec["download-$packagename"], + source=>"/tmp/$packagename", + provider=>"dpkg" + } + } + elsif $osfamily == 'RedHat' { + # Install directly from the web + package{ 'snmpcollector' : + ensure => 'installed', + source=>"$url", + provider=>"rpm" + } + } } From 15b2c4c47ae319eeed44632a009eeaf30d205d14 Mon Sep 17 00:00:00 2001 From: David Hartley Date: Wed, 1 May 2019 22:17:00 +1000 Subject: [PATCH 2/4] Added support for Ubuntu 18.04 and CentOS 7 --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index fd87e25..b7b4bf6 100644 --- a/README.md +++ b/README.md @@ -83,3 +83,6 @@ Below is the absolute minimum required for each type, see manifest -> *.pp for a Configure SNMP Devices such as routers and switch. Required parametres: host, database (name of an influxserver instance) + +## Limitations +This *should* work on all Debian/RHEL variants, however there may be cases where specific releases of a distribution have minor dependency differences. For example, there's a single dependency package difference between Ubuntu 16.04 and 18.04. It has been tested on Ubuntu Xenial (16.04) LTS, Bionic (18.04) and CentOS 7. \ No newline at end of file From b771f8b7fdfa425c7a0b320e9ce8dbebd0556de9 Mon Sep 17 00:00:00 2001 From: David Hartley Date: Mon, 6 May 2019 16:16:51 +1000 Subject: [PATCH 3/4] Added conversion parameter to the metric class --- lib/puppet/type/snmpcollector_metric.rb | 8 +++++++- lib/puppet_x/snmpcollector/mapping.rb | 6 ++++-- manifests/metric.pp | 9 ++++++--- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/lib/puppet/type/snmpcollector_metric.rb b/lib/puppet/type/snmpcollector_metric.rb index 4203dac..ecd8425 100644 --- a/lib/puppet/type/snmpcollector_metric.rb +++ b/lib/puppet/type/snmpcollector_metric.rb @@ -51,4 +51,10 @@ desc 'Additional Data.' defaultto '' end -end \ No newline at end of file + + newproperty(conversion) do + desc 'Conversion value' + defaultto 0 + end +end + diff --git a/lib/puppet_x/snmpcollector/mapping.rb b/lib/puppet_x/snmpcollector/mapping.rb index 43c6fed..b8424fd 100644 --- a/lib/puppet_x/snmpcollector/mapping.rb +++ b/lib/puppet_x/snmpcollector/mapping.rb @@ -66,7 +66,8 @@ def self.metric 'scale' => 'Scale', 'shift' => 'Shift', 'is_tag' => 'IsTag', - 'extra_data' => 'ExtraData',} + 'extra_data' => 'ExtraData', + 'conversion' => 'Conversion',} end def self.measurement @@ -101,4 +102,5 @@ def self.measurement_filter 'description' => 'Description',} end end -end \ No newline at end of file +end + diff --git a/manifests/metric.pp b/manifests/metric.pp index d535468..6d22670 100644 --- a/manifests/metric.pp +++ b/manifests/metric.pp @@ -8,7 +8,8 @@ Integer $scale = 0, Integer $shift = 0, Boolean $is_tag = false, - String $extra_data = '' + String $extra_data = '', + Integer $conversion = 0 ) { include snmpcollector::reload @@ -25,6 +26,8 @@ scale => $scale, shift => $shift, is_tag => $is_tag, - extra_data => $extra_data + extra_data => $extra_data, + conversion => $conversion } ~> Class['snmpcollector::reload'] -} \ No newline at end of file +} + From 64cdf7716da416c01a8267f42199671c20b61b30 Mon Sep 17 00:00:00 2001 From: hewisaurus Date: Mon, 6 May 2019 17:05:35 +1000 Subject: [PATCH 4/4] Update snmpcollector_metric.rb --- lib/puppet/type/snmpcollector_metric.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/puppet/type/snmpcollector_metric.rb b/lib/puppet/type/snmpcollector_metric.rb index ecd8425..45f2cc8 100644 --- a/lib/puppet/type/snmpcollector_metric.rb +++ b/lib/puppet/type/snmpcollector_metric.rb @@ -52,7 +52,7 @@ defaultto '' end - newproperty(conversion) do + newproperty(:conversion) do desc 'Conversion value' defaultto 0 end