sms-logparser 0.15.4 → 0.15.5
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/README.md +2 -2
- data/lib/sms-logparser/cli.rb +1 -2
- data/lib/sms-logparser/log_message.rb +12 -14
- data/lib/sms-logparser/parser.rb +14 -10
- data/lib/sms-logparser/version.rb +1 -1
- data/spec/log_message_spec.rb +19 -0
- 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: 3bc6a6c493db206f9b0e26204b31abd83ab8b9fe
|
4
|
+
data.tar.gz: 39672cbbd824b8132d253343add492c2c11ae753
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f6a85ed18dec43437b4a2a46014150b6101004d7f3f3ec51df8fc00303b5483171acd6d2fbf50c892d6018cbe825a823ae199920441e3f3954628b6951f8a16
|
7
|
+
data.tar.gz: f2aa9eb052adde2c6af76ef2da369e646cb176d513cf635d2ab4ec3ac335daf9bc415bb51a777081d9fce77608b6a7f012e94561d77e2a17368157d90c34b447
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# SMS Logparser
|
2
2
|
|
3
|
-
sms-logparser - Logparser for Simplex Media Server (SMS). Reads access logs stored in a MySQL database (coming from the SWISS TXT CDN) and sends them to the SMS API.
|
3
|
+
sms-logparser - Logparser for Simplex Media Server (SMS). Reads access logs stored in a MySQL database (coming from the SWISS TXT CDN) accumulates and sends them to the SMS API.
|
4
4
|
|
5
5
|
[](http://badge.fury.io/rb/sms-logparser)
|
6
6
|
|
@@ -23,7 +23,7 @@ $ sms-logparser setup
|
|
23
23
|
Make a test run:
|
24
24
|
|
25
25
|
```bash
|
26
|
-
$ sms-logparser parse --simulate
|
26
|
+
$ sms-logparser parse --simulate
|
27
27
|
```
|
28
28
|
|
29
29
|
## Usage
|
data/lib/sms-logparser/cli.rb
CHANGED
@@ -29,11 +29,10 @@ module SmsLogparser
|
|
29
29
|
option :api_key, aliases: %w(-k), desc: "SMS API Key"
|
30
30
|
option :simulate, type: :boolean, aliases: %w(-s),
|
31
31
|
desc: "Dry run without submitting any data"
|
32
|
-
option :verbose, type: :boolean, aliases: %w(-v), desc: "Verbose output"
|
33
32
|
option :limit, type: :numeric, aliases: %w(-L), desc: "Limit the number of entries to query"
|
34
33
|
option :accepted_api_responses, type: :array, aliases: %w(-r),
|
35
34
|
desc: "API HTTP responses which are accepted (Default: only accept 200)"
|
36
|
-
option :accumulate, type: :boolean, aliases: %w(-A),
|
35
|
+
option :accumulate, type: :boolean, aliases: %w(-A), default: true,
|
37
36
|
desc: "Accumulate and cache results and send totals"
|
38
37
|
option :concurrency, type: :numeric, default: 4, aliases: %w(-C),
|
39
38
|
desc: "How many threads to use in parallel when sending cached results"
|
@@ -4,32 +4,36 @@ module SmsLogparser
|
|
4
4
|
@message = message
|
5
5
|
end
|
6
6
|
|
7
|
+
def match
|
8
|
+
@match ||= @message.match /\/content\/(\d+)\/(\d+)\/+(\d+)\/(\w+\.\w+)*(\?\S*)*\s.*\"\s(\d+)\s(\d+).+"(.*)"$/
|
9
|
+
end
|
10
|
+
|
7
11
|
def customer_id
|
8
|
-
match[1]
|
12
|
+
match[1] if match
|
9
13
|
end
|
10
14
|
|
11
15
|
def author_id
|
12
|
-
match[2]
|
16
|
+
match[2] if match
|
13
17
|
end
|
14
18
|
|
15
19
|
def project_id
|
16
|
-
match[3]
|
20
|
+
match[3] if match
|
17
21
|
end
|
18
22
|
|
19
23
|
def file
|
20
|
-
match[4]
|
24
|
+
match[4] if match
|
21
25
|
end
|
22
26
|
|
23
27
|
def args
|
24
|
-
match[5][1..-1] if match[5]
|
28
|
+
match[5][1..-1] if match && match[5]
|
25
29
|
end
|
26
30
|
|
27
31
|
def status
|
28
|
-
match[6].to_i
|
32
|
+
match[6].to_i if match
|
29
33
|
end
|
30
34
|
|
31
35
|
def bytes
|
32
|
-
match[7].to_i
|
36
|
+
match[7].to_i if match
|
33
37
|
end
|
34
38
|
|
35
39
|
def file_extname
|
@@ -37,7 +41,7 @@ module SmsLogparser
|
|
37
41
|
end
|
38
42
|
|
39
43
|
def user_agent
|
40
|
-
match[8]
|
44
|
+
match[8] if match
|
41
45
|
end
|
42
46
|
|
43
47
|
def account_info
|
@@ -61,11 +65,5 @@ module SmsLogparser
|
|
61
65
|
def to_h
|
62
66
|
account_info.merge(transfer_info)
|
63
67
|
end
|
64
|
-
|
65
|
-
private
|
66
|
-
|
67
|
-
def match
|
68
|
-
@match ||= @message.match /\/content\/(\d+)\/(\d+)\/(\d+)\/(\w+\.\w+)*(\?\S*)*\s.*\"\s(\d+)\s(\d+).+"(.*)"$/
|
69
|
-
end
|
70
68
|
end
|
71
69
|
end
|
data/lib/sms-logparser/parser.rb
CHANGED
@@ -11,18 +11,22 @@ module SmsLogparser
|
|
11
11
|
if Parser.match?(message)
|
12
12
|
@logger.debug { "Parser MATCH: #{message}" }
|
13
13
|
log_message = LogMessage.new(message)
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
)
|
19
|
-
if log_message.status == 200 &&
|
20
|
-
(log_message.file_extname =~ /\.(mp3|mp4|flv|f4v)/ ||
|
21
|
-
log_message.file == 'index.m3u8')
|
14
|
+
unless log_message.match
|
15
|
+
@logger.warn { "Can't extract data from message: #{message}" }
|
16
|
+
else
|
17
|
+
type = Parser.get_type(log_message.user_agent)
|
22
18
|
data << log_message.account_info.merge(
|
23
|
-
type: "
|
24
|
-
value:
|
19
|
+
type: "TRAFFIC_#{type}",
|
20
|
+
value: (log_message.bytes * traffic_correction_factor(type)).round(0)
|
25
21
|
)
|
22
|
+
if log_message.status == 200 &&
|
23
|
+
(log_message.file_extname =~ /\.(mp3|mp4|flv|f4v)/ ||
|
24
|
+
log_message.file == 'index.m3u8')
|
25
|
+
data << log_message.account_info.merge(
|
26
|
+
type: "VISITORS_#{type}",
|
27
|
+
value: 1,
|
28
|
+
)
|
29
|
+
end
|
26
30
|
end
|
27
31
|
else
|
28
32
|
@logger.debug { "Parser IGNORE: #{message}" }
|
data/spec/log_message_spec.rb
CHANGED
@@ -41,4 +41,23 @@ describe SmsLogparser::LogMessage do
|
|
41
41
|
log_message.user_agent.must_equal 'Googlebot-Video/1.0'
|
42
42
|
end
|
43
43
|
|
44
|
+
it "does not fail on double slashes" do
|
45
|
+
log_message = SmsLogparser::LogMessage.new('- - [23/Apr/2014:23:01:24 +0200] "GET /content/244/245/42601//player_logo.jpg?0.19035581778734922 HTTP/1.1" 200 21671 "http://blick.simplex.tv/content/244/245/42601/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.116 Safari/537.36"')
|
46
|
+
log_message.customer_id.must_equal nil
|
47
|
+
log_message.author_id.must_equal nil
|
48
|
+
log_message.project_id.must_equal nil
|
49
|
+
log_message.status.must_equal nil
|
50
|
+
log_message.bytes.must_equal nil
|
51
|
+
log_message.file.must_equal nil
|
52
|
+
log_message.args.must_equal nil
|
53
|
+
log_message.file_extname.must_equal nil
|
54
|
+
log_message.user_agent.must_equal nil
|
55
|
+
#log_message.status.must_equal 200
|
56
|
+
#log_message.bytes.must_equal 1181
|
57
|
+
#log_message.file.must_equal 'player_logo.jpg'
|
58
|
+
#log_message.args.must_equal '0.19035581778734922'
|
59
|
+
#log_message.file_extname.must_equal 'jpg'
|
60
|
+
#log_message.user_agent.must_equal 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.116 Safari/537.36'
|
61
|
+
end
|
62
|
+
|
44
63
|
end
|
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.15.
|
4
|
+
version: 0.15.5
|
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-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|