ring-sqa 0.2.1 → 0.2.2

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: 25c8208dc0edbfafa044993cfb78dd16780b07f5
4
- data.tar.gz: b9aca6535337fb3b1f13d91b96d26e3b7ecda319
3
+ metadata.gz: 575a1fe95c4b6aeef9d1469fbbd3ad738bb3df11
4
+ data.tar.gz: 983918acc69c27d86ec309245aaaa6bab7ae2892
5
5
  SHA512:
6
- metadata.gz: a7cdc36b8eb6a647626e0eed44babfeaf43eb5bbaedbc55a1b35e4ed0cc11ac4dc9d936fbc5f4db653ecebf1c405b06e0dd48af618ec962fb31d82b214bba502
7
- data.tar.gz: d2016d09b13fbdf445996f867075e81d91f804704029cc77242dd7cba1b328b43eaa17b179b468f24d8ba8f68dceb6834dd8f54c90bf9e41ad4b610e143886f0
6
+ metadata.gz: 33866954ec631f08093ac610f2f0069208a27fae7f643156eb5dce998d966e7eb8f7ecce4332508ffc43a09c268f93a484edf19401a49a6da5e8ac173864eacd
7
+ data.tar.gz: d10307beb8fcf195df725eaa6a280e16b49a4d0adb92cabc64d28b039cdb2ea44704fe254dc824a400d2be06cd6ff4812a18912cbb7de5d35c89b566812dc2c3
@@ -0,0 +1,55 @@
1
+ require 'net/http'
2
+ require 'timeout'
3
+
4
+ module Ring
5
+ class SQA
6
+ class Alarm
7
+
8
+ class Slack
9
+ TIMEOUT = 10
10
+ def send opts
11
+ short, long = opts[:short], opts[:long]
12
+ cfg = CFG.slack
13
+ json = JSON.pretty_generate(
14
+ {
15
+ "attachments" => [
16
+ {
17
+ "fallback" => short,
18
+ "pretext" => short,
19
+ "author_name" => "NLNog Ring SQA",
20
+ "author_link" => "https://ring.nlnog.net/news/2014/07/new-monitoring-tool-ring-sqa/",
21
+ "text" => long,
22
+ },
23
+ ],
24
+ },
25
+ )
26
+ post json, cfg.url
27
+ rescue => error
28
+ Log.error "Slack send raised '#{error.class}' with message '#{error.message}'"
29
+ end
30
+
31
+ private
32
+
33
+ def post json, url
34
+ Thread.new do
35
+ begin
36
+ Timeout::timeout(TIMEOUT) do
37
+ uri = URI.parse url
38
+ http = Net::HTTP.new uri.host, uri.port
39
+ http.use_ssl = true if uri.scheme == 'https'
40
+ req = Net::HTTP::Post.new(uri.request_uri, { 'Content-Type' => 'application/json' })
41
+ req.body = json
42
+ _response = http.request req
43
+ end
44
+ rescue Timeout::Error
45
+ Log.error "Slack post timed out"
46
+ rescue => error
47
+ Log.error "Slack post raised '#{error.class}' with message '#{error.message}'"
48
+ end
49
+ end
50
+ end
51
+ end
52
+
53
+ end
54
+ end
55
+ end
@@ -1,6 +1,7 @@
1
1
  require_relative 'alarm/email'
2
2
  require_relative 'alarm/udp2irc'
3
3
  require_relative 'alarm/exec'
4
+ require_relative 'alarm/slack'
4
5
  require_relative 'alarm/cfg'
5
6
  require_relative 'alarm/message'
6
7
  require_relative 'alarm/collector'
@@ -38,6 +39,7 @@ class SQA
38
39
  @methods << Email.new if CFG.email.to?
39
40
  @methods << UDP2IRC.new if Array === CFG.irc or CFG.irc.password?
40
41
  @methods << Exec.new if CFG.exec.command?
42
+ @methods << Slack.new if CFG.slack.url?
41
43
  @methods << Collector.new
42
44
  @hostname = Ring::SQA::CFG.host.name
43
45
  @afi = Ring::SQA::CFG.afi
@@ -11,9 +11,11 @@ class SQA
11
11
  loop do
12
12
  start = Time.now
13
13
  @db.purge
14
- @db_id_seen, records = @db.nodes_down(@db_id_seen+1)
14
+ first_id = @db_id_seen+1
15
+ @db_id_seen, records = @db.nodes_down(first_id)
15
16
  sleep INFLIGHT_WAIT
16
17
  records = records.all
18
+ @graphite.add @db.id_range(first_id, @db_id_seen).all if @graphite
17
19
  @buffer.push records.map { |record| record.peer }
18
20
  @buffer.exceed_median? ? @alarm.set(@buffer) : @alarm.clear(@buffer)
19
21
  delay = INTERVAL-(Time.now-start)
@@ -38,7 +40,14 @@ class SQA
38
40
  @alarm = Alarm.new @nodes
39
41
  @buffer = AnalyzeBuffer.new @nodes.all.size
40
42
  @db_id_seen = 0
43
+ @graphite = graphite if CFG.graphite?
41
44
  end
45
+
46
+ def graphite
47
+ require_relative 'graphite'
48
+ Graphite.new
49
+ end
50
+
42
51
  end
43
52
 
44
53
  class AnalyzeBuffer
data/lib/ring/sqa/cfg.rb CHANGED
@@ -16,7 +16,7 @@ module Ring
16
16
  Config.default.analyzer.size = 30
17
17
  Config.default.analyzer.median_of = 27
18
18
  Config.default.nodes_json = '/etc/ring/nodes.json'
19
- Config.default.mtr.args = '-i0.5 -c5 -r -w -n'
19
+ Config.default.mtr.args = '-i0.5 -c5 -r -w -n --aslookup'
20
20
  Config.default.mtr.timeout = 15
21
21
  Config.default.ram_database = false
22
22
  Config.default.paste.url = 'https://ring.nlnog.net/paste/'
@@ -24,7 +24,7 @@ class SQA
24
24
 
25
25
  def nodes_down first_id
26
26
  max_id = (Ping.max(:id) or first_id)
27
- [max_id, Ping.distinct.where(:id=>first_id..max_id).exclude(:result => 'ok')]
27
+ [max_id, id_range(first_id, max_id).exclude(:result => 'ok')]
28
28
  end
29
29
 
30
30
  def up_since? id, peer
@@ -35,6 +35,10 @@ class SQA
35
35
  Ping.where{time < (Time.now.utc-older_than).to_i}.delete
36
36
  end
37
37
 
38
+ def id_range first, last
39
+ Ping.distinct.where(:id=>first..last)
40
+ end
41
+
38
42
  private
39
43
 
40
44
  def initialize
@@ -0,0 +1,29 @@
1
+ require 'graphite-api'
2
+
3
+ module Ring
4
+ class SQA
5
+
6
+ class Graphite
7
+ ROOT = "nlnog.ring_sqa.#{CFG.afi}"
8
+
9
+ def add records
10
+ records.each do |record|
11
+ hash = {
12
+ "#{ROOT}.#{record.peer}.state" => record.result
13
+ }
14
+ if record.result == 'success'
15
+ hash["#{ROOT}.#{record.peer}.latency"] = record.latency
16
+ end
17
+ @client.metrics hash, record.time
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ def initialize server=CFG.graphite
24
+ @client = GraphiteAPI.new graphite: server
25
+ end
26
+ end
27
+
28
+ end
29
+ end
data/ring-sqa.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'ring-sqa'
3
- s.version = '0.2.1'
3
+ s.version = '0.2.2'
4
4
  s.licenses = %w( Apache-2.0 )
5
5
  s.platform = Gem::Platform::RUBY
6
6
  s.authors = [ 'Saku Ytti', 'Job Snijders' ]
@@ -13,10 +13,11 @@ Gem::Specification.new do |s|
13
13
  s.executables = %w( ring-sqad )
14
14
  s.require_path = 'lib'
15
15
 
16
- s.required_ruby_version = '>= 1.9.3'
17
- s.add_runtime_dependency 'slop', '~> 3.5'
18
- s.add_runtime_dependency 'rb-inotify', '~> 0.9'
19
- s.add_runtime_dependency 'sequel', '~> 4.12'
20
- s.add_runtime_dependency 'sqlite3', '~> 1.3'
21
- s.add_runtime_dependency 'asetus', '~> 0.1', '>= 0.1.2'
16
+ s.required_ruby_version = '>= 1.9.3'
17
+ s.add_runtime_dependency 'slop', '~> 3.5'
18
+ s.add_runtime_dependency 'rb-inotify', '~> 0.9'
19
+ s.add_runtime_dependency 'sequel', '~> 4.12'
20
+ s.add_runtime_dependency 'sqlite3', '~> 1.3'
21
+ s.add_runtime_dependency 'asetus', '~> 0.1', '>= 0.1.2'
22
+ s.add_runtime_dependency 'graphite-api', '~> 0.1', '>= 0.1.6'
22
23
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ring-sqa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Saku Ytti
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-05-28 00:00:00.000000000 Z
12
+ date: 2016-06-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: slop
@@ -87,6 +87,26 @@ dependencies:
87
87
  - - '>='
88
88
  - !ruby/object:Gem::Version
89
89
  version: 0.1.2
90
+ - !ruby/object:Gem::Dependency
91
+ name: graphite-api
92
+ requirement: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: '0.1'
97
+ - - '>='
98
+ - !ruby/object:Gem::Version
99
+ version: 0.1.6
100
+ type: :runtime
101
+ prerelease: false
102
+ version_requirements: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ~>
105
+ - !ruby/object:Gem::Version
106
+ version: '0.1'
107
+ - - '>='
108
+ - !ruby/object:Gem::Version
109
+ version: 0.1.6
90
110
  description: gets list of nodes and pings from each to each storing results
91
111
  email:
92
112
  - saku@ytti.fi
@@ -107,6 +127,7 @@ files:
107
127
  - lib/ring/sqa/alarm/email.rb
108
128
  - lib/ring/sqa/alarm/exec.rb
109
129
  - lib/ring/sqa/alarm/message.rb
130
+ - lib/ring/sqa/alarm/slack.rb
110
131
  - lib/ring/sqa/alarm/udp2irc.rb
111
132
  - lib/ring/sqa/analyzer.rb
112
133
  - lib/ring/sqa/cfg.rb
@@ -114,6 +135,7 @@ files:
114
135
  - lib/ring/sqa/core.rb
115
136
  - lib/ring/sqa/database.rb
116
137
  - lib/ring/sqa/database/model.rb
138
+ - lib/ring/sqa/graphite.rb
117
139
  - lib/ring/sqa/log.rb
118
140
  - lib/ring/sqa/mtr.rb
119
141
  - lib/ring/sqa/nodes.rb
@@ -143,7 +165,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
143
165
  version: '0'
144
166
  requirements: []
145
167
  rubyforge_project: ring-sqa
146
- rubygems_version: 2.0.14
168
+ rubygems_version: 2.0.14.1
147
169
  signing_key:
148
170
  specification_version: 4
149
171
  summary: NLNOG Ring SQA