Skip to content

Commit

Permalink
Merge pull request sous-chefs#16 from kamaradclimber/multiserver
Browse files Browse the repository at this point in the history
Allow attribute configuration for datasources
  • Loading branch information
JonathanTron committed Jul 31, 2014
2 parents 8f5688a + 9a4242a commit 32198e8
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 17 deletions.
13 changes: 13 additions & 0 deletions attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,16 @@
default['grafana']['grafana_index'] = 'grafana-index'
default['grafana']['unsaved_changes_warning'] = 'true'
default['grafana']['playlist_timespan'] = '1m'
default['grafana']['datasources'] = {
'graphite' => {
'type' => "'graphite'",
'url' => 'window.location.protocol+"//"+window.location.hostname+":"+window.location.port+"/_graphite"',
'default' => true
},
'elasticsearch' => {
'type' => "'elasticsearch'",
'url' => 'window.location.protocol+"//"+window.location.hostname+":"+window.location.port',
'index' => "'#{node['grafana']['grafana_index']}'",
'grafanaDB' => true
}
}
20 changes: 20 additions & 0 deletions libraries/javascript_pp.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module JavascriptPP
def pprint(obj, indent=1)
case obj
when Hash
res = "{\n"
obj.each do |k,v|
res += " " * indent
res += k.to_s + ": "
res += pprint(v, indent+1)
res += ",\n"
end
res.gsub!(/,\n$/, "\n")
res += " " * (indent - 1)
res += "}"
else
res = obj.to_s
end
res
end
end
4 changes: 4 additions & 0 deletions recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,12 @@
template "#{node['grafana']['web_dir']}/config.js" do
source node['grafana']['config_template']
cookbook node['grafana']['config_cookbook']
variables({
'datasources' => node['grafana']['datasources'],
})
mode '0644'
user grafana_user
helpers(::JavascriptPP)
end

unless node['grafana']['webserver'].empty?
Expand Down
19 changes: 2 additions & 17 deletions templates/default/config.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,14 @@
// config.js is where you will find the core Grafana configuration. This file contains parameter that
// must be set before Grafana is run for the first time.
///
<% require 'json' %>
define(['settings'],
function (Settings) {


return new Settings({

// datasources, you can add multiple
datasources: {
graphite: {
type: 'graphite',
url: window.location.protocol+"//"+window.location.hostname+":"+window.location.port+"/_graphite",
default: true
}
},

// elasticsearch url
// used for storing and loading dashboards, optional
// For Basic authentication use: http://username:password@domain.com:9200
elasticsearch: window.location.protocol+"//"+window.location.hostname+":"+window.location.port,
datasources: <%= pprint(@datasources,3) %>,

// default start dashboard
default_route: '/dashboard/file/default.json',
Expand All @@ -38,17 +27,13 @@ function (Settings) {
//
timezoneOffset: <%= node['grafana']['timezone_offset'] %>,

// Elasticsearch index for storing dashboards
grafana_index: "<%= node['grafana']['grafana_index'] %>",

// set to false to disable unsaved changes warning
unsaved_changes_warning: <%= node['grafana']['unsaved_changes_warning'] %>,

// set the default timespan for the playlist feature
// Example: "1m", "1h"
playlist_timespan: "<%= node['grafana']['playlist_timespan'] %>",


// Add your own custom pannels
plugins: {
panels: []
Expand Down

0 comments on commit 32198e8

Please sign in to comment.