Puppet Class: puppet_operational_dashboards::profile::dashboards

Defined in:
manifests/profile/dashboards.pp

Summary

Installs Grafana and several dashboards to display Puppet metrics. Included via the base class.

Overview

Examples:

Basic usage

include puppet_operational_dashboards

class {'puppet_operational_dashboards::profile::dashboards':
  token         => '<my_sensitive_token>',
  influxdb_host => '<influxdb_fqdn>',
  influxdb_port => 8086,
  initial_bucket => '<my_bucket>',
}

Parameters:

  • token (Optional[Sensitive[String]]) (defaults to: $puppet_operational_dashboards::telegraf_token)

    Token in Sensitive format used to query InfluxDB. The token must grant priviledges to query the associated bucket in InfluxDB

  • grafana_host (String) (defaults to: $facts['networking']['fqdn'])

    FQDN of the Grafana host.

  • grafana_port (Integer) (defaults to: 3000)

    Port used by the Grafana service.

  • grafana_use_ssl (Boolean) (defaults to: false)

    Enable use of HTTPS/SSL for Grafana.

  • manage_grafana_ssl (Boolean) (defaults to: true)

    Whether to manage the SSL certificate files when using the grafana_use_ssl parameter.

  • grafana_cert_file (Stdlib::Absolutepath) (defaults to: '/etc/grafana/client.pem')

    SSL certificate file to use when ‘grafana_use_ssl’ and ‘manage_grafana’ are enabled.

  • grafana_key_file (Stdlib::Absolutepath) (defaults to: '/etc/grafana/client.key')

    SSL private key file to use when ‘grafana_use_ssl’ and ‘manage_grafana’ are enabled.

  • grafana_cert_file_source (Stdlib::Absolutepath) (defaults to: "/etc/puppetlabs/puppet/ssl/certs/${trusted['certname']}.pem")

    SSL certificate file to use as the source for the grafana_cert_file parameter.

  • grafana_key_file_source (Stdlib::Absolutepath) (defaults to: "/etc/puppetlabs/puppet/ssl/private_keys/${trusted['certname']}.pem")

    SSL certificate file to use as the source for the grafana_key_file parameter.

  • grafana_timeout (Integer) (defaults to: 10)

    How long to wait for the Grafana service to start.

  • grafana_password (Sensitive[String]) (defaults to: Sensitive('admin'))

    Grafana admin password in Sensitive format.

  • grafana_version (String) (defaults to: '8.5.27')

    Version of the Grafana package to install.

  • grafana_datasource (String) (defaults to: 'influxdb_puppet')

    Name to use for the Grafana datasource.

  • grafana_install (String) (defaults to: $facts['os']['family'] ? { /(RedHat|Debian)/ => 'repo', default => 'package')

    Method to use for installing Grafana.

  • use_ssl (Boolean) (defaults to: $puppet_operational_dashboards::use_ssl)

    Whether to use SSL when querying InfluxDB.

  • use_system_store (Boolean) (defaults to: $puppet_operational_dashboards::use_system_store)

    Whether to use the system CA bundle.

  • manage_grafana (Boolean) (defaults to: true)

    Whether to manage installation and configuration of Grafana.

  • manage_grafana_repo (Boolean) (defaults to: true)

    Whether to manage the Grafana repository definition.

  • influxdb_host (String) (defaults to: $puppet_operational_dashboards::influxdb_host)

    FQDN of the InfluxDB host.

  • influxdb_port (Integer) (defaults to: $puppet_operational_dashboards::influxdb_port)

    Port used by the InfluxDB service.

  • influxdb_bucket (String) (defaults to: $puppet_operational_dashboards::initial_bucket)

    Name of the InfluxDB bucket to query.

  • telegraf_token_name (String) (defaults to: $puppet_operational_dashboards::telegraf_token_name)

    Name of the token to retrieve from InfluxDB if not given $token

  • influxdb_token_file (Stdlib::Absolutepath) (defaults to: $puppet_operational_dashboards::influxdb_token_file)

    Location on disk of an InfluxDB admin token. This token is used in this class in a Deferred function call to retrieve a Telegraf token if $token is unset

  • provisioning_datasource_file (Stdlib::Absolutepath) (defaults to: '/etc/grafana/provisioning/datasources/influxdb.yaml')

    Location on disk to store datasource definition

  • include_pe_metrics (Boolean) (defaults to: $puppet_operational_dashboards::include_pe_metrics)

    Whether to include Filesync and Orchestrator dashboards

  • manage_system_board (Boolean) (defaults to: $puppet_operational_dashboards::manage_system_board)

    Whether the System Performance dashboard should be created

  • system_dashboard_version (Enum['v1', 'v2', 'all']) (defaults to: 'v2')

    Version of the system dashboard to manage. v2 is compatible with puppet_metrics_collector version 7 and up



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
# File 'manifests/profile/dashboards.pp', line 66

class puppet_operational_dashboards::profile::dashboards (
  Optional[Sensitive[String]] $token = $puppet_operational_dashboards::telegraf_token,
  String $grafana_host = $facts['networking']['fqdn'],
  Integer $grafana_port = 3000,
  Boolean $grafana_use_ssl = false,
  Boolean $manage_grafana_ssl = true,
  Stdlib::Absolutepath $grafana_cert_file_source = "/etc/puppetlabs/puppet/ssl/certs/${trusted['certname']}.pem",
  Stdlib::Absolutepath $grafana_key_file_source ="/etc/puppetlabs/puppet/ssl/private_keys/${trusted['certname']}.pem",
  Stdlib::Absolutepath $grafana_cert_file = '/etc/grafana/client.pem',
  Stdlib::Absolutepath $grafana_key_file = '/etc/grafana/client.key',
  Integer $grafana_timeout = 10,
  #TODO: document using task to change
  Sensitive[String] $grafana_password = Sensitive('admin'),
  String $grafana_version = '8.5.27',
  String $grafana_datasource = 'influxdb_puppet',
  String $grafana_install = $facts['os']['family'] ? {
    /(RedHat|Debian)/ => 'repo',
    default           => 'package',
  },
  Stdlib::Absolutepath $provisioning_datasource_file = '/etc/grafana/provisioning/datasources/influxdb.yaml',
  Boolean $use_ssl = $puppet_operational_dashboards::use_ssl,
  Boolean $use_system_store = $puppet_operational_dashboards::use_system_store,
  Boolean $manage_grafana = true,
  Boolean $manage_grafana_repo = true,
  String $influxdb_host = $puppet_operational_dashboards::influxdb_host,
  Integer $influxdb_port = $puppet_operational_dashboards::influxdb_port,
  String $influxdb_bucket = $puppet_operational_dashboards::initial_bucket,
  String $telegraf_token_name = $puppet_operational_dashboards::telegraf_token_name,
  Stdlib::Absolutepath $influxdb_token_file = $puppet_operational_dashboards::influxdb_token_file,
  Boolean $include_pe_metrics = $puppet_operational_dashboards::include_pe_metrics,
  Boolean $manage_system_board = $puppet_operational_dashboards::manage_system_board,
  Enum['v1', 'v2', 'all'] $system_dashboard_version = 'v2',
) {
  $grafana_protocol = $grafana_use_ssl ? {
    true  => 'https',
    false => 'http',
  }
  $grafana_url = "${grafana_protocol}://${grafana_host}:${grafana_port}"

  $protocol = $use_ssl ? {
    true  => 'https',
    false => 'http',
  }
  $influxdb_uri = "${protocol}://${influxdb_host}:${influxdb_port}"

  if $manage_grafana {
    if $grafana_use_ssl {
      $grafana_cfg = {
        'server' => {
          'protocol' => 'https',
          'cert_file' => $grafana_cert_file,
          'cert_key' => $grafana_key_file,
        },
      }
      class { 'grafana':
        install_method      => $grafana_install,
        version             => $grafana_version,
        manage_package_repo => $manage_grafana_repo,
        cfg                 => $grafana_cfg,
      }
      if $manage_grafana_ssl {
        file { $grafana_key_file:
          ensure => file,
          source => "file:///${grafana_key_file_source}",
          notify => Service['grafana-server'],
        }
        file { $grafana_cert_file:
          ensure => file,
          source => "file:///${grafana_cert_file_source}",
          notify => Service['grafana-server'],
        }
      }
    }
    else {
      class { 'grafana':
        install_method      => $grafana_install,
        version             => $grafana_version,
        manage_package_repo => $manage_grafana_repo,
      }
    }

    file { 'grafana-conf-d':
      ensure => directory,
      path   => '/etc/systemd/system/grafana-server.service.d',
    }
    file { 'wait-for-grafana':
      ensure    => file,
      path      => '/etc/systemd/system/grafana-server.service.d/wait.conf',
      subscribe => Exec['puppet_grafana_daemon_reload'],
      content   => epp('puppet_operational_dashboards/grafana_wait.epp', { timeout => $grafana_timeout, port => $grafana_port }),
    }

    exec { 'puppet_grafana_daemon_reload':
      command     => 'systemctl daemon-reload',
      path        => ['/bin', '/usr/bin'],
      refreshonly => true,
      notify      => Service['grafana-server'],
    }

    # Require the install class for any dashboards when managing Grafana
    Grafana_dashboard {
      require => Class['grafana::install'],
    }

    if $token {
      file { 'grafana_provisioning_datasource':
        ensure  => file,
        path    => $provisioning_datasource_file,
        mode    => '0600',
        owner   => 'grafana',
        content => inline_epp(file('puppet_operational_dashboards/datasource.epp'), {
            name     => $grafana_datasource,
            token    => $token,
            database => $influxdb_bucket,
            url      => $influxdb_uri,
        }),
        require => Class['grafana::install'],
        notify  => Service['grafana-server'],
      }
    }
    else {
      $token_vars = {
        name     => $grafana_datasource,
        token => Sensitive(Deferred('influxdb::retrieve_token',
          [$influxdb_uri, $telegraf_token_name, $influxdb_token_file, $use_system_store])
        ),
        database => $influxdb_bucket,
        url      => $influxdb_uri,
      }

      file { $provisioning_datasource_file:
        ensure  => file,
        mode    => '0600',
        owner   => 'grafana',
        content => Deferred('inline_epp',
        [file('puppet_operational_dashboards/datasource.epp'), $token_vars]),
        require => Class['grafana::install'],
        notify  => Service['grafana-server'],
      }
    }
  }

  ['Puppetserver', 'Puppetdb', 'Postgresql'].each |$service| {
    grafana_dashboard { "${service} Performance":
      grafana_user     => 'admin',
      grafana_password => $grafana_password.unwrap,
      grafana_url      => $grafana_url,
      content          => file("puppet_operational_dashboards/${service}_performance.json"),
    }
  }

  $ensure_system_performance =  $manage_system_board ? {
    true    => 'present',
    default => 'absent',
  }
  $system_dashboards = $system_dashboard_version ? {
    'all' => ['System', 'System_v2'],
    'v1'  => ['System'],
    'v2'  => ['System_v2'],
  }

  # ensure => absent should remove both versions of the system performance dashboards
  if $ensure_system_performance == 'absent' {
    ['System Performance', 'System_v2 Performance'].each |$board| {
      grafana_dashboard { $board:
        ensure           => 'absent',
        grafana_user     => 'admin',
        grafana_password => $grafana_password.unwrap,
        grafana_url      => $grafana_url,
        content          => '{}',
      }
    }
  }
  else {
    $system_dashboards.each |$board| {
      grafana_dashboard { "${board} Performance":
        ensure           => present,
        grafana_user     => 'admin',
        grafana_password => $grafana_password.unwrap,
        grafana_url      => $grafana_url,
        content          => file("puppet_operational_dashboards/${board}_performance.json"),
      }
    }
  }

  if $include_pe_metrics {
    ['Filesync', 'Orchestrator'].each |$pe_service| {
      grafana_dashboard { "${pe_service} Performance":
        grafana_user     => 'admin',
        grafana_password => $grafana_password.unwrap,
        grafana_url      => $grafana_url,
        content          => file("puppet_operational_dashboards/${pe_service}_performance.json"),
      }
    }
  }
  else {
    ['Filesync', 'Orchestrator'].each |$pe_service| {
      grafana_dashboard { "${pe_service} Performance":
        ensure           => absent,
        grafana_user     => 'admin',
        grafana_password => $grafana_password.unwrap,
        grafana_url      => $grafana_url,
      }
    }
  }
}