-
Notifications
You must be signed in to change notification settings - Fork 1
/
matrix.rb
74 lines (63 loc) · 1.49 KB
/
matrix.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
require 'csv'
require 'time'
require 'net/http'
require 'json'
require 'yaml'
require "./source"
require "./sentinel"
require "./sniffer"
require "./loophole"
class Matrix
def initialize
config = YAML.load_file('config.yml')
@passphrase = config["passphrase"]
@uri = config["uri"]
end
def run
# parse sentinels
sentinel = Sentinel.new("data/sentinels/routes.csv")
routes = sentinel.parse
# send
send_data routes, 'sentinels'
# parse sniffers
sniffer = Sniffer.new("data/sniffers")
routes = sniffer.parse
# send
send_data routes, 'sniffers'
# parse loopholes
loophole = Loophole.new("data/loopholes")
routes = loophole.parse
# send
send_data routes, 'loopholes'
end
def send_data routes, source
response_codes = []
uri = URI(@uri)
routes.each do |route|
data = {
passphrase: @passphrase,
source: source,
start_node: route[:start_node],
end_node: route[:end_node],
start_time: route[:start_time],
end_time: route[:end_time]
}
puts data.inspect
puts "-"*50
res = Net::HTTP.post_form(uri, data)
puts res.body
puts res.code
response_codes << res.code if res
puts
end
if response_codes.size == routes.size &&
response_codes.uniq.size == 1 &&
response_codes.uniq.first == "201"
return true
else
return false
end
end
end
matrix = Matrix.new
matrix.run