naminori 0.1.4 → 0.2.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 +4 -4
- data/README.md +12 -14
- data/lib/naminori/lb.rb +0 -18
- data/lib/naminori/lb/base.rb +2 -2
- data/lib/naminori/notifier.rb +9 -5
- data/lib/naminori/notifier/base.rb +1 -6
- data/lib/naminori/notifier/configure.rb +28 -10
- data/lib/naminori/notifier/slack.rb +10 -4
- data/lib/naminori/service/base.rb +17 -2
- data/lib/naminori/service/dns.rb +1 -2
- data/lib/naminori/service/http.rb +1 -2
- data/lib/naminori/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9613921c03bceebc050a914297919fe5f775d604
|
4
|
+
data.tar.gz: 35099756e8655cb6b4e5e701715588b000a67971
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d7591a77ea8bd35e685a8d500b4d0443a3cfa6b96869f9b116cbf3e26e55d70fb2e8c135a2cb578d6506768075cf5985c9cef3fc6410660b29df236509bcc39
|
7
|
+
data.tar.gz: c123f60e9b2424f6aac66ba3a5f4edb4dade94c93fd2816416a351020fa0e797541bcbf47662ff7c6f7346c8cc75266d6e0ee81cb6e078d99160bb663009bd3e
|
data/README.md
CHANGED
@@ -28,22 +28,22 @@ Or install it yourself as:
|
|
28
28
|
require 'rubygems'
|
29
29
|
require 'naminori'
|
30
30
|
|
31
|
-
|
32
|
-
webhook_url
|
33
|
-
channel
|
34
|
-
|
35
|
-
})
|
31
|
+
Naminoti::Notifier.configure do
|
32
|
+
webhook_url "https://hooks.slack.com/services/XXXXXX"
|
33
|
+
channel "#pyama"
|
34
|
+
end
|
36
35
|
|
37
36
|
service_options = {
|
38
37
|
vip:"192.168.77.9",
|
39
|
-
role: "dns"
|
38
|
+
role: "dns",
|
39
|
+
notifier: Naminori::Notifier.get_notifier("slack" ,notifier_options)
|
40
40
|
}
|
41
41
|
|
42
42
|
case
|
43
43
|
when Naminori::Serf.role?("dns")
|
44
|
-
Naminori::Service.event("
|
44
|
+
Naminori::Service::Dns.event("lvs", service_options)
|
45
45
|
when Naminori::Serf.role?("lb")
|
46
|
-
Naminori::
|
46
|
+
Naminori::Service::Dns.health_check("lvs", service_options)
|
47
47
|
end
|
48
48
|
|
49
49
|
```
|
@@ -89,7 +89,7 @@ require 'naminori'
|
|
89
89
|
|
90
90
|
service_options = { vip:"192.168.77.9", role: "dns" }
|
91
91
|
|
92
|
-
Naminori::
|
92
|
+
Naminori::Service::Dns.health_check("lvs", service_options)
|
93
93
|
```
|
94
94
|
```zsh
|
95
95
|
# crontab -l
|
@@ -98,12 +98,9 @@ PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
|
|
98
98
|
* * * * * for i in `seq 0 10 59`;do (sleep ${i}; /opt/serf/event_handlers/health_check_example.rb)& done;
|
99
99
|
```
|
100
100
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
101
|
### Service Event Detail
|
105
102
|
```
|
106
|
-
Naminori::Service.event(
|
103
|
+
Naminori::Service::Dns.event(lb_name, options)
|
107
104
|
```
|
108
105
|
* service_name:
|
109
106
|
dns or http
|
@@ -121,7 +118,8 @@ Naminori::Service.event(service_name, lb_name, options)
|
|
121
118
|
method: "gateway", # lvs_method gateway/ip/nat
|
122
119
|
query: "pepabo.com", # health_check_query
|
123
120
|
retry: 3, # health_check_retry_count
|
124
|
-
timeout: 3
|
121
|
+
timeout: 3, # health_check_time_out
|
122
|
+
notifier: nil # notifier
|
125
123
|
}
|
126
124
|
```
|
127
125
|
## Author
|
data/lib/naminori/lb.rb
CHANGED
@@ -2,30 +2,12 @@
|
|
2
2
|
module Naminori
|
3
3
|
class Lb
|
4
4
|
class << self
|
5
|
-
def health_check(service_name, lb_name, options={})
|
6
|
-
service = Naminori::Service.get_service(service_name).new(options)
|
7
|
-
members = Naminori::Serf.get_alive_member_by_role(service.config.role)
|
8
|
-
|
9
|
-
members.each do |member|
|
10
|
-
ip = member_ip(member)
|
11
|
-
if service.healty?(ip)
|
12
|
-
get_lb(lb_name).add_member(ip, service)
|
13
|
-
elsif service.config.retry.times.all? { sleep 1; !service.healty?(ip) }
|
14
|
-
get_lb(lb_name).delete_member(ip, service)
|
15
|
-
end
|
16
|
-
end if members
|
17
|
-
end
|
18
|
-
|
19
5
|
def get_lb(lb_name)
|
20
6
|
case lb_name
|
21
7
|
when "lvs"
|
22
8
|
Naminori::Lb::Lvs
|
23
9
|
end
|
24
10
|
end
|
25
|
-
|
26
|
-
def member_ip(member)
|
27
|
-
member[:ip]
|
28
|
-
end
|
29
11
|
end
|
30
12
|
end
|
31
13
|
end
|
data/lib/naminori/lb/base.rb
CHANGED
@@ -9,11 +9,11 @@ module Naminori
|
|
9
9
|
def delete_member(rip, service)
|
10
10
|
raise "Called abstract method: add_member"
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
def notifier(type, options)
|
14
14
|
message = "#{type} member ip:#{options[:rip]} protocol:#{options[:protocol]} in vip:#{options[:vip]}"
|
15
15
|
puts message
|
16
|
-
Naminori::Notifier.
|
16
|
+
Naminori::Notifier.notify(type, message)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
data/lib/naminori/notifier.rb
CHANGED
@@ -1,12 +1,11 @@
|
|
1
1
|
#! /usr/bin/env ruby
|
2
2
|
module Naminori
|
3
|
-
|
3
|
+
module Notifier
|
4
4
|
class << self
|
5
|
-
def
|
6
|
-
config = Naminori::Notifier::Configure.instance
|
5
|
+
def notify(type, message)
|
7
6
|
case
|
8
|
-
when
|
9
|
-
get_notifier("slack").
|
7
|
+
when Naminori::Notifier.config.slack_enable?
|
8
|
+
get_notifier("slack").notify(type, message)
|
10
9
|
end
|
11
10
|
end
|
12
11
|
|
@@ -16,6 +15,11 @@ module Naminori
|
|
16
15
|
Naminori::Notifier::Slack.new
|
17
16
|
end
|
18
17
|
end
|
18
|
+
|
19
|
+
def configure(&block)
|
20
|
+
Naminori::Notifier.config(&block)
|
21
|
+
end
|
19
22
|
end
|
20
23
|
end
|
24
|
+
|
21
25
|
end
|
@@ -1,12 +1,7 @@
|
|
1
1
|
#! /usr/bin/env ruby
|
2
2
|
module Naminori
|
3
|
-
|
3
|
+
module Notifier
|
4
4
|
class Base
|
5
|
-
attr_reader :config
|
6
|
-
def initialize()
|
7
|
-
@config = Naminori::Notifier::Configure.instance
|
8
|
-
end
|
9
|
-
|
10
5
|
def notifier(type, message)
|
11
6
|
raise "Called abstract method: add_server"
|
12
7
|
end
|
@@ -1,20 +1,38 @@
|
|
1
1
|
#! /usr/bin/env ruby
|
2
|
-
require 'singleton'
|
3
2
|
module Naminori
|
4
|
-
|
3
|
+
module Notifier
|
5
4
|
class Configure
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
@webhook_url = options[:webhook_url]
|
11
|
-
@channel = options[:channel]
|
12
|
-
@user = options[:user]
|
5
|
+
def clear
|
6
|
+
instance_variables.each do |v|
|
7
|
+
instance_variable_set(v, nil)
|
8
|
+
end
|
13
9
|
end
|
14
10
|
|
15
|
-
def
|
11
|
+
def slack_enable?
|
16
12
|
webhook_url && channel && user
|
17
13
|
end
|
14
|
+
|
15
|
+
def webhook_url(url=nil)
|
16
|
+
@_webhook_url = url if url
|
17
|
+
@_webhook_url
|
18
|
+
end
|
19
|
+
|
20
|
+
def channel(channel=nil)
|
21
|
+
@_channel = channel if channel
|
22
|
+
@_channel
|
23
|
+
end
|
24
|
+
|
25
|
+
def user(user=nil)
|
26
|
+
@_user = user if user
|
27
|
+
@_user
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.config(&block)
|
32
|
+
@_config ||= Naminori::Notifier::Configure.new
|
33
|
+
@_config.instance_eval(&block) if block
|
34
|
+
@_config
|
18
35
|
end
|
19
36
|
end
|
37
|
+
|
20
38
|
end
|
@@ -1,11 +1,17 @@
|
|
1
1
|
#! /usr/bin/env ruby
|
2
2
|
module Naminori
|
3
|
-
|
3
|
+
module Notifier
|
4
4
|
class Slack < Base
|
5
|
-
def
|
5
|
+
def notify(type, message)
|
6
6
|
icon = type == "add" ? ":white_check_mark:" : ":no_entry_sign:"
|
7
|
-
notifier = ::Slack::Notifier.new(
|
8
|
-
|
7
|
+
notifier = ::Slack::Notifier.new(
|
8
|
+
Naminori::Notifier.config.webhook_url,
|
9
|
+
{
|
10
|
+
channel: Naminori::Notifier.config.channel,
|
11
|
+
username: Naminori::Notifier.config.user
|
12
|
+
}
|
13
|
+
)
|
14
|
+
notifier.ping icon + message, icon_emoji: ":sparkle:"
|
9
15
|
rescue => e
|
10
16
|
p e
|
11
17
|
end
|
@@ -16,14 +16,28 @@ module Naminori
|
|
16
16
|
def event_ip
|
17
17
|
Naminori::Serf.gets[:ip]
|
18
18
|
end
|
19
|
+
|
20
|
+
def health_check(lb_name, options)
|
21
|
+
service = self.new(options)
|
22
|
+
members = Naminori::Serf.get_alive_member_by_role(service.config.role)
|
23
|
+
members.each do |member|
|
24
|
+
ip = member[:ip]
|
25
|
+
if service.healty?(ip)
|
26
|
+
Naminori::Lb.get_lb(lb_name).add_member(ip, service)
|
27
|
+
elsif service.config.retry.times.all? { sleep 1; !service.healty?(ip) }
|
28
|
+
Naminori::Lb.get_lb(lb_name).delete_member(ip, service)
|
29
|
+
end
|
30
|
+
end if members
|
31
|
+
end
|
32
|
+
|
19
33
|
end
|
20
34
|
|
21
|
-
def initialize(options
|
35
|
+
def initialize(options)
|
22
36
|
@config = Naminori::Service::Configure.new(
|
23
37
|
default_config.merge(options)
|
24
38
|
)
|
25
39
|
end
|
26
|
-
|
40
|
+
|
27
41
|
def healty?(ip)
|
28
42
|
raise "Called abstract method: healty?"
|
29
43
|
end
|
@@ -31,6 +45,7 @@ module Naminori
|
|
31
45
|
def default_config
|
32
46
|
raise "Called abstract method: default_config"
|
33
47
|
end
|
48
|
+
|
34
49
|
end
|
35
50
|
end
|
36
51
|
end
|
data/lib/naminori/service/dns.rb
CHANGED
data/lib/naminori/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: naminori
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kazuhiko yamahsita
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-07-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: slack-notifier
|
@@ -116,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
116
116
|
version: '0'
|
117
117
|
requirements: []
|
118
118
|
rubyforge_project:
|
119
|
-
rubygems_version: 2.4.
|
119
|
+
rubygems_version: 2.4.6
|
120
120
|
signing_key:
|
121
121
|
specification_version: 4
|
122
122
|
summary: LoadBarancer library on Serf.
|