2 changes: 1 addition & 1 deletion .msync.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
modulesync_config_version: '1.5.0'
modulesync_config_version: '1.6.0'
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Style/HashSyntax:
Style/RedundantReturn:
Enabled: True

Style/EndOfLine:
Layout/EndOfLine:
Enabled: False

Lint/AmbiguousOperator:
Expand Down
31 changes: 13 additions & 18 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,24 @@ dist: trusty
language: ruby
cache: bundler
before_install:
- bundle -v
- rm Gemfile.lock || true
- gem update --system
- gem update bundler
- gem --version
- bundle -v
- rm -f Gemfile.lock
script:
- 'bundle exec rake $CHECK'
matrix:
fast_finish: true
include:
- rvm: 2.1.9
bundler_args: --without system_tests development release
env: PUPPET_VERSION="~> 4.0" CHECK=test PARALLEL_TEST_PROCESSORS=16
- rvm: 2.4.2
bundler_args: --without system_tests development release
env: PUPPET_VERSION="~> 5.0" CHECK=test_with_coveralls
- rvm: 2.4.2
bundler_args: --without system_tests development release
env: PUPPET_VERSION="~> 5.0" CHECK=rubocop
- rvm: 2.4.2
bundler_args: --without system_tests development release
env: PUPPET_VERSION="~> 5.0" CHECK=build DEPLOY_TO_FORGE=yes
- rvm: 2.4.2
bundler_args: --without development release
dist: trusty
Expand All @@ -39,18 +46,6 @@ matrix:
env: PUPPET_INSTALL_TYPE=agent BEAKER_debug=true BEAKER_set=docker/centos-7 CHECK=beaker
services: docker
sudo: required
- rvm: 2.1.9
bundler_args: --without system_tests development release
env: PUPPET_VERSION="~> 4.0" CHECK=test PARALLEL_TEST_PROCESSORS=16
- rvm: 2.4.2
bundler_args: --without system_tests development release
env: PUPPET_VERSION="~> 5.0" CHECK=test_with_coveralls
- rvm: 2.4.2
bundler_args: --without system_tests development release
env: PUPPET_VERSION="~> 5.0" CHECK=rubocop
- rvm: 2.4.2
bundler_args: --without system_tests development release
env: PUPPET_VERSION="~> 5.0" CHECK=build DEPLOY_TO_FORGE=yes
branches:
only:
- master
Expand Down
36 changes: 35 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,39 @@ All notable changes to this project will be documented in this file.
Each new release typically also includes the latest modulesync defaults.
These should not affect the functionality of the module.

## [v4.0.0](https://github.com/voxpupuli/puppet-prometheus/tree/v4.0.0) (2018-01-04)

