sms-logparser 0.12.2 → 0.12.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sms-logparser/api.rb +7 -8
- data/lib/sms-logparser/cli.rb +9 -6
- data/lib/sms-logparser/loggster.rb +6 -6
- data/lib/sms-logparser/version.rb +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: ad817588ffc290e40e11563db5d856da73a1c058
|
4
|
+
data.tar.gz: 6a68fbf74e90aed8127c356cb37d2a6e48762172
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af70780b477df0155f6fe10d06ea02327f7879c4cca38f413778345f3318f531a60a84de91b27124c874ee6911f402520953b9dded8c96de31fd775a1e195d3d
|
7
|
+
data.tar.gz: 099385b75fb60fa67bc62d002c84d35007870a727af9b4a534cd3332a5eab6a3b30a95e515c6dc42b3c31b633fe3d87e2b4557e63b967879e34b4d93a3af058e
|
data/lib/sms-logparser/api.rb
CHANGED
@@ -52,21 +52,20 @@ module SmsLogparser
|
|
52
52
|
data[:value]
|
53
53
|
].join('/')
|
54
54
|
if @options[:simulate]
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
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?(
|
65
|
-
msg = "Received HTTP status #{
|
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,
|
68
|
+
yield url, status
|
70
69
|
}
|
71
70
|
end
|
72
71
|
end
|
data/lib/sms-logparser/cli.rb
CHANGED
@@ -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 <
|
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 :
|
37
|
-
|
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[:
|
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[:
|
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[:
|
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 =
|
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
|