naminori 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +54 -17
- data/lib/naminori.rb +1 -0
- data/lib/naminori/lb/base.rb +1 -1
- data/lib/naminori/lb/lvs.rb +1 -1
- data/lib/naminori/naminori.rb +3 -0
- data/lib/naminori/notifier.rb +10 -2
- data/lib/naminori/notifier/base.rb +3 -10
- data/lib/naminori/notifier/configure.rb +8 -1
- data/lib/naminori/notifier/slack.rb +2 -10
- data/lib/naminori/service.rb +2 -0
- data/lib/naminori/service/configure.rb +9 -10
- data/lib/naminori/service/dns.rb +9 -9
- data/lib/naminori/service/http.rb +32 -0
- data/lib/naminori/version.rb +1 -1
- data/naminori.gemspec +1 -1
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 58042c9fc2a028c2477172fb869d01bd6bea87f8
|
4
|
+
data.tar.gz: 7157f21c3e7187ae21819186dbea5bb005b1436c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 242c270180459d79ee1e8ce31e4cf4a5369c253a2ad4eaff1a96753510ca1e94a5cdaa3582a3b740d9ad556c30b11bf665877fe756de0ed2c5644bc84ccb07e7
|
7
|
+
data.tar.gz: 8ec7daa5745f5be8c0782ca99902221022ae3967569be731687a4239c80e173d3b48947ea688350208827ef41fa3048fdcc176d69c09dfdb41b9def1960a2bee
|
data/README.md
CHANGED
@@ -18,22 +18,25 @@ Or install it yourself as:
|
|
18
18
|
## Usage
|
19
19
|
|
20
20
|
### exemple
|
21
|
-
|
22
21
|
#### envent_example.rb
|
22
|
+
1. check the event classification
|
23
|
+
2. add or delete rip if these member-join or member-leave(faile)
|
24
|
+
3. enent target LoadBaranser is health_check with fetch member
|
25
|
+
|
23
26
|
```ruby
|
24
27
|
#! /usr/bin/env ruby
|
25
28
|
require 'rubygems'
|
26
29
|
require 'naminori'
|
27
30
|
|
28
|
-
|
31
|
+
Naminori::Notifier::Configure.instance.set({
|
29
32
|
webhook_url: "https://hooks.slack.com/services/XXXXXX",
|
30
|
-
channel: "#pyama"
|
31
|
-
|
33
|
+
channel: "#pyama",
|
34
|
+
user: "#naminori"
|
35
|
+
})
|
32
36
|
|
33
37
|
service_options = {
|
34
38
|
vip:"192.168.77.9",
|
35
|
-
role: "dns"
|
36
|
-
notifier: Naminori::Notifier.get_notifier("slack" ,notifier_options)
|
39
|
+
role: "dns"
|
37
40
|
}
|
38
41
|
|
39
42
|
case
|
@@ -45,7 +48,40 @@ end
|
|
45
48
|
|
46
49
|
```
|
47
50
|
|
51
|
+
#### example loadbarance serf config
|
52
|
+
```
|
53
|
+
{
|
54
|
+
"event_handlers": [
|
55
|
+
"/opt/serf/event_handlers/envent_example.rb"
|
56
|
+
],
|
57
|
+
"interface": "enp0s9",
|
58
|
+
"discover": "cache-dns",
|
59
|
+
"tags": {
|
60
|
+
"role": "lb"
|
61
|
+
},
|
62
|
+
"log_level": "debug"
|
63
|
+
}
|
64
|
+
```
|
65
|
+
|
66
|
+
#### example dns serf config
|
67
|
+
```
|
68
|
+
{
|
69
|
+
"event_handlers": [
|
70
|
+
|
71
|
+
],
|
72
|
+
"interface": "enp0s8",
|
73
|
+
"discover": "cache-dns",
|
74
|
+
"tags": {
|
75
|
+
"role": "dns"
|
76
|
+
}
|
77
|
+
}
|
78
|
+
```
|
79
|
+
|
48
80
|
#### health_check_example.rb
|
81
|
+
1. Using cron to the health check of the service
|
82
|
+
2. Service is removed from the member if that is not healthy
|
83
|
+
* Parameter [query, timeout ,retry]
|
84
|
+
|
49
85
|
```ruby
|
50
86
|
#! /usr/bin/env ruby
|
51
87
|
require 'rubygems'
|
@@ -65,7 +101,7 @@ PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
|
|
65
101
|
|
66
102
|
|
67
103
|
|
68
|
-
|
104
|
+
### Service Event Detail
|
69
105
|
```
|
70
106
|
Naminori::Service.event(service_name, lb_name, options)
|
71
107
|
```
|
@@ -73,18 +109,19 @@ Naminori::Service.event(service_name, lb_name, options)
|
|
73
109
|
dns or http
|
74
110
|
* lb_name:
|
75
111
|
lvs
|
76
|
-
* options
|
112
|
+
* options
|
113
|
+
|
77
114
|
```
|
115
|
+
#dns default
|
78
116
|
{
|
79
|
-
role: "dns",
|
80
|
-
port: "53",
|
81
|
-
|
82
|
-
vip: "192.168.77.9",
|
83
|
-
method: "gateway",
|
84
|
-
query: "pepabo.com",
|
85
|
-
retry: 3,
|
86
|
-
timeout: 3
|
87
|
-
notifier: nil # notifier
|
117
|
+
role: "dns", # role name
|
118
|
+
port: "53", # service port
|
119
|
+
protocols: ["udp", "tcp"], # protocol(array)
|
120
|
+
vip: "192.168.77.9", # service vip
|
121
|
+
method: "gateway", # lvs_method gateway/ip/nat
|
122
|
+
query: "pepabo.com", # health_check_query
|
123
|
+
retry: 3, # health_check_retry_count
|
124
|
+
timeout: 3 # health_check_time_out
|
88
125
|
}
|
89
126
|
```
|
90
127
|
## Author
|
data/lib/naminori.rb
CHANGED
@@ -7,6 +7,7 @@ require 'naminori/service'
|
|
7
7
|
require 'naminori/service/base'
|
8
8
|
require 'naminori/service/configure'
|
9
9
|
require 'naminori/service/dns'
|
10
|
+
require 'naminori/service/http'
|
10
11
|
require 'naminori/notifier'
|
11
12
|
require 'naminori/notifier/base'
|
12
13
|
require 'naminori/notifier/configure'
|
data/lib/naminori/lb/base.rb
CHANGED
@@ -13,7 +13,7 @@ module Naminori
|
|
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
|
-
|
16
|
+
Naminori::Notifier.notifier(type, message) if Naminori::Notifier::Configure.instance.enable?
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
data/lib/naminori/lb/lvs.rb
CHANGED
@@ -45,7 +45,7 @@ module Naminori
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def lvs_option(rip, service)
|
48
|
-
{ service: service, vip: service.config.vip, rip: rip, protocols: service.config.
|
48
|
+
{ service: service, vip: service.config.vip, rip: rip, protocols: service.config.protocols, port: service.config.port, method: service.config.method }
|
49
49
|
end
|
50
50
|
|
51
51
|
def command_option(type, ops)
|
data/lib/naminori/naminori.rb
CHANGED
@@ -7,5 +7,8 @@ require File.dirname(__FILE__) + '/service'
|
|
7
7
|
require File.dirname(__FILE__) + '/service/base'
|
8
8
|
require File.dirname(__FILE__) + '/service/configure'
|
9
9
|
require File.dirname(__FILE__) + '/service/dns'
|
10
|
+
require File.dirname(__FILE__) + '/service/http'
|
10
11
|
require 'resolv'
|
12
|
+
require 'net/http'
|
13
|
+
require 'net/https'
|
11
14
|
|
data/lib/naminori/notifier.rb
CHANGED
@@ -2,10 +2,18 @@
|
|
2
2
|
module Naminori
|
3
3
|
class Notifier
|
4
4
|
class << self
|
5
|
-
def
|
5
|
+
def notifier(type, message)
|
6
|
+
config = Naminori::Notifier::Configure.instance
|
7
|
+
case
|
8
|
+
when config.webhook_url && config.user && config.channel
|
9
|
+
get_notifier("slack").notifier(type, message)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def get_notifier(notifier)
|
6
14
|
case notifier
|
7
15
|
when "slack"
|
8
|
-
Naminori::Notifier::Slack.new
|
16
|
+
Naminori::Notifier::Slack.new
|
9
17
|
end
|
10
18
|
end
|
11
19
|
end
|
@@ -3,20 +3,13 @@ module Naminori
|
|
3
3
|
class Notifier
|
4
4
|
class Base
|
5
5
|
attr_reader :config
|
6
|
-
def initialize(
|
7
|
-
@config = Naminori::Notifier::Configure.
|
8
|
-
default_config.merge(options)
|
9
|
-
)
|
6
|
+
def initialize()
|
7
|
+
@config = Naminori::Notifier::Configure.instance
|
10
8
|
end
|
11
9
|
|
12
|
-
def
|
10
|
+
def notifier(type, message)
|
13
11
|
raise "Called abstract method: add_server"
|
14
12
|
end
|
15
|
-
|
16
|
-
def default_config
|
17
|
-
raise "Called abstract method: default_config"
|
18
|
-
end
|
19
|
-
|
20
13
|
end
|
21
14
|
end
|
22
15
|
end
|
@@ -1,13 +1,20 @@
|
|
1
1
|
#! /usr/bin/env ruby
|
2
|
+
require 'singleton'
|
2
3
|
module Naminori
|
3
4
|
class Notifier
|
4
5
|
class Configure
|
6
|
+
include Singleton
|
5
7
|
attr_reader :webhook_url, :channel, :user
|
6
|
-
|
8
|
+
|
9
|
+
def set(options)
|
7
10
|
@webhook_url = options[:webhook_url]
|
8
11
|
@channel = options[:channel]
|
9
12
|
@user = options[:user]
|
10
13
|
end
|
14
|
+
|
15
|
+
def enable?
|
16
|
+
webhook_url && channel && user
|
17
|
+
end
|
11
18
|
end
|
12
19
|
end
|
13
20
|
end
|
@@ -2,21 +2,13 @@
|
|
2
2
|
module Naminori
|
3
3
|
class Notifier
|
4
4
|
class Slack < Base
|
5
|
-
def
|
5
|
+
def notifier(type, message)
|
6
6
|
icon = type == "add" ? ":white_check_mark:" : ":no_entry_sign:"
|
7
7
|
notifier = ::Slack::Notifier.new(config.webhook_url, { channel: config.channel, username: config.user})
|
8
|
-
notifier.ping icon + message, icon_emoji: ":sparkle:"
|
8
|
+
notifier.ping icon + Time.new.strftime("%H:%M:%S ") + message, icon_emoji: ":sparkle:"
|
9
9
|
rescue => e
|
10
10
|
p e
|
11
11
|
end
|
12
|
-
|
13
|
-
def default_config
|
14
|
-
{
|
15
|
-
webhook_url: "",
|
16
|
-
channel: "general",
|
17
|
-
user: "naminori-notifier"
|
18
|
-
}
|
19
|
-
end
|
20
12
|
end
|
21
13
|
end
|
22
14
|
end
|
data/lib/naminori/service.rb
CHANGED
@@ -2,17 +2,16 @@
|
|
2
2
|
module Naminori
|
3
3
|
class Service
|
4
4
|
class Configure
|
5
|
-
attr_reader :role, :port, :
|
5
|
+
attr_reader :role, :port, :protocols, :vip, :method, :query, :retry, :timeout
|
6
6
|
def initialize(options)
|
7
|
-
@role
|
8
|
-
@port
|
9
|
-
@
|
10
|
-
@vip
|
11
|
-
@method
|
12
|
-
@query
|
13
|
-
@retry
|
14
|
-
@timeout
|
15
|
-
@notifier = options[:notifier]
|
7
|
+
@role = options[:role]
|
8
|
+
@port = options[:port]
|
9
|
+
@protocols = options[:protocols]
|
10
|
+
@vip = options[:vip]
|
11
|
+
@method = options[:method]
|
12
|
+
@query = options[:query]
|
13
|
+
@retry = options[:retry]
|
14
|
+
@timeout = options[:timeout]
|
16
15
|
end
|
17
16
|
end
|
18
17
|
end
|
data/lib/naminori/service/dns.rb
CHANGED
@@ -15,15 +15,15 @@ module Naminori
|
|
15
15
|
|
16
16
|
def default_config
|
17
17
|
{
|
18
|
-
role:
|
19
|
-
port:
|
20
|
-
|
21
|
-
vip:
|
22
|
-
method:
|
23
|
-
query:
|
24
|
-
retry:
|
25
|
-
timeout:
|
26
|
-
notifier:
|
18
|
+
role: "dns",
|
19
|
+
port: "53",
|
20
|
+
protocols: ["udp", "tcp"],
|
21
|
+
vip: "192.168.77.9",
|
22
|
+
method: "nat",
|
23
|
+
query: "pepabo.com",
|
24
|
+
retry: 3,
|
25
|
+
timeout: 3,
|
26
|
+
notifier: nil
|
27
27
|
}
|
28
28
|
end
|
29
29
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
module Naminori
|
3
|
+
class Service
|
4
|
+
class Http < Naminori::Service::Base
|
5
|
+
|
6
|
+
def healty?(ip)
|
7
|
+
http = Net::HTTP.new(ip, config.port)
|
8
|
+
http.open_timeout = config.timeout
|
9
|
+
|
10
|
+
begin
|
11
|
+
http.get("/#{@query}")
|
12
|
+
rescue => e
|
13
|
+
false
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def default_config
|
18
|
+
{
|
19
|
+
role: "http",
|
20
|
+
port: "80",
|
21
|
+
protocols: ["tcp"],
|
22
|
+
vip: "192.168.77.9",
|
23
|
+
method: "nat",
|
24
|
+
query: "index.html",
|
25
|
+
retry: 3,
|
26
|
+
timeout: 3,
|
27
|
+
notifier: nil
|
28
|
+
}
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/naminori/version.rb
CHANGED
data/naminori.gemspec
CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.require_paths = ["lib"]
|
19
19
|
|
20
20
|
spec.add_dependency 'slack-notifier', "~> 1.2"
|
21
|
-
spec.add_development_dependency "bundler", "
|
21
|
+
spec.add_development_dependency "bundler", ">= 1.7.6"
|
22
22
|
spec.add_development_dependency "rake", "~> 10.0"
|
23
23
|
spec.add_development_dependency "rspec", "~> 3.2"
|
24
24
|
end
|
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.1.
|
4
|
+
version: 0.1.3
|
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-06-
|
11
|
+
date: 2015-06-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: slack-notifier
|
@@ -28,16 +28,16 @@ dependencies:
|
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 1.
|
33
|
+
version: 1.7.6
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 1.
|
40
|
+
version: 1.7.6
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -93,6 +93,7 @@ files:
|
|
93
93
|
- lib/naminori/service/base.rb
|
94
94
|
- lib/naminori/service/configure.rb
|
95
95
|
- lib/naminori/service/dns.rb
|
96
|
+
- lib/naminori/service/http.rb
|
96
97
|
- lib/naminori/version.rb
|
97
98
|
- naminori.gemspec
|
98
99
|
homepage: http://ten-snapon.com
|
@@ -115,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
115
116
|
version: '0'
|
116
117
|
requirements: []
|
117
118
|
rubyforge_project:
|
118
|
-
rubygems_version: 2.4.
|
119
|
+
rubygems_version: 2.4.8
|
119
120
|
signing_key:
|
120
121
|
specification_version: 4
|
121
122
|
summary: LoadBarancer library on Serf.
|