sms-logparser 0.12.1 → 0.12.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 +4 -4
- data/lib/sms-logparser/api.rb +2 -3
- data/lib/sms-logparser/cli.rb +15 -72
- data/lib/sms-logparser/mysql.rb +1 -1
- data/lib/sms-logparser/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f0b45a865df500739a1bea384895fbee8fbad15c
|
4
|
+
data.tar.gz: 41b69f59f7d1d691a66e7c0b2cced2ad16e4ec66
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 39d0e9abc5cb3777f2b222196b94387ede340817fcf52b58999bc9c93175ae20f156b384940ada9946703799883ed20fb4c3a2f6eb792a7f830cb2f04571eb5f
|
7
|
+
data.tar.gz: 8c3efb728d6c670cdcac62bf9cecbf022d65a2f1dc9e12528dde9aa89e77a0cbcfa6e3ee4e8d416606edf00f5bbcecedab0aad51059bea24d41be265420f369c
|
data/lib/sms-logparser/api.rb
CHANGED
@@ -13,7 +13,6 @@ module SmsLogparser
|
|
13
13
|
@data_cache = {}
|
14
14
|
end
|
15
15
|
|
16
|
-
|
17
16
|
def send(data)
|
18
17
|
requests = build_urls(data)
|
19
18
|
return requests if @options[:simulate]
|
@@ -36,11 +35,11 @@ module SmsLogparser
|
|
36
35
|
requests
|
37
36
|
end
|
38
37
|
|
39
|
-
def
|
38
|
+
def send_sets(data_sets, concurrency=4)
|
40
39
|
queue = Queue.new
|
41
40
|
semaphore = Mutex.new
|
42
41
|
data_sets.each {|set| queue << set }
|
43
|
-
threads =
|
42
|
+
threads = concurrency.times.map do
|
44
43
|
Thread.new do
|
45
44
|
while !queue.empty?
|
46
45
|
begin
|
data/lib/sms-logparser/cli.rb
CHANGED
@@ -33,10 +33,14 @@ 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,
|
38
|
+
desc: "How many threads to use in parallel when sending cached results"
|
36
39
|
def parse
|
37
40
|
start_message = "Parser started"
|
38
41
|
start_message += options[:simulate] ? " in simulation mode." : "."
|
39
42
|
logger.info(start_message)
|
43
|
+
cache = DataCache.new if options[:cache]
|
40
44
|
mysql = Mysql.new(options)
|
41
45
|
if !options[:simulate] && mysql.parser_running?
|
42
46
|
logger.warn("Exit. Another instance of the parser is already running.")
|
@@ -55,83 +59,23 @@ module SmsLogparser
|
|
55
59
|
entries.each do |entry|
|
56
60
|
Parser.extract_data_from_msg(entry['Message']) do |data|
|
57
61
|
if data
|
58
|
-
|
59
|
-
|
60
|
-
|
62
|
+
if options[:cache]
|
63
|
+
cache.add(data)
|
64
|
+
logger.debug {"Cached data: #{data}"}
|
65
|
+
else
|
66
|
+
requests = api.send(data)
|
67
|
+
verbose_parser_output(entry['ID'], data, requests)
|
68
|
+
end
|
61
69
|
state[:last_event_id] = entry['ID']
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
rescue SystemExit, Interrupt
|
67
|
-
logger.error("Received an interrupt. Stopping the parser run.")
|
68
|
-
state[:status] = STATUS[:interrupted] if state
|
69
|
-
rescue => e
|
70
|
-
logger.error "Aborting the parser run."
|
71
|
-
logger.error e
|
72
|
-
state[:status] = STATUS[:api_error] if state
|
73
|
-
else
|
74
|
-
state[:status] = STATUS[:ok]
|
75
|
-
ensure
|
76
|
-
begin
|
77
|
-
if mysql && state
|
78
|
-
state[:run_time] = (Time.now - state[:started_at]).round(2)
|
79
|
-
if state[:id]
|
80
|
-
mysql.write_parse_result(state) unless options[:simulate]
|
81
|
-
end
|
82
|
-
log_parse_results(state)
|
83
|
-
SmsLogparser::Loggster.instance.close
|
84
|
-
end
|
85
|
-
rescue => e
|
86
|
-
logger.fatal e
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
desc "cached_pase", "Check the database for pcache logs and put them into the cache"
|
91
|
-
option :api_base_url, aliases: %w(-a),
|
92
|
-
desc: "Base path of the SMS API (Default: http://localhost:8080/creator/rest/)"
|
93
|
-
option :api_key, aliases: %w(-k), desc: "SMS API Key"
|
94
|
-
option :simulate, type: :boolean, aliases: %w(-s),
|
95
|
-
desc: "Dry run without submitting any data"
|
96
|
-
option :verbose, type: :boolean, aliases: %w(-v), desc: "Verbose output"
|
97
|
-
option :limit, type: :numeric, aliases: %w(-L), desc: "Limit the number of entries to query"
|
98
|
-
option :accepted_api_responses, type: :array, aliases: %w(-r),
|
99
|
-
desc: "API HTTP responses which are accepted (Default: only accept 200)."
|
100
|
-
def cached_parse
|
101
|
-
start_message = "Parser started"
|
102
|
-
start_message += options[:simulate] ? " in simulation mode." : "."
|
103
|
-
logger.info(start_message)
|
104
|
-
mysql = Mysql.new(options)
|
105
|
-
if !options[:simulate] && mysql.parser_running?
|
106
|
-
logger.warn("Exit. Another instance of the parser is already running.")
|
107
|
-
exit!
|
108
|
-
end
|
109
|
-
state = {
|
110
|
-
last_event_id: mysql.get_last_parse_id,
|
111
|
-
match_count: 0,
|
112
|
-
status: STATUS[:running],
|
113
|
-
started_at: Time.now,
|
114
|
-
run_time: 0.0
|
115
|
-
}
|
116
|
-
state = mysql.start_run(state) unless options[:simulate]
|
117
|
-
cache = DataCache.new
|
118
|
-
mysql = Mysql.new(options)
|
119
|
-
say "Getting entries from database..."
|
120
|
-
mysql.get_entries(last_id: state[:last_event_id], limit: options[:limit]) do |entries|
|
121
|
-
entries.each do |entry|
|
122
|
-
Parser.extract_data_from_msg(entry['Message']) do |data|
|
123
|
-
if data
|
124
|
-
cache.add(data)
|
125
|
-
logger.debug {"Cached data: #{data}"}
|
126
70
|
state[:match_count] += 1
|
127
|
-
state[:last_event_id] = entry['ID']
|
128
71
|
end
|
129
72
|
end
|
130
73
|
end
|
131
74
|
end
|
132
|
-
|
133
|
-
|
134
|
-
|
75
|
+
if options[:cache]
|
76
|
+
api.send_sets(cache.data_sets, options[:concurrency]) do |url, response|
|
77
|
+
logger.info { "POST #{url} (#{response})" }
|
78
|
+
end
|
135
79
|
end
|
136
80
|
rescue SystemExit, Interrupt
|
137
81
|
logger.error("Received an interrupt. Stopping the parser run.")
|
@@ -155,7 +99,6 @@ module SmsLogparser
|
|
155
99
|
rescue => e
|
156
100
|
logger.fatal e
|
157
101
|
end
|
158
|
-
|
159
102
|
end
|
160
103
|
|
161
104
|
desc "history", "List the last paser runs"
|
data/lib/sms-logparser/mysql.rb
CHANGED
@@ -108,7 +108,7 @@ module SmsLogparser
|
|
108
108
|
def select_entries(last_id, max_id)
|
109
109
|
query = %Q{
|
110
110
|
SELECT ID, Message FROM SystemEvents
|
111
|
-
WHERE ID BETWEEN #{last_id} AND #{max_id}
|
111
|
+
WHERE ID BETWEEN #{last_id + 1} AND #{max_id}
|
112
112
|
ORDER BY ID ASC
|
113
113
|
LIMIT #{@query_limit};
|
114
114
|
}.gsub(/\s+/, " ").strip
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sms-logparser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.12.
|
4
|
+
version: 0.12.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- niwo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|