hotdog 0.6.6 → 0.7.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 72dc15c8a8c3c455d56966dfc98939ff41c756c5
4
- data.tar.gz: 391d7824e973ef9052b74b4f12147126d1e9d16d
3
+ metadata.gz: 5d906ae40a16258f5ad595603dd51cf64b503e46
4
+ data.tar.gz: 50186c1878f0de3534a4e7b8a502ce4380bbe2df
5
5
  SHA512:
6
- metadata.gz: 2808053dc1e82f575acd539c47a3a5ef55aad0a205b53d58df352ec3d4fca4545a28add805c21be27d880aaa11eab2fa5e93f447ffcd9946b29687ee4886370f
7
- data.tar.gz: 95179c55f323d9dd2d3fcacde85b63bb3ab57615e6940e6345d6089f7bed69b68cd9fe67652f104eedacf8860c37c65d2de102c9197a85307a3e232d421e6adc
6
+ metadata.gz: 84a3883786cf631e1874fb39ed08c6475ee4ca293c8bca4d80ca6852191b8e59facfdbb7bcd3ca5ff3ed41632dae89620776986e6e03e9868e029ac796ec003c
7
+ data.tar.gz: ee613ad02480b125061011cbd80e05e60ca1716abd48242659552b8b3865ee083fcafca7733bf75eceaf2d2281f2b96403fa6d9e3c63f4a8c24c18b7407365f3
data/Rakefile CHANGED
@@ -1,2 +1,6 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
2
3
 
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => [:spec]
@@ -277,7 +277,7 @@ module Hotdog
277
277
  logger.debug("execute: #{q} -- #{args.inspect}")
278
278
  prepare(db, q).execute(args)
279
279
  rescue
280
- logger.error("failed: #{q} -- #{args.inspect}")
280
+ logger.warn("failed: #{q} -- #{args.inspect}")
281
281
  raise
282
282
  end
283
283
  end
@@ -287,7 +287,8 @@ module Hotdog
287
287
  requests = {all_downtime: "/api/v1/downtime", all_tags: "/api/v1/tags/hosts"}
288
288
  query = URI.encode_www_form(api_key: options[:api_key], application_key: options[:application_key])
289
289
  begin
290
- responses = Hash[Parallel.map(requests) { |name, request_path|
290
+ parallelism = Parallel.processor_count
291
+ responses = Hash[Parallel.map(requests, in_threads: parallelism) { |name, request_path|
291
292
  uri = URI.join(endpoint, "#{request_path}?#{query}")
292
293
  begin
293
294
  response = uri.open("User-Agent" => "hotdog/#{Hotdog::VERSION}") { |fp| fp.read }
@@ -304,7 +305,7 @@ module Hotdog
304
305
  now = Time.new.to_i
305
306
  downtimes = responses.fetch(:all_downtime, []).select { |downtime|
306
307
  # active downtimes
307
- downtime["active"] and ( downtime["start"].nil? or downtime["start"] < now ) and ( downtime["end"].nil? or now <= downtime["end"] )
308
+ downtime["active"] and ( downtime["start"].nil? or downtime["start"] < now ) and ( downtime["end"].nil? or now <= downtime["end"] ) and downtime["monitor_id"].nil?
308
309
  }.flat_map { |downtime|
309
310
  # find host scopes
310
311
  downtime["scope"].select { |scope| scope.start_with?("host:") }.map { |scope| scope.sub(/\Ahost:/, "") }
@@ -33,8 +33,8 @@ module Hotdog
33
33
  # Remove persistent.db to schedule update on next invocation
34
34
  if @db
35
35
  close_db(@db)
36
- FileUtils.rm_f(File.join(options[:confdir], PERSISTENT_DB))
37
36
  end
37
+ FileUtils.rm_f(File.join(options[:confdir], PERSISTENT_DB))
38
38
  end
39
39
  end
40
40
  end
@@ -9,11 +9,20 @@ require "hotdog/commands/ssh"
9
9
  module Hotdog
10
10
  module Commands
11
11
  class Pssh < SshAlike
12
+ def define_options(optparse, options={})
13
+ super
14
+ options[:show_identifier] = true
15
+ optparse.on("--[no-]identifier", "Each output line will be prepended with identifier.") do |identifier|
16
+ options[:show_identifier] = identifier
17
+ end
18
+ end
19
+
12
20
  private
13
21
  def run_main(hosts, options={})
14
22
  stats = Parallel.map(hosts.each_with_index.to_a, in_threads: parallelism(hosts)) { |host, i|
15
23
  cmdline = build_command_string(host, @remote_command, options)
16
- exec_command(host, cmdline, index: i, output: true)
24
+ identifier = options[:show_identifier] ? host : nil
25
+ exec_command(identifier, cmdline, index: i, output: true)
17
26
  }
18
27
  if stats.all?
19
28
  exit(0)
@@ -162,15 +162,17 @@ module Hotdog
162
162
  IO.popen(cmdline, in: :close, err: [:child, :out]) do |io|
163
163
  io.each_with_index do |s, i|
164
164
  if output
165
- if color
166
- STDOUT.write("\e[0;#{color}m")
167
- end
168
- STDOUT.write(identifier)
169
- STDOUT.write(":")
170
- STDOUT.write(i.to_s)
171
- STDOUT.write(":")
172
- if color
173
- STDOUT.write("\e[0m")
165
+ if identifier
166
+ if color
167
+ STDOUT.write("\e[0;#{color}m")
168
+ end
169
+ STDOUT.write(identifier)
170
+ STDOUT.write(":")
171
+ STDOUT.write(i.to_s)
172
+ STDOUT.write(":")
173
+ if color
174
+ STDOUT.write("\e[0m")
175
+ end
174
176
  end
175
177
  STDOUT.puts(s)
176
178
  end
@@ -32,8 +32,8 @@ module Hotdog
32
32
  # Remove persistent.db to schedule update on next invocation
33
33
  if @db
34
34
  close_db(@db)
35
- FileUtils.rm_f(File.join(options[:confdir], PERSISTENT_DB))
36
35
  end
36
+ FileUtils.rm_f(File.join(options[:confdir], PERSISTENT_DB))
37
37
  end
38
38
  end
39
39
  end
@@ -1,3 +1,3 @@
1
1
  module Hotdog
2
- VERSION = "0.6.6"
2
+ VERSION = "0.7.0"
3
3
  end
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.6.6
4
+ version: 0.7.0
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-11-13 00:00:00.000000000 Z
11
+ date: 2015-12-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler