alerty 0.0.7 → 0.0.8

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: 7dc780dc6ff3b7cb73a5a2437a14c8d3b20dd6b9
4
- data.tar.gz: 69c93803fae418ba85eb59209d7f72be131e7c0d
3
+ metadata.gz: 99625b0f092fb2052e60c8129488d491979362b1
4
+ data.tar.gz: 880411be5f61727839f2cfb6e72c5d5113fd4ffa
5
5
  SHA512:
6
- metadata.gz: 024cebed5e8cdb6e2ba635b4843ad7eccd8aef3b7ae236d59a73fc23feb022fe90c1a97d74164ba7f96d7fd8631c0408d29ee2bbfaff1ba62ef1f3e20183db51
7
- data.tar.gz: 001e13b2d87b2456fda46b973690fd1080c2ae676cc08f4e5d92db5f0a8b12cfe3948c3e5062d5fa0b6893855c2d9aafd25699cae56447db44b3036f3a150a7f
6
+ metadata.gz: 9233e87fdfc4cb57d2421749a2b5596d9d6e06c20518ecef6fac7d5a902ccd1d65ad3066c74d7e5787ca729ec5023c86c98d732536f35e5becfde49ffe37583e
7
+ data.tar.gz: d55ebdb2a4aa61cb5cad01599789acbdea3f3ec219efb2de4be783b853ada5bb61e9375f19ca099c59295cb8d0f520ea451b14624bb9b4e14a18d6f0d5792e41
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ # 0.0.8 (2015/08/15)
2
+
3
+ Enhancements:
4
+
5
+ * Send alert if timeout or locked occurs
6
+
1
7
  # 0.0.7 (2015/08/15)
2
8
 
3
9
  Enhancements:
data/README.md CHANGED
@@ -44,8 +44,8 @@ $ bin/alerty -h
44
44
  -c, --config CONFIG_FILE config file path (default: /etc/alerty/alerty.yml)
45
45
  --log LOG_FILE log file path (default: STDOUT)
46
46
  -l, --log-level LOG_LEVEL log level (default: warn)
47
- -t, --timeout SECONDS timeout the command (default: no timeout)
48
- --lock LOCK_FILE exclusive lock file to prevent running a command duplicatedly (default: no lock)
47
+ -t, --timeout SECONDS timeout of the command, send alert if timeout reached (default: no timeout)
48
+ --lock LOCK_FILE exclusive lock file to prevent running a command duplicatedly, send alert if locked (default: no lock)
49
49
  -d, --debug debug mode (same with --log-level debug)
50
50
  ```
51
51
 
data/alerty.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = "alerty"
3
- gem.version = '0.0.7'
3
+ gem.version = '0.0.8'
4
4
  gem.author = ['Naotoshi Seo']
5
5
  gem.email = ['sonots@gmail.com']
6
6
  gem.homepage = 'https://github.com/sonots/alerty'
@@ -15,7 +15,7 @@ Gem::Specification.new do |gem|
15
15
 
16
16
  gem.add_runtime_dependency 'hashie'
17
17
  gem.add_runtime_dependency 'oneline_log_formatter'
18
- gem.add_runtime_dependency 'frontkick'
18
+ gem.add_runtime_dependency 'frontkick', '>= 0.4.0'
19
19
 
20
20
  gem.add_development_dependency 'rspec'
21
21
  gem.add_development_dependency 'pry'
@@ -12,17 +12,38 @@ class Alerty
12
12
 
13
13
  def run!
14
14
  started_at = Time.now
15
- result = Frontkick.exec("#{@command} 2>&1", @opts)
16
- record = {
17
- hostname: @hostname,
18
- command: @command,
19
- exitstatus: result.exitstatus,
20
- output: result.stdout,
21
- started_at: started_at.to_f,
22
- duration: result.duration,
23
- }
15
+ begin
16
+ result = Frontkick.exec("#{@command} 2>&1", @opts)
17
+ rescue Frontkick::Timeout => e
18
+ record = {
19
+ hostname: @hostname,
20
+ command: @command,
21
+ exitstatus: 1,
22
+ output: "`#{@command}` is timeout (#{@opts[:timeout]} sec)",
23
+ started_at: started_at.to_f,
24
+ duration: @opts[:timeout],
25
+ }
26
+ rescue Frontkick::Locked => e
27
+ record = {
28
+ hostname: @hostname,
29
+ command: @command,
30
+ exitstatus: 1,
31
+ output: "`#{@opts[:exclusive]}` is locked by another process",
32
+ started_at: started_at.to_f,
33
+ duration: 0,
34
+ }
35
+ else
36
+ record = {
37
+ hostname: @hostname,
38
+ command: @command,
39
+ exitstatus: result.exitstatus,
40
+ output: result.stdout,
41
+ started_at: started_at.to_f,
42
+ duration: result.duration,
43
+ }
44
+ end
24
45
  Alerty.logger.info { "result: #{record.to_json}" }
