From f945188b099297ea2f3e7e7e9b341703442e1d9d Mon Sep 17 00:00:00 2001 From: Davide Ferrari Date: Tue, 20 Jun 2017 11:16:17 +0200 Subject: [PATCH 1/6] Backport alerts to puppet3 --- manifests/alerts.pp | 20 ++++++++++---------- templates/alerts.epp | 15 --------------- templates/alerts.erb | 15 +++++++++++++++ 3 files changed, 25 insertions(+), 25 deletions(-) delete mode 100644 templates/alerts.epp create mode 100644 templates/alerts.erb diff --git a/manifests/alerts.pp b/manifests/alerts.pp index db4ea4833..cbf234cf4 100644 --- a/manifests/alerts.pp +++ b/manifests/alerts.pp @@ -9,18 +9,18 @@ # Array of alerts (see README) # class prometheus::alerts ( - String $location, - Array $alerts, - String $alertfile_name = 'alert.rules' + $alerts, + $location, + $alertfile_name = 'alert.rules', ) inherits prometheus::params { - if $alerts != [] { - file{ "${location}/${alertfile_name}": - ensure => 'file', - owner => $prometheus::user, - group => $prometheus::group, - content => epp("${module_name}/alerts.epp"), - } + if $alerts != [] { + file{ "${location}/${alertfile_name}": + ensure => 'file', + owner => $prometheus::user, + group => $prometheus::group, + content => template("${module_name}/alerts.erb"), } + } } diff --git a/templates/alerts.epp b/templates/alerts.epp deleted file mode 100644 index ba0816c38..000000000 --- a/templates/alerts.epp +++ /dev/null @@ -1,15 +0,0 @@ -<% $prometheus::alerts::alerts.each |$alert| { -%> -ALERT <%= $alert['name'] %> - IF <%= $alert['condition'] %> - FOR <%= $alert['timeduration'] %> - LABELS { - <% $alert['labels'].each |$label| { -%> - <%= $label['name'] %> = "<%= $label['content'] %>", - <% } -%> - } - ANNOTATIONS { - <% $alert['annotations'].each |$annotation| { -%> - <%= $annotation['name'] %> = "<%= $annotation['content'] %>", - <% } -%> - } -<% } -%> diff --git a/templates/alerts.erb b/templates/alerts.erb new file mode 100644 index 000000000..92f574686 --- /dev/null +++ b/templates/alerts.erb @@ -0,0 +1,15 @@ +<% @alerts.each do |alert| -%> +ALERT <%= alert['name'] %> + IF <%= alert['condition'] %> + FOR <%= alert['timeduration'] %> + LABELS { + <% alert['labels'].each do |label| -%> + <%= label['name'] %> = "<%= label['content'] %>", + <% end -%> + } + ANNOTATIONS { + <% alert['annotations'].each do |annotation| -%> + <%= annotation['name'] %> = "<%= annotation['content'] %>", + <% end -%> + } +<% end -%> From 0ae4c303195ce60f5f4af137381e4e5b3c0bedaf Mon Sep 17 00:00:00 2001 From: Davide Ferrari Date: Tue, 20 Jun 2017 16:52:37 +0200 Subject: [PATCH 2/6] Implemented service reload for Prometheus With this commit all the configuration files that can be reload on-the-fly like prometheus.yml and alerts rules do not trigger a full service restart like they did til now. I left the possibility to choose if a change to a command-line flag should or not restart prometheus (thus applying the change on puppet run) with the already existing flag (still true by default). --- manifests/config.pp | 16 +++++++++++++++- manifests/init.pp | 9 +++------ manifests/run_service.pp | 6 +++--- manifests/service_reload.pp | 23 +++++++++++++++++++++++ 4 files changed, 44 insertions(+), 10 deletions(-) create mode 100644 manifests/service_reload.pp diff --git a/manifests/config.pp b/manifests/config.pp index ed54c4bae..69a83c4c4 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -10,6 +10,17 @@ if $prometheus::init_style { + # the vast majority of files here are init-files + # so any change there should trigger a full service restart + if $::prometheus::restart_on_change { + File { + notify => [Class['::prometheus::run_service']] + } + $systemd_notify = [Exec['prometheus-systemd-reload'], Class['::prometheus::run_service']] + } else { + $systemd_notify = Exec['prometheus-systemd-reload'] + } + case $prometheus::init_style { 'upstart' : { file { '/etc/init/prometheus.conf': @@ -31,8 +42,10 @@ mode => '0644', owner => 'root', group => 'root', + notify => $systemd_notify, content => template('prometheus/prometheus.systemd.erb'), - }~> + } + exec { 'prometheus-systemd-reload': command => 'systemctl daemon-reload', path => [ '/usr/bin', '/bin', '/usr/sbin' ], @@ -90,6 +103,7 @@ owner => $prometheus::user, group => $prometheus::group, mode => $prometheus::config_mode, + notify => Class['::prometheus::service_reload'], content => template($config_template), } diff --git a/manifests/init.pp b/manifests/init.pp index ca14dcf6c..3e2d35840 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -84,6 +84,8 @@ # # [*restart_on_change*] # Should puppet restart prometheus on configuration change? (default true) +# Note: this applies only to command-line options changes. Configuration +# options are always *reloaded* without restarting. # # [*init_style*] # Service startup scripts style (e.g. rc, upstart or systemd) @@ -158,10 +160,6 @@ $config_hash_real = deep_merge($config_defaults, $config_hash) validate_hash($config_hash_real) - $notify_service = $restart_on_change ? { - true => Class['::prometheus::run_service'], - default => undef, - } anchor {'prometheus_first': } -> @@ -171,14 +169,13 @@ rule_files => $rule_files, scrape_configs => $scrape_configs, purge => $purge_config_dir, - notify => $notify_service, config_template => $config_template, } -> class { '::prometheus::alerts': location => $config_dir, alerts => $alerts, - notify => $notify_service, } -> class { '::prometheus::run_service': } -> + class { '::prometheus::service_reload': } -> anchor {'prometheus_last': } } diff --git a/manifests/run_service.pp b/manifests/run_service.pp index ece7efba2..01f3dbb15 100644 --- a/manifests/run_service.pp +++ b/manifests/run_service.pp @@ -12,9 +12,9 @@ if $prometheus::manage_service == true { service { 'prometheus': - ensure => $prometheus::service_ensure, - name => $init_selector, - enable => $prometheus::service_enable, + ensure => $prometheus::service_ensure, + name => $init_selector, + enable => $prometheus::service_enable, } } } diff --git a/manifests/service_reload.pp b/manifests/service_reload.pp new file mode 100644 index 000000000..b974de4e7 --- /dev/null +++ b/manifests/service_reload.pp @@ -0,0 +1,23 @@ +# This class implements prometheus service reload +# without restarting the whole service when a config +# changes +class prometheus::service_reload() { + + if $prometheus::manage_service == true { + $init_selector = $prometheus::run_service::init_selector + + $prometheus_reload = $prometheus::init_style ? { + 'systemd' => "systemctl reload ${init_selector}", + 'upstart' => "upstart reload ${init_selector}", + 'sysv' => "/etc/init.d/${init_selector} reload", + 'sles' => "/etc/init.d/${init_selector} reload", + 'debian' => "/etc/init.d/${init_selector} reload", + 'launchd' => "launchctl stop ${init_selector} && launchctl start ${init_selector}", + } + + exec { 'prometheus-reload': + command => $prometheus_reload, + refreshonly => true, + } + } +} From 8bf302a03121752f9de2fbe1593265db33d402f8 Mon Sep 17 00:00:00 2001 From: Davide Ferrari Date: Tue, 20 Jun 2017 17:10:40 +0200 Subject: [PATCH 3/6] Fix alerts in our puppet3 branch --- manifests/alerts.pp | 1 + 1 file changed, 1 insertion(+) diff --git a/manifests/alerts.pp b/manifests/alerts.pp index cbf234cf4..302a1df20 100644 --- a/manifests/alerts.pp +++ b/manifests/alerts.pp @@ -19,6 +19,7 @@ ensure => 'file', owner => $prometheus::user, group => $prometheus::group, + notify => Class['::prometheus::service_reload'], content => template("${module_name}/alerts.erb"), } } From 635d393d475b138d0e2874a299e48c5f9143a3c7 Mon Sep 17 00:00:00 2001 From: Davide Ferrari Date: Thu, 22 Jun 2017 15:25:29 +0200 Subject: [PATCH 4/6] Rebased against voxpupuli/master --- .fixtures.yml | 2 +- .github/CONTRIBUTING.md | 104 ++++ .github/ISSUE_TEMPLATE.md | 26 + .github/PULL_REQUEST_TEMPLATE.md | 8 + .gitignore | 20 +- .msync.yml | 1 + .overcommit.yml | 63 +++ .pmtignore | 20 + .rspec | 2 + .rspec_parallel | 1 + .rubocop.yml | 535 ++++++++++++++++++ .sync.yml | 3 + .travis.yml | 89 +-- .yardopts | 2 + Gemfile | 89 ++- LICENSE | 202 +++++++ README.md | 15 +- Rakefile | 68 +-- examples/init.pp | 6 + manifests/alertmanager.pp | 9 +- manifests/alerts.pp | 22 +- manifests/config.pp | 17 +- manifests/daemon.pp | 271 ++++----- manifests/haproxy_exporter.pp | 136 +++++ manifests/init.pp | 30 +- manifests/install.pp | 30 +- manifests/node_exporter.pp | 8 +- manifests/params.pp | 26 +- manifests/process_exporter.pp | 144 +++++ manifests/run_service.pp | 7 +- metadata.json | 68 ++- spec/acceptance/nodesets/archlinux-2-x64.yml | 13 + spec/acceptance/nodesets/centos-511-x64.yml | 15 + spec/acceptance/nodesets/centos-6-x64.yml | 15 + spec/acceptance/nodesets/centos-66-x64-pe.yml | 17 + spec/acceptance/nodesets/centos-66-x64.yml | 15 + spec/acceptance/nodesets/centos-7-x64.yml | 15 + spec/acceptance/nodesets/centos-72-x64.yml | 15 + spec/acceptance/nodesets/debian-78-x64.yml | 15 + spec/acceptance/nodesets/debian-82-x64.yml | 15 + spec/acceptance/nodesets/docker/centos-5.yml | 19 + spec/acceptance/nodesets/docker/centos-6.yml | 20 + spec/acceptance/nodesets/docker/centos-7.yml | 19 + spec/acceptance/nodesets/docker/debian-7.yml | 19 + spec/acceptance/nodesets/docker/debian-8.yml | 21 + .../nodesets/docker/ubuntu-12.04.yml | 19 + .../nodesets/docker/ubuntu-14.04.yml | 21 + .../nodesets/docker/ubuntu-16.04.yml | 19 + .../nodesets/ec2/amazonlinux-2016091.yml | 31 + .../nodesets/ec2/image_templates.yaml | 34 ++ spec/acceptance/nodesets/ec2/rhel-73-x64.yml | 29 + .../nodesets/ec2/sles-12sp2-x64.yml | 29 + .../nodesets/ec2/ubuntu-1604-x64.yml | 29 + .../nodesets/ec2/windows-2016-base-x64.yml | 29 + spec/acceptance/nodesets/fedora-24-x64.yml | 15 + spec/acceptance/nodesets/fedora-25-x64.yml | 18 + .../nodesets/ubuntu-server-1204-x64.yml | 15 + .../nodesets/ubuntu-server-1404-x64.yml | 15 + .../nodesets/ubuntu-server-1604-x64.yml | 15 + spec/classes/coverage_spec.rb | 4 + spec/classes/haproxy_exporter_spec.rb | 25 + spec/classes/node_exporter_spec.rb | 48 +- spec/classes/statsd_exporter_spec.rb | 0 spec/default_facts.yml | 14 + spec/defines/daemon_spec.rb | 68 --- spec/fixtures/manifests/site.pp | 0 spec/spec.opts | 6 - spec/spec_helper.rb | 32 +- templates/process-exporter.yaml.erb | 2 + templates/prometheus.yaml.erb | 10 +- tests/init.pp | 5 - 71 files changed, 2366 insertions(+), 423 deletions(-) create mode 100644 .github/CONTRIBUTING.md create mode 100644 .github/ISSUE_TEMPLATE.md create mode 100644 .github/PULL_REQUEST_TEMPLATE.md create mode 100644 .msync.yml create mode 100644 .overcommit.yml create mode 100644 .pmtignore create mode 100644 .rspec create mode 100644 .rspec_parallel create mode 100644 .rubocop.yml create mode 100644 .sync.yml create mode 100644 .yardopts create mode 100644 LICENSE create mode 100644 examples/init.pp create mode 100644 manifests/haproxy_exporter.pp create mode 100644 manifests/process_exporter.pp create mode 100644 spec/acceptance/nodesets/archlinux-2-x64.yml create mode 100644 spec/acceptance/nodesets/centos-511-x64.yml create mode 100644 spec/acceptance/nodesets/centos-6-x64.yml create mode 100644 spec/acceptance/nodesets/centos-66-x64-pe.yml create mode 100644 spec/acceptance/nodesets/centos-66-x64.yml create mode 100644 spec/acceptance/nodesets/centos-7-x64.yml create mode 100644 spec/acceptance/nodesets/centos-72-x64.yml create mode 100644 spec/acceptance/nodesets/debian-78-x64.yml create mode 100644 spec/acceptance/nodesets/debian-82-x64.yml create mode 100644 spec/acceptance/nodesets/docker/centos-5.yml create mode 100644 spec/acceptance/nodesets/docker/centos-6.yml create mode 100644 spec/acceptance/nodesets/docker/centos-7.yml create mode 100644 spec/acceptance/nodesets/docker/debian-7.yml create mode 100644 spec/acceptance/nodesets/docker/debian-8.yml create mode 100644 spec/acceptance/nodesets/docker/ubuntu-12.04.yml create mode 100644 spec/acceptance/nodesets/docker/ubuntu-14.04.yml create mode 100644 spec/acceptance/nodesets/docker/ubuntu-16.04.yml create mode 100644 spec/acceptance/nodesets/ec2/amazonlinux-2016091.yml create mode 100644 spec/acceptance/nodesets/ec2/image_templates.yaml create mode 100644 spec/acceptance/nodesets/ec2/rhel-73-x64.yml create mode 100644 spec/acceptance/nodesets/ec2/sles-12sp2-x64.yml create mode 100644 spec/acceptance/nodesets/ec2/ubuntu-1604-x64.yml create mode 100644 spec/acceptance/nodesets/ec2/windows-2016-base-x64.yml create mode 100644 spec/acceptance/nodesets/fedora-24-x64.yml create mode 100644 spec/acceptance/nodesets/fedora-25-x64.yml create mode 100644 spec/acceptance/nodesets/ubuntu-server-1204-x64.yml create mode 100644 spec/acceptance/nodesets/ubuntu-server-1404-x64.yml create mode 100644 spec/acceptance/nodesets/ubuntu-server-1604-x64.yml create mode 100644 spec/classes/coverage_spec.rb create mode 100644 spec/classes/haproxy_exporter_spec.rb delete mode 100644 spec/classes/statsd_exporter_spec.rb create mode 100644 spec/default_facts.yml delete mode 100644 spec/defines/daemon_spec.rb delete mode 100644 spec/fixtures/manifests/site.pp delete mode 100644 spec/spec.opts create mode 100644 templates/process-exporter.yaml.erb delete mode 100644 tests/init.pp diff --git a/.fixtures.yml b/.fixtures.yml index 07ec5c0da..2fd3ba85c 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -1,6 +1,6 @@ fixtures: repositories: + archive: "https://github.com/voxpupuli/puppet-archive" stdlib: "https://github.com/puppetlabs/puppetlabs-stdlib" - staging: "https://github.com/nanliu/puppet-staging" symlinks: "prometheus": "#{source_dir}" diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md new file mode 100644 index 000000000..602f324b9 --- /dev/null +++ b/.github/CONTRIBUTING.md @@ -0,0 +1,104 @@ +This module has grown over time based on a range of contributions from +people using it. If you follow these contributing guidelines your patch +will likely make it into a release a little quicker. + +## Contributing + +Please note that this project is released with a Contributor Code of Conduct. +By participating in this project you agree to abide by its terms. +[Contributor Code of Conduct](https://voxpupuli.org/coc/). + +1. Fork the repo. + +1. Create a separate branch for your change. + +1. Run the tests. We only take pull requests with passing tests, and + documentation. + +1. Add a test for your change. Only refactoring and documentation + changes require no new tests. If you are adding functionality + or fixing a bug, please add a test. + +1. Squash your commits down into logical components. Make sure to rebase + against the current master. + +1. Push the branch to your fork and submit a pull request. + +Please be prepared to repeat some of these steps as our contributors review +your code. + +## Dependencies + +The testing and development tools have a bunch of dependencies, +all managed by [bundler](http://bundler.io/) according to the +[Puppet support matrix](http://docs.puppetlabs.com/guides/platforms.html#ruby-versions). + +By default the tests use a baseline version of Puppet. + +If you have Ruby 2.x or want a specific version of Puppet, +you must set an environment variable such as: + + export PUPPET_VERSION="~> 4.2.0" + +Install the dependencies like so... + + bundle install + +## Syntax and style + +The test suite will run [Puppet Lint](http://puppet-lint.com/) and +[Puppet Syntax](https://github.com/gds-operations/puppet-syntax) to +check various syntax and style things. You can run these locally with: + + bundle exec rake lint + bundle exec rake validate + +It will also run some [Rubocop](http://batsov.com/rubocop/) tests +against it. You can run those locally ahead of time with: + + bundle exec rake rubocop + +## Running the unit tests + +The unit test suite covers most of the code, as mentioned above please +add tests if you're adding new functionality. If you've not used +[rspec-puppet](http://rspec-puppet.com/) before then feel free to ask +about how best to test your new feature. + +To run your all the unit tests + + bundle exec rake spec SPEC_OPTS='--format documentation' + +To run a specific spec test set the `SPEC` variable: + + bundle exec rake spec SPEC=spec/foo_spec.rb + +To run the linter, the syntax checker and the unit tests: + + bundle exec rake test + +## Integration tests + +The unit tests just check the code runs, not that it does exactly what +we want on a real machine. For that we're using +[beaker](https://github.com/puppetlabs/beaker). + +This fires up a new virtual machine (using vagrant) and runs a series of +simple tests against it after applying the module. You can run this +with: + + bundle exec rake acceptance + +This will run the tests on an Ubuntu 12.04 virtual machine. You can also +run the integration tests against Centos 6.6 with. + + BEAKER_set=centos-66-x64 bundle exec rake acceptances + +If you don't want to have to recreate the virtual machine every time you +can use `BEAKER_DESTROY=no` and `BEAKER_PROVISION=no`. On the first run you will +at least need `BEAKER_PROVISION` set to yes (the default). The Vagrantfile +for the created virtual machines will be in `.vagrant/beaker_vagrant_fies`. + +The easiest way to debug in a docker container is to open a shell: + + docker exec -it -u root ${container_id_or_name} bash diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md new file mode 100644 index 000000000..593e7aa83 --- /dev/null +++ b/.github/ISSUE_TEMPLATE.md @@ -0,0 +1,26 @@ + + +## Affected Puppet, Ruby, OS and module versions/distributions + +- Puppet: +- Ruby: +- Distribution: +- Module version: + +## How to reproduce (e.g Puppet code you use) + +## What are you seeing + +## What behaviour did you expect instead + +## Output log + +## Any additional information you'd like to impart diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 000000000..66f80444c --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,8 @@ + diff --git a/.gitignore b/.gitignore index 1612d7f11..e9b3cf4bc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,20 @@ +pkg/ Gemfile.lock -spec/fixtures/modules/* +Gemfile.local +vendor/ +.vendor/ +spec/fixtures/manifests/ +spec/fixtures/modules/ +.vagrant/ +.bundle/ +.ruby-version +coverage/ +log/ +.idea/ +.dependencies/ +.librarian/ +Puppetfile.lock +*.iml +.*.sw? +.yardoc/ +Guardfile diff --git a/.msync.yml b/.msync.yml new file mode 100644 index 000000000..4abde2202 --- /dev/null +++ b/.msync.yml @@ -0,0 +1 @@ +modulesync_config_version: '0.21.3' diff --git a/.overcommit.yml b/.overcommit.yml new file mode 100644 index 000000000..31699e747 --- /dev/null +++ b/.overcommit.yml @@ -0,0 +1,63 @@ +# Managed by https://github.com/voxpupuli/modulesync_configs +# +# Hooks are only enabled if you take action. +# +# To enable the hooks run: +# +# ``` +# bundle exec overcommit --install +# # ensure .overcommit.yml does not harm to you and then +# bundle exec overcommit --sign +# ``` +# +# (it will manage the .git/hooks directory): +# +# Examples howto skip a test for a commit or push: +# +# ``` +# SKIP=RuboCop git commit +# SKIP=PuppetLint git commit +# SKIP=RakeTask git push +# ``` +# +# Don't invoke overcommit at all: +# +# ``` +# OVERCOMMIT_DISABLE=1 git commit +# ``` +# +# Read more about overcommit: https://github.com/brigade/overcommit +# +# To manage this config yourself in your module add +# +# ``` +# .overcommit.yml: +# unmanaged: true +# ``` +# +# to your modules .sync.yml config +--- +PreCommit: + RuboCop: + enabled: true + description: 'Runs rubocop on modified files only' + command: ['bundle', 'exec', 'rubocop'] + PuppetLint: + enabled: true + description: 'Runs puppet-lint on modified files only' + command: ['bundle', 'exec', 'puppet-lint'] + YamlSyntax: + enabled: true + JsonSyntax: + enabled: true + TrailingWhitespace: + enabled: true + +PrePush: + RakeTarget: + enabled: true + description: 'Run rake targets' + targets: + - 'test' + - 'rubocop' + command: [ 'bundle', 'exec', 'rake' ] diff --git a/.pmtignore b/.pmtignore new file mode 100644 index 000000000..fb5895753 --- /dev/null +++ b/.pmtignore @@ -0,0 +1,20 @@ +docs/ +pkg/ +Gemfile.lock +Gemfile.local +vendor/ +.vendor/ +spec/fixtures/manifests/ +spec/fixtures/modules/ +.vagrant/ +.bundle/ +.ruby-version +coverage/ +log/ +.idea/ +.dependencies/ +.librarian/ +Puppetfile.lock +*.iml +.*.sw? +.yardoc/ diff --git a/.rspec b/.rspec new file mode 100644 index 000000000..8c18f1abd --- /dev/null +++ b/.rspec @@ -0,0 +1,2 @@ +--format documentation +--color diff --git a/.rspec_parallel b/.rspec_parallel new file mode 100644 index 000000000..e4d136b75 --- /dev/null +++ b/.rspec_parallel @@ -0,0 +1 @@ +--format progress diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 000000000..d92e4e456 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,535 @@ +require: rubocop-rspec +AllCops: + TargetRubyVersion: 1.9 + Include: + - ./**/*.rb + Exclude: + - files/**/* + - vendor/**/* + - .vendor/**/* + - pkg/**/* + - spec/fixtures/**/* + - Gemfile + - Rakefile + - Guardfile +Lint/ConditionPosition: + Enabled: True + +Lint/ElseLayout: + Enabled: True + +Lint/UnreachableCode: + Enabled: True + +Lint/UselessComparison: + Enabled: True + +Lint/EnsureReturn: + Enabled: True + +Lint/HandleExceptions: + Enabled: True + +Lint/LiteralInCondition: + Enabled: True + +Lint/ShadowingOuterLocalVariable: + Enabled: True + +Lint/LiteralInInterpolation: + Enabled: True + +Style/HashSyntax: + Enabled: True + +Style/RedundantReturn: + Enabled: True + +Lint/AmbiguousOperator: + Enabled: True + +Lint/AssignmentInCondition: + Enabled: True + +Style/SpaceBeforeComment: + Enabled: True + +Style/AndOr: + Enabled: True + +Style/RedundantSelf: + Enabled: True + +Metrics/BlockLength: + Enabled: False + +# Method length is not necessarily an indicator of code quality +Metrics/MethodLength: + Enabled: False + +# Module length is not necessarily an indicator of code quality +Metrics/ModuleLength: + Enabled: False + +Style/WhileUntilModifier: + Enabled: True + +Lint/AmbiguousRegexpLiteral: + Enabled: True + +Security/Eval: + Enabled: True + +Lint/BlockAlignment: + Enabled: True + +Lint/DefEndAlignment: + Enabled: True + +Lint/EndAlignment: + Enabled: True + +Lint/DeprecatedClassMethods: + Enabled: True + +Lint/Loop: + Enabled: True + +Lint/ParenthesesAsGroupedExpression: + Enabled: True + +Lint/RescueException: + Enabled: True + +Lint/StringConversionInInterpolation: + Enabled: True + +Lint/UnusedBlockArgument: + Enabled: True + +Lint/UnusedMethodArgument: + Enabled: True + +Lint/UselessAccessModifier: + Enabled: True + +Lint/UselessAssignment: + Enabled: True + +Lint/Void: + Enabled: True + +Style/AccessModifierIndentation: + Enabled: True + +Style/AccessorMethodName: + Enabled: True + +Style/Alias: + Enabled: True + +Style/AlignArray: + Enabled: True + +Style/AlignHash: + Enabled: True + +Style/AlignParameters: + Enabled: True + +Metrics/BlockNesting: + Enabled: True + +Style/AsciiComments: + Enabled: True + +Style/Attr: + Enabled: True + +Style/BracesAroundHashParameters: + Enabled: True + +Style/CaseEquality: + Enabled: True + +Style/CaseIndentation: + Enabled: True + +Style/CharacterLiteral: + Enabled: True + +Style/ClassAndModuleCamelCase: + Enabled: True + +Style/ClassAndModuleChildren: + Enabled: False + +Style/ClassCheck: + Enabled: True + +# Class length is not necessarily an indicator of code quality +Metrics/ClassLength: + Enabled: False + +Style/ClassMethods: + Enabled: True + +Style/ClassVars: + Enabled: True + +Style/WhenThen: + Enabled: True + +Style/WordArray: + Enabled: True + +Style/UnneededPercentQ: + Enabled: True + +Style/Tab: + Enabled: True + +Style/SpaceBeforeSemicolon: + Enabled: True + +Style/TrailingBlankLines: + Enabled: True + +Style/SpaceInsideBlockBraces: + Enabled: True + +Style/SpaceInsideBrackets: + Enabled: True + +Style/SpaceInsideHashLiteralBraces: + Enabled: True + +Style/SpaceInsideParens: + Enabled: True + +Style/LeadingCommentSpace: + Enabled: True + +Style/SpaceBeforeFirstArg: + Enabled: True + +Style/SpaceAfterColon: + Enabled: True + +Style/SpaceAfterComma: + Enabled: True + +Style/SpaceAfterMethodName: + Enabled: True + +Style/SpaceAfterNot: + Enabled: True + +Style/SpaceAfterSemicolon: + Enabled: True + +Style/SpaceAroundEqualsInParameterDefault: + Enabled: True + +Style/SpaceAroundOperators: + Enabled: True + +Style/SpaceBeforeBlockBraces: + Enabled: True + +Style/SpaceBeforeComma: + Enabled: True + +Style/CollectionMethods: + Enabled: True + +Style/CommentIndentation: + Enabled: True + +Style/ColonMethodCall: + Enabled: True + +Style/CommentAnnotation: + Enabled: True + +# 'Complexity' is very relative +Metrics/CyclomaticComplexity: + Enabled: False + +Style/ConstantName: + Enabled: True + +Style/Documentation: + Enabled: False + +Style/DefWithParentheses: + Enabled: True + +Style/PreferredHashMethods: + Enabled: True + +Style/DotPosition: + EnforcedStyle: trailing + +Style/DoubleNegation: + Enabled: True + +Style/EachWithObject: + Enabled: True + +Style/EmptyLineBetweenDefs: + Enabled: True + +Style/IndentArray: + Enabled: True + +Style/IndentHash: + Enabled: True + +Style/IndentationConsistency: + Enabled: True + +Style/IndentationWidth: + Enabled: True + +Style/EmptyLines: + Enabled: True + +Style/EmptyLinesAroundAccessModifier: + Enabled: True + +Style/EmptyLiteral: + Enabled: True + +# Configuration parameters: AllowURI, URISchemes. +Metrics/LineLength: + Enabled: False + +Style/MethodCallWithoutArgsParentheses: + Enabled: True + +Style/MethodDefParentheses: + Enabled: True + +Style/LineEndConcatenation: + Enabled: True + +Style/TrailingWhitespace: + Enabled: True + +Style/StringLiterals: + Enabled: True + +Style/TrailingCommaInArguments: + Enabled: True + +Style/TrailingCommaInLiteral: + Enabled: True + +Style/GlobalVars: + Enabled: True + +Style/GuardClause: + Enabled: True + +Style/IfUnlessModifier: + Enabled: True + +Style/MultilineIfThen: + Enabled: True + +Style/NegatedIf: + Enabled: True + +Style/NegatedWhile: + Enabled: True + +Style/Next: + Enabled: True + +Style/SingleLineBlockParams: + Enabled: True + +Style/SingleLineMethods: + Enabled: True + +Style/SpecialGlobalVars: + Enabled: True + +Style/TrivialAccessors: + Enabled: True + +Style/UnlessElse: + Enabled: True + +Style/VariableInterpolation: + Enabled: True + +Style/VariableName: + Enabled: True + +Style/WhileUntilDo: + Enabled: True + +Style/EvenOdd: + Enabled: True + +Style/FileName: + Enabled: True + +Style/For: + Enabled: True + +Style/Lambda: + Enabled: True + +Style/MethodName: + Enabled: True + +Style/MultilineTernaryOperator: + Enabled: True + +Style/NestedTernaryOperator: + Enabled: True + +Style/NilComparison: + Enabled: True + +Style/FormatString: + Enabled: True + +Style/MultilineBlockChain: + Enabled: True + +Style/Semicolon: + Enabled: True + +Style/SignalException: + Enabled: True + +Style/NonNilCheck: + Enabled: True + +Style/Not: + Enabled: True + +Style/NumericLiterals: + Enabled: True + +Style/OneLineConditional: + Enabled: True + +Style/OpMethod: + Enabled: True + +Style/ParenthesesAroundCondition: + Enabled: True + +Style/PercentLiteralDelimiters: + Enabled: True + +Style/PerlBackrefs: + Enabled: True + +Style/PredicateName: + Enabled: True + +Style/RedundantException: + Enabled: True + +Style/SelfAssignment: + Enabled: True + +Style/Proc: + Enabled: True + +Style/RaiseArgs: + Enabled: True + +Style/RedundantBegin: + Enabled: True + +Style/RescueModifier: + Enabled: True + +# based on https://github.com/voxpupuli/modulesync_config/issues/168 +Style/RegexpLiteral: + EnforcedStyle: percent_r + Enabled: True + +Lint/UnderscorePrefixedVariableName: + Enabled: True + +Metrics/ParameterLists: + Enabled: False + +Lint/RequireParentheses: + Enabled: True + +Style/SpaceBeforeFirstArg: + Enabled: True + +Style/ModuleFunction: + Enabled: True + +Lint/Debugger: + Enabled: True + +Style/IfWithSemicolon: + Enabled: True + +Style/Encoding: + Enabled: True + +Style/BlockDelimiters: + Enabled: True + +Style/MultilineBlockLayout: + Enabled: True + +# 'Complexity' is very relative +Metrics/AbcSize: + Enabled: False + +# 'Complexity' is very relative +Metrics/PerceivedComplexity: + Enabled: False + +Lint/UselessAssignment: + Enabled: True + +Style/ClosingParenthesisIndentation: + Enabled: True + +# RSpec + +RSpec/BeforeAfterAll: + Exclude: + - spec/acceptance/**/* + +# We don't use rspec in this way +RSpec/DescribeClass: + Enabled: False + +# Example length is not necessarily an indicator of code quality +RSpec/ExampleLength: + Enabled: False + +RSpec/NamedSubject: + Enabled: False + +# disabled for now since they cause a lot of issues +# these issues aren't easy to fix +RSpec/RepeatedDescription: + Enabled: False + +RSpec/NestedGroups: + Enabled: False + +# this is broken on ruby1.9 +Style/IndentHeredoc: + Enabled: False + +# disable Yaml safe_load. This is needed to support ruby2.0.0 development envs +Security/YAMLLoad: + Enabled: false diff --git a/.sync.yml b/.sync.yml new file mode 100644 index 000000000..55f7b62d7 --- /dev/null +++ b/.sync.yml @@ -0,0 +1,3 @@ +--- +.travis.yml: + secure: "JquGPtLafZM/F6sNke12hW2VlKIn5yKfTXh/iAVIOLG/GLi2Om7enhvxl81nuyu1qjeXqMla+6WUKqWHu1s5odzI6JRjaWjdikxwcwuU464h3Fg8r3/enDlZtL6VWbLGQf0pqiaNNKlRl/2P9dYTCx8cbgAUPTqNIGY1Hf/V0oSIXRV1L3DbtDa0Qt5e3WOC0oAHYjoMLDFx/LhAUoFH6h5VGmM2hiuw641OE1PdZcdzkD64xFUpOSuFP7hknNyeGMftr+ZtwH3oymKHhpeH4IYJIiuI74+HEUtSzNsh+8Ok35gRZz3hgab4YmGjbJIVR2BiMIIghbD41Izcp2FmH4mMqkfJx5slLv/uoAtVeyyOgFOz9rcGuGlQE6mFXDeAWTNeXMQdnTEZGiwj7/sKYzbfdRKiPquGqr//so7RiN+0QwO+9MJoQuwZDhIsHsr1EEJhkA9kLy/gZpOD54Ef4w3EcRzu76grxRMzEgwLTOYFKVKIuXUY4y0u6SV/uJeoi80Ke5fCwfGRG/U1heWto2sns5LhEkV+nfH31iM5BLzMLYukuTgX9CJRje22+s/gL8bvXvD6LCQ0bckzZI8Pq+g1w41iILXRYJ7kJsjFszdDG8pQPk1rM5ZNHl+CNq1u7wXEci2ND0b9WQu2QDcOH8eGtasPaVFX+2LBhpaw0k0=" diff --git a/.travis.yml b/.travis.yml index 20180011a..caa27c9e2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,45 +1,52 @@ --- -language: ruby -bundler_args: --without development -before_install: rm Gemfile.lock || true sudo: false +dist: trusty +language: ruby cache: bundler -rvm: - - 1.9.3 - - 2.0.0 - - 2.1.0 -script: bundle exec rake test -env: - - PUPPET_VERSION="~> 3.1.0" - - PUPPET_VERSION="~> 3.3.0" - - PUPPET_VERSION="~> 3.7.4" FUTURE_PARSER=yes - - PUPPET_VERSION="~> 3.8.4" - - PUPPET_VERSION="~> 3.8.4" FUTURE_PARSER=yes - - PUPPET_VERSION="~> 4.0.0" - - PUPPET_VERSION="~> 4.1.0" +before_install: + - bundle -v + - rm Gemfile.lock || true + - gem update --system + - gem update bundler + - gem --version + - bundle -v +script: + - 'bundle exec rake $CHECK' matrix: - exclude: - - rvm: 1.9.3 - env: PUPPET_VERSION="~> 2.7.0" - - rvm: 2.0.0 - env: PUPPET_VERSION="~> 2.7.0" - - rvm: 2.0.0 - env: PUPPET_VERSION="~> 3.1.0" - - rvm: 2.1.0 - env: PUPPET_VERSION="~> 2.7.0" - - rvm: 2.1.0 - env: PUPPET_VERSION="~> 3.1.0" - - rvm: 2.1.0 - env: PUPPET_VERSION="~> 3.2.0" - - rvm: 2.1.0 - env: PUPPET_VERSION="~> 3.3.0" - - rvm: 2.1.0 - env: PUPPET_VERSION="~> 3.4.0" - - rvm: 1.9.3 - env: PUPPET_VERSION="~> 4.0.0" - - rvm: 2.0.0 - env: PUPPET_VERSION="~> 4.0.0" - - rvm: 1.9.3 - env: PUPPET_VERSION="~> 4.1.0" - - rvm: 2.0.0 - env: PUPPET_VERSION="~> 4.1.0" + fast_finish: true + include: + - rvm: 2.1.9 + bundler_args: --without system_tests development + env: PUPPET_VERSION="~> 4.0" CHECK=test + - rvm: 2.2.7 + bundler_args: --without system_tests development + env: PUPPET_VERSION="~> 4.0" CHECK=test + - rvm: 2.3.4 + bundler_args: --without system_tests development + env: PUPPET_VERSION="~> 4.0" CHECK=test + - rvm: 2.4.1 + bundler_args: --without system_tests development + env: PUPPET_VERSION="~> 4.0" CHECK=test + - rvm: 2.4.1 + bundler_args: --without system_tests development + env: PUPPET_VERSION="~> 4.0" CHECK=rubocop + - rvm: 2.4.1 + bundler_args: --without system_tests development + env: PUPPET_VERSION="~> 4.0" CHECK=build DEPLOY_TO_FORGE=yes +branches: + only: + - master + - /^v\d/ +notifications: + email: false +deploy: + provider: puppetforge + user: puppet + password: + secure: "JquGPtLafZM/F6sNke12hW2VlKIn5yKfTXh/iAVIOLG/GLi2Om7enhvxl81nuyu1qjeXqMla+6WUKqWHu1s5odzI6JRjaWjdikxwcwuU464h3Fg8r3/enDlZtL6VWbLGQf0pqiaNNKlRl/2P9dYTCx8cbgAUPTqNIGY1Hf/V0oSIXRV1L3DbtDa0Qt5e3WOC0oAHYjoMLDFx/LhAUoFH6h5VGmM2hiuw641OE1PdZcdzkD64xFUpOSuFP7hknNyeGMftr+ZtwH3oymKHhpeH4IYJIiuI74+HEUtSzNsh+8Ok35gRZz3hgab4YmGjbJIVR2BiMIIghbD41Izcp2FmH4mMqkfJx5slLv/uoAtVeyyOgFOz9rcGuGlQE6mFXDeAWTNeXMQdnTEZGiwj7/sKYzbfdRKiPquGqr//so7RiN+0QwO+9MJoQuwZDhIsHsr1EEJhkA9kLy/gZpOD54Ef4w3EcRzu76grxRMzEgwLTOYFKVKIuXUY4y0u6SV/uJeoi80Ke5fCwfGRG/U1heWto2sns5LhEkV+nfH31iM5BLzMLYukuTgX9CJRje22+s/gL8bvXvD6LCQ0bckzZI8Pq+g1w41iILXRYJ7kJsjFszdDG8pQPk1rM5ZNHl+CNq1u7wXEci2ND0b9WQu2QDcOH8eGtasPaVFX+2LBhpaw0k0=" + on: + tags: true + # all_branches is required to use tags + all_branches: true + # Only publish the build marked with "DEPLOY_TO_FORGE" + condition: "$DEPLOY_TO_FORGE = yes" diff --git a/.yardopts b/.yardopts new file mode 100644 index 000000000..3687f5184 --- /dev/null +++ b/.yardopts @@ -0,0 +1,2 @@ +--markup markdown +--output-dir docs/ diff --git a/Gemfile b/Gemfile index aadf97296..0914f7cbb 100644 --- a/Gemfile +++ b/Gemfile @@ -1,19 +1,72 @@ -source "https://rubygems.org" - -group :development,:test do - gem "json" - # Pin for 1.8.7 compatibility for now - gem "rake", '< 11.0.0' - gem "puppet", ENV['PUPPET_VERSION'] || '~> 3.7.0' - gem "puppet-lint" - - # Pin for 1.8.7 compatibility for now - gem "rspec", '< 3.2.0' - gem "rspec-core", "3.1.7" - gem "rspec-puppet", "~> 2.1" - - gem "puppet-syntax" - gem "puppetlabs_spec_helper" - gem "hiera" - gem "hiera-puppet-helper" +source ENV['GEM_SOURCE'] || "https://rubygems.org" + +def location_for(place, fake_version = nil) + if place =~ /^(git[:@][^#]*)#(.*)/ + [fake_version, { :git => $1, :branch => $2, :require => false }].compact + elsif place =~ /^file:\/\/(.*)/ + ['>= 0', { :path => File.expand_path($1), :require => false }] + else + [place, { :require => false }] + end +end + +group :test do + gem 'puppetlabs_spec_helper', '~> 2.1.1', :require => false + gem 'rspec-puppet', '~> 2.5', :require => false + gem 'rspec-puppet-facts', :require => false + gem 'rspec-puppet-utils', :require => false + gem 'puppet-lint-absolute_classname-check', :require => false + gem 'puppet-lint-leading_zero-check', :require => false + gem 'puppet-lint-trailing_comma-check', :require => false + gem 'puppet-lint-version_comparison-check', :require => false + gem 'puppet-lint-classes_and_types_beginning_with_digits-check', :require => false + gem 'puppet-lint-unquoted_string-check', :require => false + gem 'puppet-lint-variable_contains_upcase', :require => false + gem 'metadata-json-lint', :require => false + gem 'puppet-blacksmith', :require => false + gem 'voxpupuli-release', :require => false, :git => 'https://github.com/voxpupuli/voxpupuli-release-gem.git' + gem 'puppet-strings', '~> 1.0', :require => false + gem 'redcarpet', :require => false + gem 'rubocop', '~> 0.48.0', :require => false if RUBY_VERSION >= '2.3.0' + gem 'rubocop-rspec', '~> 1.15.0', :require => false if RUBY_VERSION >= '2.3.0' + gem 'mocha', '>= 1.2.1', :require => false + gem 'coveralls', :require => false + gem 'simplecov-console', :require => false + gem 'github_changelog_generator', '~> 1.13.0', :require => false if RUBY_VERSION < '2.2.2' + gem 'rack', '~> 1.0', :require => false if RUBY_VERSION < '2.2.2' + gem 'github_changelog_generator', :require => false if RUBY_VERSION >= '2.2.2' + gem 'parallel_tests', :require => false +end + +group :development do + gem 'travis', :require => false + gem 'travis-lint', :require => false + gem 'guard-rake', :require => false + gem 'overcommit', '~> 0.39.1', :require => false +end + +group :system_tests do + if beaker_version = ENV['BEAKER_VERSION'] + gem 'beaker', *location_for(beaker_version) + end + if beaker_rspec_version = ENV['BEAKER_RSPEC_VERSION'] + gem 'beaker-rspec', *location_for(beaker_rspec_version) + else + gem 'beaker-rspec', :require => false + end + gem 'serverspec', :require => false + gem 'beaker-puppet_install_helper', :require => false end + + + +if facterversion = ENV['FACTER_GEM_VERSION'] + gem 'facter', facterversion.to_s, :require => false, :groups => [:test] +else + gem 'facter', :require => false, :groups => [:test] +end + +ENV['PUPPET_VERSION'].nil? ? puppetversion = '~> 4.0' : puppetversion = ENV['PUPPET_VERSION'].to_s +gem 'puppet', puppetversion, :require => false, :groups => [:test] + +# vim: syntax=ruby diff --git a/LICENSE b/LICENSE new file mode 100644 index 000000000..8f71f43fe --- /dev/null +++ b/LICENSE @@ -0,0 +1,202 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "{}" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright {yyyy} {name of copyright owner} + + 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. + diff --git a/README.md b/README.md index fad9ce8aa..47dc5096e 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,7 @@ # puppet-prometheus -[![Puppet Forge](https://img.shields.io/puppetforge/e/brutus777/prometheus.svg)](https://forge.puppetlabs.com/brutus777/prometheus) -[![Puppet Forge](https://img.shields.io/puppetforge/v/brutus777/prometheus.svg)](https://forge.puppetlabs.com/brutus777/prometheus) -[![Puppet Forge](https://img.shields.io/puppetforge/f/brutus777/prometheus.svg)](https://forge.puppetlabs.com/brutus777/prometheus) - -## Deprecation notice - -I'm moving this module to voxpopuli repository: https://github.com/voxpupuli/puppet-prometheus - -Please do not issue any additional PR here. +[![Puppet Forge](https://img.shields.io/puppetforge/e/puppet/prometheus.svg)](https://forge.puppetlabs.com/puppet/prometheus) +[![Puppet Forge](https://img.shields.io/puppetforge/v/puppet/prometheus.svg)](https://forge.puppetlabs.com/puppet/prometheus) +[![Puppet Forge](https://img.shields.io/puppetforge/f/puppet/prometheus.svg)](https://forge.puppetlabs.com/puppet/prometheus) ## Compatibility @@ -28,6 +22,7 @@ This module automates the install and configuration of Prometheus monitoring too * Installs a configuration file for prometheus daemon (/etc/prometheus/prometheus.yaml) or for alertmanager (/etc/prometheus/alert.rules) * Manages the services via upstart, sysv, or systemd * Optionally creates alert rules +* The following exporters are currently implemented: node_exporter, statsd_exporter, process_exporter, haproxy_exporter, mysqld_exporter ## Usage @@ -48,7 +43,7 @@ On the server (for prometheus version >= 1.0.0): class { 'prometheus': version => '1.0.0', scrape_configs => [ {'job_name'=>'prometheus','scrape_interval'=> '30s','scrape_timeout'=>'30s','static_configs'=> [{'targets'=>['localhost:9090'], 'labels'=> { 'alias'=>'Prometheus'}}]}], - extra_options => '-alertmanager.url http://localhost:9093 -web.console.templates=/opt/staging/prometheus-1.0.0.linux-amd64/consoles -web.console.libraries=/opt/staging/prometheus-1.0.0.linux-amd64/console_libraries', + extra_options => '-alertmanager.url http://localhost:9093 -web.console.templates=/opt/prometheus-1.0.0.linux-amd64/consoles -web.console.libraries=/opt/prometheus-1.0.0.linux-amd64/console_libraries', localstorage => '/prometheus/prometheus', } ``` diff --git a/Rakefile b/Rakefile index bc5cdb974..82c896088 100644 --- a/Rakefile +++ b/Rakefile @@ -1,42 +1,44 @@ -require 'rubygems' -require 'bundler/setup' require 'puppetlabs_spec_helper/rake_tasks' -require 'puppet-lint/tasks/puppet-lint' -require 'puppet-syntax/tasks/puppet-syntax' +require 'puppet_blacksmith/rake_tasks' +require 'voxpupuli/release/rake_tasks' +require 'puppet-strings/tasks' -# These two gems aren't always present, for instance -# on Travis with --without development -begin - require 'puppet_blacksmith/rake_tasks' -rescue LoadError -end - -PuppetLint.configuration.send("disable_80chars") -PuppetLint.configuration.log_format = "%{path}:%{linenumber}:%{check}:%{KIND}:%{message}" -PuppetLint.configuration.fail_on_warnings = false - -# Forsake support for Puppet 2.6.2 for the benefit of cleaner code. -# http://puppet-lint.com/checks/class_parameter_defaults/ -PuppetLint.configuration.send('disable_class_parameter_defaults') -# http://puppet-lint.com/checks/class_inherits_from_params_class/ +PuppetLint.configuration.log_format = '%{path}:%{line}:%{check}:%{KIND}:%{message}' +PuppetLint.configuration.fail_on_warnings = true +PuppetLint.configuration.send('relative') +PuppetLint.configuration.send('disable_140chars') PuppetLint.configuration.send('disable_class_inherits_from_params_class') +PuppetLint.configuration.send('disable_documentation') +PuppetLint.configuration.send('disable_single_quote_string_with_variables') -exclude_paths = [ - "pkg/**/*", - "vendor/**/*", - "spec/**/*", -] +exclude_paths = %w( + pkg/**/* + vendor/**/* + .vendor/**/* + spec/**/* +) PuppetLint.configuration.ignore_paths = exclude_paths PuppetSyntax.exclude_paths = exclude_paths -#desc "Run acceptance tests" -#RSpec::Core::RakeTask.new(:acceptance) do |t| -# t.pattern = 'spec/acceptance' -#end +desc 'Run acceptance tests' +RSpec::Core::RakeTask.new(:acceptance) do |t| + t.pattern = 'spec/acceptance' +end -desc "Run syntax, lint, and spec tests." -task :test => [ - :syntax, - :lint, - :spec, +desc 'Run tests metadata_lint, release_checks' +task test: [ + :metadata_lint, + :release_checks, ] + +begin + require 'github_changelog_generator/task' + GitHubChangelogGenerator::RakeTask.new :changelog do |config| + version = (Blacksmith::Modulefile.new).version + config.future_release = "v#{version}" + config.header = "# Change log\n\nAll notable changes to this project will be documented in this file.\nEach new release typically also includes the latest modulesync defaults.\nThese should not impact the functionality of the module." + config.exclude_labels = %w{duplicate question invalid wontfix modulesync} + end +rescue LoadError +end +# vim: syntax=ruby diff --git a/examples/init.pp b/examples/init.pp new file mode 100644 index 000000000..5aa5a78f4 --- /dev/null +++ b/examples/init.pp @@ -0,0 +1,6 @@ +include ::prometheus +include ::prometheus::node_exporter +include ::prometheus::alertmanager +include ::prometheus::alerts +include ::prometheus::statsd_exporter +include ::prometheus::process_exporter diff --git a/manifests/alertmanager.pp b/manifests/alertmanager.pp index 5e6b4be21..7acd9a48a 100644 --- a/manifests/alertmanager.pp +++ b/manifests/alertmanager.pp @@ -114,6 +114,9 @@ # [*service_ensure*] # State ensured for the service (default 'running') # +# [*service_name*] +# Name of the alertmanager service (default 'alertmanager') +# # [*storage_path*] # The storage path to pass to the alertmanager. Defaults to '/var/lib/alertmanager' # @@ -153,6 +156,7 @@ $route = $::prometheus::params::alertmanager_route, $service_enable = true, $service_ensure = 'running', + $service_name = 'alertmanager', $storage_path = $::prometheus::params::alertmanager_storage_path, $templates = $::prometheus::params::alertmanager_templates, $user = $::prometheus::params::alertmanager_user, @@ -175,7 +179,7 @@ validate_hash($global) validate_hash($route) $notify_service = $restart_on_change ? { - true => Service['alertmanager'], + true => Service[$service_name], default => undef, } @@ -193,6 +197,7 @@ group => $group, mode => $config_mode, content => template('prometheus/alertmanager.yaml.erb'), + notify => Service['alertmanager'], require => File[$config_dir], } @@ -214,7 +219,7 @@ $options = "-config.file=${prometheus::alertmanager::config_file} ${prometheus::alertmanager::extra_options}" } - prometheus::daemon { 'alertmanager': + prometheus::daemon { $service_name: install_method => $install_method, version => $version, download_extension => $download_extension, diff --git a/manifests/alerts.pp b/manifests/alerts.pp index 302a1df20..ce1eb4bf2 100644 --- a/manifests/alerts.pp +++ b/manifests/alerts.pp @@ -9,19 +9,19 @@ # Array of alerts (see README) # class prometheus::alerts ( - $alerts, - $location, - $alertfile_name = 'alert.rules', + String $location, + Array $alerts, + String $alertfile_name = 'alert.rules' ) inherits prometheus::params { - if $alerts != [] { - file{ "${location}/${alertfile_name}": - ensure => 'file', - owner => $prometheus::user, - group => $prometheus::group, - notify => Class['::prometheus::service_reload'], - content => template("${module_name}/alerts.erb"), + if $alerts != [] { + file{ "${location}/${alertfile_name}": + ensure => 'file', + owner => $prometheus::user, + group => $prometheus::group, + notify => Class['::prometheus::service_reload'], + content => epp("${module_name}/alerts.epp"), + } } - } } diff --git a/manifests/config.pp b/manifests/config.pp index 69a83c4c4..0d05d30e1 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -14,7 +14,7 @@ # so any change there should trigger a full service restart if $::prometheus::restart_on_change { File { - notify => [Class['::prometheus::run_service']] + notify => [Class['::prometheus::run_service']], } $systemd_notify = [Exec['prometheus-systemd-reload'], Class['::prometheus::run_service']] } else { @@ -38,14 +38,13 @@ } } 'systemd' : { - file { '/lib/systemd/system/prometheus.service': + file { '/etc/systemd/system/prometheus.service': mode => '0644', owner => 'root', group => 'root', notify => $systemd_notify, content => template('prometheus/prometheus.systemd.erb'), } - exec { 'prometheus-systemd-reload': command => 'systemctl daemon-reload', path => [ '/usr/bin', '/bin', '/usr/sbin' ], @@ -57,7 +56,7 @@ mode => '0555', owner => 'root', group => 'root', - content => template('prometheus/prometheus.sysv.erb') + content => template('prometheus/prometheus.sysv.erb'), } } 'debian' : { @@ -65,7 +64,7 @@ mode => '0555', owner => 'root', group => 'root', - content => template('prometheus/prometheus.debian.erb') + content => template('prometheus/prometheus.debian.erb'), } } 'sles' : { @@ -73,7 +72,7 @@ mode => '0555', owner => 'root', group => 'root', - content => template('prometheus/prometheus.sles.erb') + content => template('prometheus/prometheus.sles.erb'), } } 'launchd' : { @@ -81,7 +80,7 @@ mode => '0644', owner => 'root', group => 'wheel', - content => template('prometheus/prometheus.launchd.erb') + content => template('prometheus/prometheus.launchd.erb'), } } default : { @@ -96,8 +95,8 @@ group => $prometheus::group, purge => $purge, recurse => $purge, - } -> - file { 'prometheus.yaml': + } + -> file { 'prometheus.yaml': ensure => present, path => "${prometheus::config_dir}/prometheus.yaml", owner => $prometheus::user, diff --git a/manifests/daemon.pp b/manifests/daemon.pp index 108a0dbb8..a59d09664 100644 --- a/manifests/daemon.pp +++ b/manifests/daemon.pp @@ -1,165 +1,166 @@ define prometheus::daemon ( - $install_method, $version, - $download_extension, - $os, - $arch, $real_download_url, - $bin_dir, $notify_service, - $package_name, - $package_ensure, - $manage_user, $user, - $extra_groups, $group, - $manage_group, - $purge, - $options, - $init_style, - $service_ensure, - $service_enable, - $manage_service, - ) { - case $install_method { - 'url': { - include staging - $staging_file = "${name}-${version}.${download_extension}" - $binary = "${::staging::path}/${name}-${version}.${os}-${arch}/${name}" - staging::file { $staging_file: - source => $real_download_url, - } -> - staging::extract { $staging_file: - target => $::staging::path, - creates => $binary, - } -> - file { $binary: - owner => 'root', - group => 0, # 0 instead of root because OS X uses "wheel". - mode => '0555', - } -> - file { "${bin_dir}/${name}": - ensure => link, - notify => $notify_service, - target => $binary, - } + + $install_method = $prometheus::params::install_method, + $download_extension = $prometheus::params::download_extension, + $os = $prometheus::params::os, + $arch = $prometheus::params::arch, + $bin_dir = $prometheus::params::bin_dir, + $package_name = undef, + $package_ensure = undef, + $manage_user = true, + $extra_groups = [], + $manage_group = true, + $purge = true, + $options = '', + $init_style = $prometheus::params::init_style, + $service_ensure = 'running', + $service_enable = true, + $manage_service = true, +) { + + case $install_method { + 'url': { + archive { "/tmp/${name}-${version}.${download_extension}": + ensure => present, + extract => true, + extract_path => '/opt', + source => $real_download_url, + checksum_verify => false, + creates => "/opt/${name}-${version}.${os}-${arch}/${name}", + cleanup => true, } - 'package': { - package { $package_name: - ensure => $package_ensure, - } - if $manage_user { - User[$user] -> Package[$package_name] - } + -> file { "/opt/${name}-${version}.${os}-${arch}/${name}": + owner => 'root', + group => 0, # 0 instead of root because OS X uses "wheel". + mode => '0555', } - 'none': {} - default: { - fail("The provided install method ${install_method} is invalid") + -> file { "${bin_dir}/${name}": + ensure => link, + notify => $notify_service, + target => "/opt/${name}-${version}.${os}-${arch}/${name}", } } - if $manage_user { - ensure_resource('user', [ $user ], { - ensure => 'present', - system => true, - groups => $extra_groups, - }) - - if $manage_group { - Group[$group] -> User[$user] + 'package': { + package { $package_name: + ensure => $package_ensure, } + if $manage_user { + User[$user] -> Package[$package_name] + } + } + 'none': {} + default: { + fail("The provided install method ${install_method} is invalid") } + } + if $manage_user { + ensure_resource('user', [ $user ], { + ensure => 'present', + system => true, + groups => $extra_groups, + }) + if $manage_group { - ensure_resource('group', [ $group ], { - ensure => 'present', - system => true, - }) + Group[$group] -> User[$user] } + } + if $manage_group { + ensure_resource('group', [ $group ], { + ensure => 'present', + system => true, + }) + } - if $init_style { + if $init_style { - case $init_style { - 'upstart' : { - file { "/etc/init/${name}.conf": - mode => '0444', - owner => 'root', - group => 'root', - content => template('prometheus/daemon.upstart.erb'), - notify => $notify_service, - } - file { "/etc/init.d/${name}": - ensure => link, - target => '/lib/init/upstart-job', - owner => 'root', - group => 'root', - mode => '0755', - } + case $init_style { + 'upstart' : { + file { "/etc/init/${name}.conf": + mode => '0444', + owner => 'root', + group => 'root', + content => template('prometheus/daemon.upstart.erb'), + notify => $notify_service, } - 'systemd' : { - file { "/etc/systemd/system/${name}.service": - mode => '0644', - owner => 'root', - group => 'root', - content => template('prometheus/daemon.systemd.erb'), - }~> - exec { "${name}-systemd-reload": - command => 'systemctl daemon-reload', - path => [ '/usr/bin', '/bin', '/usr/sbin' ], - refreshonly => true, - notify => $notify_service, - } + file { "/etc/init.d/${name}": + ensure => link, + target => '/lib/init/upstart-job', + owner => 'root', + group => 'root', + mode => '0755', } - 'sysv' : { - file { "/etc/init.d/${name}": - mode => '0555', - owner => 'root', - group => 'root', - content => template('prometheus/daemon.sysv.erb'), - } + } + 'systemd' : { + file { "/etc/systemd/system/${name}.service": + mode => '0644', + owner => 'root', + group => 'root', + content => template('prometheus/daemon.systemd.erb'), + } + ~> exec { "${name}-systemd-reload": + command => 'systemctl daemon-reload', + path => [ '/usr/bin', '/bin', '/usr/sbin' ], + refreshonly => true, + notify => $notify_service, } - 'debian' : { - file { "/etc/init.d/${name}": - mode => '0555', - owner => 'root', - group => 'root', - content => template('prometheus/daemon.debian.erb'), - notify => $notify_service, - } + } + 'sysv' : { + file { "/etc/init.d/${name}": + mode => '0555', + owner => 'root', + group => 'root', + content => template('prometheus/daemon.sysv.erb'), } - 'sles' : { - file { "/etc/init.d/${name}": - mode => '0555', - owner => 'root', - group => 'root', - content => template('prometheus/daemon.sles.erb'), - notify => $notify_service, - } + } + 'debian' : { + file { "/etc/init.d/${name}": + mode => '0555', + owner => 'root', + group => 'root', + content => template('prometheus/daemon.debian.erb'), + notify => $notify_service, } - 'launchd' : { - file { "/Library/LaunchDaemons/io.${name}.daemon.plist": - mode => '0644', - owner => 'root', - group => 'wheel', - content => template('prometheus/daemon.launchd.erb'), - notify => $notify_service, - } + } + 'sles' : { + file { "/etc/init.d/${name}": + mode => '0555', + owner => 'root', + group => 'root', + content => template('prometheus/daemon.sles.erb'), + notify => $notify_service, } - default : { - fail("I don't know how to create an init script for style ${init_style}") + } + 'launchd' : { + file { "/Library/LaunchDaemons/io.${name}.daemon.plist": + mode => '0644', + owner => 'root', + group => 'wheel', + content => template('prometheus/daemon.launchd.erb'), + notify => $notify_service, } } + default : { + fail("I don't know how to create an init script for style ${init_style}") + } } + } - $init_selector = $init_style ? { - 'launchd' => "io.${name}.daemon", - default => $name, - } + $init_selector = $init_style ? { + 'launchd' => "io.${name}.daemon", + default => $name, + } - if $manage_service == true { - service { $name: - ensure => $service_ensure, - name => $init_selector, - enable => $service_enable, - } + if $manage_service == true { + service { $name: + ensure => $service_ensure, + name => $init_selector, + enable => $service_enable, } } +} diff --git a/manifests/haproxy_exporter.pp b/manifests/haproxy_exporter.pp new file mode 100644 index 000000000..da397d85c --- /dev/null +++ b/manifests/haproxy_exporter.pp @@ -0,0 +1,136 @@ +# Class: prometheus::haproxy_exporter +# +# This module manages prometheus haproxy_exporter +# +# Parameters: +# [*arch*] +# Architecture (amd64 or i386) +# +# [*bin_dir*] +# Directory where binaries are located +# +# [*cnf_scrape_uri*] +# The URI to obtain HAProxy stats from +# +# [*download_extension*] +# Extension for the release binary archive +# +# [*download_url*] +# Complete URL corresponding to the where the release binary archive can be downloaded +# +# [*download_url_base*] +# Base URL for the binary archive +# +# [*extra_groups*] +# Extra groups to add the binary user to +# +# [*extra_options*] +# Extra options added to the startup command +# +# [*group*] +# Group under which the binary is running +# +# [*init_style*] +# Service startup scripts style (e.g. rc, upstart or systemd) +# +# [*install_method*] +# Installation method: url or package (only url is supported currently) +# +# [*manage_group*] +# Whether to create a group for or rely on external code for that +# +# [*manage_service*] +# Should puppet manage the service? (default true) +# +# [*manage_user*] +# Whether to create user or rely on external code for that +# +# [*os*] +# Operating system (linux is the only one supported) +# +# [*package_ensure*] +# If package, then use this for package ensure default 'latest' +# +# [*package_name*] +# The binary package name - not available yet +# +# [*purge_config_dir*] +# Purge config files no longer generated by Puppet +# +# [*restart_on_change*] +# Should puppet restart the service on configuration change? (default true) +# +# [*service_enable*] +# Whether to enable the service from puppet (default true) +# +# [*service_ensure*] +# State ensured for the service (default 'running') +# +# [*user*] +# User which runs the service +# +# [*version*] +# The binary release version +class prometheus::haproxy_exporter( + $arch = $::prometheus::params::arch, + $bin_dir = $::prometheus::params::bin_dir, + $cnf_scrape_uri = $::prometheus::params::haproxy_exporter_cnf_scrape_uri, + $download_extension = $::prometheus::params::haproxy_exporter_download_extension, + $download_url = undef, + $download_url_base = $::prometheus::params::haproxy_exporter_download_url_base, + $extra_groups = $::prometheus::params::haproxy_exporter_extra_groups, + $extra_options = '', + $group = $::prometheus::params::haproxy_exporter_group, + $init_style = $::prometheus::params::init_style, + $install_method = $::prometheus::params::install_method, + $manage_group = true, + $manage_service = true, + $manage_user = true, + $os = $::prometheus::params::os, + $package_ensure = $::prometheus::params::haproxy_exporter_package_ensure, + $package_name = $::prometheus::params::haproxy_exporter_package_name, + $purge_config_dir = true, + $restart_on_change = true, + $service_enable = true, + $service_ensure = 'running', + $user = $::prometheus::params::haproxy_exporter_user, + $version = $::prometheus::params::haproxy_exporter_version, +) inherits prometheus::params { + + $real_download_url = pick($download_url,"${download_url_base}/download/v${version}/${package_name}-${version}.${os}-${arch}.${download_extension}") + validate_bool($purge_config_dir) + validate_bool($manage_user) + validate_bool($manage_service) + validate_bool($restart_on_change) + $notify_service = $restart_on_change ? { + true => Service['haproxy_exporter'], + default => undef, + } + + $options = "-haproxy.scrape-uri=\"${cnf_scrape_uri}\" ${extra_options}" + + prometheus::daemon { 'haproxy_exporter': + install_method => $install_method, + version => $version, + download_extension => $download_extension, + os => $os, + arch => $arch, + real_download_url => $real_download_url, + bin_dir => $bin_dir, + notify_service => $notify_service, + package_name => $package_name, + package_ensure => $package_ensure, + manage_user => $manage_user, + user => $user, + extra_groups => $extra_groups, + group => $group, + manage_group => $manage_group, + purge => $purge_config_dir, + options => $options, + init_style => $init_style, + service_ensure => $service_ensure, + service_enable => $service_enable, + manage_service => $manage_service, + } + +} diff --git a/manifests/init.pp b/manifests/init.pp index 3e2d35840..5fb4168a1 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -99,6 +99,12 @@ # [*scrape_configs*] # Prometheus scrape configs # +# [*alert_relabel_config*] +# Prometheus alert relabel config under alerting +# +# [*alertmanagers_config*] +# Prometheus managers config under alerting +# # Actions: # # Requires: see Modulefile @@ -138,8 +144,9 @@ $global_config = $::prometheus::params::global_config, $rule_files = $::prometheus::params::rule_files, $scrape_configs = $::prometheus::params::scrape_configs, - $alerts = $::prometheus::params::alerts - + $alerts = $::prometheus::params::alerts, + $alert_relabel_config = $::prometheus::params::alert_relabel_config, + $alertmanagers_config = $::prometheus::params::alertmanagers_config, ) inherits prometheus::params { if( versioncmp($::prometheus::version, '1.0.0') == -1 ){ $real_download_url = pick($download_url, @@ -157,25 +164,26 @@ validate_hash($global_config) validate_array($rule_files) validate_array($scrape_configs) + validate_array($alert_relabel_config) + validate_array($alertmanagers_config) $config_hash_real = deep_merge($config_defaults, $config_hash) validate_hash($config_hash_real) anchor {'prometheus_first': } - -> - class { '::prometheus::install': } -> - class { '::prometheus::config': + -> class { '::prometheus::install': } + -> class { '::prometheus::config': global_config => $global_config, rule_files => $rule_files, scrape_configs => $scrape_configs, purge => $purge_config_dir, config_template => $config_template, - } -> - class { '::prometheus::alerts': + } + -> class { '::prometheus::alerts': location => $config_dir, alerts => $alerts, - } -> - class { '::prometheus::run_service': } -> - class { '::prometheus::service_reload': } -> - anchor {'prometheus_last': } + } + -> class { '::prometheus::run_service': } + -> class { '::prometheus::service_reload': } + -> anchor {'prometheus_last': } } diff --git a/manifests/install.pp b/manifests/install.pp index c64548fc4..125308c0d 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -15,26 +15,24 @@ } case $::prometheus::install_method { 'url': { - include staging - staging::file { "prometheus-${prometheus::version}.${prometheus::download_extension}": - source => $prometheus::real_download_url, - } -> - file { "${::staging::path}/prometheus-${prometheus::version}": - ensure => directory, - } -> - staging::extract { "prometheus-${prometheus::version}.${prometheus::download_extension}": - target => $::staging::path, - creates => "${::staging::path}/prometheus-${prometheus::version}.${prometheus::os}-${prometheus::arch}/prometheus", - } -> - file { - "${::staging::path}/prometheus-${prometheus::version}.${prometheus::os}-${prometheus::arch}/prometheus": + archive { "/tmp/prometheus-${prometheus::version}.${prometheus::download_extension}": + ensure => present, + extract => true, + extract_path => '/opt', + source => $prometheus::real_download_url, + checksum_verify => false, + creates => "/opt/prometheus-${prometheus::version}.${prometheus::os}-${prometheus::arch}/prometheus", + cleanup => true, + } + -> file { + "/opt/prometheus-${prometheus::version}.${prometheus::os}-${prometheus::arch}/prometheus": owner => 'root', group => 0, # 0 instead of root because OS X uses "wheel". mode => '0555'; "${::prometheus::bin_dir}/prometheus": ensure => link, notify => $::prometheus::notify_service, - target => "${::staging::path}/prometheus-${prometheus::version}.${prometheus::os}-${prometheus::arch}/prometheus"; + target => "/opt/prometheus-${prometheus::version}.${prometheus::os}-${prometheus::arch}/prometheus"; $::prometheus::shared_dir: ensure => directory, owner => $::prometheus::user, @@ -43,11 +41,11 @@ "${::prometheus::shared_dir}/consoles": ensure => link, notify => $::prometheus::notify_service, - target => "${::staging::path}/prometheus-${prometheus::version}.${prometheus::os}-${prometheus::arch}/consoles"; + target => "/opt/prometheus-${prometheus::version}.${prometheus::os}-${prometheus::arch}/consoles"; "${::prometheus::shared_dir}/console_libraries": ensure => link, notify => $::prometheus::notify_service, - target => "${::staging::path}/prometheus-${prometheus::version}.${prometheus::os}-${prometheus::arch}/console_libraries"; + target => "/opt/prometheus-${prometheus::version}.${prometheus::os}-${prometheus::arch}/console_libraries"; } } 'package': { diff --git a/manifests/node_exporter.pp b/manifests/node_exporter.pp index 94b4356f0..e1bcfce5c 100644 --- a/manifests/node_exporter.pp +++ b/manifests/node_exporter.pp @@ -67,6 +67,9 @@ # [*service_ensure*] # State ensured for the service (default 'running') # +# [*service_name*] +# Name of the node exporter service (default 'node_exporter') +# # [*user*] # User which runs the service # @@ -94,6 +97,7 @@ $restart_on_change = true, $service_enable = true, $service_ensure = 'running', + $service_name = 'node_exporter', $user = $::prometheus::params::node_exporter_user, $version = $::prometheus::params::node_exporter_version, ) inherits prometheus::params { @@ -111,14 +115,14 @@ validate_bool($restart_on_change) validate_array($collectors) $notify_service = $restart_on_change ? { - true => Service['node_exporter'], + true => Service[$service_name], default => undef, } $str_collectors = join($collectors, ',') $options = "-collectors.enabled=${str_collectors} ${extra_options}" - prometheus::daemon { 'node_exporter': + prometheus::daemon { $service_name : install_method => $install_method, version => $version, download_extension => $download_extension, diff --git a/manifests/params.pp b/manifests/params.pp index a991a2764..0d8c680e6 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -1,6 +1,8 @@ # Class prometheus::params # Include default parameters for prometheus class class prometheus::params { + $alert_relabel_config = [] + $alertmanagers_config = [] $alertmanager_config_dir = '/etc/alertmanager' $alertmanager_config_file = "${alertmanager_config_dir}/alertmanager.yaml" $alertmanager_download_extension = 'tar.gz' @@ -16,7 +18,7 @@ $alertmanager_storage_path='/var/lib/alertmanager' $alertmanager_templates = [ "${alertmanager_config_dir}/*.tmpl" ] $alertmanager_user = 'alertmanager' - $alertmanager_version = '0.3.0' + $alertmanager_version = '0.5.1' $alerts = [] $bin_dir = '/usr/local/bin' $config_dir = '/etc/prometheus' @@ -29,6 +31,24 @@ $group = 'prometheus' $install_method = 'url' $localstorage = '/var/lib/prometheus' + $haproxy_exporter_cnf_scrape_uri = 'http://localhost:1234/haproxy?stats;csv' + $haproxy_exporter_download_extension = 'tar.gz' + $haproxy_exporter_download_url_base = 'https://github.com/prometheus/haproxy_exporter/releases' + $haproxy_exporter_extra_groups = [] + $haproxy_exporter_group = 'haproxy-exporter' + $haproxy_exporter_package_ensure = 'latest' + $haproxy_exporter_package_name = 'haproxy_exporter' + $haproxy_exporter_user = 'haproxy-user' + $haproxy_exporter_version = '0.7.1' + $process_exporter_download_extension = 'tar.gz' + $process_exporter_download_url_base = 'https://github.com/ncabatoff/process-exporter/releases' + $process_exporter_extra_groups = [] + $process_exporter_group = 'process-exporter' + $process_exporter_package_ensure = 'latest' + $process_exporter_package_name = 'process-exporter' + $process_exporter_user = 'process-exporter' + $process_exporter_version = '0.1.0' + $process_exporter_config_path = '/etc/process-exporter.yaml' $mysqld_exporter_cnf_config_path = '/etc/.my.cnf' $mysqld_exporter_cnf_host = 'localhost' $mysqld_exporter_cnf_password = 'password' @@ -50,7 +70,7 @@ $node_exporter_package_ensure = 'latest' $node_exporter_package_name = 'node_exporter' $node_exporter_user = 'node-exporter' - $node_exporter_version = '0.13.0' + $node_exporter_version = '0.14.0' $package_ensure = 'latest' $package_name = 'prometheus' $rule_files = [ "${config_dir}/alert.rules" ] @@ -67,7 +87,7 @@ $statsd_exporter_user = 'statsd-exporter' $statsd_exporter_version = '0.3.0' $user = 'prometheus' - $version = '1.0.1' + $version = '1.5.2' case $::architecture { 'x86_64', 'amd64': { $arch = 'amd64' } 'i386': { $arch = '386' } diff --git a/manifests/process_exporter.pp b/manifests/process_exporter.pp new file mode 100644 index 000000000..cd82610da --- /dev/null +++ b/manifests/process_exporter.pp @@ -0,0 +1,144 @@ +# Class: prometheus::process_exporter +# +# This module manages prometheus process_exporter +# +# Parameters: +# [*arch*] +# Architecture (amd64 or i386) +# +# [*bin_dir*] +# Directory where binaries are located +# +# [*download_extension*] +# Extension for the release binary archive +# +# [*download_url*] +# Complete URL corresponding to the where the release binary archive can be downloaded +# +# [*download_url_base*] +# Base URL for the binary archive +# +# [*extra_groups*] +# Extra groups to add the binary user to +# +# [*extra_options*] +# Extra options added to the startup command +# +# [*group*] +# Group under which the binary is running +# +# [*init_style*] +# Service startup scripts style (e.g. rc, upstart or systemd) +# +# [*install_method*] +# Installation method: url or package (only url is supported currently) +# +# [*manage_group*] +# Whether to create a group for or rely on external code for that +# +# [*manage_service*] +# Should puppet manage the service? (default true) +# +# [*manage_user*] +# Whether to create user or rely on external code for that +# +# [*os*] +# Operating system (linux is the only one supported) +# +# [*package_ensure*] +# If package, then use this for package ensure default 'latest' +# +# [*package_name*] +# The binary package name - not available yet +# +# [*purge_config_dir*] +# Purge config files no longer generated by Puppet +# +# [*restart_on_change*] +# Should puppet restart the service on configuration change? (default true) +# +# [*service_enable*] +# Whether to enable the service from puppet (default true) +# +# [*service_ensure*] +# State ensured for the service (default 'running') +# +# [*user*] +# User which runs the service +# +# [*version*] +# The binary release version +class prometheus::process_exporter( + $arch = $::prometheus::params::arch, + $bin_dir = $::prometheus::params::bin_dir, + $download_extension = $::prometheus::params::process_exporter_download_extension, + $download_url = undef, + $download_url_base = $::prometheus::params::process_exporter_download_url_base, + $extra_groups = $::prometheus::params::process_exporter_extra_groups, + $extra_options = '', + $config_mode = $::prometheus::params::config_mode, + $group = $::prometheus::params::process_exporter_group, + $init_style = $::prometheus::params::init_style, + $install_method = $::prometheus::params::install_method, + $manage_group = true, + $manage_service = true, + $manage_user = true, + $os = $::prometheus::params::os, + $package_ensure = $::prometheus::params::process_exporter_package_ensure, + $package_name = $::prometheus::params::process_exporter_package_name, + $purge_config_dir = true, + $restart_on_change = true, + $service_enable = true, + $service_ensure = 'running', + $user = $::prometheus::params::process_exporter_user, + $version = $::prometheus::params::process_exporter_version, + $config_path = $::prometheus::params::process_exporter_config_path, + $watched_processes = [] +) inherits prometheus::params { + + $real_download_url = pick($download_url,"${download_url_base}/download/v${version}/${package_name}-${version}.${os}-${arch}.${download_extension}") + validate_bool($purge_config_dir) + validate_bool($manage_user) + validate_bool($manage_service) + validate_bool($restart_on_change) + $notify_service = $restart_on_change ? { + true => Service['process-exporter'], + default => undef, + } + + file { $config_path: + ensure => 'file', + mode => $config_mode, + owner => $user, + group => $group, + content => template('prometheus/process-exporter.yaml.erb'), + notify => $notify_service, + } + + $options = "-config.path=${config_path} ${extra_options}" + + prometheus::daemon { 'process-exporter': + install_method => $install_method, + version => $version, + download_extension => $download_extension, + os => $os, + arch => $arch, + real_download_url => $real_download_url, + bin_dir => $bin_dir, + notify_service => $notify_service, + package_name => $package_name, + package_ensure => $package_ensure, + manage_user => $manage_user, + user => $user, + extra_groups => $extra_groups, + group => $group, + manage_group => $manage_group, + purge => $purge_config_dir, + options => $options, + init_style => $init_style, + service_ensure => $service_ensure, + service_enable => $service_enable, + manage_service => $manage_service, + } + +} diff --git a/manifests/run_service.pp b/manifests/run_service.pp index 01f3dbb15..d20845bda 100644 --- a/manifests/run_service.pp +++ b/manifests/run_service.pp @@ -12,9 +12,10 @@ if $prometheus::manage_service == true { service { 'prometheus': - ensure => $prometheus::service_ensure, - name => $init_selector, - enable => $prometheus::service_enable, + ensure => $prometheus::service_ensure, + name => $init_selector, + enable => $prometheus::service_enable, + hasrestart => true, } } } diff --git a/metadata.json b/metadata.json index 3e71145fd..694147e3c 100644 --- a/metadata.json +++ b/metadata.json @@ -1,23 +1,59 @@ { - "author": "Virgil Chereches", - "dependencies": [{"name":"puppetlabs/stdlib","version_requirement":">= 4.6.0 <5.0.0"}, - {"name":"nanliu/staging","version_requirement":">=0.4.0 <2.0.0"}], - "license": "Apache 2.0", - "name": "brutus777-prometheus", + "name": "puppet-prometheus", + "version": "1.0.0", + "author": "Vox Pupuli", + "summary": "This module installs, configures and manages the Prometheus service.", + "license": "Apache-2.0", + "source": "https://github.com/voxpupuli/puppet-prometheus.git", + "project_page": "https://github.com/voxpupuli/puppet-prometheus", + "issue_url": "https://github.com/voxpupuli/puppet-prometheus/issues", + "dependencies": [ + { + "name":"puppet/archive", + "version_requirement":">=1.3.0 <2.0.0" + }, + { + "name":"puppetlabs/stdlib", + "version_requirement":">= 4.6.0 <5.0.0" + } + ], "operatingsystem_support": [ - { + { + "operatingsystem": "Debian", + "operatingsystemrelease": [ + "7", + "8" + ] + }, + { + "operatingsystem": "Ubuntu", + "operatingsystemrelease": [ + "14.04", + "16.04" + ] + }, + { + "operatingsystem": "CentOS", "operatingsystemrelease": [ - "5", "6", "7" - ], - "operatingsystem": "RedHat" + ] + }, + { + "operatingsystem": "RedHat", + "operatingsystemrelease": [ + "6", + "7" + ] + } + ], + "requirements": [ + { + "name": "puppet", + "version_requirements": "=> 4.6.1 < 5.0.0" } - ], - "project_page": "https://github.com/brutus333/puppet-prometheus", - "requirements": [], - "source": "https://github.com/brutus333/puppet-prometheus", - "summary": "Prometheus Puppet module", - "tags": [], - "version": "0.2.00" + ], + "tags": [ + "prometheus" + ] } diff --git a/spec/acceptance/nodesets/archlinux-2-x64.yml b/spec/acceptance/nodesets/archlinux-2-x64.yml new file mode 100644 index 000000000..89b63003f --- /dev/null +++ b/spec/acceptance/nodesets/archlinux-2-x64.yml @@ -0,0 +1,13 @@ +--- +# This file is managed via modulesync +# https://github.com/voxpupuli/modulesync +# https://github.com/voxpupuli/modulesync_config +HOSTS: + archlinux-2-x64: + roles: + - master + platform: archlinux-2-x64 + box: archlinux/archlinux + hypervisor: vagrant +CONFIG: + type: foss diff --git a/spec/acceptance/nodesets/centos-511-x64.yml b/spec/acceptance/nodesets/centos-511-x64.yml new file mode 100644 index 000000000..089d646a5 --- /dev/null +++ b/spec/acceptance/nodesets/centos-511-x64.yml @@ -0,0 +1,15 @@ +--- +# This file is managed via modulesync +# https://github.com/voxpupuli/modulesync +# https://github.com/voxpupuli/modulesync_config +HOSTS: + centos-511-x64: + roles: + - master + platform: el-5-x86_64 + box: puppetlabs/centos-5.11-64-nocm + hypervisor: vagrant +CONFIG: + type: foss +... +# vim: syntax=yaml diff --git a/spec/acceptance/nodesets/centos-6-x64.yml b/spec/acceptance/nodesets/centos-6-x64.yml new file mode 100644 index 000000000..16abc8f1c --- /dev/null +++ b/spec/acceptance/nodesets/centos-6-x64.yml @@ -0,0 +1,15 @@ +--- +# This file is managed via modulesync +# https://github.com/voxpupuli/modulesync +# https://github.com/voxpupuli/modulesync_config +HOSTS: + centos-6-x64: + roles: + - master + platform: el-6-x86_64 + box: centos/6 + hypervisor: vagrant +CONFIG: + type: aio +... +# vim: syntax=yaml diff --git a/spec/acceptance/nodesets/centos-66-x64-pe.yml b/spec/acceptance/nodesets/centos-66-x64-pe.yml new file mode 100644 index 000000000..1e7aea6d4 --- /dev/null +++ b/spec/acceptance/nodesets/centos-66-x64-pe.yml @@ -0,0 +1,17 @@ +--- +# This file is managed via modulesync +# https://github.com/voxpupuli/modulesync +# https://github.com/voxpupuli/modulesync_config +HOSTS: + centos-66-x64: + roles: + - master + - database + - dashboard + platform: el-6-x86_64 + box: puppetlabs/centos-6.6-64-puppet-enterprise + hypervisor: vagrant +CONFIG: + type: pe +... +# vim: syntax=yaml diff --git a/spec/acceptance/nodesets/centos-66-x64.yml b/spec/acceptance/nodesets/centos-66-x64.yml new file mode 100644 index 000000000..42455e7ae --- /dev/null +++ b/spec/acceptance/nodesets/centos-66-x64.yml @@ -0,0 +1,15 @@ +--- +# This file is managed via modulesync +# https://github.com/voxpupuli/modulesync +# https://github.com/voxpupuli/modulesync_config +HOSTS: + centos-66-x64: + roles: + - master + platform: el-6-x86_64 + box: puppetlabs/centos-6.6-64-nocm + hypervisor: vagrant +CONFIG: + type: foss +... +# vim: syntax=yaml diff --git a/spec/acceptance/nodesets/centos-7-x64.yml b/spec/acceptance/nodesets/centos-7-x64.yml new file mode 100644 index 000000000..e05a3ae16 --- /dev/null +++ b/spec/acceptance/nodesets/centos-7-x64.yml @@ -0,0 +1,15 @@ +--- +# This file is managed via modulesync +# https://github.com/voxpupuli/modulesync +# https://github.com/voxpupuli/modulesync_config +HOSTS: + centos-7-x64: + roles: + - master + platform: el-7-x86_64 + box: centos/7 + hypervisor: vagrant +CONFIG: + type: aio +... +# vim: syntax=yaml diff --git a/spec/acceptance/nodesets/centos-72-x64.yml b/spec/acceptance/nodesets/centos-72-x64.yml new file mode 100644 index 000000000..85af89d3f --- /dev/null +++ b/spec/acceptance/nodesets/centos-72-x64.yml @@ -0,0 +1,15 @@ +--- +# This file is managed via modulesync +# https://github.com/voxpupuli/modulesync +# https://github.com/voxpupuli/modulesync_config +HOSTS: + centos-72-x64: + roles: + - master + platform: el-7-x86_64 + box: puppetlabs/centos-7.2-64-nocm + hypervisor: vagrant +CONFIG: + type: foss +... +# vim: syntax=yaml diff --git a/spec/acceptance/nodesets/debian-78-x64.yml b/spec/acceptance/nodesets/debian-78-x64.yml new file mode 100644 index 000000000..6ef6de8c8 --- /dev/null +++ b/spec/acceptance/nodesets/debian-78-x64.yml @@ -0,0 +1,15 @@ +--- +# This file is managed via modulesync +# https://github.com/voxpupuli/modulesync +# https://github.com/voxpupuli/modulesync_config +HOSTS: + debian-78-x64: + roles: + - master + platform: debian-7-amd64 + box: puppetlabs/debian-7.8-64-nocm + hypervisor: vagrant +CONFIG: + type: foss +... +# vim: syntax=yaml diff --git a/spec/acceptance/nodesets/debian-82-x64.yml b/spec/acceptance/nodesets/debian-82-x64.yml new file mode 100644 index 000000000..9897a8fc7 --- /dev/null +++ b/spec/acceptance/nodesets/debian-82-x64.yml @@ -0,0 +1,15 @@ +--- +# This file is managed via modulesync +# https://github.com/voxpupuli/modulesync +# https://github.com/voxpupuli/modulesync_config +HOSTS: + debian-82-x64: + roles: + - master + platform: debian-8-amd64 + box: puppetlabs/debian-8.2-64-nocm + hypervisor: vagrant +CONFIG: + type: foss +... +# vim: syntax=yaml diff --git a/spec/acceptance/nodesets/docker/centos-5.yml b/spec/acceptance/nodesets/docker/centos-5.yml new file mode 100644 index 000000000..c17bc3d00 --- /dev/null +++ b/spec/acceptance/nodesets/docker/centos-5.yml @@ -0,0 +1,19 @@ +--- +# This file is managed via modulesync +# https://github.com/voxpupuli/modulesync +# https://github.com/voxpupuli/modulesync_config +HOSTS: + centos-5-x64: + platform: el-5-x86_64 + hypervisor: docker + image: centos:5 + docker_preserve_image: true + docker_cmd: '["/sbin/init"]' + docker_image_commands: + - 'yum install -y crontabs initscripts iproute openssl sysvinit-tools tar wget which' + - 'sed -i -e "/mingetty/d" /etc/inittab' +CONFIG: + trace_limit: 200 + masterless: true +... +# vim: syntax=yaml diff --git a/spec/acceptance/nodesets/docker/centos-6.yml b/spec/acceptance/nodesets/docker/centos-6.yml new file mode 100644 index 000000000..d93f884cb --- /dev/null +++ b/spec/acceptance/nodesets/docker/centos-6.yml @@ -0,0 +1,20 @@ +--- +# This file is managed via modulesync +# https://github.com/voxpupuli/modulesync +# https://github.com/voxpupuli/modulesync_config +HOSTS: + centos-6-x64: + platform: el-6-x86_64 + hypervisor: docker + image: centos:6 + docker_preserve_image: true + docker_cmd: '["/sbin/init"]' + docker_image_commands: + - 'rm -rf /var/run/network/*' + - 'yum install -y crontabs initscripts iproute openssl sysvinit-tools tar wget which' + - 'rm /etc/init/tty.conf' +CONFIG: + trace_limit: 200 + masterless: true +... +# vim: syntax=yaml diff --git a/spec/acceptance/nodesets/docker/centos-7.yml b/spec/acceptance/nodesets/docker/centos-7.yml new file mode 100644 index 000000000..41e924b50 --- /dev/null +++ b/spec/acceptance/nodesets/docker/centos-7.yml @@ -0,0 +1,19 @@ +--- +# This file is managed via modulesync +# https://github.com/voxpupuli/modulesync +# https://github.com/voxpupuli/modulesync_config +HOSTS: + centos-7-x64: + platform: el-7-x86_64 + hypervisor: docker + image: centos:7 + docker_preserve_image: true + docker_cmd: '["/usr/sbin/init"]' + docker_image_commands: + - 'yum install -y crontabs initscripts iproute openssl sysvinit-tools tar wget which ss' + - 'systemctl mask getty@tty1.service' +CONFIG: + trace_limit: 200 + masterless: true +... +# vim: syntax=yaml diff --git a/spec/acceptance/nodesets/docker/debian-7.yml b/spec/acceptance/nodesets/docker/debian-7.yml new file mode 100644 index 000000000..071acbf90 --- /dev/null +++ b/spec/acceptance/nodesets/docker/debian-7.yml @@ -0,0 +1,19 @@ +--- +# This file is managed via modulesync +# https://github.com/voxpupuli/modulesync +# https://github.com/voxpupuli/modulesync_config +HOSTS: + debian-7-x64: + platform: debian-7-amd64 + hypervisor: docker + image: debian:7 + docker_preserve_image: true + docker_cmd: '["/sbin/init"]' + docker_image_commands: + - 'echo deb http://ftp.debian.org/debian wheezy-backports main >> /etc/apt/sources.list' + - 'apt-get update && apt-get install -y cron locales-all net-tools wget' +CONFIG: + trace_limit: 200 + masterless: true +... +# vim: syntax=yaml diff --git a/spec/acceptance/nodesets/docker/debian-8.yml b/spec/acceptance/nodesets/docker/debian-8.yml new file mode 100644 index 000000000..7a1f35c37 --- /dev/null +++ b/spec/acceptance/nodesets/docker/debian-8.yml @@ -0,0 +1,21 @@ +--- +# This file is managed via modulesync +# https://github.com/voxpupuli/modulesync +# https://github.com/voxpupuli/modulesync_config +HOSTS: + debian-8-x64: + platform: debian-8-amd64 + hypervisor: docker + image: debian:8 + docker_preserve_image: true + docker_cmd: '["/sbin/init"]' + docker_image_commands: + - 'echo deb http://ftp.debian.org/debian jessie-backports main >> /etc/apt/sources.list' + - 'apt-get update && apt-get install -y cron locales-all net-tools wget' + - 'rm -f /usr/sbin/policy-rc.d' + - 'systemctl mask getty@tty1.service getty-static.service' +CONFIG: + trace_limit: 200 + masterless: true +... +# vim: syntax=yaml diff --git a/spec/acceptance/nodesets/docker/ubuntu-12.04.yml b/spec/acceptance/nodesets/docker/ubuntu-12.04.yml new file mode 100644 index 000000000..ab77cda48 --- /dev/null +++ b/spec/acceptance/nodesets/docker/ubuntu-12.04.yml @@ -0,0 +1,19 @@ +--- +# This file is managed via modulesync +# https://github.com/voxpupuli/modulesync +# https://github.com/voxpupuli/modulesync_config +HOSTS: + ubuntu-1204-x64: + platform: ubuntu-12.04-amd64 + hypervisor: docker + image: ubuntu:12.04 + docker_preserve_image: true + docker_cmd: '["/sbin/init"]' + docker_image_commands: + - 'apt-get install -y net-tools wget' + - 'locale-gen en_US.UTF-8' +CONFIG: + trace_limit: 200 + masterless: true +... +# vim: syntax=yaml diff --git a/spec/acceptance/nodesets/docker/ubuntu-14.04.yml b/spec/acceptance/nodesets/docker/ubuntu-14.04.yml new file mode 100644 index 000000000..54d5e5a5b --- /dev/null +++ b/spec/acceptance/nodesets/docker/ubuntu-14.04.yml @@ -0,0 +1,21 @@ +--- +# This file is managed via modulesync +# https://github.com/voxpupuli/modulesync +# https://github.com/voxpupuli/modulesync_config +HOSTS: + ubuntu-1404-x64: + platform: ubuntu-14.04-amd64 + hypervisor: docker + image: ubuntu:14.04 + docker_preserve_image: true + docker_cmd: '["/sbin/init"]' + docker_image_commands: + - 'rm /usr/sbin/policy-rc.d' + - 'rm /sbin/initctl; dpkg-divert --rename --remove /sbin/initctl' + - 'apt-get install -y net-tools wget' + - 'locale-gen en_US.UTF-8' +CONFIG: + trace_limit: 200 + masterless: true +... +# vim: syntax=yaml diff --git a/spec/acceptance/nodesets/docker/ubuntu-16.04.yml b/spec/acceptance/nodesets/docker/ubuntu-16.04.yml new file mode 100644 index 000000000..bac2d5b34 --- /dev/null +++ b/spec/acceptance/nodesets/docker/ubuntu-16.04.yml @@ -0,0 +1,19 @@ +--- +# This file is managed via modulesync +# https://github.com/voxpupuli/modulesync +# https://github.com/voxpupuli/modulesync_config +HOSTS: + ubuntu-1604-x64: + platform: ubuntu-16.04-amd64 + hypervisor: docker + image: ubuntu:16.04 + docker_preserve_image: true + docker_cmd: '["/sbin/init"]' + docker_image_commands: + - 'apt-get install -y net-tools wget locales' + - 'locale-gen en_US.UTF-8' +CONFIG: + trace_limit: 200 + masterless: true +... +# vim: syntax=yaml diff --git a/spec/acceptance/nodesets/ec2/amazonlinux-2016091.yml b/spec/acceptance/nodesets/ec2/amazonlinux-2016091.yml new file mode 100644 index 000000000..19dd43ed7 --- /dev/null +++ b/spec/acceptance/nodesets/ec2/amazonlinux-2016091.yml @@ -0,0 +1,31 @@ +--- +# This file is managed via modulesync +# https://github.com/voxpupuli/modulesync +# https://github.com/voxpupuli/modulesync_config +# +# Additional ~/.fog config file with AWS EC2 credentials +# required. +# +# see: https://github.com/puppetlabs/beaker/blob/master/docs/how_to/hypervisors/ec2.md +# +# Amazon Linux is not a RHEL clone. +# +HOSTS: + amazonlinux-2016091-x64: + roles: + - master + platform: centos-6-x86_64 + hypervisor: ec2 + # refers to image_tempaltes.yaml AMI[vmname] entry: + vmname: amazonlinux-2016091-eu-central-1 + # refers to image_tempaltes.yaml entry inside AMI[vmname][:image]: + snapshot: aio + # t2.micro is free tier eligible (https://aws.amazon.com/en/free/): + amisize: t2.micro + # required so that beaker sanitizes sshd_config and root authorized_keys: + user: ec2-user +CONFIG: + type: aio + :ec2_yaml: spec/acceptance/nodesets/ec2/image_templates.yaml +... +# vim: syntax=yaml diff --git a/spec/acceptance/nodesets/ec2/image_templates.yaml b/spec/acceptance/nodesets/ec2/image_templates.yaml new file mode 100644 index 000000000..e50593ee0 --- /dev/null +++ b/spec/acceptance/nodesets/ec2/image_templates.yaml @@ -0,0 +1,34 @@ +# This file is managed via modulesync +# https://github.com/voxpupuli/modulesync +# https://github.com/voxpupuli/modulesync_config +# +# see also: https://github.com/puppetlabs/beaker/blob/master/docs/how_to/hypervisors/ec2.md +# +# Hint: image IDs (ami-*) for the same image are different per location. +# +AMI: + # Amazon Linux AMI 2016.09.1 (HVM), SSD Volume Type + amazonlinux-2016091-eu-central-1: + :image: + :aio: ami-af0fc0c0 + :region: eu-central-1 + # Red Hat Enterprise Linux 7.3 (HVM), SSD Volume Type + rhel-73-eu-central-1: + :image: + :aio: ami-e4c63e8b + :region: eu-central-1 + # SUSE Linux Enterprise Server 12 SP2 (HVM), SSD Volume Type + sles-12sp2-eu-central-1: + :image: + :aio: ami-c425e4ab + :region: eu-central-1 + # Ubuntu Server 16.04 LTS (HVM), SSD Volume Type + ubuntu-1604-eu-central-1: + :image: + :aio: ami-fe408091 + :region: eu-central-1 + # Microsoft Windows Server 2016 Base + windows-2016-base-eu-central-1: + :image: + :aio: ami-88ec20e7 + :region: eu-central-1 diff --git a/spec/acceptance/nodesets/ec2/rhel-73-x64.yml b/spec/acceptance/nodesets/ec2/rhel-73-x64.yml new file mode 100644 index 000000000..7fac8236a --- /dev/null +++ b/spec/acceptance/nodesets/ec2/rhel-73-x64.yml @@ -0,0 +1,29 @@ +--- +# This file is managed via modulesync +# https://github.com/voxpupuli/modulesync +# https://github.com/voxpupuli/modulesync_config +# +# Additional ~/.fog config file with AWS EC2 credentials +# required. +# +# see: https://github.com/puppetlabs/beaker/blob/master/docs/how_to/hypervisors/ec2.md +# +HOSTS: + rhel-73-x64: + roles: + - master + platform: el-7-x86_64 + hypervisor: ec2 + # refers to image_tempaltes.yaml AMI[vmname] entry: + vmname: rhel-73-eu-central-1 + # refers to image_tempaltes.yaml entry inside AMI[vmname][:image]: + snapshot: aio + # t2.micro is free tier eligible (https://aws.amazon.com/en/free/): + amisize: t2.micro + # required so that beaker sanitizes sshd_config and root authorized_keys: + user: ec2-user +CONFIG: + type: aio + :ec2_yaml: spec/acceptance/nodesets/ec2/image_templates.yaml +... +# vim: syntax=yaml diff --git a/spec/acceptance/nodesets/ec2/sles-12sp2-x64.yml b/spec/acceptance/nodesets/ec2/sles-12sp2-x64.yml new file mode 100644 index 000000000..8542154df --- /dev/null +++ b/spec/acceptance/nodesets/ec2/sles-12sp2-x64.yml @@ -0,0 +1,29 @@ +--- +# This file is managed via modulesync +# https://github.com/voxpupuli/modulesync +# https://github.com/voxpupuli/modulesync_config +# +# Additional ~/.fog config file with AWS EC2 credentials +# required. +# +# see: https://github.com/puppetlabs/beaker/blob/master/docs/how_to/hypervisors/ec2.md +# +HOSTS: + sles-12sp2-x64: + roles: + - master + platform: sles-12-x86_64 + hypervisor: ec2 + # refers to image_tempaltes.yaml AMI[vmname] entry: + vmname: sles-12sp2-eu-central-1 + # refers to image_tempaltes.yaml entry inside AMI[vmname][:image]: + snapshot: aio + # t2.micro is free tier eligible (https://aws.amazon.com/en/free/): + amisize: t2.micro + # required so that beaker sanitizes sshd_config and root authorized_keys: + user: ec2-user +CONFIG: + type: aio + :ec2_yaml: spec/acceptance/nodesets/ec2/image_templates.yaml +... +# vim: syntax=yaml diff --git a/spec/acceptance/nodesets/ec2/ubuntu-1604-x64.yml b/spec/acceptance/nodesets/ec2/ubuntu-1604-x64.yml new file mode 100644 index 000000000..9cf59d59e --- /dev/null +++ b/spec/acceptance/nodesets/ec2/ubuntu-1604-x64.yml @@ -0,0 +1,29 @@ +--- +# This file is managed via modulesync +# https://github.com/voxpupuli/modulesync +# https://github.com/voxpupuli/modulesync_config +# +# Additional ~/.fog config file with AWS EC2 credentials +# required. +# +# see: https://github.com/puppetlabs/beaker/blob/master/docs/how_to/hypervisors/ec2.md +# +HOSTS: + ubuntu-1604-x64: + roles: + - master + platform: ubuntu-16.04-amd64 + hypervisor: ec2 + # refers to image_tempaltes.yaml AMI[vmname] entry: + vmname: ubuntu-1604-eu-central-1 + # refers to image_tempaltes.yaml entry inside AMI[vmname][:image]: + snapshot: aio + # t2.micro is free tier eligible (https://aws.amazon.com/en/free/): + amisize: t2.micro + # required so that beaker sanitizes sshd_config and root authorized_keys: + user: ubuntu +CONFIG: + type: aio + :ec2_yaml: spec/acceptance/nodesets/ec2/image_templates.yaml +... +# vim: syntax=yaml diff --git a/spec/acceptance/nodesets/ec2/windows-2016-base-x64.yml b/spec/acceptance/nodesets/ec2/windows-2016-base-x64.yml new file mode 100644 index 000000000..0932e29c8 --- /dev/null +++ b/spec/acceptance/nodesets/ec2/windows-2016-base-x64.yml @@ -0,0 +1,29 @@ +--- +# This file is managed via modulesync +# https://github.com/voxpupuli/modulesync +# https://github.com/voxpupuli/modulesync_config +# +# Additional ~/.fog config file with AWS EC2 credentials +# required. +# +# see: https://github.com/puppetlabs/beaker/blob/master/docs/how_to/hypervisors/ec2.md +# +HOSTS: + windows-2016-base-x64: + roles: + - master + platform: windows-2016-64 + hypervisor: ec2 + # refers to image_tempaltes.yaml AMI[vmname] entry: + vmname: windows-2016-base-eu-central-1 + # refers to image_tempaltes.yaml entry inside AMI[vmname][:image]: + snapshot: aio + # t2.micro is free tier eligible (https://aws.amazon.com/en/free/): + amisize: t2.micro + # required so that beaker sanitizes sshd_config and root authorized_keys: + user: ec2-user +CONFIG: + type: aio + :ec2_yaml: spec/acceptance/nodesets/ec2/image_templates.yaml +... +# vim: syntax=yaml diff --git a/spec/acceptance/nodesets/fedora-24-x64.yml b/spec/acceptance/nodesets/fedora-24-x64.yml new file mode 100644 index 000000000..820b62d26 --- /dev/null +++ b/spec/acceptance/nodesets/fedora-24-x64.yml @@ -0,0 +1,15 @@ +--- +# This file is managed via modulesync +# https://github.com/voxpupuli/modulesync +# https://github.com/voxpupuli/modulesync_config +HOSTS: + fedora-24-x64: + roles: + - master + platform: fedora-24-x86_64 + box: fedora/24-cloud-base + hypervisor: vagrant +CONFIG: + type: aio +... +# vim: syntax=yaml diff --git a/spec/acceptance/nodesets/fedora-25-x64.yml b/spec/acceptance/nodesets/fedora-25-x64.yml new file mode 100644 index 000000000..60ae01179 --- /dev/null +++ b/spec/acceptance/nodesets/fedora-25-x64.yml @@ -0,0 +1,18 @@ +--- +# This file is managed via modulesync +# https://github.com/voxpupuli/modulesync +# https://github.com/voxpupuli/modulesync_config +# +# platform is fedora 24 because there is no +# puppet-agent for fedora 25 by 2016-12-30 +HOSTS: + fedora-25-x64: + roles: + - master + platform: fedora-25-x86_64 + box: fedora/25-cloud-base + hypervisor: vagrant +CONFIG: + type: aio +... +# vim: syntax=yaml diff --git a/spec/acceptance/nodesets/ubuntu-server-1204-x64.yml b/spec/acceptance/nodesets/ubuntu-server-1204-x64.yml new file mode 100644 index 000000000..29102c565 --- /dev/null +++ b/spec/acceptance/nodesets/ubuntu-server-1204-x64.yml @@ -0,0 +1,15 @@ +--- +# This file is managed via modulesync +# https://github.com/voxpupuli/modulesync +# https://github.com/voxpupuli/modulesync_config +HOSTS: + ubuntu-server-1204-x64: + roles: + - master + platform: ubuntu-12.04-amd64 + box: puppetlabs/ubuntu-12.04-64-nocm + hypervisor: vagrant +CONFIG: + type: foss +... +# vim: syntax=yaml diff --git a/spec/acceptance/nodesets/ubuntu-server-1404-x64.yml b/spec/acceptance/nodesets/ubuntu-server-1404-x64.yml new file mode 100644 index 000000000..054e65880 --- /dev/null +++ b/spec/acceptance/nodesets/ubuntu-server-1404-x64.yml @@ -0,0 +1,15 @@ +--- +# This file is managed via modulesync +# https://github.com/voxpupuli/modulesync +# https://github.com/voxpupuli/modulesync_config +HOSTS: + ubuntu-server-1404-x64: + roles: + - master + platform: ubuntu-14.04-amd64 + box: puppetlabs/ubuntu-14.04-64-nocm + hypervisor: vagrant +CONFIG: + type: foss +... +# vim: syntax=yaml diff --git a/spec/acceptance/nodesets/ubuntu-server-1604-x64.yml b/spec/acceptance/nodesets/ubuntu-server-1604-x64.yml new file mode 100644 index 000000000..bc85e0e84 --- /dev/null +++ b/spec/acceptance/nodesets/ubuntu-server-1604-x64.yml @@ -0,0 +1,15 @@ +--- +# This file is managed via modulesync +# https://github.com/voxpupuli/modulesync +# https://github.com/voxpupuli/modulesync_config +HOSTS: + ubuntu-server-1604-x64: + roles: + - master + platform: ubuntu-16.04-amd64 + box: puppetlabs/ubuntu-16.04-64-nocm + hypervisor: vagrant +CONFIG: + type: foss +... +# vim: syntax=yaml diff --git a/spec/classes/coverage_spec.rb b/spec/classes/coverage_spec.rb new file mode 100644 index 000000000..de446548b --- /dev/null +++ b/spec/classes/coverage_spec.rb @@ -0,0 +1,4 @@ +require 'rspec-puppet' + +at_exit { RSpec::Puppet::Coverage.report! } +# vim: syntax=ruby diff --git a/spec/classes/haproxy_exporter_spec.rb b/spec/classes/haproxy_exporter_spec.rb new file mode 100644 index 000000000..e9bbddbad --- /dev/null +++ b/spec/classes/haproxy_exporter_spec.rb @@ -0,0 +1,25 @@ +require 'spec_helper' + +describe 'prometheus::haproxy_exporter' do + on_supported_os.each do |os, facts| + context "on #{os}" do + let(:facts) do + facts + end + + context 'with version specified' do + let(:params) do + { + version: '0.7.1', + arch: 'amd64', + os: 'linux' + } + end + + describe 'install correct binary' do + it { is_expected.to contain_file('/usr/local/bin/haproxy_exporter').with('target' => '/opt/haproxy_exporter-0.7.1.linux-amd64/haproxy_exporter') } + end + end + end + end +end diff --git a/spec/classes/node_exporter_spec.rb b/spec/classes/node_exporter_spec.rb index 1bda49abd..a4b38f500 100644 --- a/spec/classes/node_exporter_spec.rb +++ b/spec/classes/node_exporter_spec.rb @@ -1,37 +1,25 @@ require 'spec_helper' -describe "prometheus::node_exporter" do - let :default_facts do - { - 'operatingsystem' => 'CentOS', - 'osfamily' => 'Redhat', - 'operatingsystemrelease' => '7.0', - 'architecture' => 'amd64', - 'kernel' => 'Linux', - } - end - - context 'uses the correct binary path for version' do - let(:facts) { default_facts } - - let(:params) { {:version => '0.10.0', :arch => 'amd64', :os => 'linux'} } - - it do - should contain_file('/usr/local/bin/node_exporter').with({ - 'target' => '/opt/staging/node_exporter-0.10.0.linux-amd64/node_exporter' - }) - end - end - - context 'uses the correct binary path for version' do - let(:facts) { default_facts } +describe 'prometheus::node_exporter' do + on_supported_os.each do |os, facts| + context "on #{os}" do + let(:facts) do + facts + end - let(:params) { {:version => '0.10.0', :arch => 'amd64', :os => 'linux'} } + context 'with version specified' do + let(:params) do + { + version: '0.13.0', + arch: 'amd64', + os: 'linux' + } + end - it do - should contain_file('/usr/local/bin/node_exporter').with({ - 'target' => '/opt/staging/node_exporter-0.10.0.linux-amd64/node_exporter' - }) + describe 'install correct binary' do + it { is_expected.to contain_file('/usr/local/bin/node_exporter').with('target' => '/opt/node_exporter-0.13.0.linux-amd64/node_exporter') } + end + end end end end diff --git a/spec/classes/statsd_exporter_spec.rb b/spec/classes/statsd_exporter_spec.rb deleted file mode 100644 index e69de29bb..000000000 diff --git a/spec/default_facts.yml b/spec/default_facts.yml new file mode 100644 index 000000000..13c416576 --- /dev/null +++ b/spec/default_facts.yml @@ -0,0 +1,14 @@ +# This file is managed via modulesync +# https://github.com/voxpupuli/modulesync +# https://github.com/voxpupuli/modulesync_config +# +# use default_module_facts.yaml for module specific +# facts. +# +# Hint if using with rspec-puppet-facts ("on_supported_os.each"): +# if a same named fact exists in facterdb it will be overridden. +--- +concat_basedir: "/tmp" +ipaddress: "172.16.254.254" +is_pe: false +macaddress: "AA:AA:AA:AA:AA:AA" diff --git a/spec/defines/daemon_spec.rb b/spec/defines/daemon_spec.rb deleted file mode 100644 index 63cadf95e..000000000 --- a/spec/defines/daemon_spec.rb +++ /dev/null @@ -1,68 +0,0 @@ -require 'spec_helper' - -describe "prometheus::daemon" do - let :title do - 'node_exporter' - end - - let :default_params do - { - install_method: 'url', - version: '0.13.0', - download_extension: 'tar.gz', - os: 'linux', - arch: 'amd64', - bin_dir: '/usr/local/bin', - notify_service: true, - manage_user: true, - user: 'node_exporter', - extra_groups: [], - group: 'node_exporter', - manage_group: true, - purge: true, - options: '', - init_style: 'systemd', - service_ensure: true, - service_enable: true, - manage_service: true, - real_download_url: "https://github.com/prometheus/node_exporter/releases/download/v0.13.0/node_exporter-0.13.0.linux-amd64.tar.gz", - package_name: 'node_exporter', - package_ensure: false, - } - end - - context 'should define a service' do - let(:params) { default_params } - - it do - should contain_service('node_exporter').with({ - 'ensure' => true, - 'enable' => true, - }) - end - end - - context 'should create a link to the downloaded binary' do - let(:params) { default_params } - - it do - should contain_file('/usr/local/bin/node_exporter').with({ - 'ensure' => 'link', - 'target' => '/opt/staging/node_exporter-0.13.0.linux-amd64/node_exporter' - }) - end - end - - context 'should create a user and group' do - let(:params) { default_params } - - it do - should contain_user('node_exporter').with({ - 'ensure' => 'present', - }) - should contain_group('node_exporter').with({ - 'ensure' => 'present', - }) - end - end -end diff --git a/spec/fixtures/manifests/site.pp b/spec/fixtures/manifests/site.pp deleted file mode 100644 index e69de29bb..000000000 diff --git a/spec/spec.opts b/spec/spec.opts deleted file mode 100644 index 91cd6427e..000000000 --- a/spec/spec.opts +++ /dev/null @@ -1,6 +0,0 @@ ---format -s ---colour ---loadby -mtime ---backtrace diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index dc7e9f4a0..2aa9da74c 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,2 +1,32 @@ -require 'rubygems' require 'puppetlabs_spec_helper/module_spec_helper' +require 'rspec-puppet-facts' +include RspecPuppetFacts + +if Dir.exist?(File.expand_path('../../lib', __FILE__)) + require 'coveralls' + require 'simplecov' + require 'simplecov-console' + SimpleCov.formatters = [ + SimpleCov::Formatter::HTMLFormatter, + SimpleCov::Formatter::Console, + Coveralls::SimpleCov::Formatter + ] + SimpleCov.start do + track_files 'lib/**/*.rb' + add_filter '/spec' + add_filter '/vendor' + add_filter '/.vendor' + end +end + +RSpec.configure do |c| + default_facts = { + puppetversion: Puppet.version, + facterversion: Facter.version + } + default_facts.merge!(YAML.load(File.read(File.expand_path('../default_facts.yml', __FILE__)))) if File.exist?(File.expand_path('../default_facts.yml', __FILE__)) + default_facts.merge!(YAML.load(File.read(File.expand_path('../default_module_facts.yml', __FILE__)))) if File.exist?(File.expand_path('../default_module_facts.yml', __FILE__)) + c.default_facts = default_facts +end + +# vim: syntax=ruby diff --git a/templates/process-exporter.yaml.erb b/templates/process-exporter.yaml.erb new file mode 100644 index 000000000..e7c9dbfda --- /dev/null +++ b/templates/process-exporter.yaml.erb @@ -0,0 +1,2 @@ +<% require 'yaml' -%> +<%= {"process_names" => @watched_processes}.to_yaml %> diff --git a/templates/prometheus.yaml.erb b/templates/prometheus.yaml.erb index c7e9a30ec..9c06bc334 100644 --- a/templates/prometheus.yaml.erb +++ b/templates/prometheus.yaml.erb @@ -2,5 +2,13 @@ <% global_config = scope.lookupvar('::prometheus::global_config') -%> <% rule_files = scope.lookupvar('::prometheus::rule_files') -%> <% scrape_configs = scope.lookupvar('::prometheus::scrape_configs') -%> -<% full_config = { 'global'=>global_config, 'rule_files'=>rule_files, 'scrape_configs'=>scrape_configs } -%> +<% full_config = { + 'global'=>global_config, + 'rule_files'=>rule_files, + 'scrape_configs'=>scrape_configs, + 'alerting'=>{ + 'alert_relabel_configs'=>scope.lookupvar('::prometheus::alert_relabel_config'), + 'alertmanagers'=>scope.lookupvar('::prometheus::alertmanagers_config'), + } +} -%> <%= full_config.to_yaml -%> diff --git a/tests/init.pp b/tests/init.pp deleted file mode 100644 index 22e0869b8..000000000 --- a/tests/init.pp +++ /dev/null @@ -1,5 +0,0 @@ -include prometheus -include prometheus::node_exporter -include prometheus::alertmanager -include prometheus::alerts -include prometheus::statsd_exporter From feb85194e388e90597481fa5097b4a3573e32b54 Mon Sep 17 00:00:00 2001 From: Davide Ferrari Date: Thu, 22 Jun 2017 15:55:52 +0200 Subject: [PATCH 5/6] restore puppet4 alerts --- templates/alerts.epp | 15 +++++++++++++++ templates/alerts.erb | 15 --------------- 2 files changed, 15 insertions(+), 15 deletions(-) create mode 100644 templates/alerts.epp delete mode 100644 templates/alerts.erb diff --git a/templates/alerts.epp b/templates/alerts.epp new file mode 100644 index 000000000..ba0816c38 --- /dev/null +++ b/templates/alerts.epp @@ -0,0 +1,15 @@ +<% $prometheus::alerts::alerts.each |$alert| { -%> +ALERT <%= $alert['name'] %> + IF <%= $alert['condition'] %> + FOR <%= $alert['timeduration'] %> + LABELS { + <% $alert['labels'].each |$label| { -%> + <%= $label['name'] %> = "<%= $label['content'] %>", + <% } -%> + } + ANNOTATIONS { + <% $alert['annotations'].each |$annotation| { -%> + <%= $annotation['name'] %> = "<%= $annotation['content'] %>", + <% } -%> + } +<% } -%> diff --git a/templates/alerts.erb b/templates/alerts.erb deleted file mode 100644 index 92f574686..000000000 --- a/templates/alerts.erb +++ /dev/null @@ -1,15 +0,0 @@ -<% @alerts.each do |alert| -%> -ALERT <%= alert['name'] %> - IF <%= alert['condition'] %> - FOR <%= alert['timeduration'] %> - LABELS { - <% alert['labels'].each do |label| -%> - <%= label['name'] %> = "<%= label['content'] %>", - <% end -%> - } - ANNOTATIONS { - <% alert['annotations'].each do |annotation| -%> - <%= annotation['name'] %> = "<%= annotation['content'] %>", - <% end -%> - } -<% end -%> From 00b9f23098719e1ec16d048b91309062203ea931 Mon Sep 17 00:00:00 2001 From: Davide Ferrari Date: Fri, 23 Jun 2017 10:55:19 +0200 Subject: [PATCH 6/6] Replaced internal systemd reload with external systemd module's one --- .fixtures.yml | 1 + manifests/config.pp | 10 +++------- metadata.json | 4 ++++ 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/.fixtures.yml b/.fixtures.yml index 2fd3ba85c..c25bfadb4 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -2,5 +2,6 @@ fixtures: repositories: archive: "https://github.com/voxpupuli/puppet-archive" stdlib: "https://github.com/puppetlabs/puppetlabs-stdlib" + systemd: "https://github.com/camptocamp/puppet-systemd" symlinks: "prometheus": "#{source_dir}" diff --git a/manifests/config.pp b/manifests/config.pp index 0d05d30e1..ad796f415 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -12,13 +12,14 @@ # the vast majority of files here are init-files # so any change there should trigger a full service restart + # systemd reload comes from the systemd module if $::prometheus::restart_on_change { File { notify => [Class['::prometheus::run_service']], } - $systemd_notify = [Exec['prometheus-systemd-reload'], Class['::prometheus::run_service']] + $systemd_notify = [Exec['systemctl-daemon-reload'], Class['::prometheus::run_service']] } else { - $systemd_notify = Exec['prometheus-systemd-reload'] + $systemd_notify = Exec['systemctl-daemon-reload'] } case $prometheus::init_style { @@ -45,11 +46,6 @@ notify => $systemd_notify, content => template('prometheus/prometheus.systemd.erb'), } - exec { 'prometheus-systemd-reload': - command => 'systemctl daemon-reload', - path => [ '/usr/bin', '/bin', '/usr/sbin' ], - refreshonly => true, - } } 'sysv' : { file { '/etc/init.d/prometheus': diff --git a/metadata.json b/metadata.json index 694147e3c..3eb6ce80e 100644 --- a/metadata.json +++ b/metadata.json @@ -12,6 +12,10 @@ "name":"puppet/archive", "version_requirement":">=1.3.0 <2.0.0" }, + { + "name":"camptocamp/systemd", + "version_requirement":">=0.4.0 <1.0.0" + }, { "name":"puppetlabs/stdlib", "version_requirement":">= 4.6.0 <5.0.0"