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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 77e9e92c2424a9499aeee50be651f668afc050a1
4
- data.tar.gz: 9802a517be8a05f7759b384fa3bb142f6cb2a8f5
3
+ metadata.gz: 58042c9fc2a028c2477172fb869d01bd6bea87f8
4
+ data.tar.gz: 7157f21c3e7187ae21819186dbea5bb005b1436c
5
5
  SHA512:
6
- metadata.gz: 9abed3bdce6ca095c08211612dcfb981bd639fb127edfdadf69384c0fa3dd84a5d473aff87906b8fe2b3cf52122fcc4e1beb0dd88bb7be1235defd55c935ae92
7
- data.tar.gz: 393f9c42eb59c33a8287418eed10c59f4ce765bb7ab626a4a70b5abfc98e6153691e9e1233fbae60659107ea6bb77d0c7d8cbfc07dbbac7af41248bd9f7c0dfc
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
- notifier_options = {
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
- #### Service Event
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(dns_default)
112
+ * options
113
+
77
114
  ```
115
+ #dns default
78
116
  {
79
- role: "dns", # role name
80
- port: "53", # service port
81
- protocol: ["udp", "tcp"], # protocol(array)
82
- vip: "192.168.77.9", # service vip
83
- method: "gateway", # lvs_method gateway/ip/nat
84
- query: "pepabo.com", # health_check_query
85
- retry: 3, # health_check_retry_count
86
- timeout: 3, # health_check_time_out
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
@@ -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'
@@ -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
- options[:service].config.notifier.send(type, message) if options[:service].config.notifier
16
+ Naminori::Notifier.notifier(type, message) if Naminori::Notifier::Configure.instance.enable?
17
17
  end
18
18
  end
19
19
  end
@@ -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.protocol, port: service.config.port, method: service.config.method }
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)
@@ -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
 
@@ -2,10 +2,18 @@
2
2
  module Naminori
3
3
  class Notifier
4
4
  class << self
5
- def get_notifier(notifier, options={})
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(options)
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(options={})
7
- @config = Naminori::Notifier::Configure.new(
8
- default_config.merge(options)
9
- )
6
+ def initialize()
7
+ @config = Naminori::Notifier::Configure.instance
10
8
  end
11
9
 
12
- def send(type, message)
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
- def initialize(options)
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 send(type, message)
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
@@ -10,6 +10,8 @@ module Naminori
10
10
  case service_name
11
11
  when "dns"
12
12
  Naminori::Service::Dns
13
+ when "http"
14
+ Naminori::Service::Http
13
15
  end
14
16
  end
15
17
  end
@@ -2,17 +2,16 @@
2
2
  module Naminori
3
3
  class Service
4
4
  class Configure
5
- attr_reader :role, :port, :protocol, :vip, :method, :query, :retry, :timeout, :notifier
5
+ attr_reader :role, :port, :protocols, :vip, :method, :query, :retry, :timeout
6
6
  def initialize(options)
7
- @role = options[:role]
8
- @port = options[:port]
9
- @protocol = options[:protocol]
10
- @vip = options[:vip]
11
- @method = options[:method]
12
- @query = options[:query]
13
- @retry = options[:retry]
14
- @timeout = options[: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
@@ -15,15 +15,15 @@ module Naminori
15
15
 
16
16
  def default_config
17
17
  {
18
- role: "dns",
19
- port: "53",
20
- protocol: ["udp", "tcp"],
21
- vip: "192.168.77.9",
22
- method: "nat",
23
- query: "pepabo.com",
24
- retry: 3,
25
- timeout: 3,
26
- notifier: nil
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
@@ -1,3 +1,3 @@
1
1
  module Naminori
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -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", "~> 1.9.8"
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.2
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-21 00:00:00.000000000 Z
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.9.8
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.9.8
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.6
119
+ rubygems_version: 2.4.8
119
120
  signing_key:
120
121
  specification_version: 4
121
122
  summary: LoadBarancer library on Serf.