chihuahua 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +193 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/chihuahua.gemspec +27 -0
- data/exe/chihuahua +5 -0
- data/images/chihuahua.png +0 -0
- data/lib/chihuahua.rb +10 -0
- data/lib/chihuahua/cli.rb +66 -0
- data/lib/chihuahua/client.rb +16 -0
- data/lib/chihuahua/common.rb +29 -0
- data/lib/chihuahua/export.rb +73 -0
- data/lib/chihuahua/update.rb +83 -0
- data/lib/chihuahua/version.rb +3 -0
- metadata +145 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 17b3368c2f4e8d6e09f7f09ffd9be09b495af7e2
|
4
|
+
data.tar.gz: d3e1d6d403c878481b803d5fa0e05528c4f6a584
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f59911e85a752e51ace8e4dad46440264aa2faa6c74a6a382fa0d2c1c5a585fdd2cb65e829f1961dceaa18e115abc77b69d2b4bd381ec67955eee1ba96ef1b5a
|
7
|
+
data.tar.gz: 918100d36e89194f47df7c28fe823eb39375016af61f48825ee744a798170f508877d2b6706e9f7aaa391dc56fc6d595b24623a43a212a88c2a12f593ff95919
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2017 Yohei Kawahara
|
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
@@ -0,0 +1,193 @@
|
|
1
|
+
# Chihuahua
|
2
|
+
|
3
|
+
![chihuahua](https://raw.githubusercontent.com/inokappa/chihuahua/master/images/chihuahua.png)
|
4
|
+
|
5
|
+
Chihuahua は [Datadog monitors](http://docs.datadoghq.com/guides/monitoring/) を管理するツールです.
|
6
|
+
|
7
|
+
## Caution
|
8
|
+
|
9
|
+
* Datadog monitors を YAML DSL で管理してみる試みです
|
10
|
+
* Monitor Name や Monitor Tags で絞り込んで任意の Monitor のみ抽出して管理出来る筈です
|
11
|
+
* 基本的には [codenize-tools/barkdog](https://github.com/codenize-tools/barkdog) を使いましょう
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
```sh
|
16
|
+
git clone ...
|
17
|
+
cd chihuahua
|
18
|
+
bundle install --path vendor/bundle
|
19
|
+
```
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```sh
|
24
|
+
export DATADOG_API_KEY=...
|
25
|
+
export DATADOG_APP_KEY=...
|
26
|
+
|
27
|
+
bundle exec ./bin/chihuahua init
|
28
|
+
bundle exec ./bin/chihuahua export --project=your_project_name --tags=project:foo,stage:production
|
29
|
+
vi ./monitors/your_project_name/monitors.yml
|
30
|
+
bundle exec ./bin/chihuahua apply --project=your_project_name --dry-run
|
31
|
+
bundle exec ./bin/chihuahua apply --project=your_project_name
|
32
|
+
```
|
33
|
+
|
34
|
+
## Help
|
35
|
+
|
36
|
+
```
|
37
|
+
$ bundle exec ./bin/chihuahua --help
|
38
|
+
Commands:
|
39
|
+
chihuahua apply # Monitor 設定を apply する
|
40
|
+
chihuahua export # Monitor 設定を export する
|
41
|
+
chihuahua help [COMMAND] # Describe available commands or one specific command
|
42
|
+
chihuahua init # Project の Root ディレクトリ(./monitors)を作成する.
|
43
|
+
chihuahua version # version 情報を出力.
|
44
|
+
```
|
45
|
+
|
46
|
+
## Chihuahua example
|
47
|
+
|
48
|
+
### 書き出し
|
49
|
+
|
50
|
+
```sh
|
51
|
+
#
|
52
|
+
# 初回の書き出し
|
53
|
+
#
|
54
|
+
$ bundle exec ./bin/chihuahua export --project=foo --tags=host:vagrant-ubuntu-trusty-64
|
55
|
+
Export...
|
56
|
+
4 monitors output done.
|
57
|
+
|
58
|
+
$ tree -a monitors/
|
59
|
+
monitors/
|
60
|
+
└── foo
|
61
|
+
├── .filter.yml
|
62
|
+
└── monitors.yml
|
63
|
+
|
64
|
+
1 directory, 2 files
|
65
|
+
|
66
|
+
#
|
67
|
+
# 2 回目以降、絞込の条件(--name や --tags に変更が無い場合)
|
68
|
+
#
|
69
|
+
$ bundle exec ./bin/chihuahua export --project=foo
|
70
|
+
|
71
|
+
```
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
### 新規作成
|
76
|
+
|
77
|
+
- YAML 定義を ./monitors/your_project_name/monitors.yml に追記
|
78
|
+
|
79
|
+
```yaml
|
80
|
+
- query: avg(last_1m):avg:system.load.5{host:vagrant-ubuntu-trusty-64} > 1
|
81
|
+
message: |-
|
82
|
+
CPU load is very high on {{host.name}}
|
83
|
+
@slack-datadog-notification
|
84
|
+
name: Test 5 [{{#is_alert}}CRITICAL{{/is_alert}}{{#is_warning}}WARNING{{/is_warning}}]
|
85
|
+
CPU load is very high on {{host.name}}
|
86
|
+
type: metric alert
|
87
|
+
options:
|
88
|
+
thresholds:
|
89
|
+
critical: 1.0
|
90
|
+
warning: 0.8
|
91
|
+
```
|
92
|
+
|
93
|
+
詳細は http://docs.datadoghq.com/ja/api/?lang=ruby#monitor-create を御確認ください.
|
94
|
+
|
95
|
+
- dry-run
|
96
|
+
|
97
|
+
```sh
|
98
|
+
$ bundle exec ./bin/chihuahua apply --project=foo --dry-run
|
99
|
+
Apply...(dry-run)
|
100
|
+
Check add line.
|
101
|
+
---
|
102
|
+
query: avg(last_1m):avg:system.load.5{host:vagrant-ubuntu-trusty-64} > 1
|
103
|
+
message: |-
|
104
|
+
CPU load is very high on {{host.name}}
|
105
|
+
@slack-datadog-notification
|
106
|
+
name: Test 5 [{{#is_alert}}CRITICAL{{/is_alert}}{{#is_warning}}WARNING{{/is_warning}}]
|
107
|
+
CPU load is very high on {{host.name}}
|
108
|
+
type: metric alert
|
109
|
+
options:
|
110
|
+
thresholds:
|
111
|
+
critical: 1.0
|
112
|
+
warning: 0.8
|
113
|
+
```
|
114
|
+
|
115
|
+
- apply
|
116
|
+
|
117
|
+
```sh
|
118
|
+
$ bundle exec ./bin/chihuahua apply --project=foo
|
119
|
+
Apply...
|
120
|
+
Add line.
|
121
|
+
...
|
122
|
+
... Latest Monitors List ...
|
123
|
+
...
|
124
|
+
done.
|
125
|
+
```
|
126
|
+
|
127
|
+
### 更新
|
128
|
+
|
129
|
+
- thresholds を追記
|
130
|
+
|
131
|
+
```yaml
|
132
|
+
- tags: []
|
133
|
+
query: avg(last_1m):avg:system.load.5{host:vagrant-ubuntu-trusty-64} > 1
|
134
|
+
message: |-
|
135
|
+
CPU load is very high on {{host.name}}
|
136
|
+
@slack-datadog-notification
|
137
|
+
id: 12345678
|
138
|
+
name: Test3 [{{#is_alert}}CRITICAL{{/is_alert}}{{#is_warning}}WARNING{{/is_warning}}]
|
139
|
+
CPU load is very high on {{host.name}}
|
140
|
+
type: metric alert
|
141
|
+
options:
|
142
|
+
notify_audit: false
|
143
|
+
locked: false
|
144
|
+
silenced: {}
|
145
|
+
new_host_delay: 300
|
146
|
+
require_full_window: true
|
147
|
+
notify_no_data: false
|
148
|
+
thresholds:
|
149
|
+
critical: 1.0
|
150
|
+
warning: 0.8
|
151
|
+
```
|
152
|
+
|
153
|
+
詳細は http://docs.datadoghq.com/ja/api/?lang=ruby#monitor-edit を御確認ください.
|
154
|
+
|
155
|
+
- dry-run
|
156
|
+
|
157
|
+
```sh
|
158
|
+
$ bundle exec ./bin/chihuahua apply --project=foo --dry-run
|
159
|
+
Apply...(dry-run)
|
160
|
+
Check update line.
|
161
|
+
---
|
162
|
+
tags: []
|
163
|
+
query: avg(last_1m):avg:system.load.5{host:vagrant-ubuntu-trusty-64} > 1
|
164
|
+
message: |-
|
165
|
+
CPU load is very high on {{host.name}}
|
166
|
+
@slack-datadog-notification
|
167
|
+
id: 12345678
|
168
|
+
name: Test3 [{{#is_alert}}CRITICAL{{/is_alert}}{{#is_warning}}WARNING{{/is_warning}}]
|
169
|
+
CPU load is very high on {{host.name}}
|
170
|
+
type: metric alert
|
171
|
+
options:
|
172
|
+
notify_audit: false
|
173
|
+
locked: false
|
174
|
+
silenced: {}
|
175
|
+
new_host_delay: 300
|
176
|
+
require_full_window: true
|
177
|
+
notify_no_data: false
|
178
|
+
+ thresholds:
|
179
|
+
+ critical: 1.0
|
180
|
+
+ warning: 0.8
|
181
|
+
```
|
182
|
+
|
183
|
+
- apply
|
184
|
+
|
185
|
+
```sh
|
186
|
+
$ bundle exec ./bin/chihuahua apply --project=foo
|
187
|
+
Apply...
|
188
|
+
Update line.
|
189
|
+
...
|
190
|
+
... Latest Monitors List ...
|
191
|
+
...
|
192
|
+
done.
|
193
|
+
```
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "chihuahua"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/chihuahua.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'chihuahua/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "chihuahua"
|
8
|
+
spec.version = Chihuahua::VERSION
|
9
|
+
spec.authors = ["kapp"]
|
10
|
+
spec.email = ["inokara@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Chihuahua is a tool to manage Datadog monitors.}
|
13
|
+
spec.description = %q{Chihuahua is a tool to manage Datadog monitors.}
|
14
|
+
spec.homepage = "https://github.com/inokappa/chihuahua"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_dependency 'thor'
|
24
|
+
spec.add_dependency 'diffy'
|
25
|
+
spec.add_dependency 'dogapi'
|
26
|
+
spec.add_dependency 'highline'
|
27
|
+
end
|
data/exe/chihuahua
ADDED
Binary file
|
data/lib/chihuahua.rb
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'thor'
|
3
|
+
require 'dogapi'
|
4
|
+
require 'yaml'
|
5
|
+
require 'json'
|
6
|
+
require 'diffy'
|
7
|
+
require 'highline'
|
8
|
+
|
9
|
+
module Chihuahua
|
10
|
+
class CLI < Thor
|
11
|
+
default_command :version
|
12
|
+
# class_option :api_key
|
13
|
+
# class_option :app_key
|
14
|
+
|
15
|
+
desc 'version', 'version 情報を出力.'
|
16
|
+
def version
|
17
|
+
puts Chihuahua::VERSION
|
18
|
+
end
|
19
|
+
|
20
|
+
desc 'export', 'Monitors 定義を export する'
|
21
|
+
option :project, type: :string, aliases: '-p', desc: 'Project を指定.(Project 名でディレクトリを作成する)'
|
22
|
+
option :name, type: :string, aliases: '-n', desc: 'Monitor を name キーで絞り込む.'
|
23
|
+
option :tags, type: :array, aliases: '-t', desc: 'Monitor を tags キーで絞り込む.'
|
24
|
+
def export
|
25
|
+
unless options[:project] then
|
26
|
+
puts 'Project 名がセットされていません. (--project xxxxxx)'
|
27
|
+
exit 1
|
28
|
+
end
|
29
|
+
|
30
|
+
puts 'Export...'
|
31
|
+
# exporter = Chihuahua::Export.new(options[:project])
|
32
|
+
args = {}
|
33
|
+
args['name'] = options[:name]
|
34
|
+
args['tags'] = options[:tags]
|
35
|
+
p args.class
|
36
|
+
exporter = Chihuahua::Export.new(options[:project], args)
|
37
|
+
monitors_data = exporter.export_monitors(options[:project])
|
38
|
+
exporter.store_monitors_data(monitors_data)
|
39
|
+
end
|
40
|
+
#
|
41
|
+
desc 'apply', 'Monitors 定義を apply する'
|
42
|
+
option :project, type: :string, aliases: '-p', desc: 'Project を指定.'
|
43
|
+
option :dry_run, type: :boolean, aliases: '-d', desc: 'apply 前の試行.'
|
44
|
+
def apply
|
45
|
+
if options[:dry_run] then
|
46
|
+
puts 'Apply...(dry-run)'
|
47
|
+
else
|
48
|
+
puts 'Apply...'
|
49
|
+
end
|
50
|
+
updater = Chihuahua::Update.new(options[:project])
|
51
|
+
updater.update_monitors(options[:dry_run])
|
52
|
+
end
|
53
|
+
|
54
|
+
desc 'generate', 'Monitors 定義の雛形を生成する.'
|
55
|
+
option :project, type: :string, aliases: '-p', desc: 'Project を指定.'
|
56
|
+
def generate
|
57
|
+
#
|
58
|
+
end
|
59
|
+
|
60
|
+
desc 'init', 'Project の Root ディレクトリ(./monitors)を作成する.'
|
61
|
+
def init
|
62
|
+
Chihuahua::Helper.create_project_root_dir
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
module Chihuahua
|
3
|
+
class Client
|
4
|
+
def initialize
|
5
|
+
raise 'API Key がセットされていません.' unless ENV['DATADOG_API_KEY']
|
6
|
+
raise 'Application Key がセットされていません.' unless ENV['DATADOG_APP_KEY']
|
7
|
+
@api_key = ENV['DATADOG_API_KEY']
|
8
|
+
@app_key = ENV['DATADOG_APP_KEY']
|
9
|
+
end
|
10
|
+
|
11
|
+
def dog
|
12
|
+
Dogapi::Client.new(@api_key, @app_key)
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
module Chihuahua
|
3
|
+
module Helper
|
4
|
+
def create_project_root_dir
|
5
|
+
FileUtils.mkdir_p('./monitors') unless FileTest.exist?('./monitors')
|
6
|
+
puts 'done.'
|
7
|
+
end
|
8
|
+
|
9
|
+
def filter_monitor(monitor)
|
10
|
+
filter = %w[tags query type message id name options]
|
11
|
+
filterd_monitor = monitor.select { |key, _| filter.include? key }
|
12
|
+
return filterd_monitor
|
13
|
+
end
|
14
|
+
|
15
|
+
def get_filter(project)
|
16
|
+
filter = open('./monitors/' + project + '/.filter.yml', 'r') { |f| YAML.load(f) }
|
17
|
+
return filter
|
18
|
+
end
|
19
|
+
|
20
|
+
def hl
|
21
|
+
HighLine.new
|
22
|
+
end
|
23
|
+
|
24
|
+
module_function :create_project_root_dir
|
25
|
+
module_function :filter_monitor
|
26
|
+
module_function :get_filter
|
27
|
+
module_function :hl
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
module Chihuahua
|
3
|
+
class Export
|
4
|
+
|
5
|
+
include Chihuahua::Helper
|
6
|
+
|
7
|
+
def initialize(project, *args)
|
8
|
+
@dog = Chihuahua::Client.new.dog
|
9
|
+
@project = project
|
10
|
+
@args = args.last
|
11
|
+
@project_dir = './monitors/' + @project
|
12
|
+
@monitors_file_path = @project_dir + '/monitors.yml'
|
13
|
+
@filter_file_path = @project_dir + '/.filter.yml'
|
14
|
+
end
|
15
|
+
|
16
|
+
def export_result_display(name)
|
17
|
+
puts hl.color(name, :magenta) + ' を export しました.'
|
18
|
+
end
|
19
|
+
|
20
|
+
def export_monitors(project)
|
21
|
+
call_from = caller[0][/`([^']*)'/, 1]
|
22
|
+
|
23
|
+
if FileTest.exist?(@filter_file_path) && @args == nil then
|
24
|
+
filter = get_filter(project)
|
25
|
+
name = filter['name']
|
26
|
+
tags = filter['tags']
|
27
|
+
else
|
28
|
+
if FileTest.exist?(@filter_file_path) && @args['name'] == nil && @args['tags'] == nil then
|
29
|
+
filter = get_filter(@project)
|
30
|
+
name = filter['name']
|
31
|
+
tags = filter['tags']
|
32
|
+
else
|
33
|
+
name = @args['name']
|
34
|
+
tags = @args['tags']
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
filterd_monitors = []
|
39
|
+
begin
|
40
|
+
@dog.get_all_monitors({:name => name, :tags => tags}).last.each do |monitor|
|
41
|
+
export_result_display(monitor['name']) unless call_from == 'update_monitors'
|
42
|
+
filterd_monitors << filter_monitor(monitor)
|
43
|
+
end
|
44
|
+
rescue => e
|
45
|
+
puts e
|
46
|
+
end
|
47
|
+
return filterd_monitors
|
48
|
+
end
|
49
|
+
|
50
|
+
def store_monitors_data(monitors_data)
|
51
|
+
FileUtils.mkdir_p(@project_dir) unless FileTest.exist?(@project_dir)
|
52
|
+
|
53
|
+
unless FileTest.exist?(@filter_file_path) and @args == nil or \
|
54
|
+
FileTest.exist?(@filter_file_path) && @args['name'] == nil && @args['tags'] == nil then
|
55
|
+
filter = {}
|
56
|
+
filter['name'] = @args['name']
|
57
|
+
filter['tags'] = @args['tags']
|
58
|
+
begin
|
59
|
+
YAML.dump(filter, File.open(@filter_file_path, 'w'))
|
60
|
+
rescue => e
|
61
|
+
puts e
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
begin
|
66
|
+
YAML.dump(monitors_data, File.open(@monitors_file_path, 'w'))
|
67
|
+
rescue => e
|
68
|
+
puts e
|
69
|
+
end
|
70
|
+
puts monitors_data.length.to_s + ' 件の Monitors 定義を出力しました.'
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
module Chihuahua
|
3
|
+
class Update
|
4
|
+
|
5
|
+
include Chihuahua::Helper
|
6
|
+
|
7
|
+
def initialize(project)
|
8
|
+
@dog = Chihuahua::Client.new.dog
|
9
|
+
@exporter = Chihuahua::Export.new(project)
|
10
|
+
@project = project
|
11
|
+
@project_dir = './monitors/' + @project
|
12
|
+
@monitors_file_path = @project_dir + '/monitors.yml'
|
13
|
+
@filter_file_path = @project_dir + '/.filter.yml'
|
14
|
+
end
|
15
|
+
|
16
|
+
def apply_result_display(res)
|
17
|
+
result = res.last
|
18
|
+
puts hl.color(result['name'], :light_cyan) + ' を apply しました.'
|
19
|
+
end
|
20
|
+
|
21
|
+
def update_monitor(data)
|
22
|
+
puts hl.color('Update line.', :yellow, :underline)
|
23
|
+
begin
|
24
|
+
res = @dog.update_monitor(data['id'], data['query'], :message => data['message'], :name => data['name'], :options => data['options'])
|
25
|
+
rescue => e
|
26
|
+
puts e
|
27
|
+
end
|
28
|
+
apply_result_display(res)
|
29
|
+
end
|
30
|
+
|
31
|
+
def create_monitor(data)
|
32
|
+
puts hl.color('Add line.', :yellow, :underline)
|
33
|
+
begin
|
34
|
+
res = @dog.monitor(data['type'], data['query'], :message => data['message'], :name => data['name'], :options => data['options'])
|
35
|
+
rescue => e
|
36
|
+
puts e
|
37
|
+
end
|
38
|
+
apply_result_display(res)
|
39
|
+
end
|
40
|
+
|
41
|
+
def update_monitors(dry_run)
|
42
|
+
filter = get_filter(@project)
|
43
|
+
# current_monitors = @exporter.export_monitors(filter['name'], filter['tags']) { |f| YAML.load(f) }
|
44
|
+
current_monitors = @exporter.export_monitors(@project) { |f| YAML.load(f) }
|
45
|
+
datas = open(@monitors_file_path) { |f| YAML.load(f) }
|
46
|
+
datas.each do |data|
|
47
|
+
# 新規登録 or 更新のチェック(id キーが有れば更新)
|
48
|
+
if data.has_key?('id') then
|
49
|
+
current_monitor = YAML.dump(current_monitors.select {|m| m['id'] == data['id']}.last)
|
50
|
+
latest_monitor = YAML.dump(data)
|
51
|
+
diff = Diffy::Diff.new(current_monitor, latest_monitor).to_s(:color)
|
52
|
+
# 差分の有無をチェック(diff != "\n" であれば差分が有ると判断)
|
53
|
+
if diff != "\n" then
|
54
|
+
# --dry-run フラグのチェック
|
55
|
+
if dry_run != nil then
|
56
|
+
puts hl.color('Check update line.', :gray, :underline)
|
57
|
+
puts diff
|
58
|
+
puts ''
|
59
|
+
else
|
60
|
+
update_monitor(data)
|
61
|
+
monitors_data = @exporter.export_monitors(@project)
|
62
|
+
@exporter.store_monitors_data(monitors_data)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
else
|
66
|
+
# 新規登録
|
67
|
+
# --dry-run フラグのチェック
|
68
|
+
if dry_run == nil then
|
69
|
+
create_monitor(data)
|
70
|
+
monitors_data = @exporter.export_monitors(@project)
|
71
|
+
@exporter.store_monitors_data(monitors_data)
|
72
|
+
else
|
73
|
+
puts hl.color('Check add line.', :gray, :underline)
|
74
|
+
puts hl.color(YAML.dump(data), :light_cyan)
|
75
|
+
puts ''
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
puts 'done.'
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
end
|
metadata
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: chihuahua
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- kapp
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-03-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: thor
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: diffy
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: dogapi
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: highline
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: Chihuahua is a tool to manage Datadog monitors.
|
98
|
+
email:
|
99
|
+
- inokara@gmail.com
|
100
|
+
executables:
|
101
|
+
- chihuahua
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".gitignore"
|
106
|
+
- Gemfile
|
107
|
+
- LICENSE.txt
|
108
|
+
- README.md
|
109
|
+
- Rakefile
|
110
|
+
- bin/console
|
111
|
+
- bin/setup
|
112
|
+
- chihuahua.gemspec
|
113
|
+
- exe/chihuahua
|
114
|
+
- images/chihuahua.png
|
115
|
+
- lib/chihuahua.rb
|
116
|
+
- lib/chihuahua/cli.rb
|
117
|
+
- lib/chihuahua/client.rb
|
118
|
+
- lib/chihuahua/common.rb
|
119
|
+
- lib/chihuahua/export.rb
|
120
|
+
- lib/chihuahua/update.rb
|
121
|
+
- lib/chihuahua/version.rb
|
122
|
+
homepage: https://github.com/inokappa/chihuahua
|
123
|
+
licenses: []
|
124
|
+
metadata: {}
|
125
|
+
post_install_message:
|
126
|
+
rdoc_options: []
|
127
|
+
require_paths:
|
128
|
+
- lib
|
129
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - ">="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
requirements: []
|
140
|
+
rubyforge_project:
|
141
|
+
rubygems_version: 2.5.1
|
142
|
+
signing_key:
|
143
|
+
specification_version: 4
|
144
|
+
summary: Chihuahua is a tool to manage Datadog monitors.
|
145
|
+
test_files: []
|