datadog-sync 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d766665d8efbf5ea63faa76d8b6609c361a34f36
4
+ data.tar.gz: 7d35002a21ea7204cc12b745224381a9cb6fe6ee
5
+ SHA512:
6
+ metadata.gz: 75de678587c9cc0f753751ebfc4a80a67b38e9753a9f29c92f1fa685ae60d3aee222b8c9c7df130cffd704684b1389ab5a22aed4e9e5bdd82637a55a6ece0e9c
7
+ data.tar.gz: ad5272730e374e2f2997958a15f97425b9c8a19365f314dfe94d1c6a78adf3cf88c8c7790c6606f4ce71375609110ef0e9dd0ffdeabf48b671b5998d3d37b1ee
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Ivan Larionov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
File without changes
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ require 'rubygems'
2
+ require 'rubygems/package_task'
3
+
4
+ gemspec = eval(File.read("datadog-sync.gemspec"))
5
+ Gem::PackageTask.new(gemspec).define
6
+
7
+ require 'rdoc/task'
8
+ Rake::RDocTask.new do |rdoc|
9
+ version = File.exist?("VERSION") ? File.read("VERSION") : ""
10
+
11
+ rdoc.rdoc_dir = "rdoc"
12
+ rdoc.title = "datadog-sync #{version}"
13
+ rdoc.rdoc_files.include("README*")
14
+ rdoc.rdoc_files.include("lib/**/*.rb")
15
+ end
data/bin/dd-sync ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'datadog-sync'
4
+
5
+ puts "Currently it doesn't do anything. See work in progress here https://github.com/xeron/datadog-sync."
6
+
7
+ # ARGS parser will be here
8
+
9
+ # ds = DatadogSync.new(DD_API_KEY, DD_APP_KEY)
10
+
11
+ # ds.save_dashboards(PATH, PATTERN)
@@ -0,0 +1 @@
1
+ require 'datadog_sync'
@@ -0,0 +1,11 @@
1
+ class DatadogSync
2
+ attr_reader :dd_client
3
+
4
+ def initialize(api_key, app_key)
5
+ @dd_client = Dogapi::Client.new(api_key, app_key)
6
+ end
7
+
8
+ def sanitize_filename(filename)
9
+ filename.gsub(/[\?\*\/\\]/, "_")
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ class DatadogSync
2
+ AlreadyExists = Class.new(RuntimeError)
3
+ end
@@ -0,0 +1,31 @@
1
+ class DatadogSync
2
+ def save_dashboards(dashboards_path, title_pattern="")
3
+ regex = Regexp.new(title_pattern)
4
+ base_path = File.expand_path(dashboards_path)
5
+
6
+ if File.file?(base_path)
7
+ raise AlreadyExists, "Provided gashboards path already exists and it's not a directory."
8
+ elsif !File.directory?(base_path)
9
+ puts "Creating directory for dashboards: '#{base_path}'"
10
+ FileUtils.mkdir_p(base_path)
11
+ end
12
+
13
+ all_dashes = dd_client.get_dashboards[1]["dashes"]
14
+
15
+ puts "Found #{all_dashes.count} dashboards"
16
+
17
+ filtered_dashes = all_dashes.select { |dash| dash["title"] =~ regex }
18
+ filtered_dashes_ids = filtered_dashes.collect { |dash| dash["id"] }
19
+
20
+ puts "Saving #{filtered_dashes.count} dashboards with pattern /#{title_pattern}/ into '#{base_path}'"
21
+
22
+ filtered_dashes_ids.each do |dash_id|
23
+ dash_data = dd_client.get_dashboard(dash_id)[1]["dash"]
24
+ filename = sanitize_filename(dash_data["title"])
25
+ filepath = File.join(base_path, "#{filename}.json")
26
+ File.open(filepath, "wb") do |f|
27
+ f.puts JSON.pretty_generate(dash_data)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,3 @@
1
+ class DatadogSync
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,8 @@
1
+ require 'dogapi'
2
+ require 'json'
3
+ require 'fileutils'
4
+
5
+ require 'datadog_sync/version'
6
+ require 'datadog_sync/errors'
7
+ require 'datadog_sync/base'
8
+ require 'datadog_sync/save_dashboards'
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: datadog-sync
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ivan Larionov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-05-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: dogapi
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Sync your DataDog.
42
+ email: xeron.oskom@gmail.com
43
+ executables:
44
+ - dd-sync
45
+ extensions: []
46
+ extra_rdoc_files:
47
+ - README.md
48
+ - LICENSE
49
+ files:
50
+ - LICENSE
51
+ - README.md
52
+ - Rakefile
53
+ - bin/dd-sync
54
+ - lib/datadog-sync.rb
55
+ - lib/datadog_sync.rb
56
+ - lib/datadog_sync/base.rb
57
+ - lib/datadog_sync/errors.rb
58
+ - lib/datadog_sync/save_dashboards.rb
59
+ - lib/datadog_sync/version.rb
60
+ homepage: http://github.com/xeron/datadog-sync
61
+ licenses:
62
+ - MIT
63
+ metadata: {}
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: 1.9.3
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubyforge_project:
80
+ rubygems_version: 2.5.1
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: Sync your DataDog.
84
+ test_files: []