Skip to content
This repository was archived by the owner on Jun 1, 2023. It is now read-only.

Commit 79de36f

Browse files
authored
Merge pull request #139 from jarretlavallee/client_auth
Enable remote PuppetDB collection in 2019.8.5+
2 parents 357bd69 + 0c232d9 commit 79de36f

File tree

14 files changed

+70
-33
lines changed

14 files changed

+70
-33
lines changed

functions/localhost_or_hosts_with_pe_profile.pp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,23 @@
1212
function puppet_metrics_dashboard::localhost_or_hosts_with_pe_profile(
1313
String $profile,
1414
) >> Array {
15-
if ($profile == 'puppetdb') and (puppet_metrics_dashboard::puppetdb_no_remote_metrics()) {
16-
if $facts['puppet_server'] == $trusted['certname'] {
17-
$hosts = ['localhost']
15+
if ($profile == 'puppetdb') {
16+
if $settings::storeconfigs {
17+
# PuppetDB metrics in the following versions can only be reached via localhost
18+
# PE 2018.1.13 - PE 2019.0.0
19+
# PE 2019.5 - PE 2019.8.4
20+
$hosts = puppetdb_query('inventory[certname]{
21+
facts.puppet_metrics_dashboard.versions.puppetdb >= "6.15.0" or
22+
facts.puppet_metrics_dashboard.versions.puppetdb < "5.2.13"
23+
}').map |$nodes| { $nodes['certname'] }
1824
} else {
1925
$hosts = []
2026
}
27+
if empty($hosts) and $facts.dig('puppet_metrics_dashboard', 'versions', 'puppetdb') {
28+
['localhost']
29+
} else {
30+
sort($hosts)
31+
}
2132
} else {
2233
if $settings::storeconfigs {
2334
$_profile = capitalize($profile)

functions/puppetdb_no_remote_metrics.pp

Lines changed: 0 additions & 13 deletions
This file was deleted.

functions/puppetdb_v2_metrics.pp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# @summary function used to determine if the metrics v2 endpoint in PuppetDB can be used
2+
3+
function puppet_metrics_dashboard::puppetdb_v2_metrics() >> Boolean {
4+
if versioncmp($facts['puppetversion'], '5.5.19') >= 0 {
5+
true
6+
} else {
7+
false
8+
}
9+
}

lib/facter/overwrite_dashboards.rb

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Facter.add(:puppet_metrics_dashboard) do
2+
confine kernel: 'linux'
3+
4+
setcode do
5+
result = { versions: {} }
6+
if File.readable?('/opt/puppetlabs/server/apps/puppetdb/ezbake.manifest')
7+
version = File.read('/opt/puppetlabs/server/apps/puppetdb/ezbake.manifest').match(%r{puppetlabs/puppetdb "(.*)"})
8+
9+
result[:versions][:puppetdb] = version.captures.first.gsub(%r{^(\d+\.\d+\.\d+).*}, '\1') unless version.nil?
10+
end
11+
12+
result[:overwrite_dashboards_disabled] = File.exist?('/opt/puppetlabs/puppet/cache/state/overwrite_dashboards_disabled')
13+
14+
result
15+
end
16+
end

manifests/dashboards.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
mode => '0644',
1616
}
1717

18-
$_overwrite = $facts['overwrite_dashboards_disabled'] ? {
18+
$_overwrite = $facts.dig('puppet_metrics_dashboard', 'overwrite_dashboards_disabled') ? {
1919
true => false,
2020
default => true,
2121
}

manifests/dashboards/telegraf.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
default => 'http',
1010
}
1111

12-
if puppet_metrics_dashboard::puppetdb_no_remote_metrics() {
12+
if puppet_metrics_dashboard::puppetdb_v2_metrics() {
1313
$pdb_dash_version = '_v2'
1414
} else {
1515
$pdb_dash_version = undef

manifests/profile/puppetdb.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
default => 'http'
5959
}
6060

61-
if puppet_metrics_dashboard::puppetdb_no_remote_metrics() {
61+
if puppet_metrics_dashboard::puppetdb_v2_metrics() {
6262
$metrics_version = 'v2/read'
6363
} else {
6464
$metrics_version = 'v1/mbeans'

spec/classes/dashboards/graphite_spec.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111
<<-PRE_COND
1212
class {'puppet_metrics_dashboard':
1313
add_dashboard_examples => false,
14-
influxdb_database_name => ['puppet_metrics','telegraf','graphite'],
14+
influxdb_database_name => ['graphite'],
1515
grafana_password => 'puppetlabs',
16+
enable_telegraf => false,
17+
configure_telegraf => false,
1618
}
1719
PRE_COND
1820
end

spec/classes/dashboards/puppet_metrics_spec.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111
<<-PRE_COND
1212
class {'puppet_metrics_dashboard':
1313
add_dashboard_examples => false,
14-
influxdb_database_name => ['puppet_metrics','telegraf','graphite'],
14+
influxdb_database_name => ['puppet_metrics'],
1515
grafana_password => 'puppetlabs',
16+
enable_telegraf => false,
17+
configure_telegraf => false,
1618
}
1719
PRE_COND
1820
end

0 commit comments

Comments
 (0)