25
- if result.success?
46
+ if record[:exitstatus] == 0
26
47
  exit 0
27
48
  else
28
49
  Config.plugins.each do |plugin|
@@ -32,7 +53,7 @@ class Alerty
32
53
  Alerty.logger.warn "#{e.class} #{e.message} #{e.backtrace.join("\n")}"
33
54
  end
34
55
  end
35
- exit result.exitstatus
56
+ exit record[:exitstatus]
36
57
  end
37
58
  end
38
59
  end
data/spec/command_spec.rb CHANGED
@@ -49,5 +49,60 @@ describe Alerty::Command do
49
49
  expect(JSON.parse(stdout)["output"]).to eql("foo")
50
50
  end
51
51
  end
52
+
53
+ context 'timeout' do
54
+ before do
55
+ Alerty::Config.instance_variable_set(:@config, Hashie::Mash.new(
56
+ plugins: [{
57
+ type: 'stdout',
58
+ }]
59
+ ))
60
+ Alerty::Config.configure(
61
+ log_path: '/tmp/foo',
62
+ log_level: 'fatal',
63
+ timeout: 0.1,
64
+ lock_path: '/tmp/lock',
65
+ )
66
+ end
67
+
68
+ let(:command) { Alerty::Command.new(command: 'sleep 1') }
69
+
70
+ it do
71
+ expect(Frontkick).to receive(:exec).with("sleep 1 2>&1", {
72
+ timeout: 0.1,
73
+ exclusive: '/tmp/lock',
74
+ }).and_raise(Frontkick::Timeout.new(111, 'sleep 1 2>&1', true))
75
+ stdout = capture_stdout { expect { command.run! }.to raise_error(SystemExit) }
76
+ expect(JSON.parse(stdout)["output"]).to include("timeout")
77
+ end
78
+ end
79
+
80
+ context 'lock' do
81
+ before do
82
+ Alerty::Config.instance_variable_set(:@config, Hashie::Mash.new(
83
+ plugins: [{
84
+ type: 'stdout',
85
+ }]
86
+ ))
87
+ Alerty::Config.configure(
88
+ log_path: '/tmp/foo',
89
+ log_level: 'fatal',
90
+ timeout: 20,
91
+ lock_path: '/tmp/lock',
92
+ )
93
+ end
94
+
95
+ let(:command) { Alerty::Command.new(command: 'sleep 1') }
96
+
97
+ it do
98
+ expect(Frontkick).to receive(:exec).with("sleep 1 2>&1", {
99
+ timeout: 20,
100
+ exclusive: '/tmp/lock',
101
+ }).and_raise(Frontkick::Locked)
102
+ stdout = capture_stdout { expect { command.run! }.to raise_error(SystemExit) }
103
+ expect(JSON.parse(stdout)["output"]).to include("lock")
104
+ end
105
+ end
106
+
52
107
  end
53
108
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alerty
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Naotoshi Seo
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: 0.4.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: 0.4.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement