pushyd 0.5.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/bin/pushyd +2 -2
- data/lib/pushyd/conf.rb +0 -2
- data/lib/pushyd/constants.rb +6 -8
- data/lib/pushyd/endpoint.rb +27 -22
- data/lib/pushyd/formatter.rb +13 -14
- data/lib/pushyd/proxy.rb +6 -14
- data/lib/pushyd/shouter.rb +3 -8
- data/pushyd.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c164022741e67725c4df7becef21483e55a6859
|
4
|
+
data.tar.gz: 613a5d94c098c12f4f39e023ddd163712a8581c3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 228e4f772c5f5d6541e426d288b5e29b7f32382897d058511b229ffdb7e058325cd303e35eb62f88c0b94c3726c01b41683fc588047d61a841cb332f068ab541
|
7
|
+
data.tar.gz: a659b7425f0ff0a5859582ceb28a37156be0befe66d2e14f35e6b8d648209607ebd73832944b05840852a6a7cc320bed3adfece419fce586961db9ccd1e4e430
|
data/Gemfile.lock
CHANGED
data/bin/pushyd
CHANGED
@@ -34,8 +34,8 @@ begin
|
|
34
34
|
Conf.prepare config: cmd_config, logfile: cmd_logfile
|
35
35
|
|
36
36
|
# Override log file
|
37
|
-
Conf[:
|
38
|
-
Conf[:
|
37
|
+
Conf[:logs] ||= {}
|
38
|
+
Conf[:logs][:file] = cmd_logfile.to_s if cmd_logfile
|
39
39
|
|
40
40
|
rescue OptionParser::InvalidOption => e
|
41
41
|
abort "EXITING: InvalidOption: #{e.message} \n #{e.backtrace.to_yaml}"
|
data/lib/pushyd/conf.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
require "chamber"
|
2
2
|
|
3
3
|
# FIXME: files named with hyphens will not be found by Chamber for now
|
4
|
-
# FIXME: reloading of configuration from API
|
5
|
-
|
6
4
|
class ConfigMissingParameter < StandardError; end
|
7
5
|
class ConfigOtherError < StandardError; end
|
8
6
|
class ConfigParseError < StandardError; end
|
data/lib/pushyd/constants.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# Constants: global
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
MSG_SEND = "SEND"
|
3
|
+
MSG_RECV = "RECV"
|
4
|
+
WAY_PROP = "PROP"
|
5
5
|
|
6
6
|
# Constants: proxy
|
7
7
|
PROXY_MESSAGE_MAX = 1
|
@@ -11,10 +11,8 @@ PROXY_USE_ACK = false
|
|
11
11
|
LOG_ROTATION = "daily"
|
12
12
|
LOG_TRIM_LINE = 200
|
13
13
|
LOG_FORMAT_TIME = "%Y-%m-%d %H:%M:%S"
|
14
|
-
LOG_FORMAT_HEADER = "%s\t%-8s
|
15
|
-
LOG_FORMAT_LINE = LOG_FORMAT_HEADER+" %s\n"
|
16
|
-
LOG_FORMAT_ARRAY = LOG_FORMAT_HEADER+" %s\n"
|
17
|
-
LOG_FORMAT_HASH = LOG_FORMAT_HEADER+" %-17s %s\n"
|
18
|
-
LOG_FORMAT_PROGNAME = "%d\t%s"
|
14
|
+
LOG_FORMAT_HEADER = "%s %d\t%-8s %-15s "
|
19
15
|
|
16
|
+
LOG_FORMAT_ARRAY = " %s"
|
17
|
+
LOG_FORMAT_HASH = " %-15s %s\n"
|
20
18
|
|
data/lib/pushyd/endpoint.rb
CHANGED
@@ -41,7 +41,7 @@ module PushyDaemon
|
|
41
41
|
@logger.formatter = Formatter
|
42
42
|
|
43
43
|
# Set progname
|
44
|
-
@logger.progname =
|
44
|
+
@logger.progname = me.split('::').last
|
45
45
|
|
46
46
|
# Set expected level
|
47
47
|
@logger.level = case loglevel
|
@@ -63,36 +63,31 @@ module PushyDaemon
|
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
|
-
def
|
67
|
-
@logger.
|
66
|
+
def info message, lines = []
|
67
|
+
@logger.info message
|
68
|
+
debug_lines lines
|
68
69
|
end
|
69
70
|
|
70
|
-
def
|
71
|
-
@logger.
|
71
|
+
def error messages
|
72
|
+
@logger.error messages
|
72
73
|
end
|
73
74
|
|
74
75
|
def debug messages
|
75
76
|
@logger.debug messages
|
76
77
|
end
|
77
78
|
|
78
|
-
def
|
79
|
-
#
|
80
|
-
@logger.info sprintf(
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
# Attributes
|
88
|
-
@logger.debug params[:attrs] if params[:attrs].is_a?(Hash)
|
89
|
-
|
90
|
-
# Body (split in lines to log them separately)
|
91
|
-
if params[:body].is_a?(Enumerable) && !params[:body].empty?
|
92
|
-
body_json = JSON.pretty_generate(params[:body])
|
93
|
-
#puts "log? #{params[:body]} "
|
94
|
-
@logger.debug body_json.lines
|
79
|
+
def log_message msg_way, msg_exchange, msg_key, msg_body = [], msg_attrs = {}
|
80
|
+
# Message header
|
81
|
+
@logger.info sprintf("%3s %-15s %s", msg_way, msg_exchange, msg_key)
|
82
|
+
|
83
|
+
# Body lines
|
84
|
+
if msg_body.is_a?(Enumerable) && !msg_body.empty?
|
85
|
+
body_json = JSON.pretty_generate(msg_body)
|
86
|
+
debug_lines body_json.lines
|
95
87
|
end
|
88
|
+
|
89
|
+
# Attributes lines
|
90
|
+
debug_lines msg_attrs
|
96
91
|
end
|
97
92
|
|
98
93
|
# Start connexion to RabbitMQ
|
@@ -171,5 +166,15 @@ module PushyDaemon
|
|
171
166
|
def handle_message rule, delivery_info, metadata, payload
|
172
167
|
end
|
173
168
|
|
169
|
+
private
|
170
|
+
|
171
|
+
def debug_lines lines
|
172
|
+
if lines.is_a? Array
|
173
|
+
@logger.debug lines.map{ |line| sprintf(LOG_FORMAT_ARRAY, line) }
|
174
|
+
elsif lines.is_a? Hash
|
175
|
+
@logger.debug lines.map{ |key, value| sprintf(LOG_FORMAT_HASH, key, value) }
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
174
179
|
end
|
175
180
|
end
|
data/lib/pushyd/formatter.rb
CHANGED
@@ -1,25 +1,24 @@
|
|
1
1
|
module PushyDaemon
|
2
2
|
class Formatter
|
3
3
|
|
4
|
-
def self.call severity, datetime, progname,
|
4
|
+
def self.call severity, datetime, progname, payload
|
5
5
|
# Build common values
|
6
6
|
timestamp = datetime.strftime(LOG_FORMAT_TIME)
|
7
7
|
|
8
|
-
#
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
elsif messages.is_a? Hash
|
15
|
-
messages.map do |key, value|
|
16
|
-
sprintf LOG_FORMAT_HASH, timestamp, severity, progname, key, value
|
17
|
-
end.join
|
8
|
+
# Build header
|
9
|
+
header = sprintf LOG_FORMAT_HEADER,
|
10
|
+
timestamp,
|
11
|
+
Process.pid,
|
12
|
+
severity,
|
13
|
+
progname
|
18
14
|
|
19
|
-
|
20
|
-
|
15
|
+
# If we have a bunch of lines, prefix them and send them together
|
16
|
+
return payload.map do |line|
|
17
|
+
"#{header}#{trimmed(line)}\n"
|
18
|
+
end.join if payload.is_a?(Array)
|
21
19
|
|
22
|
-
|
20
|
+
# Otherwise, just prefix the only line
|
21
|
+
return "#{header}#{trimmed(payload)}\n"
|
23
22
|
end
|
24
23
|
|
25
24
|
protected
|
data/lib/pushyd/proxy.rb
CHANGED
@@ -36,8 +36,7 @@ module PushyDaemon
|
|
36
36
|
end
|
37
37
|
|
38
38
|
# Send config table to logs
|
39
|
-
info "proxy initialized"
|
40
|
-
info @table.to_s.lines
|
39
|
+
info "proxy initialized", @table.to_s.lines
|
41
40
|
|
42
41
|
rescue Bunny::TCPConnectionFailedForAllHosts => e
|
43
42
|
error "ERROR: cannot connect to RabbitMQ hosts (#{e.inspect})"
|
@@ -58,14 +57,10 @@ module PushyDaemon
|
|
58
57
|
data = parse payload, metadata.content_type #, rule
|
59
58
|
|
60
59
|
# Announce match
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
attrs: {
|
66
|
-
'rule' => rule_name,
|
67
|
-
'app-id' => metadata.app_id,
|
68
|
-
'content-type' => metadata.content_type,
|
60
|
+
log_message MSG_RECV, msg_exchange, msg_rkey, data, {
|
61
|
+
'rule' => rule_name,
|
62
|
+
'app-id' => metadata.app_id,
|
63
|
+
'content-type' => metadata.content_type,
|
69
64
|
}
|
70
65
|
|
71
66
|
# Build notification payload
|
@@ -87,10 +82,7 @@ module PushyDaemon
|
|
87
82
|
id = SecureRandom.random_number(100)
|
88
83
|
|
89
84
|
# Log message details
|
90
|
-
|
91
|
-
exchange: id,
|
92
|
-
key: relay_url,
|
93
|
-
body: post_body
|
85
|
+
log_message WAY_PROP, id, relay_url, post_body
|
94
86
|
|
95
87
|
# Push message to URL
|
96
88
|
response = RestClient.post relay_url.to_s, JSON.pretty_generate(post_body), :content_type => :json
|
data/lib/pushyd/shouter.rb
CHANGED
@@ -36,8 +36,7 @@ module PushyDaemon
|
|
36
36
|
|
37
37
|
# Send shouter info to logs
|
38
38
|
shouter_info = { topic: @topic, period: @period, keys: @keys }
|
39
|
-
info "shouter initialized"
|
40
|
-
info shouter_info
|
39
|
+
info "shouter initialized", shouter_info
|
41
40
|
|
42
41
|
rescue Bunny::TCPConnectionFailedForAllHosts => e
|
43
42
|
error "ERROR: cannot connect to RabbitMQ hosts (#{e.inspect})"
|
@@ -50,7 +49,7 @@ module PushyDaemon
|
|
50
49
|
loop do
|
51
50
|
random_string = SecureRandom.hex
|
52
51
|
random_key = @keys.sample || "random"
|
53
|
-
channel_shout [:ping, random_key, random_string], {}
|
52
|
+
channel_shout [:ping, random_key, random_string], {dummy: true, time: Time.now.to_f, host: Conf.host}
|
54
53
|
sleep @period
|
55
54
|
end
|
56
55
|
rescue AMQ::Protocol::EmptyResponseError => e
|
@@ -78,11 +77,7 @@ module PushyDaemon
|
|
78
77
|
routing_key = keys.unshift(exchange_name).join('.')
|
79
78
|
|
80
79
|
# Announce shout
|
81
|
-
|
82
|
-
exchange: exchange_name,
|
83
|
-
key: routing_key,
|
84
|
-
body: body,
|
85
|
-
attrs: {}
|
80
|
+
log_message MSG_SEND, exchange_name, routing_key, body
|
86
81
|
|
87
82
|
# Publish
|
88
83
|
@exchange.publish(body.to_json,
|
data/pushyd.gemspec
CHANGED