sms-logparser 0.12.2 → 0.12.4

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: f0b45a865df500739a1bea384895fbee8fbad15c
4
- data.tar.gz: 41b69f59f7d1d691a66e7c0b2cced2ad16e4ec66
3
+ metadata.gz: ad817588ffc290e40e11563db5d856da73a1c058
4
+ data.tar.gz: 6a68fbf74e90aed8127c356cb37d2a6e48762172
5
5
  SHA512:
6
- metadata.gz: 39d0e9abc5cb3777f2b222196b94387ede340817fcf52b58999bc9c93175ae20f156b384940ada9946703799883ed20fb4c3a2f6eb792a7f830cb2f04571eb5f
7
- data.tar.gz: 8c3efb728d6c670cdcac62bf9cecbf022d65a2f1dc9e12528dde9aa89e77a0cbcfa6e3ee4e8d416606edf00f5bbcecedab0aad51059bea24d41be265420f369c
6
+ metadata.gz: af70780b477df0155f6fe10d06ea02327f7879c4cca38f413778345f3318f531a60a84de91b27124c874ee6911f402520953b9dded8c96de31fd775a1e195d3d
7
+ data.tar.gz: 099385b75fb60fa67bc62d002c84d35007870a727af9b4a534cd3332a5eab6a3b30a95e515c6dc42b3c31b633fe3d87e2b4557e63b967879e34b4d93a3af058e
@@ -52,21 +52,20 @@ module SmsLogparser
52
52
  data[:value]
53
53
  ].join('/')
54
54
  if @options[:simulate]
55
- semaphore.synchronize {
56
- yield url, 0
57
- }
58
- break
55
+ status = 200
56
+ else
57
+ response = @connection.post(url)
58
+ status = response.status
59
59
  end
60
- response = @connection.post(url)
61
60
  rescue => e
62
61
  raise RuntimeError, "Can't send request to #{url}. #{e.message}", caller
63
62
  end
64
- unless @accepted_responses.include?(response.status)
65
- msg = "Received HTTP status #{response.status} from API. Only accepting #{@accepted_responses.join(', ')}."
63
+ unless @accepted_responses.include?(status)
64
+ msg = "Received HTTP status #{status} from API. Only accepting #{@accepted_responses.join(', ')}."
66
65
  raise RuntimeError, msg, caller
67
66
  end
68
67
  semaphore.synchronize {
69
- yield url, response.status
68
+ yield url, status
70
69
  }
71
70
  end
72
71
  end
@@ -10,7 +10,7 @@ module SmsLogparser
10
10
  desc: "Configuration file for default options"
11
11
 
12
12
  class_option :severity, type: :string, aliases: %w(-S),
13
- desc: "Log severity <debug|info|warn|error|fatal> (Default: warn)"
13
+ desc: "Log severity <DEBUG|INFO|WARN|ERROR|FATAL> (Default: INFO)"
14
14
  class_option :logfile, desc: "Path to the logfile (Default: STDOUT)", aliases: %w(-l)
15
15
  class_option :mysql_host, aliases: %w(-h), desc: "MySQL host"
16
16
  class_option :mysql_user, aliases: %w(-u), desc: "MySQL user (Default: root)"
@@ -33,17 +33,19 @@ module SmsLogparser
33
33
  option :limit, type: :numeric, aliases: %w(-L), desc: "Limit the number of entries to query"
34
34
  option :accepted_api_responses, type: :array, aliases: %w(-r),
35
35
  desc: "API HTTP responses which are accepted (Default: only accept 200)."
36
- option :cache, type: :boolean, desc: "Accumulate and cache results and send totals"
37
- option :concurrency, type: :numeric, default: 4,
36
+ option :accumulate, type: :boolean, aliases: %w(-A),
37
+ desc: "Accumulate and cache results and send totals"
38
+ option :concurrency, type: :numeric, default: 4, aliases: %w(-C),
38
39
  desc: "How many threads to use in parallel when sending cached results"
39
40
  def parse
40
41
  start_message = "Parser started"
41
42
  start_message += options[:simulate] ? " in simulation mode." : "."
42
43
  logger.info(start_message)
43
- cache = DataCache.new if options[:cache]
44
+ cache = DataCache.new if options[:accumulate]
44
45
  mysql = Mysql.new(options)
45
46
  if !options[:simulate] && mysql.parser_running?
46
47
  logger.warn("Exit. Another instance of the parser is already running.")
48
+ SmsLogparser::Loggster.instance.close
47
49
  exit!
48
50
  end
49
51
  state = {
@@ -56,10 +58,11 @@ module SmsLogparser
56
58
  state = mysql.start_run(state) unless options[:simulate]
57
59
  api = Api.new(options)
58
60
  mysql.get_entries(last_id: state[:last_event_id], limit: options[:limit]) do |entries|
61
+ logger.info { "Getting log messages from database..." }
59
62
  entries.each do |entry|
60
63
  Parser.extract_data_from_msg(entry['Message']) do |data|
61
64
  if data
62
- if options[:cache]
65
+ if options[:accumulate]
63
66
  cache.add(data)
64
67
  logger.debug {"Cached data: #{data}"}
65
68
  else
@@ -72,7 +75,7 @@ module SmsLogparser
72
75
  end
73
76
  end
74
77
  end
75
- if options[:cache]
78
+ if options[:accumulate]
76
79
  api.send_sets(cache.data_sets, options[:concurrency]) do |url, response|
77
80
  logger.info { "POST #{url} (#{response})" }
78
81
  end
@@ -20,17 +20,17 @@ module SmsLogparser
20
20
  self
21
21
  end
22
22
 
23
- def set_severity(severity = "info")
23
+ def set_severity(severity = :info)
24
24
  self.sev_threshold = case severity
25
- when "debug"
25
+ when "DEBUG" || :debug
26
26
  Logger::DEBUG
27
- when "info"
27
+ when "INFO" || :info
28
28
  Logger::INFO
29
- when "warn"
29
+ when "WARN" || :warn
30
30
  Logger::WARN
31
- when "error"
31
+ when "ERROR" || :error
32
32
  Logger::ERROR
33
- when "fatal"
33
+ when "FATAL" || :fatal
34
34
  Logger::FATAL
35
35
  else
36
36
  Logger::INFO
@@ -1,3 +1,3 @@
1
1
  module SmsLogparser
2
- VERSION = "0.12.2"
2
+ VERSION = "0.12.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sms-logparser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.2
4
+ version: 0.12.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - niwo