Ori.livneh has uploaded a new change for review.
https://gerrit.wikimedia.org/r/246252
Change subject: grafana: provide the ability to provision dashboards via Puppet
......................................................................
grafana: provide the ability to provision dashboards via Puppet
Grafana dashboards are stored either in Grafana's database, or as JSON files
in a specially-configured folder that Grafana watches. This patch adds a Puppet
resource representing a JSON file dashboard definition.
Change-Id: Ia558d44249db98cedf9d2187709c0de6e8ed595a
---
A modules/grafana/manifests/dashboard.pp
M modules/grafana/manifests/init.pp
2 files changed, 69 insertions(+), 1 deletion(-)
git pull ssh://gerrit.wikimedia.org:29418/operations/puppet
refs/changes/52/246252/1
diff --git a/modules/grafana/manifests/dashboard.pp
b/modules/grafana/manifests/dashboard.pp
new file mode 100644
index 0000000..a640fd4
--- /dev/null
+++ b/modules/grafana/manifests/dashboard.pp
@@ -0,0 +1,50 @@
+# == Define: grafana:dashboard
+#
+# Provisions a Grafana dashboard definition. Grafana dashboards may
+# be defined via the web interface, or by placing a JSON dashboard
+# definition in Grafana's dashboard directory. This resource is meant
+# to help you do the latter.
+#
+# The Grafana JSON format is not documented, but you can see what
+# it looks like by creating or loading a dashboard in Grafana and
+# then using the "export" feature to see the dashboard's JSON
+# representation.
+#
+# === Parameters
+#
+# [*content*]
+# If defined, will be used as the content of the dashboard JSON
+# file. Undefined by default. Mutually exclusive with 'source'.
+#
+# [*source*]
+# Path to file containing JSON dashboard definition. Undefined
+# by default. Mutually exclusive with 'content'.
+#
+# === Examples
+#
+# grafana::dashboard { 'reqerror':
+# source => 'puppet:///modules/varnish/dashboards/reqerror.json',
+# }
+#
+define grafana::dashboard(
+ $content = undef,
+ $source = undef,
+) {
+ include ::grafana
+
+ $basename = regsubst($title, '\W', '-', 'G')
+
+ if ( $source == undef and $content == undef ) or ( $source != undef and
$content != undef ) {
+ fail('you must provide either "source" or "content" (but not both)')
+ }
+
+ file { "/var/lib/grafana/dashboards/${basename}.json":
+ ensure => $ensure,
+ content => $content,
+ source => $source,
+ owner => 'root',
+ group => 'root',
+ mode => '0444',
+ notify => Service['grafana-server'],
+ }
+}
diff --git a/modules/grafana/manifests/init.pp
b/modules/grafana/manifests/init.pp
index d914e30..774fced 100644
--- a/modules/grafana/manifests/init.pp
+++ b/modules/grafana/manifests/init.pp
@@ -23,18 +23,36 @@
#
class grafana( $config ) {
+ $defaults = {
+ 'dashboards.json' => {
+ enabled => true,
+ path => '/var/lib/grafana/dashboards',
+ },
+ }
+
package { 'grafana':
ensure => present,
}
file { '/etc/grafana/grafana.ini':
- content => ini($config),
+ content => ini($defaults, $config),
owner => 'root',
group => 'root',
mode => '0444',
require => Package['grafana'],
}
+ file { '/var/lib/grafana/dashboards':
+ ensure => directory,
+ owner => 'grafana',
+ group => 'grafana',
+ mode => '0755',
+ recurse => true,
+ purge => true,
+ force => true,
+ require => Package['grafana'],
+ }
+
service { 'grafana-server':
ensure => running,
enable => true,
--
To view, visit https://gerrit.wikimedia.org/r/246252
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia558d44249db98cedf9d2187709c0de6e8ed595a
Gerrit-PatchSet: 1
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Ori.livneh <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits