hotdog 0.4.1 → 0.5.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
  SHA1:
3
- metadata.gz: ffbad3cddd1c8a203564a0a72f76f4afcdeedb31
4
- data.tar.gz: 0b2a720a116b8a7744cfe91e83145106f6841bb6
3
+ metadata.gz: 4c464a62cf28997e088dd57a9e0ede3f2983f274
4
+ data.tar.gz: 85ad0d5644e20a84eaa99fee56c86ad8ead5de21
5
5
  SHA512:
6
- metadata.gz: e460694b774e72633795116768078474b89e3ff5196b1fd6081102264bd29f496b0b1e7addf9742c8912eeb6ec9fb0e1d8592220db10d4fa25e27a94a4fb4a91
7
- data.tar.gz: 898f4efe04b91dff88a420d257c839391162354e5d985599940199c6afa91b37a3efba0f3c99fc48208241e5fa4ec72edbd48cacfef078932b18066a66145739
6
+ metadata.gz: b1ae715a85cc4ad9531cbbb23a965df3c0dede59a5c2fdaf4b09fd3bf24b4e4eb2f98863357924d88feff3729c4f89bf54c484311c9a2c7152ddb59e85db2101
7
+ data.tar.gz: d79aa608eecf509fc7838f2ab3682eeea5f7009bea8479f334a7194f875b9b8b05572f16dbbdaa1788f818c3f04ba002e64a12ec931bfc856c631f34ec9f37e3
data/README.md CHANGED
@@ -105,6 +105,7 @@ expression: expression0
105
105
 
106
106
  expression0: expression1 "and" expression
107
107
  | expression1 "or" expression
108
+ | expression1 "xor" expression
108
109
  | expression1
109
110
  ;
110
111
 
@@ -118,6 +119,9 @@ expression2: expression3 expression
118
119
 
119
120
  expression3: expression4 "&&" expression
120
121
  | expression4 "||" expression
122
+ | expression4 '&' expression
123
+ | expression4 '^' expression
124
+ | expression4 '|' expression
121
125
  | expression4
122
126
  ;
123
127
 
@@ -28,6 +28,7 @@ module Hotdog
28
28
  logger.level = Logger::INFO
29
29
  },
30
30
  max_time: 5,
31
+ offline: false,
31
32
  print0: false,
32
33
  print1: true,
33
34
  primary_tag: nil,
@@ -50,25 +51,27 @@ module Hotdog
50
51
  end
51
52
  args = @optparse.order(argv)
52
53
 
53
- unless options[:api_key]
54
- raise("DATADOG_API_KEY is not set")
55
- end
54
+ begin
55
+ command = ( args.shift || "help" )
56
+ get_command(command).new(self).tap do |cmd|
57
+ cmd.define_options(@optparse)
58
+ args = cmd.parse_options(@optparse, args)
59
+ unless options[:api_key]
60
+ raise("DATADOG_API_KEY is not set")
61
+ end
56
62
 
57
- unless options[:application_key]
58
- raise("DATADOG_APPLICATION_KEY is not set")
59
- end
63
+ unless options[:application_key]
64
+ raise("DATADOG_APPLICATION_KEY is not set")
65
+ end
60
66
 
61
- options[:formatter] = get_formatter(options[:format]).new
67
+ options[:formatter] = get_formatter(options[:format]).new
62
68
 
63
- if options[:debug] or options[:verbose]
64
- options[:logger].level = Logger::DEBUG
65
- else
66
- options[:logger].level = Logger::INFO
67
- end
69
+ if options[:debug] or options[:verbose]
70
+ options[:logger].level = Logger::DEBUG
71
+ else
72
+ options[:logger].level = Logger::INFO
73
+ end
68
74
 
69
- begin
70
- command = ( args.shift || "help" )
71
- get_command(command).new(self).tap do |cmd|
72
75
  cmd.run(args)
73
76
  end
74
77
  rescue Errno::EPIPE
@@ -120,6 +123,9 @@ module Hotdog
120
123
  @optparse.on("-V", "--[no-]verbose", "Enable verbose mode") do |v|
121
124
  options[:verbose] = v
122
125
  end
126
+ @optparse.on("--[no-]offline", "Enable offline mode") do |v|
127
+ options[:offline] = v
128
+ end
123
129
  end
124
130
 
125
131
  def const_name(name)
@@ -5,24 +5,26 @@ require "fileutils"
5
5
  module Hotdog
6
6
  module Commands
7
7
  class Down < BaseCommand
8
- def run(args=[])
9
- downtime = 86400
10
- start = Time.new
8
+ def define_options(optparse)
9
+ @downtime = 86400
10
+ @start = Time.new
11
11
  optparse.on("--downtime DURATION") do |v|
12
- downtime = v.to_i
12
+ @downtime = v.to_i
13
13
  end
14
14
  optparse.on("--start TIME") do |v|
15
- start = Time.parse(v)
15
+ @start = Time.parse(v)
16
16
  end
17
- args = optparse.parse(args)
17
+ end
18
+
19
+ def run(args=[])
18
20
  args.each do |arg|
19
21
  if arg.index(":").nil?
20
22
  scope = "host:#{arg}"
21
23
  else
22
24
  scope = arg
23
25
  end
24
- code, schedule = @dog.schedule_downtime(scope, :start => start.to_i, :end => (start+downtime).to_i)
25
- logger.debug("dog.schedule_donwtime(%s, :start => %s, :end => %s) #==> [%s, %s]" % [scope.inspect, start.to_i, (start+downtime).to_i, code.inspect, schedule.inspect])
26
+ code, schedule = @dog.schedule_downtime(scope, :start => @start.to_i, :end => (@start+@downtime).to_i)
27
+ logger.debug("dog.schedule_donwtime(%s, :start => %s, :end => %s) #==> [%s, %s]" % [scope.inspect, @start.to_i, (@start+@downtime).to_i, code.inspect, schedule.inspect])
26
28
  if code.to_i / 100 != 2
27
29
  raise("dog.schedule_downtime(%s, ...) returns [%s, %s]" % [scope.inspect, code.inspect, schedule.inspect])
28
30
  end
@@ -4,7 +4,6 @@ module Hotdog
4
4
  module Commands
5
5
  class Hosts < BaseCommand
6
6
  def run(args=[])
7
- args = optparse.parse(args)
8
7
  if args.empty?
9
8
  result = execute("SELECT id FROM hosts").to_a.reduce(:+)
10
9
  show_hosts(result)
@@ -9,36 +9,39 @@ require "parallel"
9
9
  module Hotdog
10
10
  module Commands
11
11
  class Pssh < Search
12
- def run(args=[])
13
- ssh_option = {
12
+ def define_options(optparse)
13
+ @ssh_options = @options.merge({
14
14
  options: [],
15
15
  user: nil,
16
16
  port: nil,
17
17
  identity_file: nil,
18
18
  max_parallelism: nil,
19
- }
19
+ })
20
20
 
21
21
  optparse.on("-o SSH_OPTION", "Passes this string to ssh command through shell. This option may be given multiple times") do |option|
22
- ssh_option[:options] += [option]
22
+ @ssh_options[:options] += [option]
23
23
  end
24
24
  optparse.on("-i SSH_IDENTITY_FILE", "SSH identity file path") do |path|
25
- ssh_option[:identity_file] = path
25
+ @ssh_options[:identity_file] = path
26
26
  end
27
27
  optparse.on("-p PORT", "Port of the remote host", Integer) do |port|
28
- ssh_option[:port] = port
28
+ @ssh_options[:port] = port
29
29
  end
30
30
  optparse.on("-u SSH_USER", "SSH login user name") do |user|
31
- ssh_option[:user] = user
31
+ @ssh_options[:user] = user
32
32
  end
33
33
  optparse.on("-P PARALLELISM", "Max parallelism", Integer) do |n|
34
- ssh_option[:max_parallelism] = n
34
+ @ssh_options[:max_parallelism] = n
35
35
  end
36
+ end
36
37
 
37
- use_color = STDOUT.tty?
38
+ def parse_options(optparse, args=[])
39
+ optparse.order(args)
40
+ end
38
41
 
39
- search_args = []
40
- optparse.order!(args) {|search_arg| search_args.push(search_arg) }
41
- expression = search_args.join(" ").strip
42
+ def run(args=[])
43
+ use_color = STDOUT.tty?
44
+ expression = args.join(" ").strip
42
45
  if expression.empty? || args.empty?
43
46
  exit(1)
44
47
  end
@@ -62,25 +65,25 @@ module Hotdog
62
65
 
63
66
  # build ssh command
64
67
  cmdline = ["ssh"]
65
- ssh_option[:options].each do |option|
68
+ @ssh_options[:options].each do |option|
66
69
  cmdline << "-o" << option
67
70
  end
68
- if path = ssh_option[:identity_file]
71
+ if path = @ssh_options[:identity_file]
69
72
  cmdline << "-i" << Shellwords.escape(path)
70
73
  end
71
- if port = ssh_option[:port]
74
+ if port = @ssh_options[:port]
72
75
  cmdline << "-p" << port.to_s
73
76
  end
74
- if ssh_option[:forward_agent]
77
+ if @ssh_options[:forward_agent]
75
78
  cmdline << "-A"
76
79
  end
77
80
 
78
81
  cmdline << "-o" << "BatchMode=yes"
79
82
 
80
- user = ssh_option[:user]
83
+ user = @ssh_options[:user]
81
84
 
82
- threads = ssh_option[:max_parallelism] || addresses.size
83
- stats = Parallel.map(addresses, in_threads: threads) do |address,name|
85
+ threads = @ssh_options[:max_parallelism] || addresses.size
86
+ stats = Parallel.map(addresses, in_threads: threads) { |address,name|
84
87
  if use_color
85
88
  header = "\e[0;36m#{name}\e[00m"
86
89
  else
@@ -97,14 +100,14 @@ module Hotdog
97
100
  c.concat(args)
98
101
 
99
102
  IO.popen([*c, in: :close, err: [:child, :out]]) do |io|
100
- io.each_line {|line|
103
+ io.each_line do |line|
101
104
  STDOUT.write "#{header}: #{line}"
102
- }
105
+ end
103
106
  end
104
- $?.success? # $? is thread-local variable
105
- end
107
+ $?.success? # $? is thread-local variable
108
+ }
106
109
 
107
- unless stats.all? {|success| success }
110
+ unless stats.all?
108
111
  exit(1)
109
112
  end
110
113
  end