[Full Changelog](https://github.com/voxpupuli/puppet-prometheus/compare/v3.1.0...v4.0.0)

**Breaking changes:**

- Bump dependencies [\#124](https://github.com/voxpupuli/puppet-prometheus/pull/124) ([juniorsysadmin](https://github.com/juniorsysadmin))
- Add validation to config changes [\#122](https://github.com/voxpupuli/puppet-prometheus/pull/122) ([costela](https://github.com/costela))

**Implemented enhancements:**

- Install Promtool [\#31](https://github.com/voxpupuli/puppet-prometheus/issues/31)
- add explicit parameter for retention [\#137](https://github.com/voxpupuli/puppet-prometheus/pull/137) ([costela](https://github.com/costela))
- Feature/alerts prometheus2 [\#127](https://github.com/voxpupuli/puppet-prometheus/pull/127) ([jhooyberghs](https://github.com/jhooyberghs))

**Fixed bugs:**

- not up to date dependencies: puppetlabs-stdlib should be \>= 4.13.0 [\#123](https://github.com/voxpupuli/puppet-prometheus/issues/123)
- prometheus.yaml broken syntax when generated from hiera [\#108](https://github.com/voxpupuli/puppet-prometheus/issues/108)
- prometheus systemd wants and depends "multi-user.target" [\#139](https://github.com/voxpupuli/puppet-prometheus/pull/139) ([bastelfreak](https://github.com/bastelfreak))
- daemon: explicitly pass provider to service [\#133](https://github.com/voxpupuli/puppet-prometheus/pull/133) ([costela](https://github.com/costela))

**Closed issues:**

- Minor: add explicit retention option? [\#136](https://github.com/voxpupuli/puppet-prometheus/issues/136)
- node\_exporter: "Could not find init script for node\_exporter" [\#132](https://github.com/voxpupuli/puppet-prometheus/issues/132)
- Usage of `puppet` in custom alertmanager fact breaks if puppet not in $PATH \(e.g. systemd service\) [\#130](https://github.com/voxpupuli/puppet-prometheus/issues/130)

**Merged pull requests:**

- Use puppet internals to determine the state of the alert\_manager [\#131](https://github.com/voxpupuli/puppet-prometheus/pull/131) ([vStone](https://github.com/vStone))
- Correct typo in documentation header for node\_exporter [\#121](https://github.com/voxpupuli/puppet-prometheus/pull/121) ([jhooyberghs](https://github.com/jhooyberghs))

## [v3.1.0](https://github.com/voxpupuli/puppet-prometheus/tree/v3.1.0) (2017-11-26)

[Full Changelog](https://github.com/voxpupuli/puppet-prometheus/compare/v3.0.0...v3.1.0)
Expand All @@ -30,6 +63,7 @@ These should not affect the functionality of the module.

**Merged pull requests:**

- release 3.1.0 [\#115](https://github.com/voxpupuli/puppet-prometheus/pull/115) ([bastelfreak](https://github.com/bastelfreak))
- replace all Variant\[Undef.. with Optional\[... [\#103](https://github.com/voxpupuli/puppet-prometheus/pull/103) ([TheMeier](https://github.com/TheMeier))
- release 3.0.0 [\#99](https://github.com/voxpupuli/puppet-prometheus/pull/99) ([bastelfreak](https://github.com/bastelfreak))
- Tests for prometheus::daemon [\#87](https://github.com/voxpupuli/puppet-prometheus/pull/87) ([sathieu](https://github.com/sathieu))
Expand Down Expand Up @@ -204,4 +238,4 @@ These should not affect the functionality of the module.



\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
\* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ group :system_tests do
end

group :release do
gem 'github_changelog_generator', :require => false if RUBY_VERSION >= '2.2.2'
gem 'github_changelog_generator', :require => false, :git => 'https://github.com/skywinder/github-changelog-generator'
gem 'puppet-blacksmith', :require => false
gem 'voxpupuli-release', :require => false, :git => 'https://github.com/voxpupuli/voxpupuli-release-gem'
gem 'puppet-strings', '~> 1.0', :require => false
Expand Down
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ or simply:
include ::prometheus
```

To add alert rules, add the following to the class prometheus:
To add alert rules, add the following to the class prometheus in case you are using prometheus < 2.0:
```puppet
alerts => [{ 'name' => 'InstanceDown', 'condition' => 'up == 0', 'timeduration' => '5m', labels => [{ 'name' => 'severity', 'content' => 'page'}], 'annotations' => [{ 'name' => 'summary', content => 'Instance {{ $labels.instance }} down'}, {'name' => 'description', content => '{{ $labels.instance }} of job {{ $labels.job }} has been down for more than 5 minutes.' }]}]
```
Expand All @@ -91,6 +91,23 @@ alertrules:

```

When using prometheus >= 2.0, we use the new yaml format (https://prometheus.io/docs/prometheus/2.0/migration/#recording-rules-and-alerts) configuration

```yaml
alerts:
groups:
- name: alert.rules
rules:
- alert: 'InstanceDown'
expr: 'up == 0'
for: '5m'
labels:
'severity': 'page'
annotations:
'summary': 'Instance {{ $labels.instance }} down'
'description': '{{ $labels.instance }} of job {{ $labels.job }} has been down for more than 5 minutes.'
```
On the monitored nodes:
```puppet
Expand Down
27 changes: 27 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ exclude_paths = %w(
PuppetLint.configuration.ignore_paths = exclude_paths
PuppetSyntax.exclude_paths = exclude_paths

desc 'Auto-correct puppet-lint offenses'
task 'lint:auto_correct' do
PuppetLint.configuration.fix = true
Rake::Task[:lint].invoke
end

desc 'Run acceptance tests'
RSpec::Core::RakeTask.new(:acceptance) do |t|
t.pattern = 'spec/acceptance'
Expand All @@ -48,6 +54,27 @@ task test_with_coveralls: [:test] do
end
end

desc "Print supported beaker sets"
task 'beaker_sets', [:directory] do |t, args|
directory = args[:directory]

metadata = JSON.load(File.read('metadata.json'))

(metadata['operatingsystem_support'] || []).each do |os|
(os['operatingsystemrelease'] || []).each do |release|
if directory
beaker_set = "#{directory}/#{os['operatingsystem'].downcase}-#{release}"
else
beaker_set = "#{os['operatingsystem'].downcase}-#{release}-x64"
end

filename = "spec/acceptance/nodesets/#{beaker_set}.yml"

puts beaker_set if File.exists? filename
end
end
end

begin
require 'github_changelog_generator/task'
GitHubChangelogGenerator::RakeTask.new :changelog do |config|
Expand Down
6 changes: 5 additions & 1 deletion lib/facter/alert_manager_running.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
require 'puppet'

service = Puppet::Type.type(:service).new(name: 'alert_manager')

Facter.add('prometheus_alert_manager_running') do
setcode do
Facter::Core::Execution.execute('puppet resource service alert_manager 2>&1').scan('running')[0]
service.provider.status == :running
end
end
40 changes: 26 additions & 14 deletions manifests/alerts.pp
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,37 @@
# This module manages prometheus alerts for prometheus
#
# [*location*]
# Whether to create the alert file for prometheus
# Where to create the alert file for prometheus
#
# [*alerts*]
# Array of alerts (see README)
# Array (< prometheus 2.0.0) or Hash (>= prometheus 2.0.0) of alerts (see README).
#
# [*alertfile_name*]
# Filename to use when storing the alerts file
#
class prometheus::alerts (
String $location,
Array $alerts,
String $alertfile_name = 'alert.rules'
Variant[Array,Hash] $alerts,
String $alertfile_name = $prometheus::params::alertfile_name,
) inherits prometheus::params {

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"),
}
if ( versioncmp($::prometheus::version, '2.0.0') < 0 ){
file { "${location}/${alertfile_name}":
ensure => 'file',
owner => $prometheus::user,
group => $prometheus::group,
notify => Class['::prometheus::service_reload'],
content => epp("${module_name}/alerts.epp"),
validate_cmd => "${prometheus::bin_dir}/promtool check-rules %",
}
}
else {
file { "${location}/${alertfile_name}":
ensure => 'file',
owner => $prometheus::user,
group => $prometheus::group,
notify => Class['::prometheus::service_reload'],
content => $alerts.to_yaml,
validate_cmd => "${prometheus::bin_dir}/promtool check rules %",
}

}
}
35 changes: 19 additions & 16 deletions manifests/config.pp
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Class prometheus::config
# Configuration class for prometheus monitoring system
class prometheus::config(
class prometheus::config (
$global_config,
$rule_files,
$scrape_configs,
$remote_read_configs,
$purge = true,
$config_template = $::prometheus::params::config_template,
$storage_retention = $::prometheus::params::storage_retention,
) {

if $prometheus::init_style {
Expand All @@ -19,6 +19,7 @@
$daemon_flags = [
"-config.file=${::prometheus::config_dir}/prometheus.yaml",
"-storage.local.path=${::prometheus::localstorage}",
"-storage.local.retention=${storage_retention}",
"-web.console.templates=${::prometheus::shared_dir}/consoles",
"-web.console.libraries=${::prometheus::shared_dir}/console_libraries",
]
Expand All @@ -28,6 +29,7 @@
$daemon_flags = [
"--config.file=${::prometheus::config_dir}/prometheus.yaml",
"--storage.tsdb.path=${::prometheus::localstorage}",
"--storage.tsdb.retention=${storage_retention}",
"--web.console.templates=${::prometheus::shared_dir}/consoles",
"--web.console.libraries=${::prometheus::shared_dir}/console_libraries",
]
Expand Down Expand Up @@ -104,21 +106,22 @@
}
}

file { $prometheus::config_dir:
ensure => 'directory',
owner => $prometheus::user,
group => $prometheus::group,
purge => $purge,
recurse => $purge,
if versioncmp($prometheus::version, '2.0.0') >= 0 {
$cfg_verify_cmd = 'check config'
} else {
$cfg_verify_cmd = 'check-config'
}
-> file { 'prometheus.yaml':
ensure => present,
path => "${prometheus::config_dir}/prometheus.yaml",
owner => $prometheus::user,
group => $prometheus::group,
mode => $prometheus::config_mode,
notify => Class['::prometheus::service_reload'],
content => template($config_template),

file { 'prometheus.yaml':
ensure => present,
path => "${prometheus::config_dir}/prometheus.yaml",
owner => $prometheus::user,
group => $prometheus::group,
mode => $prometheus::config_mode,
notify => Class['::prometheus::service_reload'],
require => File["${prometheus::config_dir}/${prometheus::alertfile_name}"],
content => template($config_template),
validate_cmd => "${prometheus::bin_dir}/promtool ${cfg_verify_cmd} %",
}

}
13 changes: 10 additions & 3 deletions manifests/daemon.pp
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,18 @@
default => $name,
}

$real_provider = $init_style ? {
'sles' => 'redhat', # mimics puppet's default behaviour
'sysv' => 'redhat', # all currently used cases for 'sysv' are redhat-compatible
default => $init_style,
}

if $manage_service == true {
service { $name:
ensure => $service_ensure,
name => $init_selector,
enable => $service_enable,
ensure => $service_ensure,
name => $init_selector,
enable => $service_enable,
provider => $real_provider,
}
}
}
Loading