diff --git a/.coveralls.yml b/.coveralls.yml new file mode 100644 index 0000000..de00189 --- /dev/null +++ b/.coveralls.yml @@ -0,0 +1,2 @@ +service_name: travis-pro +repo_token: 7msLgVvXyGptO9sHn47l34uP8BMdZzCyz diff --git a/.fixtures.yml b/.fixtures.yml new file mode 100644 index 0000000..1e26426 --- /dev/null +++ b/.fixtures.yml @@ -0,0 +1,8 @@ +fixtures: + forge_modules: + chocolatey: "rismoney/chocolatey" + inifile: "puppetlabs/inifile" + stdlib: "puppetlabs/stdlib" + symlinks: + zabbixagent: "#{source_dir}" + diff --git a/.gitignore b/.gitignore index 0c6117d..9f0a068 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,8 @@ -pkg \ No newline at end of file +/.bundle/ +/.idea/ +/.vagrant/ +/coverage/ +/pkg/ +/spec/fixtures/ +/vendor/ +Gemfile.lock diff --git a/.project b/.project new file mode 100644 index 0000000..67d38eb --- /dev/null +++ b/.project @@ -0,0 +1,18 @@ + + + zabbixagent + + + + + + org.eclipse.xtext.ui.shared.xtextBuilder + + + + + + com.puppetlabs.geppetto.pp.dsl.ui.puppetNature + org.eclipse.xtext.ui.shared.xtextNature + + diff --git a/.puppet-lint.rc b/.puppet-lint.rc new file mode 100644 index 0000000..0a6b04e --- /dev/null +++ b/.puppet-lint.rc @@ -0,0 +1 @@ +--no-class_inherits_from_params_class-check diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..1c73f0b --- /dev/null +++ b/.travis.yml @@ -0,0 +1,17 @@ +language: ruby +cache: bundler +rvm: + - 1.8.7 + - 1.9.3 + - 2.0.0 + - 2.1.1 + +env: + - PUPPET_VERSION=3.7.3 + +script: 'bundle exec rake tests' + +notifications: + email: + on_failure: change + on_success: never diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b99b02..2339c2a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,15 @@ +2015-01-17 Fork - Release 2.0.0 +Total Rework by genebean: +- Converted to use the install -> config -> service pattern +- Moved all parameters to `params.pp` +- Removed dependency on epel module +- Added Zabbix repo +- Added option to disable repo management per repo +- Changed Windows setup to utilize the official Zabbix package via Chocolatey +- Added .project file for Geppetto +- Added Vagrant config to facilitate testing and development +- Added several new parameters (see changes to README.md) + 2014-07-15 Release 1.0.1 Changes: - Upgrade package format and fix deprecation warnings. @@ -16,6 +28,6 @@ Bugfixes: 2013-01-02 Release 0.1.0 Changes: - Use ini_setting module to only change necessary settings rather than use -the entire config file as a template. This will insulate us from changes in the +the entire config file as a template. This will insulate us from changes in the Zabbix configuration with new versions. -- Other fixes \ No newline at end of file +- Other fixes diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..772ad3f --- /dev/null +++ b/Gemfile @@ -0,0 +1,17 @@ +# vim:ft=ruby +source ENV['GEM_SOURCE'] || "https://rubygems.org" + +if ENV.key?('PUPPET_VERSION') + puppetversion = "= #{ENV['PUPPET_VERSION']}" +else + puppetversion = ['>= 3.7.3', '< 4.0'] +end + +group :development, :unit_tests do + gem 'puppet', puppetversion + gem 'puppet-lint', ['>= 1.0.0', '< 1.1.0'] + gem 'puppetlabs_spec_helper', '~> 0.8' + gem 'rspec-puppet', :git => 'https://github.com/rodjek/rspec-puppet.git' +end + + diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..1836ded --- /dev/null +++ b/LICENSE @@ -0,0 +1,27 @@ +Copyright (c) 2015, Gene Liverman +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of genebean-zabbixagent nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/README.md b/README.md index bd1f7e7..aab3c64 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,132 @@ -# Zabbix Agent Puppet Module -This module manages the zabbix agent for a monitored machine. - -This module has been tested against Puppet 3.0.1 on Windows Server 2008R2, Ubuntu Server 12.04, and CentOS 6.3. - -## Usage - -```puppet -class { 'zabbixagent': - servers => 'zabbix.example.com', # Optional: defaults to localhost (accepts an array) - hostname => 'web01.example.com' # Optional: defaults to the fully qualified domain name of the machine -} -``` - -This is the only configuration supported at this time. Custom user parameters may -come at a later date. If there is any other configuration that ought to be made available, -then please let me know. - -### Authors -* Scott Smerchek (@smerchek) - -### Contributors -* Martijn Storck (@martijn) - Added CentOS support +[![Build Status][travis-img-master]][travis-ci] +[![Puppet Forge][pf-img]][pf-link] +[![GitHub tag][gh-tag-img]][gh-link] + +# Zabbix Agent Puppet Module + +#### Table of Contents + +1. [Overview](#overview) +2. [Setup requirements](#setup-requirements) +3. [Parameters](#parameters) +4. [Limitations](#limitations) +5. [Usage](#usage) +6. [Contributing](#contributing) +7. [Contributors](#contributors) +8. [License](#license) + +## Overview + +This module manages the zabbix agent for a monitored machine. It can +also, optionally, manage repositories related to Zabbix on Linux. On the Red Hat +family of OS's, this includes both EPEL and Zabbix. On the Debian family, +this is just the Zabbix repo. On Windows this module utilizes the +[Chocolatey](chocolatey.org) provider. + +## Setup Requirements + +This module has been tested against Puppet 3.7.3 on: +* CentOS 6.6 +* Ubuntu Server 14.04 +* Windows 7 +* Windows Server 2012 R2 + + +## Parameters: + +##### `ensure_setting` +Passed directly to ensure of package resource +Default: `'present'` + +##### `hostname` +The hostname used in the config file. +Default: `downcase($::fqdn)` + +##### `include_dir` +The directory that additional config files will be placed in. +Default: `'zabbix_agentd.d'` +Type: String + +##### `include_file` +A file that that contain additional settings +Default: `''` +Type: String + +##### `logfile` +The full path to where Zabbix should store it's logs. +Default: `'C:\zabbix_agentd.log'` +Type: String + +##### `manage_repo_epel` +Determines if the EPEL repo is managed on the RedHat family of OS's. +Default: `false` +Type: boolean + +##### `manage_repo_zabbix` +Determines if the Zabbix repo is managed on the RedHat family of OS's. +Default: `false` +Type: boolean + +##### `servers` +The server or servers used in the Servers setting. +Default: `'127.0.0.1'` +Type: String separated by commas OR Array + +##### `servers_active` +The server or servers used in the Servers setting. +Default: `'127.0.0.1'` +Type: String separated by commas OR Array + + +## Usage + +```puppet +class { 'zabbixagent': + ensure_setting => 'latest', + include_file => 'userparams.conf', + servers => 'zabbix.example.com', + servers_active => 'zabbix.example.com', +} +``` + +The list of params above is the only configuration supported at this time but a +fully parameterized `zabbix_agentd.conf` will be coming soon. + +## Contributing + +Pull requests, bug reports, and enancement requrest are welcome! Enhancement +requests should be file just like other issues. + +## Contributors + +* Scott Smerchek (@smerchek) - Author of [softek-zabbixagent][pf-softek-zabbixagent] +* Martijn Storck (@martijn) - Added CentOS support + +## License + +This is released under the New BSD / BSD 3 Clause license. A copy of the license +can be found in the root of the module. + +### History + +This was originally [softek-zabbixagent][pf-softek-zabbixagent] before undergoing +a total rewrite in January 2015. Post rewrite, only a couple of comments and part of +one line of the original code was left. Since no 'substantial portions' of the code +was reused and no written licence was contained in the repository I have chosen not +to reuse the MIT license that was referenced in the original metadata.json file. + +This module has been released independant of the origial after reviewing the +original author's GitHub issue tracker. Specificaly, it appeared that they had +not been responding to issues or pull requests for at least six months and some +had sat for nearly two years. This response timeframe and my needs didn't line +up so here we are. + +[coveralls-master]: https://coveralls.io/r/genebean/genebean-zabbixagent?branch=master +[coveralls-img-master]: https://img.shields.io/coveralls/genebean/genebean-zabbixagent/master.svg +[gh-tag-img]: https://img.shields.io/github/tag/genebean/genebean-zabbixagent.svg +[gh-link]: https://github.com/genebean/genebean-zabbixagent +[pf-img]: https://img.shields.io/puppetforge/v/genebean/zabbixagent.svg +[pf-link]: https://forge.puppetlabs.com/genebean/zabbixagent +[pf-softek-zabbixagent]: https://forge.puppetlabs.com/softek/zabbixagent +[travis-ci]: https://travis-ci.org/genebean/genebean-zabbixagent +[travis-img-master]: https://img.shields.io/travis/genebean/genebean-zabbixagent/master.svg diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..5562932 --- /dev/null +++ b/Rakefile @@ -0,0 +1,13 @@ +require 'rubygems' +require 'puppetlabs_spec_helper/rake_tasks' +require 'puppet-lint/tasks/puppet-lint' + +PuppetLint.configuration.ignore_paths = ["vendor/**/*.pp", "spec/**/*.pp"] +PuppetSyntax.exclude_paths = ["vendor/**/*", "spec/**/*"] + +task :tests do + Rake::Task[:lint].invoke + Rake::Task[:validate].invoke + Rake::Task[:spec].invoke +end + diff --git a/Vagrantfile b/Vagrantfile new file mode 100644 index 0000000..34d8635 --- /dev/null +++ b/Vagrantfile @@ -0,0 +1,13 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +# Vagrantfile API/syntax version. Don't touch unless you know what you're doing! +VAGRANTFILE_API_VERSION = "2" + +Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| + config.vm.box = "genebean/centos6-rvm193-64bit" + + config.vm.provision "shell", inline: "su - vagrant -c 'cd /vagrant; bundle install --jobs=3 --retry=3 --path=${BUNDLE_PATH:-vendor/bundle}'" + +end + diff --git a/files/win64/zabbix_agentd.exe b/files/win64/zabbix_agentd.exe deleted file mode 100644 index 28ac0b5..0000000 Binary files a/files/win64/zabbix_agentd.exe and /dev/null differ diff --git a/files/win64/zabbix_get.exe b/files/win64/zabbix_get.exe deleted file mode 100644 index 1da1c0e..0000000 Binary files a/files/win64/zabbix_get.exe and /dev/null differ diff --git a/files/win64/zabbix_sender.exe b/files/win64/zabbix_sender.exe deleted file mode 100644 index 3b1acd8..0000000 Binary files a/files/win64/zabbix_sender.exe and /dev/null differ diff --git a/manifests/config.pp b/manifests/config.pp new file mode 100644 index 0000000..6598505 --- /dev/null +++ b/manifests/config.pp @@ -0,0 +1,81 @@ +# Manages configuration of the Zabbix agent and associated repos (if enabled) +class zabbixagent::config ( + $config_dir = $::zabbixagent::config_dir, + $hostname = $::zabbixagent::params::hostname, + $include_dir = $::zabbixagent::params::include_dir, + $include_file = $::zabbixagent::params::include_file, + $logfile = $::zabbixagent::params::logfile, + $servers = $::zabbixagent::params::servers, + $servers_active = $::zabbixagent::params::servers, +) inherits ::zabbixagent::params { + + + ini_setting { 'servers setting': + ensure => present, + path => "${config_dir}/zabbix_agentd.conf", + section => '', + setting => 'Server', + value => join(flatten([$servers]), ','), + notify => Service['zabbix-agent'], + } + + ini_setting { 'servers active setting': + ensure => present, + path => "${config_dir}/zabbix_agentd.conf", + section => '', + setting => 'ServerActive', + value => join(flatten([$servers_active]), ','), + notify => Service['zabbix-agent'], + } + + ini_setting { 'hostname setting': + ensure => present, + path => "${config_dir}/zabbix_agentd.conf", + section => '', + setting => 'Hostname', + value => $hostname, + notify => Service['zabbix-agent'], + } + + if ($include_file == '') { + ini_setting { 'include setting': + ensure => absent, + path => "${config_dir}/zabbix_agentd.conf", + section => '', + setting => 'Include', + notify => Service['zabbix-agent'], + } + + } else { + $include_value = "${config_dir}/${include_dir}/${include_file}" + + file { "${config_dir}/${include_dir}": + ensure => directory, + } + + file { "${config_dir}/${include_dir}/${include_file}": + ensure => file, + require => File["${config_dir}/${include_dir}"], + } + + ini_setting { 'include setting': + ensure => present, + path => "${config_dir}/zabbix_agentd.conf", + section => '', + setting => 'Include', + value => $include_value, + notify => Service['zabbix-agent'], + } + + } # end if / else for $include_file + + ini_setting { 'logfile setting': + ensure => present, + path => "${config_dir}/zabbix_agentd.conf", + section => '', + setting => 'LogFile', + value => $logfile, + notify => Service['zabbix-agent'], + } + +} diff --git a/manifests/init.pp b/manifests/init.pp index d862f63..3e92e47 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -2,136 +2,95 @@ # # This module manages the zabbix agent on a monitored machine. # -# Parameters: none +# Parameters: +# $ensure_setting Passed directly to ensure of package resource +# Default: 'present' +# +# $hostname The hostname used in the config file. +# Default: downcase($::fqdn) +# +# $include_dir The directory that additional config files will be +# placed in. +# Default: 'zabbix_agentd.d' +# Type: String +# +# $include_file A file that that contain additional settings +# Default: '' +# Type: String +# +# $logfile The full path to where Zabbix should store it's logs. +# Default: 'C:\zabbix_agentd.log' +# Type: String +# +# $manage_repo_epel Determines if the EPEL repo is managed on the RedHat +# family of OS's. +# Default: false +# Type: boolean +# +# $manage_repo_zabbix Determines if the Zabbix repo is managed on the RedHat +# family of OS's. +# Default: false +# Type: boolean +# +# $servers The server or servers used in the Servers setting. +# Default: '127.0.0.1' +# Type: String separated by commas OR Array +# +# $servers_active The server or servers used in the Servers setting. +# Default: '127.0.0.1' +# Type: String separated by commas OR Array +# # # Actions: # -# Requires: see Modulefile +# Requires: see metadata.json # # Sample Usage: # -class zabbixagent( - $servers = '', - $hostname = '', -) { - $servers_real = $servers ? { - '' => 'localhost', - default => $servers, - } - $hostname_real = $hostname ? { - '' => $::fqdn, - default => $hostname, - } - - Package <| |> -> Ini_setting <| |> - - case $::operatingsystem { - centos: { - include epel - - package {'zabbix-agent' : - ensure => installed, - require => Yumrepo["epel"] - } - } - - debian, ubuntu: { - package {'zabbix-agent' : - ensure => installed - } - } - } - - case $::operatingsystem { - debian, ubuntu, centos: { - service {'zabbix-agent' : - ensure => running, - enable => true, - require => Package['zabbix-agent'], - } - - ini_setting { 'servers setting': - ensure => present, - path => '/etc/zabbix/zabbix_agentd.conf', - section => '', - setting => 'Server', - value => join(flatten([$servers_real]), ','), - notify => Service['zabbix-agent'], - } - - ini_setting { 'hostname setting': - ensure => present, - path => '/etc/zabbix/zabbix_agentd.conf', - section => '', - setting => 'Hostname', - value => $hostname_real, - notify => Service['zabbix-agent'], - } - - ini_setting { 'Include setting': - ensure => present, - path => '/etc/zabbix/zabbix_agentd.conf', - section => '', - setting => 'Include', - value => '/etc/zabbix/zabbix_agentd/', - notify => Service['zabbix-agent'], - } - - file { '/etc/zabbix/zabbix_agentd': - ensure => directory, - require => Package['zabbix-agent'], - } - } - windows: { - $confdir = 'C:/ProgramData/Zabbix' - $homedir = 'C:/Program Files/Zabbix/' - - file { $confdir: ensure => directory } - file { "${confdir}/zabbix_agentd.conf": - ensure => present, - mode => '0770', - } - - ini_setting { 'servers setting': - ensure => present, - path => "${confdir}/zabbix_agentd.conf", - section => '', - setting => 'Server', - value => join(flatten([$servers_real]), ','), - require => File["${confdir}/zabbix_agentd.conf"], - notify => Service['Zabbix Agent'], - } - - ini_setting { 'hostname setting': - ensure => present, - path => "${confdir}/zabbix_agentd.conf", - section => '', - setting => 'Hostname', - value => $hostname_real, - require => File["${confdir}/zabbix_agentd.conf"], - notify => Service['Zabbix Agent'], - } - - file { $homedir: - ensure => directory, - source => 'puppet:///modules/zabbixagent/win64', - recurse => true, - mode => '0770', - } - - exec { 'install Zabbix Agent': - path => $::path, - cwd => $homedir, - command => "\"${homedir}/zabbix_agentd.exe\" --config ${confdir}/zabbix_agentd.conf --install", - require => [File[$homedir], File["${confdir}/zabbix_agentd.conf"]], - unless => 'sc query "Zabbix Agent"' - } - - service { 'Zabbix Agent': - ensure => running, - require => Exec['install Zabbix Agent'], - } - } - default: { notice "Unsupported operatingsystem ${::operatingsystem}" } - } -} +class zabbixagent ( + $ensure_setting = $::zabbixagent::params::ensure_setting, + $hostname = $::zabbixagent::params::hostname, + $include_dir = $::zabbixagent::params::include_dir, + $include_file = $::zabbixagent::params::include_file, + $logfile = $::zabbixagent::params::logfile, + $manage_repo_epel = $::zabbixagent::params::manage_repo_epel, + $manage_repo_zabbix = $::zabbixagent::params::manage_repo_zabbix, + $servers = $::zabbixagent::params::servers, + $servers_active = $::zabbixagent::params::servers_active, +) inherits ::zabbixagent::params { + + # validate booleans + validate_bool($manage_repo_epel) + validate_bool($manage_repo_zabbix) + + # validate strings + validate_string($ensure_setting) + validate_string($hostname) + validate_string($include_dir) + validate_string($include_file) + validate_string($logfile) + validate_string($servers) + validate_string($servers_active) + + class { '::zabbixagent::preinstall': + manage_repo_epel => $manage_repo_epel, + manage_repo_zabbix => $manage_repo_zabbix, + + } -> + + class { '::zabbixagent::install': + ensure_setting => $ensure_setting, + } -> + + class { '::zabbixagent::config': + hostname => $hostname, + include_dir => $include_dir, + include_file => $include_file, + logfile => $logfile, + servers => $servers, + servers_active => $servers_active, + } -> + + class { '::zabbixagent::service': } + +} diff --git a/manifests/install.pp b/manifests/install.pp new file mode 100644 index 0000000..d7e394f --- /dev/null +++ b/manifests/install.pp @@ -0,0 +1,25 @@ +# Installs the zabbix agent +class zabbixagent::install ( + $ensure_setting = $::zabbixagent::params::ensure_setting, +) inherits ::zabbixagent::params { + case $::kernel { + Linux: { + package { 'zabbix-agent': + ensure => $ensure_setting, + notify => Service['zabbix-agent'], + } + } # end Linux + + Windows: { + package { 'zabbix-agent': + ensure => $ensure_setting, + provider => 'chocolatey', + notify => Service['zabbix-agent'], + } + } # end Windows + + default: { + fail($::zabbixagent::params::fail_message) + } + } +} diff --git a/manifests/params.pp b/manifests/params.pp new file mode 100644 index 0000000..f7c8a46 --- /dev/null +++ b/manifests/params.pp @@ -0,0 +1,33 @@ +# Parameters used by this module +class zabbixagent::params { + $ensure_setting = 'present' + $hostname = downcase($::fqdn) + $include_dir = 'zabbix_agentd.d' + $include_file = '' + $manage_repo_epel = false + $manage_repo_zabbix = false + $servers = '127.0.0.1' + $servers_active = '127.0.0.1' + + # this isn't a parameter but, since this class is inherited by all classes + # it is a good place to put this message so that it's the same everywhere + $fail_message = "${::kernel} is not yet supported by this module." + + case $::kernel { + 'Linux' : { + $config_dir = '/etc/zabbix' + $logfile = '/var/log/zabbix/zabbix_agentd.log' + } + + 'Windows' : { + $config_dir = 'C:/Program Files/Zabbix Agent' + $logfile = 'C:/zabbix_agentd.log' + } + + default : { + fail($fail_message) + } + + } #end case + +} diff --git a/manifests/preinstall.pp b/manifests/preinstall.pp new file mode 100644 index 0000000..469149e --- /dev/null +++ b/manifests/preinstall.pp @@ -0,0 +1,76 @@ +# Repositories used by Zabbix +class zabbixagent::preinstall ( + $manage_repo_epel = $::zabbixagent::params::manage_repo_epel, + $manage_repo_zabbix = $::zabbixagent::params::manage_repo_zabbix, +) inherits ::zabbixagent::params { + case $::osfamily { + RedHat: { + # EPEL + if ($manage_repo_epel) { + file { '/etc/yum.repos.d/epel.repo': + ensure => file, + content => template('zabbixagent/epel.repo.erb'), + notify => Exec['yum clean all'], + } + + file { '/etc/yum.repos.d/epel-testing.repo': + ensure => file, + content => template('zabbixagent/epel-testing.repo.erb'), + notify => Exec['yum clean all'], + } + } + + # Zabbix + if ($manage_repo_zabbix) { + file { '/etc/yum.repos.d/zabbix.repo': + ensure => file, + content => template('zabbixagent/zabbix.repo.erb'), + notify => Exec['yum clean all'], + } + } + } # end RedHat + + Debian: { + case $::operatingsystem { + Ubuntu: { + # Zabbix + if ($manage_repo_zabbix) { + file { '/etc/apt/sources.list.d/zabbix.list': + ensure => file, + content => template('zabbixagent/zabbix.list.erb'), + notify => Exec['apt-get update'], + } + + } + + } # end Ubuntu + + default: { + } + + } # end case $::operatingsystem + + } # end Debian + + default: { + } + + } # end case $::osfamily + + exec { 'yum clean all': + path => '/usr/bin', + user => 'root', + logoutput => true, + refreshonly => true, + command => 'yum clean all', + } + + exec { 'apt-get update': + path => '/usr/bin', + user => 'root', + logoutput => true, + refreshonly => true, + command => 'apt-get update', + } + +} # end class diff --git a/manifests/service.pp b/manifests/service.pp new file mode 100644 index 0000000..f68af0b --- /dev/null +++ b/manifests/service.pp @@ -0,0 +1,14 @@ +# Makes sure the service is running +class zabbixagent::service { + $service_name = $::kernel ? { + 'Windows' => 'Zabbix Agent', + default => 'zabbix-agent', + } + + service { 'zabbix-agent': + ensure => running, + name => $service_name, + enable => true, + require => Package['zabbix-agent'], + } +} diff --git a/metadata.json b/metadata.json index db46b1a..62c54c3 100644 --- a/metadata.json +++ b/metadata.json @@ -1,24 +1,25 @@ { - "name": "softek-zabbixagent", - "version": "1.0.1", - "source": "git://github.com/softek/puppet-zabbixagent.git", - "author": "Scott Smerchek", - "license": "MIT", - "summary": "Zabbix Agent Puppet Module", - "description": "This module manages Zabbix Agent on Windows and Debian/Ubuntu.", - "project_page": "http://github.com/softek/puppet-zabbixagent", + "name": "genebean-zabbixagent", + "version": "2.0.0", + "author": "Gene Liverman", + "summary": "This module manages the Zabbix Agent on Windows or Linux.", + "license": "BSD-3-Clause", + "source": "https://github.com:genebean/genebean-zabbixagent.git", + "project_page": "https://github.com/genebean/genebean-zabbixagent", + "issues_url": "https://github.com/genebean/genebean-zabbixagent/issues", + "tags": ["zabbix", "monitoring"], "dependencies": [ - { - "name": "puppetlabs/stdlib", - "version_requirement": ">= 3.0.0" - }, - { - "name": "puppetlabs/inifile", - "version_requirement": ">= 0.9.0" - }, - { - "name": "stahnma/epel", - "version_requirement": ">= 0.0.3" - } + { "name": "rismoney/chocolatey", "version_requirement": ">= 0.4.1" }, + { "name": "puppetlabs/inifile", "version_requirement": ">= 0.9.0" }, + { "name": "puppetlabs/stdlib", "version_requirement": ">= 3.0.0" } + ], + "requirements": [ + { "name": "puppet", "version_requirement": ">= 2.7.0 < 4.0.0" } + ], + "operatingsystem_support": [ + { "operatingsystem": "CentOS", "operatingsystemrelease": [ "5", "6", "7" ] }, + { "operatingsystem": "RedHat", "operatingsystemrelease": [ "5", "6", "7" ] }, + { "operatingsystem": "Ubuntu", "operatingsystemrelease": [ "14.04" ] }, + { "operatingsystem": "Windows", "operatingsystemrelease": [ "7", "2012 R2" ] } ] -} \ No newline at end of file +} diff --git a/spec/classes/zabbixagent_init_spec.rb b/spec/classes/zabbixagent_init_spec.rb new file mode 100644 index 0000000..2c04d81 --- /dev/null +++ b/spec/classes/zabbixagent_init_spec.rb @@ -0,0 +1,30 @@ +require 'spec_helper' + +describe 'zabbixagent' do + + # Running an RedHat OS. + context 'On a RedHat OS with repo management enabled' do + let :facts do + { + :kernel => 'Linux', + :osfamily => 'RedHat', + :operatingsystem => 'RedHat' + } + end + + let(:params) { + { + :manage_repo_epel => true, + :manage_repo_zabbix => true + } + } + + # Check that all classes are present + it { should contain_class('zabbixagent::params')} + it { should contain_class('zabbixagent::preinstall')} + it { should contain_class('zabbixagent::install')} + it { should contain_class('zabbixagent::config')} + it { should contain_class('zabbixagent::service')} + + end +end \ No newline at end of file diff --git a/spec/classes/zabbixagent_install_spec.rb b/spec/classes/zabbixagent_install_spec.rb new file mode 100644 index 0000000..6eac747 --- /dev/null +++ b/spec/classes/zabbixagent_install_spec.rb @@ -0,0 +1,26 @@ +require 'spec_helper' + +describe 'zabbixagent::install' do + + # Running an RedHat OS. + context 'On a RedHat OS with repo management enabled' do + let :facts do + { + :kernel => 'Linux', + :osfamily => 'RedHat', + :operatingsystem => 'RedHat' + } + end + + let(:params) { + { + + } + } + + # Make sure package will be installed. + it { should contain_package('zabbix-agent').with_ensure('present') } + it { should contain_package('zabbix-agent').with_name('zabbix-agent') } + + end +end \ No newline at end of file diff --git a/spec/classes/zabbixagent_preinstall_spec.rb b/spec/classes/zabbixagent_preinstall_spec.rb new file mode 100644 index 0000000..b9eafe4 --- /dev/null +++ b/spec/classes/zabbixagent_preinstall_spec.rb @@ -0,0 +1,23 @@ +require 'spec_helper' + +describe 'zabbixagent::preinstall' do + + # Running an RedHat OS. + context 'On a RedHat OS with repo management enabled' do + let :facts do + { + :kernel => 'Linux', + :osfamily => 'RedHat', + :operatingsystem => 'RedHat' + } + end + + let(:params) { + { + :manage_repo_epel => true, + :manage_repo_zabbix => true + } + } + + end +end \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..f64ca3e --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,3 @@ +require 'rubygems' +require 'puppetlabs_spec_helper/module_spec_helper' + diff --git a/templates/epel-testing.repo.erb b/templates/epel-testing.repo.erb new file mode 100644 index 0000000..4e6cb3a --- /dev/null +++ b/templates/epel-testing.repo.erb @@ -0,0 +1,40 @@ +################################################################ +################################################################ +# +# This file is managed by Puppet +# +################################################################ +################################################################ + +################################################################ +# +# This section replaces /etc/yum.repos.d/epel-testing.repo +# +################################################################ + +[epel-testing] +name=Extra Packages for Enterprise Linux <%= @operatingsystemmajrelease %> - Testing - $basearch +#baseurl=http://download.fedoraproject.org/pub/epel/testing/<%= @operatingsystemmajrelease %>/$basearch +mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=testing-epel<%= @operatingsystemmajrelease %>&arch=$basearch +failovermethod=priority +enabled=0 +gpgcheck=1 +gpgkey=http://download.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-<%= @operatingsystemmajrelease %> + +[epel-testing-debuginfo] +name=Extra Packages for Enterprise Linux <%= @operatingsystemmajrelease %> - Testing - $basearch - Debug +#baseurl=http://download.fedoraproject.org/pub/epel/testing/<%= @operatingsystemmajrelease %>/$basearch/debug +mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=testing-debug-epel<%= @operatingsystemmajrelease %>&arch=$basearch +failovermethod=priority +enabled=0 +gpgkey=http://download.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-<%= @operatingsystemmajrelease %> +gpgcheck=1 + +[epel-testing-source] +name=Extra Packages for Enterprise Linux <%= @operatingsystemmajrelease %> - Testing - $basearch - Source +#baseurl=http://download.fedoraproject.org/pub/epel/testing/<%= @operatingsystemmajrelease %>/SRPMS +mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=testing-source-epel<%= @operatingsystemmajrelease %>&arch=$basearch +failovermethod=priority +enabled=0 +gpgkey=http://download.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-<%= @operatingsystemmajrelease %> +gpgcheck=1 diff --git a/templates/epel.repo.erb b/templates/epel.repo.erb new file mode 100644 index 0000000..413a7b8 --- /dev/null +++ b/templates/epel.repo.erb @@ -0,0 +1,42 @@ +################################################################ +################################################################ +# +# This file is managed by Puppet +# +################################################################ +################################################################ + +################################################################ +# +# This section replaces /etc/yum.repos.d/epel.repo +# +################################################################ + +[epel] +name=Extra Packages for Enterprise Linux <%= @operatingsystemmajrelease %> - $basearch +#baseurl=http://download.fedoraproject.org/pub/epel/<%= @operatingsystemmajrelease %>/$basearch +mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-<%= @operatingsystemmajrelease %>&arch=$basearch +failovermethod=priority +enabled=1 +gpgcheck=1 +gpgkey=http://download.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-<%= @operatingsystemmajrelease %> + +<% if @operatingsystemmajrelease == '7' %> +[epel-debuginfo] +name=Extra Packages for Enterprise Linux <%= @operatingsystemmajrelease %> - $basearch - Debug +#baseurl=http://download.fedoraproject.org/pub/epel/<%= @operatingsystemmajrelease %>/$basearch/debug +mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-debug-<%= @operatingsystemmajrelease %>&arch=$basearch +failovermethod=priority +enabled=0 +gpgkey=http://download.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-<%= @operatingsystemmajrelease %> +gpgcheck=1 + +[epel-source] +name=Extra Packages for Enterprise Linux <%= @operatingsystemmajrelease %> - $basearch - Source +#baseurl=http://download.fedoraproject.org/pub/epel/<%= @operatingsystemmajrelease %>/SRPMS +mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-source-<%= @operatingsystemmajrelease %>&arch=$basearch +failovermethod=priority +enabled=0 +gpgkey=http://download.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-<%= @operatingsystemmajrelease %> +gpgcheck=1 +<% end %> diff --git a/templates/zabbix.list.erb b/templates/zabbix.list.erb new file mode 100644 index 0000000..3b3ca43 --- /dev/null +++ b/templates/zabbix.list.erb @@ -0,0 +1,16 @@ +################################################################## +################################################################## +# +# This file is managed by Puppet +# +################################################################## +################################################################## + +################################################################## +# +# This section replaces /etc/apt/sources.list.d/zabbix.list +# +################################################################## + +deb http://repo.zabbix.com/zabbix/2.4/ubuntu <%= @lsbdistcodename %> main +deb-src http://repo.zabbix.com/zabbix/2.4/ubuntu <%= @lsbdistcodename %> main diff --git a/templates/zabbix.repo.erb b/templates/zabbix.repo.erb new file mode 100644 index 0000000..c33ef33 --- /dev/null +++ b/templates/zabbix.repo.erb @@ -0,0 +1,27 @@ +################################################################## +################################################################### +#### +#### This file is managed by Puppet +#### +#################################################################### +#################################################################### +### +##################################################################### +#### +#### This section replaces /etc/yum.repos.d/zabbix.repo +#### +##################################################################### + +[zabbix] +name=Zabbix Official Repository - $basearch +baseurl=http://repo.zabbix.com/zabbix/2.4/rhel/<%= @operatingsystemmajrelease %>/$basearch/ +enabled=1 +gpgcheck=1 +gpgkey=http://repo.zabbix.com/RPM-GPG-KEY-ZABBIX + +[zabbix-non-supported] +name=Zabbix Official Repository non-supported - $basearch +baseurl=http://repo.zabbix.com/non-supported/rhel/<%= @operatingsystemmajrelease %>/$basearch/ +enabled=1 +gpgcheck=1 +gpgkey=http://repo.zabbix.com/RPM-GPG-KEY-ZABBIX diff --git a/tests/init.pp b/tests/init.pp new file mode 100644 index 0000000..7ac32ee --- /dev/null +++ b/tests/init.pp @@ -0,0 +1 @@ +include zabbixagent