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

Added support for Ubuntu Bionic (18.04) and CentOS 7 #2

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -78,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.
8 changes: 7 additions & 1 deletion lib/puppet/type/snmpcollector_metric.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,10 @@
desc 'Additional Data.'
defaultto ''
end
end

newproperty(:conversion) do
desc 'Conversion value'
defaultto 0
end
end

6 changes: 4 additions & 2 deletions lib/puppet_x/snmpcollector/mapping.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -101,4 +102,5 @@ def self.measurement_filter
'description' => 'Description',}
end
end
end
end

52 changes: 26 additions & 26 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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
# -------
Expand All @@ -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
}
}
154 changes: 107 additions & 47 deletions manifests/install.pp
Original file line number Diff line number Diff line change
@@ -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",
}

}
# 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",
}
}
9 changes: 6 additions & 3 deletions manifests/metric.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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']
}
}

36 changes: 23 additions & 13 deletions manifests/remote_package.pp
Original file line number Diff line number Diff line change
@@ -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"
}
}
}