kennel 1.69.0 → 1.70.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: daadbdb69c86de7a0dcdec2bc1eeaedd4b0c2221e2059d241db57e717a8876b6
4
- data.tar.gz: 1d93147d3d88468564c6c9fcfd0a1fa3926df23d44961b876273e24ac642c851
3
+ metadata.gz: 857c5d57edd43c806560c9a97b579398f440ed311dd7b8541e1262af03de51bd
4
+ data.tar.gz: b75bf7667bcdd473732d1e69231a52a37bdd90366462890a85d39d6325004593
5
5
  SHA512:
6
- metadata.gz: 7737e951ba0e6f34bdec5c4c000e64852acfcc1939d19385a7a92d9b88821c5d6efe0f29f1d8a292692c3ae8b85bd248af0f05ed3e591595da5d2ee41382fd37
7
- data.tar.gz: 62989fb72a5bc60f052449ecf4d380f59f7e945a8d1857e7f3e789549d8625eac8ffd51c2a946b4f0367cd2d439b2ecb02eb99f79cb42202bb020dadf8a6b612
6
+ metadata.gz: 51662e560022e916c3b2e7254cb9dcc4ec331468f06cc29c47f45ea857c1dc49ded3496b9313a06073848abc782576c46d0bfcd410099ababdc5571a19cccc28
7
+ data.tar.gz: de5dd05943415b655efc290399417853a68477a81a88c098b4812d908e83a19ff06594dbb143f6b3120a41caca2cbbe8d86ef27a8eee449e2d34bc05b1da5140
data/Readme.md CHANGED
@@ -72,7 +72,7 @@ end
72
72
  ### Updating an existing monitor
