pushyd 0.5.1 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f4d99244c44f7f99042eb496abe4831847dff1dc
4
- data.tar.gz: 24c424c9b17278722785b0cabc84c3876df550ba
3
+ metadata.gz: 2c164022741e67725c4df7becef21483e55a6859
4
+ data.tar.gz: 613a5d94c098c12f4f39e023ddd163712a8581c3
5
5
  SHA512:
6
- metadata.gz: 4600f69fc437189494e35dc3d762d0f3875cee5b50531864d67db2faefb54fe9087f934e2c8b757866fad562dd03be041c31d979705b81168fb115cf8e07bf68
7
- data.tar.gz: eb7f68cbb2fc3ab2ecec2fbcd3cc6663d0879f60b8c421cc769e328d2ffc059e8b6e3a2f25aa5b14d6d5794dcc9999dec636f70566eb3fd7d8dde9af172bef0a
6
+ metadata.gz: 228e4f772c5f5d6541e426d288b5e29b7f32382897d058511b229ffdb7e058325cd303e35eb62f88c0b94c3726c01b41683fc588047d61a841cb332f068ab541
7
+ data.tar.gz: a659b7425f0ff0a5859582ceb28a37156be0befe66d2e14f35e6b8d648209607ebd73832944b05840852a6a7cc320bed3adfece419fce586961db9ccd1e4e430
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pushyd (0.5.1)
4
+ pushyd (0.5.2)
5
5
  bunny (~> 2.3)
6
6
  chamber (~> 2.9)
7
7
  daemons
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[:log] ||= {}
38
- Conf[:log][:file] = cmd_logfile.to_s if cmd_logfile
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
@@ -1,7 +1,7 @@
1
1
  # Constants: global
2
- WAY_OUT = "SENT"
3
- WAY_IN = "RECD"
4
- WAY_POST = "POST"
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\t%-30s"
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
 
@@ -41,7 +41,7 @@ module PushyDaemon
41
41
  @logger.formatter = Formatter
42
42
 
43
43
  # Set progname
44
- @logger.progname = sprintf(LOG_FORMAT_PROGNAME, Process.pid, me.split('::').last)
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 error messages
67
- @logger.error messages
66
+ def info message, lines = []
67
+ @logger.info message
68
+ debug_lines lines
68
69
  end
69
70
 
70
- def info messages
71
- @logger.info messages
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 message params = {}
79
- # Header
80
- @logger.info sprintf(
81
- "%3s %-15s %s",
82
- params[:way],
83
- params[:exchange],
84
- params[:key]
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
@@ -1,25 +1,24 @@
1
1
  module PushyDaemon
2
2
  class Formatter
3
3
 
4
- def self.call severity, datetime, progname, messages
4
+ def self.call severity, datetime, progname, payload
5
5
  # Build common values
6
6
  timestamp = datetime.strftime(LOG_FORMAT_TIME)
7
7
 
8
- # If we have a bunch of lines, prefix them and send them together
9
- if messages.is_a? Array
10
- messages.map do |line|
11
- sprintf LOG_FORMAT_ARRAY, timestamp, severity, progname, trimmed(line)
12
- end.join
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
- else
20
- sprintf LOG_FORMAT_LINE, timestamp, severity, progname, trimmed(messages)
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
- end
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
- message way: WAY_IN,
62
- exchange: msg_exchange,
63
- key: msg_rkey,
64
- body: data,
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
- message way: WAY_POST,
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
@@ -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
- message way: WAY_OUT,
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
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  Gem::Specification.new do |spec|
3
3
  # Project version
4
- spec.version = "0.5.1"
4
+ spec.version = "0.5.2"
5
5
 
6
6
  # Project description
7
7
  spec.name = "pushyd"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pushyd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bruno MEDICI