hotdog 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +20 -3
- data/lib/hotdog/application.rb +41 -6
- data/lib/hotdog/commands.rb +6 -4
- data/lib/hotdog/commands/gc.rb +1 -0
- data/lib/hotdog/commands/hosts.rb +2 -0
- data/lib/hotdog/commands/init.rb +0 -1
- data/lib/hotdog/commands/search.rb +2 -0
- data/lib/hotdog/commands/tags.rb +2 -0
- data/lib/hotdog/commands/update.rb +2 -1
- data/lib/hotdog/formatters/json.rb +4 -0
- data/lib/hotdog/formatters/yaml.rb +4 -0
- data/lib/hotdog/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7300d7cfb838327013fb49f3012e15a606cb7af4
|
4
|
+
data.tar.gz: 38666c025172a7873a7746027d64d6a388cd38b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3e9cd9dff9174e95ba9343f4af840437b721b2ad3e0c46e4bf03ab3433f54d66ea2676c0600f5f30b5278315aa48d3943480a7f40b0e5b43737be7fbb70acb3
|
7
|
+
data.tar.gz: 86870002dea94e2cefc19ac9c3f028f394d001bab658bb875ee2bbb86a68e5feb2e47bb7cbd59e5465f5416da1f88f0336ce14799a122d9e3f600a1ccf6c6f20
|
data/README.md
CHANGED
@@ -22,13 +22,30 @@ Or install it yourself as:
|
|
22
22
|
$ gem install hotdog
|
23
23
|
```
|
24
24
|
|
25
|
+
Then, setup API key and application key of Datadog. The keys can be configured in environment variables or configuration file.
|
26
|
+
|
27
|
+
```sh
|
28
|
+
export DATADOG_API_KEY="abcdefghijklmnopqrstuvwxyzabcdef"
|
29
|
+
export DATADOG_APPLICATION_KEY="abcdefghijklmnopqrstuvwxyzabcdefghijklmn"
|
30
|
+
```
|
31
|
+
|
32
|
+
Or,
|
33
|
+
|
34
|
+
```
|
35
|
+
$ mkdir ~/.hotdog
|
36
|
+
$ cat <<EOF
|
37
|
+
---
|
38
|
+
api_key: abcdefghijklmnopqrstuvwxyzabcdef
|
39
|
+
application_key: abcdefghijklmnopqrstuvwxyzabcdefghijklmn
|
40
|
+
EOF
|
41
|
+
```
|
42
|
+
|
25
43
|
## Usage
|
26
44
|
|
27
|
-
|
28
|
-
Then, create and initialize host information. This may take several minutes.
|
45
|
+
Initialize host information. This may take several minutes.
|
29
46
|
|
30
47
|
```sh
|
31
|
-
$ hotdog
|
48
|
+
$ hotdog update
|
32
49
|
```
|
33
50
|
|
34
51
|
List all registered hosts.
|
data/lib/hotdog/application.rb
CHANGED
@@ -4,21 +4,23 @@ require "logger"
|
|
4
4
|
require "optparse"
|
5
5
|
require "shellwords"
|
6
6
|
require "sqlite3"
|
7
|
+
require "yaml"
|
7
8
|
require "hotdog/commands"
|
8
9
|
require "hotdog/formatters"
|
9
10
|
|
10
11
|
module Hotdog
|
11
12
|
class Application
|
12
13
|
def initialize()
|
13
|
-
@confdir = File.
|
14
|
+
@confdir = find_confdir(File.expand_path("."))
|
14
15
|
@optparse = OptionParser.new
|
15
16
|
@options = {
|
17
|
+
debug: false,
|
16
18
|
environment: "default",
|
17
19
|
minimum_expiry: 3600, # 1 hour
|
18
20
|
random_expiry: 604800, # 7 days
|
19
21
|
fixed_string: false,
|
20
22
|
force: false,
|
21
|
-
|
23
|
+
format: "plain",
|
22
24
|
headers: false,
|
23
25
|
listing: false,
|
24
26
|
logger: Logger.new(STDERR),
|
@@ -28,6 +30,7 @@ module Hotdog
|
|
28
30
|
print0: false,
|
29
31
|
print1: true,
|
30
32
|
tags: [],
|
33
|
+
verbose: false,
|
31
34
|
}
|
32
35
|
@options[:logger].level = Logger::INFO
|
33
36
|
define_options
|
@@ -37,7 +40,10 @@ module Hotdog
|
|
37
40
|
def main(argv=[])
|
38
41
|
config = File.join(@confdir, "config.yml")
|
39
42
|
if File.file?(config)
|
40
|
-
|
43
|
+
loaded = YAML.load(File.read(config))
|
44
|
+
if Hash === loaded
|
45
|
+
@options = @options.merge(Hash[loaded.map { |key, value| [Symbol === key ? key : key.to_s.to_sym, value] }])
|
46
|
+
end
|
41
47
|
end
|
42
48
|
args = @optparse.parse(argv)
|
43
49
|
|
@@ -49,6 +55,14 @@ module Hotdog
|
|
49
55
|
raise("DATADOG_APPLICATION_KEY is not set")
|
50
56
|
end
|
51
57
|
|
58
|
+
options[:formatter] = get_formatter(options[:format]).new
|
59
|
+
|
60
|
+
if options[:debug] or options[:verbose]
|
61
|
+
options[:logger].level = Logger::DEBUG
|
62
|
+
else
|
63
|
+
options[:logger].level = Logger::INFO
|
64
|
+
end
|
65
|
+
|
52
66
|
sqlite = File.expand_path(File.join(@confdir, "#{options[:environment]}.db"))
|
53
67
|
FileUtils.mkdir_p(File.dirname(sqlite))
|
54
68
|
@db = SQLite3::Database.new(sqlite)
|
@@ -85,8 +99,11 @@ module Hotdog
|
|
85
99
|
@optparse.on("-1", "Use newline as separator") do |v|
|
86
100
|
options[:print1] = v
|
87
101
|
end
|
102
|
+
@optparse.on("-B", "--blocking", "Enable blocking mode") do
|
103
|
+
options[:max_time] = -1
|
104
|
+
end
|
88
105
|
@optparse.on("-d", "--[no-]debug", "Enable debug mode") do |v|
|
89
|
-
options[:
|
106
|
+
options[:debug] = v
|
90
107
|
end
|
91
108
|
@optparse.on("-E ENVIRONMENT", "--environment ENVIRONMENT", "Specify environment") do |environment|
|
92
109
|
options[:environment] = environment
|
@@ -98,7 +115,7 @@ module Hotdog
|
|
98
115
|
options[:force] = v
|
99
116
|
end
|
100
117
|
@optparse.on("-F FORMAT", "--format FORMAT", "Specify output format") do |format|
|
101
|
-
options[:
|
118
|
+
options[:format] = format
|
102
119
|
end
|
103
120
|
@optparse.on("-h", "--[no-]headers", "Display headeres for each columns") do |v|
|
104
121
|
options[:headers] = v
|
@@ -113,7 +130,7 @@ module Hotdog
|
|
113
130
|
options[:max_time] = seconds
|
114
131
|
end
|
115
132
|
@optparse.on("-V", "--[no-]verbose", "Enable verbose mode") do |v|
|
116
|
-
options[:
|
133
|
+
options[:verbose] = v
|
117
134
|
end
|
118
135
|
end
|
119
136
|
|
@@ -162,6 +179,24 @@ module Hotdog
|
|
162
179
|
end
|
163
180
|
end
|
164
181
|
end
|
182
|
+
|
183
|
+
def find_confdir(path)
|
184
|
+
if path == "/"
|
185
|
+
# default
|
186
|
+
if ENV.has_key?("HOTDOG_CONFDIR")
|
187
|
+
ENV["HOTDOG_CONFDIR"]
|
188
|
+
else
|
189
|
+
File.join(ENV["HOME"], ".hotdog")
|
190
|
+
end
|
191
|
+
else
|
192
|
+
confdir = File.join(path, ".hotdog")
|
193
|
+
if File.directory?(confdir)
|
194
|
+
confdir
|
195
|
+
else
|
196
|
+
find_confdir(File.dirname(path))
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
165
200
|
end
|
166
201
|
end
|
167
202
|
|
data/lib/hotdog/commands.rb
CHANGED
@@ -168,7 +168,7 @@ module Hotdog
|
|
168
168
|
( SELECT id FROM hosts WHERE LOWER(name) IN ( %s ) );
|
169
169
|
EOS
|
170
170
|
|
171
|
-
result["results"]["hosts"].
|
171
|
+
result["results"]["hosts"].each_with_index do |host_name, i|
|
172
172
|
@update_hosts_q2 ||= @db.prepare("INSERT OR IGNORE INTO hosts (name) VALUES (?);")
|
173
173
|
logger.debug("update_hosts_q2(%s)" % [host_name.inspect])
|
174
174
|
@update_hosts_q2.execute(host_name)
|
@@ -176,7 +176,8 @@ module Hotdog
|
|
176
176
|
|
177
177
|
elapsed_time = Time.new - @started_at
|
178
178
|
if 0 < options[:max_time] and options[:max_time] < elapsed_time
|
179
|
-
|
179
|
+
length = result["results"]["hosts"].length
|
180
|
+
logger.info("update_host_tags: exceeded maximum time (#{options[:max_time]} < #{elapsed_time}) after #{i+1}/#{length}. will resume on next run.")
|
180
181
|
suspend_host_tags
|
181
182
|
break
|
182
183
|
end
|
@@ -205,7 +206,7 @@ module Hotdog
|
|
205
206
|
logger.debug("update_tags_q2()")
|
206
207
|
hosts = @update_tags_q2.execute(Time.new.to_i)
|
207
208
|
end
|
208
|
-
hosts.
|
209
|
+
hosts.each_with_index do |host_id, i|
|
209
210
|
@update_tags_q3 ||= @db.prepare("DELETE FROM hosts_tags WHERE host_id = ? AND hosts_tags.expires_at < ?;")
|
210
211
|
logger.debug("update_tags_q3(%s, %s)" % [host_id.inspect, Time.new.to_i])
|
211
212
|
@update_tags_q3.execute(host_id, Time.new.to_i)
|
@@ -214,7 +215,8 @@ module Hotdog
|
|
214
215
|
|
215
216
|
elapsed_time = Time.new - @started_at
|
216
217
|
if 0 < options[:max_time] and options[:max_time] < elapsed_time
|
217
|
-
|
218
|
+
length = hosts.length
|
219
|
+
logger.info("update_host_tags: exceeded maximum time (#{options[:max_time]} < #{elapsed_time}) after #{i+1}/#{length}. will resume on next run.")
|
218
220
|
suspend_host_tags
|
219
221
|
break
|
220
222
|
end
|
data/lib/hotdog/commands/gc.rb
CHANGED
@@ -4,6 +4,7 @@ module Hotdog
|
|
4
4
|
module Commands
|
5
5
|
class Hosts < BaseCommand
|
6
6
|
def run(args=[])
|
7
|
+
application.run_command("init")
|
7
8
|
update_hosts(@options.dup)
|
8
9
|
|
9
10
|
if args.empty?
|
@@ -36,6 +37,7 @@ module Hotdog
|
|
36
37
|
if 0 < result.length
|
37
38
|
result, fields = get_hosts(result)
|
38
39
|
STDOUT.print(format(result, fields: fields))
|
40
|
+
logger.info("found %d host(s)." % result.length)
|
39
41
|
else
|
40
42
|
STDERR.puts("no match found: #{args.join(" ")}")
|
41
43
|
exit(1)
|
data/lib/hotdog/commands/init.rb
CHANGED
@@ -7,6 +7,7 @@ module Hotdog
|
|
7
7
|
module Commands
|
8
8
|
class Search < BaseCommand
|
9
9
|
def run(args=[])
|
10
|
+
application.run_command("init")
|
10
11
|
expression = args.join(" ").strip
|
11
12
|
if expression.empty?
|
12
13
|
exit(1)
|
@@ -24,6 +25,7 @@ module Hotdog
|
|
24
25
|
if 0 < result.length
|
25
26
|
result, fields = get_hosts(result)
|
26
27
|
STDOUT.print(format(result, fields: fields))
|
28
|
+
logger.info("found %d host(s)." % result.length)
|
27
29
|
else
|
28
30
|
STDERR.puts("no match found: #{args.join(" ")}")
|
29
31
|
exit(1)
|
data/lib/hotdog/commands/tags.rb
CHANGED
@@ -4,6 +4,7 @@ module Hotdog
|
|
4
4
|
module Commands
|
5
5
|
class Tags < BaseCommand
|
6
6
|
def run(args=[])
|
7
|
+
application.run_command("init")
|
7
8
|
update_tags(@options.dup)
|
8
9
|
if 0 < tags.length
|
9
10
|
fields = tags.map { |tag|
|
@@ -43,6 +44,7 @@ module Hotdog
|
|
43
44
|
end
|
44
45
|
if 0 < result.length
|
45
46
|
STDOUT.print(format(result, fields: fields))
|
47
|
+
logger.info("found %d tag(s)." % result.length)
|
46
48
|
end
|
47
49
|
end
|
48
50
|
end
|
@@ -4,7 +4,8 @@ module Hotdog
|
|
4
4
|
module Commands
|
5
5
|
class Update < BaseCommand
|
6
6
|
def run(args=[])
|
7
|
-
|
7
|
+
application.run_command("init")
|
8
|
+
options[:max_time] = -1
|
8
9
|
if 0 < args.length
|
9
10
|
args.each do |host_name|
|
10
11
|
update_host_tags(host_name, @options.dup)
|
data/lib/hotdog/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hotdog
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yamashita Yuu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|