naminori 0.1.4 → 0.2.0

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: 54e67a599ba4ae49fc096c3a3ef1d1e48d27d7d7
4
- data.tar.gz: 401ad2a2850f44d7167a6b883f17ec82fe8bb9de
3
+ metadata.gz: 9613921c03bceebc050a914297919fe5f775d604
4
+ data.tar.gz: 35099756e8655cb6b4e5e701715588b000a67971
5
5
  SHA512:
6
- metadata.gz: 66221651c57b6478359d8b942ed5ebeccacb7f914fafcef908cb05be58fd040abaa23e6d461fc9ce90143cbc046f009ee7ee28a591404e730df8e89f4fb6d82d
7
- data.tar.gz: abc6cd82206a1bac19c8c6d957f9efee335136046709cb57356273ea9253af46048ca671dde3d4f18f220f30fa2f5eb4ead19ed6a46e14f33536be89ea34cddb
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
- Naminori::Notifier::Configure.instance.set({
32
- webhook_url: "https://hooks.slack.com/services/XXXXXX",
33
- channel: "#pyama",
34
- user: "#naminori"
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("dns", "lvs", service_options)
44
+ Naminori::Service::Dns.event("lvs", service_options)
45
45
  when Naminori::Serf.role?("lb")
46
- Naminori::Lb.health_check("dns", "lvs",service_options)
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::Lb.health_check("dns", "lvs", service_options)
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(service_name, lb_name, options)
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 # health_check_time_out
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
@@ -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.notifier(type, message) if Naminori::Notifier::Configure.instance.enable?
16
+ Naminori::Notifier.notify(type, message)
17
17
  end
18
18
  end
19
19
  end
@@ -1,12 +1,11 @@
1
1
  #! /usr/bin/env ruby
2
2
  module Naminori
3
- class Notifier
3
+ module Notifier
4
4
  class << self
5
- def notifier(type, message)
6
- config = Naminori::Notifier::Configure.instance
5
+ def notify(type, message)
7
6
  case
8
- when config.webhook_url && config.user && config.channel
9
- get_notifier("slack").notifier(type, message)
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
- class Notifier
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
- class Notifier
3
+ module Notifier
5
4
  class Configure
6
- include Singleton
7
- attr_reader :webhook_url, :channel, :user
8
-
9
- def set(options)
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 enable?
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
- class Notifier
3
+ module Notifier
4
4
  class Slack < Base
5
- def notifier(type, message)
5
+ def notify(type, message)
6
6
  icon = type == "add" ? ":white_check_mark:" : ":no_entry_sign:"
7
- notifier = ::Slack::Notifier.new(config.webhook_url, { channel: config.channel, username: config.user})
8
- notifier.ping icon + Time.new.strftime("%H:%M:%S ") + message, icon_emoji: ":sparkle:"
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
@@ -22,8 +22,7 @@ module Naminori
22
22
  method: "nat",
23
23
  query: "pepabo.com",
24
24
  retry: 3,
25
- timeout: 3,
26
- notifier: nil
25
+ timeout: 3
27
26
  }
28
27
  end
29
28
  end
@@ -23,8 +23,7 @@ module Naminori
23
23
  method: "nat",
24
24
  query: "index.html",
25
25
  retry: 3,
26
- timeout: 3,
27
- notifier: nil
26
+ timeout: 3
28
27
  }
29
28
  end
30
29
  end
@@ -1,3 +1,3 @@
1
1
  module Naminori
2
- VERSION = "0.1.4"
2
+ VERSION = "0.2.0"
3
3
  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
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-06-24 00:00:00.000000000 Z
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.8
119
+ rubygems_version: 2.4.6
120
120
  signing_key:
121
121
  specification_version: 4
122
122
  summary: LoadBarancer library on Serf.