73
73
  - use [datadog monitor UI](https://app.datadoghq.com/monitors/manage) to find a monitor
74
74
  - get the `id` from the url
75
- - run `RESOURCE=monitor ID=12345 bundle exec rake kennel:import` and copy the output
75
+ - run `URL='https://app.datadoghq.com/monitors/123' bundle exec rake kennel:import` and copy the output
76
76
  - find or create a project in `projects/`
77
77
  - add the monitor to `parts: [` list, for example:
78
78
  ```Ruby
@@ -118,7 +118,7 @@ end
118
118
  ### Updating an existing dashboard
119
119
  - go to [datadog dashboard UI](https://app.datadoghq.com/dashboard/lists) and click on _New Dashboard_ to find a dashboard
120
120
  - get the `id` from the url
121
- - run `RESOURCE=dashboard ID=abc-def-ghi bundle exec rake kennel:import` and copy the output
121
+ - run `URL='https://app.datadoghq.com/dashboard/bet-foo-bar' bundle exec rake kennel:import` and copy the output
122
122
  - find or create a project in `projects/`
123
123
  - add a dashboard to `parts: [` list, for example:
124
124
  ```Ruby
@@ -116,6 +116,10 @@ module Kennel
116
116
  Utils.path_to_url "/dashboard/#{id}"
117
117
  end
118
118
 
119
+ def self.parse_url(url)
120
+ url[/\/dashboard\/([a-z\d-]+)/, 1]
121
+ end
122
+
119
123
  def resolve_linked_tracking_ids(id_map)
120
124
  widgets = as_json[:widgets].flat_map { |w| [w, *w.dig(:definition, :widgets) || []] }
121
125
  widgets.each do |widget|
@@ -120,6 +120,12 @@ module Kennel
120
120
  Utils.path_to_url "/monitors##{id}/edit"
121
121
  end
122
122
 
123
+ # datadog uses both / and # as separator in it's links
124
+ def self.parse_url(url)
125
+ return unless id = url[/\/monitors[\/#](\d+)/, 1]
126
+ Integer(id)
127
+ end
128
+
123
129
  def self.normalize(expected, actual)
124
130
  super
125
131
  options = actual.fetch(:options)
@@ -11,6 +11,14 @@ module Kennel
11
11
  settings :id, :kennel_id
12
12
 
13
13
  class << self
14
+ def parse_any_url(url)
15
+ subclasses.detect do |s|
16
+ if id = s.parse_url(url)
17
+ break s.api_resource, id
18
+ end
19
+ end
20
+ end
21
+
14
22
  private
15
23
 
16
24
  def normalize(_expected, actual)
@@ -62,6 +62,10 @@ module Kennel
62
62
  Utils.path_to_url "/slo?slo_id=#{id}"
63
63
  end
64
64
 
65
+ def self.parse_url(url)
66
+ url[/\/slo\?slo_id=([a-z\d]+)/, 1]
67
+ end
68
+
65
69
  def resolve_linked_tracking_ids(id_map)
66
70
  as_json[:monitor_ids] = as_json[:monitor_ids].map do |id|
67
71
  id.is_a?(String) ? resolve_link(id, :monitor, id_map) : id
@@ -111,12 +111,18 @@ namespace :kennel do
111
111
  end
112
112
  end
113
113
 
114
- desc "Convert existing resources to copy-pastable definitions to import existing resources RESOURCE=[dashboard,monitor,slo] ID=1234"
114
+ desc "Convert existing resources to copy-pasteable definitions to import existing resources (call with URL= or call with RESOURCE= and ID=)"
115
115
  task import: :environment do
116
- resource = ENV["RESOURCE"] || Kennel::Tasks.abort("Call with RESOURCE=dashboard or monitor or slo")
117
- id = ENV["ID"] || Kennel::Tasks.abort("Call with ID=1234")
118
- id = Integer(id) if id =~ /^\d+$/ # dashboards can have alphanumeric ids
119
- puts Kennel::Importer.new(Kennel.send(:api)).import(resource, id)
116
+ if (id = ENV["ID"]) && (resource = ENV["RESOURCE"])
117
+ id = Integer(id) if id =~ /^\d+$/ # dashboards can have alphanumeric ids
118
+ elsif (url = ENV["URL"])
119
+ resource, id = Kennel::Models::Record.parse_any_url(url) || Kennel::Tasks.abort("Unable to parse url")
120
+ else
121
+ possible_resources = Kennel::Models::Record.subclasses.map(&:api_resource)
122
+ Kennel::Tasks.abort("Call with URL= or call with RESOURCE=#{possible_resources.join(" or ")} and ID=")
123
+ end
124
+
125
+ Kennel.out.puts Kennel::Importer.new(Kennel.send(:api)).import(resource, id)
120
126
  end
121
127
 
122
128
  desc "Dump ALL of datadog config as raw json ... useful for grep/search TYPE=slo|monitor|dashboard"
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Kennel
3
- VERSION = "1.69.0"
3
+ VERSION = "1.70.0"
4
4
  end
@@ -54,7 +54,7 @@ end
54
54
  ### Updating an existing monitor
55
55
  - use [datadog monitor UI](https://app.datadoghq.com/monitors/manage) to find a monitor
56
56
  - get the `id` from the url
57
- - run `RESOURCE=monitor ID=12345 bundle exec rake kennel:import` and copy the output
57
+ - run `URL='https://app.datadoghq.com/monitors/123' bundle exec rake kennel:import` and copy the output
58
58
  - find or create a project in `projects/`
59
59
  - add the monitor to `parts: [` list, for example:
60
60
  ```Ruby
@@ -100,7 +100,7 @@ end
100
100
  ### Updating an existing dashboard
101
101
  - go to [datadog dashboard UI](https://app.datadoghq.com/dashboard/lists) and click on _New Dashboard_ to find a dashboard
102
102
  - get the `id` from the url
103
- - run `RESOURCE=dashboard ID=abc-def-ghi bundle exec rake kennel:import` and copy the output
103
+ - run `URL='https://app.datadoghq.com/dashboard/bet-foo-bar' bundle exec rake kennel:import` and copy the output
104
104
  - find or create a project in `projects/`
105
105
  - add a dashboard to `parts: [` list, for example:
106
106
  ```Ruby
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kennel
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.69.0
4
+ version: 1.70.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Grosser
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-29 00:00:00.000000000 Z
11
+ date: 2020-05-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday