nat-monitor 1.0.11 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.editorconfig +18 -0
- data/README.md +17 -1
- data/Rakefile +6 -0
- data/lib/nat-monitor.rb +33 -8
- data/lib/nat-monitor/version.rb +1 -1
- data/spec/lib/nat-monitor_spec.rb +23 -6
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 39809faab717e9222a32e1520359264a4834b6b4
|
4
|
+
data.tar.gz: 6035485c770176b543d8d05cf61a71967e494ac2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 50c4559ab357e3709eb4c38a7d78948d98334fc49ccd1fa419de097c295bd7375db66becea3444d919ad4b7f994001f9b464864aa0a7c20c03c059a70e40edc4
|
7
|
+
data.tar.gz: 03d4a9b94634733abb3685dd59a1923509de74872e727a630a43af92ac2b3115a423f55e612a323af0b3ad07f716ecd4911d2eb963da7700ed5a08a237f98bd0
|
data/.editorconfig
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
; EditorConfig is awesome: http://EditorConfig.org
|
2
|
+
|
3
|
+
root = true
|
4
|
+
|
5
|
+
; UTF-8 charset
|
6
|
+
; Unix-style newlines with a newline ending every file
|
7
|
+
; 4 space indent
|
8
|
+
; Trim trailing whitespace
|
9
|
+
[*]
|
10
|
+
indent_style = space
|
11
|
+
indent_size = 2
|
12
|
+
end_of_line = lf
|
13
|
+
charset = utf-8
|
14
|
+
trim_trailing_whitespace = true
|
15
|
+
insert_final_newline = true
|
16
|
+
|
17
|
+
[*.md]
|
18
|
+
indent_size = 4
|
data/README.md
CHANGED
@@ -44,20 +44,36 @@ nodes:
|
|
44
44
|
```
|
45
45
|
|
46
46
|
Optional properties include (Values shown are the defaults):
|
47
|
+
|
47
48
|
```yaml
|
48
49
|
pings: 3
|
49
50
|
ping_timeout: 1
|
50
51
|
heartbeat_interval: 10
|
52
|
+
monitor_enabled: false
|
51
53
|
```
|
52
54
|
|
53
55
|
Optional AWS configuration include:
|
56
|
+
|
54
57
|
```yaml
|
55
58
|
aws_access_key_id: YOUR ACCESS KEY
|
56
59
|
aws_secret_access_key: YOUR SECRET KEY
|
57
60
|
region: us-east-1
|
58
61
|
```
|
62
|
+
|
59
63
|
Note that:
|
60
|
-
|
64
|
+
|
65
|
+
- If you don't specify the AWS credentials it will use the IAM role of the instance
|
66
|
+
|
67
|
+
The NAT Monitor has the ability to report out, via a simple URL request, its start, success, and failures. This functionality is modeled after what [Cronitor.io](http://cronitor.io) expects.
|
68
|
+
|
69
|
+
Requisite configuration needed:
|
70
|
+
|
71
|
+
```yaml
|
72
|
+
monitor:
|
73
|
+
begin: your.url/run
|
74
|
+
success: your.url/complete
|
75
|
+
fail: your.url/fail
|
76
|
+
```
|
61
77
|
|
62
78
|
## Contributing
|
63
79
|
|
data/Rakefile
CHANGED
data/lib/nat-monitor.rb
CHANGED
@@ -21,31 +21,44 @@ module EtTools
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def validate!
|
24
|
+
exit_code = false
|
25
|
+
|
24
26
|
case
|
25
27
|
when !@conf['route_table_id']
|
26
|
-
|
27
|
-
|
28
|
+
msg = 'route_table_id not specified'
|
29
|
+
exit_code = 1
|
28
30
|
when !route_exists?(@conf['route_table_id'])
|
29
|
-
|
30
|
-
|
31
|
+
msg = "Route #{@conf['route_table_id']} not found"
|
32
|
+
exit_code = 2
|
31
33
|
when @conf['nodes'].count < 3
|
32
|
-
|
33
|
-
|
34
|
+
msg = '3 or more nodes are required to create a quorum'
|
35
|
+
exit_code = 3
|
34
36
|
end
|
37
|
+
|
38
|
+
return unless exit_code
|
39
|
+
|
40
|
+
notify_monitor 'fail', msg
|
41
|
+
output msg
|
42
|
+
exit exit_code
|
35
43
|
end
|
36
44
|
|
37
45
|
def defaults
|
38
46
|
{ 'pings' => 3,
|
39
47
|
'ping_timeout' => 1,
|
40
|
-
'heartbeat_interval' => 10
|
48
|
+
'heartbeat_interval' => 10,
|
49
|
+
'monitor_enabled' => false }
|
41
50
|
end
|
42
51
|
|
43
52
|
def main_loop
|
44
53
|
loop do
|
45
54
|
begin
|
55
|
+
notify_monitor 'begin'
|
46
56
|
heartbeat
|
57
|
+
notify_monitor 'success'
|
47
58
|
rescue => e
|
48
|
-
|
59
|
+
msg = "Caught #{e.class} exception: #{e.message}"
|
60
|
+
notify_monitor 'fail', msg
|
61
|
+
output msg
|
49
62
|
output e.backtrace
|
50
63
|
end
|
51
64
|
sleep @conf['heartbeat_interval']
|
@@ -146,6 +159,14 @@ module EtTools
|
|
146
159
|
current_master == node_id
|
147
160
|
end
|
148
161
|
|
162
|
+
def notify_monitor(status, msg = nil)
|
163
|
+
return unless @conf['monitor_enabled']
|
164
|
+
url = monitor_url status
|
165
|
+
url += "?msg=#{msg}" if status == 'fail' && !msg.nil?
|
166
|
+
|
167
|
+
Net::HTTP.get(URI url)
|
168
|
+
end
|
169
|
+
|
149
170
|
private
|
150
171
|
|
151
172
|
def output(message)
|
@@ -158,5 +179,9 @@ module EtTools
|
|
158
179
|
s.send(level, message)
|
159
180
|
end
|
160
181
|
end
|
182
|
+
|
183
|
+
def monitor_url(status)
|
184
|
+
@conf['monitor'][status]
|
185
|
+
end
|
161
186
|
end
|
162
187
|
end
|
data/lib/nat-monitor/version.rb
CHANGED
@@ -13,6 +13,11 @@ describe EtTools::NatMonitor do
|
|
13
13
|
@yaml_conf = { 'route_table_id' => @route_table_id,
|
14
14
|
'aws_access_key_id' => 'AWS_ACCESS_KEY_ID',
|
15
15
|
'aws_secret_access_key' => 'AWS_SECRET_ACCESS_KEY',
|
16
|
+
'monitor' => {
|
17
|
+
'begin' => 'run',
|
18
|
+
'success' => 'complete',
|
19
|
+
'fail' => 'fail'
|
20
|
+
},
|
16
21
|
'nodes' => (
|
17
22
|
{ @my_instance_id => '1.1.1.1' }
|
18
23
|
).merge(@other_nodes) }
|
@@ -26,7 +31,8 @@ describe EtTools::NatMonitor do
|
|
26
31
|
|
27
32
|
@defaults = { 'pings' => 3,
|
28
33
|
'ping_timeout' => 1,
|
29
|
-
'heartbeat_interval' => 10
|
34
|
+
'heartbeat_interval' => 10,
|
35
|
+
'monitor_enabled' => false }
|
30
36
|
|
31
37
|
allow(@nat_monitor).to receive(:my_instance_id).and_return(@my_instance_id)
|
32
38
|
end
|
@@ -39,13 +45,17 @@ describe EtTools::NatMonitor do
|
|
39
45
|
({ 'route_table_id' => @route_table_id,
|
40
46
|
'aws_access_key_id' => 'AWS_ACCESS_KEY_ID',
|
41
47
|
'aws_secret_access_key' => 'AWS_SECRET_ACCESS_KEY',
|
48
|
+
'monitor_enabled' => false,
|
42
49
|
'nodes' => @other_nodes })
|
43
50
|
)
|
44
51
|
allow(@nat_monitor).to receive(:route_exists?).with(any_args)
|
45
52
|
.and_return true
|
46
53
|
end
|
47
54
|
|
48
|
-
it 'exits with status 3' do
|
55
|
+
it 'sends a fail ping and exits with status 3' do
|
56
|
+
expect(@nat_monitor).to receive(:notify_monitor).with(
|
57
|
+
'fail',
|
58
|
+
'3 or more nodes are required to create a quorum')
|
49
59
|
expect(@nat_monitor).to receive(:exit).with(3)
|
50
60
|
@nat_monitor.validate!
|
51
61
|
end
|
@@ -60,7 +70,10 @@ describe EtTools::NatMonitor do
|
|
60
70
|
]
|
61
71
|
end
|
62
72
|
|
63
|
-
it 'exits with status 2' do
|
73
|
+
it 'sends a fail ping and exits with status 2' do
|
74
|
+
expect(@nat_monitor).to receive(:notify_monitor).with(
|
75
|
+
'fail',
|
76
|
+
'Route rtb-00000000 not found')
|
64
77
|
expect(@nat_monitor).to receive(:exit).with(2)
|
65
78
|
@nat_monitor.validate!
|
66
79
|
end
|
@@ -70,11 +83,15 @@ describe EtTools::NatMonitor do
|
|
70
83
|
before do
|
71
84
|
@nat_monitor.instance_variable_set(
|
72
85
|
:@conf,
|
86
|
+
'monitor_enabled' => false,
|
73
87
|
'nodes' => ({ @my_instance_id => '1.1.1.1' }).merge(@other_nodes)
|
74
88
|
)
|
75
89
|
end
|
76
90
|
|
77
|
-
it 'exits with status 1' do
|
91
|
+
it 'sends a fail ping and exits with status 1' do
|
92
|
+
expect(@nat_monitor).to receive(:notify_monitor).with(
|
93
|
+
'fail',
|
94
|
+
'route_table_id not specified')
|
78
95
|
expect(@nat_monitor).to receive(:exit).with(1)
|
79
96
|
@nat_monitor.validate!
|
80
97
|
end
|
@@ -89,7 +106,7 @@ describe EtTools::NatMonitor do
|
|
89
106
|
|
90
107
|
it 'sets @conf correctly' do
|
91
108
|
expect(@nat_monitor.instance_variable_get(:@conf)).to eq(
|
92
|
-
@
|
109
|
+
@defaults.merge(@yaml_conf)
|
93
110
|
)
|
94
111
|
end
|
95
112
|
|
@@ -184,7 +201,7 @@ describe EtTools::NatMonitor do
|
|
184
201
|
before do
|
185
202
|
@nat_monitor.instance_variable_set(
|
186
203
|
:@conf,
|
187
|
-
@yaml_conf.merge('mocking' => true)
|
204
|
+
@defaults.merge(@yaml_conf.merge('mocking' => true))
|
188
205
|
)
|
189
206
|
end
|
190
207
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nat-monitor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Herot
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-09-
|
11
|
+
date: 2015-09-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -122,6 +122,7 @@ executables:
|
|
122
122
|
extensions: []
|
123
123
|
extra_rdoc_files: []
|
124
124
|
files:
|
125
|
+
- ".editorconfig"
|
125
126
|
- ".gitignore"
|
126
127
|
- Gemfile
|
127
128
|
- LICENSE.txt
|
@@ -153,11 +154,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
153
154
|
version: '0'
|
154
155
|
requirements: []
|
155
156
|
rubyforge_project:
|
156
|
-
rubygems_version: 2.4.
|
157
|
+
rubygems_version: 2.4.6
|
157
158
|
signing_key:
|
158
159
|
specification_version: 4
|
159
160
|
summary: A service for providing an HA NAT in EC2
|
160
161
|
test_files:
|
161
162
|
- spec/lib/nat-monitor_spec.rb
|
162
163
|
- spec/spec_helper.rb
|
163
|
-
has_rdoc:
|