datadog-sync 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +4 -0
- data/lib/datadog_sync/base.rb +18 -2
- data/lib/datadog_sync/errors.rb +1 -0
- data/lib/datadog_sync/save_dashboards.rb +5 -4
- data/lib/datadog_sync/update_dashboards.rb +28 -0
- data/lib/datadog_sync/version.rb +1 -1
- data/lib/datadog_sync.rb +2 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 76d02c9e4e60bab67d69c9433d13f8c54a13ee66
|
4
|
+
data.tar.gz: 3689e39795d3a0af528add8829bb721df44636aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 869e8877bc21dd2e56d6a9bb6c6ff8e06fe4675b59fe1e8cf3fbf09abcb1f07cbb7dd52626522a9ba4f655ab2462ab8df34df55ae05ece84f56b6b3ba2752afd
|
7
|
+
data.tar.gz: 367443a485eb1c51f76da3778a9ed90f7307826883f45cd1b99b92af167d28851d47ebe12225e4ad4467623b0384863731d27e59ba8bc3fafdeb2702b1d2f597
|
data/README.md
CHANGED
@@ -0,0 +1,4 @@
|
|
1
|
+
* Backup in case if someone accidentally deletes dashboard and ability to recreate it with single command
|
2
|
+
* Ability to keep dashboards in git repo, make modifications using text editor, suggest Pull Requests
|
3
|
+
* 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
|
4
|
+
* Automation purposes (for example creating new dashboard or adding graphs when you deploy new version of application)
|
data/lib/datadog_sync/base.rb
CHANGED
@@ -1,11 +1,27 @@
|
|
1
1
|
class DatadogSync
|
2
|
-
attr_reader :dd_client
|
2
|
+
attr_reader :dd_client, :logger
|
3
|
+
|
4
|
+
def initialize(api_key, app_key, options={})
|
5
|
+
default_options = {
|
6
|
+
log_level: :info,
|
7
|
+
log_target: STDOUT
|
8
|
+
}
|
9
|
+
final_options = default_options.merge(options)
|
3
10
|
|
4
|
-
def initialize(api_key, app_key)
|
5
11
|
@dd_client = Dogapi::Client.new(api_key, app_key)
|
12
|
+
|
13
|
+
set_logger(final_options)
|
6
14
|
end
|
7
15
|
|
16
|
+
private
|
17
|
+
|
8
18
|
def sanitize_filename(filename)
|
9
19
|
filename.gsub(/[\?\*\/\\]/, "_")
|
10
20
|
end
|
21
|
+
|
22
|
+
def set_logger(config)
|
23
|
+
@logger = Logger.new(config[:log_target])
|
24
|
+
@logger.level = config[:log_level]
|
25
|
+
@logger.datetime_format = "%Y-%m-%d %H:%M:%S"
|
26
|
+
end
|
11
27
|
end
|
data/lib/datadog_sync/errors.rb
CHANGED
@@ -4,20 +4,21 @@ class DatadogSync
|
|
4
4
|
base_path = File.expand_path(dashboards_path)
|
5
5
|
|
6
6
|
if File.file?(base_path)
|
7
|
-
|
7
|
+
logger.error "Provided gashboards path already exists and it's not a directory."
|
8
|
+
raise AlreadyExists
|
8
9
|
elsif !File.directory?(base_path)
|
9
|
-
|
10
|
+
logger.info "Creating directory for dashboards: '#{base_path}'"
|
10
11
|
FileUtils.mkdir_p(base_path)
|
11
12
|
end
|
12
13
|
|
13
14
|
all_dashes = dd_client.get_dashboards[1]["dashes"]
|
14
15
|
|
15
|
-
|
16
|
+
logger.info "Found #{all_dashes.count} dashboards"
|
16
17
|
|
17
18
|
filtered_dashes = all_dashes.select { |dash| dash["title"] =~ regex }
|
18
19
|
filtered_dashes_ids = filtered_dashes.collect { |dash| dash["id"] }
|
19
20
|
|
20
|
-
|
21
|
+
logger.info "Saving #{filtered_dashes.count} dashboards with pattern /#{title_pattern}/ into '#{base_path}'"
|
21
22
|
|
22
23
|
filtered_dashes_ids.each do |dash_id|
|
23
24
|
dash_data = dd_client.get_dashboard(dash_id)[1]["dash"]
|
@@ -0,0 +1,28 @@
|
|
1
|
+
class DatadogSync
|
2
|
+
def update_dashboards(dashboards_path, title_pattern="")
|
3
|
+
regex = Regexp.new(title_pattern)
|
4
|
+
base_path = File.expand_path(dashboards_path)
|
5
|
+
|
6
|
+
unless File.directory?(base_path)
|
7
|
+
logger.error "Provided gashboards path does not exist."
|
8
|
+
raise DoesNotExist
|
9
|
+
end
|
10
|
+
|
11
|
+
all_dash_files = Dir.glob(File.join(base_path, "*"))
|
12
|
+
|
13
|
+
logger.info "Found #{all_dash_files.count} local dashboards"
|
14
|
+
|
15
|
+
filtered_dashes = []
|
16
|
+
all_dash_files.each do |file|
|
17
|
+
data = JSON.parse(File.read(file))
|
18
|
+
filtered_dashes << data if data["title"] =~ regex
|
19
|
+
end
|
20
|
+
# filtered_dashes_ids = filtered_dashes.collect { |dash| dash["id"] }
|
21
|
+
|
22
|
+
logger.info "Updating #{filtered_dashes.count} dashboards with pattern /#{title_pattern}/ from '#{base_path}'"
|
23
|
+
|
24
|
+
filtered_dashes.each do |dash|
|
25
|
+
dd_client.update_dashboard(dash["id"], dash["title"], dash["description"], dash["graphs"], dash["template_variables"])
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/datadog_sync/version.rb
CHANGED
data/lib/datadog_sync.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: datadog-sync
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ivan Larionov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-06-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dogapi
|
@@ -56,6 +56,7 @@ files:
|
|
56
56
|
- lib/datadog_sync/base.rb
|
57
57
|
- lib/datadog_sync/errors.rb
|
58
58
|
- lib/datadog_sync/save_dashboards.rb
|
59
|
+
- lib/datadog_sync/update_dashboards.rb
|
59
60
|
- lib/datadog_sync/version.rb
|
60
61
|
homepage: http://github.com/xeron/datadog-sync
|
61
62
|
licenses:
|