datadog-sync 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +4 -1
- data/lib/datadog_sync/base.rb +14 -1
- data/lib/datadog_sync/errors.rb +3 -0
- data/lib/datadog_sync/save_dashboards.rb +10 -1
- data/lib/datadog_sync/update_dashboards.rb +14 -2
- data/lib/datadog_sync/version.rb +2 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 362ba91faa77c572762565e3c667b04f7fbd0b84
|
4
|
+
data.tar.gz: 7f4a527f215f75d84469562ccd0c1e1ca0d678c9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8045b667b2c03d28d358a3711e8b14418da5f20547c1fd80075169272ddd39c07ea86e01b8b1446edd160521e79b6e170aa48b6b9e2c5528ea7da9794035d3ef
|
7
|
+
data.tar.gz: 49e0885662df6d105f3b7de59c058a606c837baa38a26dfa84f9dc7f231ad6530354d7ca11a30e9a605a0fe36f89f1ba1d9613d56feeb80c711a31ff70e3e77d
|
data/Rakefile
CHANGED
@@ -1,12 +1,15 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'rubygems/package_task'
|
3
3
|
|
4
|
+
$:.push File.expand_path("../lib", __FILE__)
|
5
|
+
require "datadog_sync/version"
|
6
|
+
|
4
7
|
gemspec = eval(File.read("datadog-sync.gemspec"))
|
5
8
|
Gem::PackageTask.new(gemspec).define
|
6
9
|
|
7
10
|
require 'rdoc/task'
|
8
11
|
Rake::RDocTask.new do |rdoc|
|
9
|
-
version =
|
12
|
+
version = DatadogSync::VERSION
|
10
13
|
|
11
14
|
rdoc.rdoc_dir = "rdoc"
|
12
15
|
rdoc.title = "datadog-sync #{version}"
|
data/lib/datadog_sync/base.rb
CHANGED
@@ -1,6 +1,19 @@
|
|
1
|
+
# Tool to import/export Datadog dashboards.
|
2
|
+
# * Backup in case if someone accidentally deletes dashboard and ability to recreate it with single command
|
3
|
+
# * Ability to keep dashboards in git repo, make modifications using text editor, suggest Pull Requests
|
4
|
+
# * YAML format providing simpler way to describe dashboards without repeating a lot of things in chatty JSON. Example: https://github.com/xeron/datadog-sync/blob/master/examples/dashboard_example.yml
|
5
|
+
# * Automation purposes (for example creating new dashboard or adding graphs when you deploy new version of application)
|
1
6
|
class DatadogSync
|
2
|
-
attr_reader :dd_client, :logger
|
7
|
+
attr_reader :dd_client, :logger # :nodoc:
|
3
8
|
|
9
|
+
# Create DatadogSync instance.
|
10
|
+
#
|
11
|
+
# ==== Attributes
|
12
|
+
# * +api_key+ - Datadog API key (String)
|
13
|
+
# * +app_key+ - Datadog APP key (String)
|
14
|
+
# * +options+ - Options (Hash)
|
15
|
+
# * +log_level+ - :debug < :info < :warn < :error < :fatal < :unknown
|
16
|
+
# * +log_target+ - log file path, +STDOUT+ by default
|
4
17
|
def initialize(api_key, app_key, options={})
|
5
18
|
default_options = {
|
6
19
|
log_level: :info,
|
data/lib/datadog_sync/errors.rb
CHANGED
@@ -1,4 +1,11 @@
|
|
1
1
|
class DatadogSync
|
2
|
+
# Save dashboards from Datadog to the filesystem (export from DD).
|
3
|
+
#
|
4
|
+
# ==== Attributes
|
5
|
+
# * +dashboards_path+ - local path where to save json files with dashboard data (String)
|
6
|
+
# * +title_pattern+ - pattern to filter dashboards by name using regex, empty by default (String)
|
7
|
+
# ==== Returns
|
8
|
+
# * IDs of saved dashboards (Array)
|
2
9
|
def save_dashboards(dashboards_path, title_pattern="")
|
3
10
|
regex = Regexp.new(title_pattern)
|
4
11
|
base_path = File.expand_path(dashboards_path)
|
@@ -16,7 +23,7 @@ class DatadogSync
|
|
16
23
|
logger.info "Found #{all_dashes.count} dashboards"
|
17
24
|
|
18
25
|
filtered_dashes = all_dashes.select { |dash| dash["title"] =~ regex }
|
19
|
-
filtered_dashes_ids = filtered_dashes.collect { |dash| dash["id"] }
|
26
|
+
filtered_dashes_ids = filtered_dashes.collect { |dash| dash["id"].to_i }
|
20
27
|
|
21
28
|
logger.info "Saving #{filtered_dashes.count} dashboards with pattern /#{title_pattern}/ into '#{base_path}'"
|
22
29
|
|
@@ -28,5 +35,7 @@ class DatadogSync
|
|
28
35
|
f.puts JSON.pretty_generate(dash_data)
|
29
36
|
end
|
30
37
|
end
|
38
|
+
|
39
|
+
return filtered_dashes_ids
|
31
40
|
end
|
32
41
|
end
|
@@ -1,4 +1,11 @@
|
|
1
1
|
class DatadogSync
|
2
|
+
# Update dashboards in Datadog from the local filesystem (import to DD).
|
3
|
+
#
|
4
|
+
# ==== Attributes
|
5
|
+
# * +dashboards_path+ - local path where to load json files from (String)
|
6
|
+
# * +title_pattern+ - pattern to filter dashboards by name using regex, empty by default (String)
|
7
|
+
# ==== Returns
|
8
|
+
# * IDs of updated dashboards (Array)
|
2
9
|
def update_dashboards(dashboards_path, title_pattern="")
|
3
10
|
regex = Regexp.new(title_pattern)
|
4
11
|
base_path = File.expand_path(dashboards_path)
|
@@ -13,16 +20,21 @@ class DatadogSync
|
|
13
20
|
logger.info "Found #{all_dash_files.count} local dashboards"
|
14
21
|
|
15
22
|
filtered_dashes = []
|
23
|
+
filtered_dashes_ids = []
|
16
24
|
all_dash_files.each do |file|
|
17
25
|
data = JSON.parse(File.read(file))
|
18
|
-
|
26
|
+
if data["title"] =~ regex
|
27
|
+
filtered_dashes << data
|
28
|
+
filtered_dashes_ids << data["id"]
|
29
|
+
end
|
19
30
|
end
|
20
|
-
# filtered_dashes_ids = filtered_dashes.collect { |dash| dash["id"] }
|
21
31
|
|
22
32
|
logger.info "Updating #{filtered_dashes.count} dashboards with pattern /#{title_pattern}/ from '#{base_path}'"
|
23
33
|
|
24
34
|
filtered_dashes.each do |dash|
|
25
35
|
dd_client.update_dashboard(dash["id"], dash["title"], dash["description"], dash["graphs"], dash["template_variables"])
|
26
36
|
end
|
37
|
+
|
38
|
+
return filtered_dashes_ids
|
27
39
|
end
|
28
40
|
end
|
data/lib/datadog_sync/version.rb
CHANGED