Skip to content

Commit

Permalink
also add check to rules file; centralize $alertfile_name in params
Browse files Browse the repository at this point in the history
  • Loading branch information
costela committed Nov 30, 2017
1 parent 8856269 commit bec0510
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
22 changes: 13 additions & 9 deletions manifests/alerts.pp
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,21 @@
class prometheus::alerts (
String $location,
Array $alerts,
String $alertfile_name = 'alert.rules'
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 {
$rule_verify_cmd = 'check rules'
} else {
$rule_verify_cmd = 'check-rules'
}

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 ${rule_verify_cmd} %",
}
}
3 changes: 2 additions & 1 deletion manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@
$beanstalkd_exporter_config = '/etc/beanstalkd-exporter.conf'
$package_ensure = 'latest'
$package_name = 'prometheus'
$rule_files = [ "${config_dir}/alert.rules" ]
$alertfile_name = 'alert.rules'
$rule_files = [ "${config_dir}/${alertfile_name}" ]
$scrape_configs = [ { 'job_name'=> 'prometheus', 'scrape_interval'=> '10s', 'scrape_timeout'=> '10s', 'static_configs'=> [ { 'targets'=> [ 'localhost:9090' ], 'labels'=> { 'alias'=> 'Prometheus'} } ] } ]
$remote_read_configs = []
$shared_dir = '/usr/local/share/prometheus'
Expand Down
2 changes: 1 addition & 1 deletion spec/classes/prometheus_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@

# prometheus::alerts
it {
is_expected.not_to contain_file('/etc/prometheus/alert.rules')
is_expected.to contain_file('/etc/prometheus/alert.rules')
}

# prometheus::run_service
Expand Down

0 comments on commit bec0510

Please sign in to comment.