sms-logparser 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +33 -0
- data/Rakefile +1 -0
- data/bin/sms-logparser +5 -0
- data/lib/sms-logparser/cli.rb +114 -0
- data/lib/sms-logparser/version.rb +3 -0
- data/lib/sms-logparser.rb +7 -0
- data/sms-logparser.gemspec +27 -0
- metadata +125 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5d75a8ac15fa11b1e6efc7aad0a57614bb01f948
|
4
|
+
data.tar.gz: 5b0efac19f07e16f6ac36c0a8bd2425189e6412f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2a3acae57b6f2f06a407e2329044e2007948e7ab93371e66aa5274515044ee6bbc18d5bff0867ab11a2f8c6e50b5eb242c7df4e59a1339c00c8038ffba5999d4
|
7
|
+
data.tar.gz: dcd28686f0d12f173ea318d0c8361190afe878b5b32aa0ca1247a8f537b1a6f08b615a6d8809f8da83823c3849ccbe9492c97cdc72973a4cbb0de3011455f1f2
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 niwo
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# SmsLogparser
|
2
|
+
|
3
|
+
sms-logparser for DB-Logparser for Simplex Media Server
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'sms-logparser'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install sms-logparser
|
18
|
+
|
19
|
+
## Setup
|
20
|
+
|
21
|
+
$ sms-logparser create_parser_table
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
$ sms-logparser parse
|
26
|
+
|
27
|
+
## Contributing
|
28
|
+
|
29
|
+
1. Fork it
|
30
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
31
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
32
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
33
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/sms-logparser
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
module SmsLogparser
|
2
|
+
class Cli < Thor
|
3
|
+
|
4
|
+
EXTENSION_MAP = {
|
5
|
+
'default' => 'TRAFFIC_PODCAST',
|
6
|
+
'mp4' => 'TRAFFIC_PODCAST',
|
7
|
+
'f4v' => 'TRAFFIC_PODCAST',
|
8
|
+
'flv' => 'TRAFFIC_PODCAST',
|
9
|
+
'ts' => 'TRAFFIC_MOBILE'
|
10
|
+
}
|
11
|
+
|
12
|
+
class_option :mysql_host, :default => 'localhost'
|
13
|
+
class_option :mysql_user, :default => 'root'
|
14
|
+
class_option :mysql_db, :default => 'Syslog'
|
15
|
+
|
16
|
+
desc "parse_db", "Check the database for pcache logs and send them to SMS"
|
17
|
+
option :api_base_path, :default => 'http://dev.simplex.tv/creator/rest'
|
18
|
+
option :debug, :type => :boolean, :default => false
|
19
|
+
def parse
|
20
|
+
count = 0
|
21
|
+
last_id = get_last_parse_id
|
22
|
+
begin
|
23
|
+
results = client.query(
|
24
|
+
"SELECT * FROM SystemEvents\
|
25
|
+
WHERE `FromHost` like 'pcache%'\
|
26
|
+
AND ID > #{last_id} ORDER BY ID ASC"
|
27
|
+
)
|
28
|
+
rescue Mysql2::Error
|
29
|
+
say "parser_table not found please create it with 'create_parser_table'", :red
|
30
|
+
exit 1
|
31
|
+
end
|
32
|
+
results.each do |result|
|
33
|
+
if result['Message'] =~ /\/content\/.*\.(f4v|flv|mp4|ts) .*/
|
34
|
+
data = extract_data_from_msg(result['Message'])
|
35
|
+
url = "#{options[:api_base_path]}/"
|
36
|
+
url += "#{data[:customer_id]}/"
|
37
|
+
url += "#{data[:author_id]}/"
|
38
|
+
url += "#{data[:project_id]}/"
|
39
|
+
url += "#{data[:traffic_type]}/"
|
40
|
+
url += "#{data[:bytes]}"
|
41
|
+
if options[:debug]
|
42
|
+
puts result['ID']
|
43
|
+
puts "URL: #{url}"
|
44
|
+
puts "Data: #{data}"
|
45
|
+
puts "-----------------------"
|
46
|
+
else
|
47
|
+
RestClient.get(url)
|
48
|
+
end
|
49
|
+
count += 1
|
50
|
+
end
|
51
|
+
last_id = result['ID']
|
52
|
+
end
|
53
|
+
write_parse_result(last_id, count) unless options[:debug]
|
54
|
+
puts "Number of valid messages found: #{count}"
|
55
|
+
end
|
56
|
+
|
57
|
+
desc "create_parser_table", "Create the parser table to track the last logs parsed"
|
58
|
+
def create_parser_table
|
59
|
+
client.query(
|
60
|
+
"CREATE TABLE IF NOT EXISTS\
|
61
|
+
SmsParserRuns(\
|
62
|
+
ID INT PRIMARY KEY AUTO_INCREMENT,\
|
63
|
+
LastRunAt datetime DEFAULT NULL,\
|
64
|
+
LastEventID INT DEFAULT NULL,\
|
65
|
+
EventsFound INT DEFAULT 0,\
|
66
|
+
INDEX `LastEventID_I1` (`LastEventID`)
|
67
|
+
)"
|
68
|
+
)
|
69
|
+
say "OK", :green
|
70
|
+
end
|
71
|
+
|
72
|
+
no_commands do
|
73
|
+
def get_last_parse_id
|
74
|
+
last_parse = client.query(
|
75
|
+
"SELECT LastEventID FROM SmsParserRuns ORDER BY ID DESC LIMIT 1"
|
76
|
+
)
|
77
|
+
last_parse.first ? last_parse.first['LastEventID'] : 0
|
78
|
+
rescue Mysql2::Error
|
79
|
+
say "parser_table not found please create it with 'create_parser_table'", :red
|
80
|
+
exit 1
|
81
|
+
end
|
82
|
+
|
83
|
+
def write_parse_result(id, count)
|
84
|
+
client.query("INSERT INTO SmsParserRuns(LastRunAt, LastEventID, EventsFound)\
|
85
|
+
VALUES(\
|
86
|
+
'#{Time.now.strftime("%Y-%m-%d %H:%M:%S")}',\
|
87
|
+
#{id},\
|
88
|
+
#{count}
|
89
|
+
)"
|
90
|
+
)
|
91
|
+
end
|
92
|
+
|
93
|
+
def extract_data_from_msg(msg)
|
94
|
+
m = msg.match /\/content\/(\d+)\/(\d+)\/(\d+)\/.+\.(\S+)\s.*\"\s\d+\s(\d+)/
|
95
|
+
data = {
|
96
|
+
:customer_id => m[1],
|
97
|
+
:author_id => m[2],
|
98
|
+
:project_id => m[3],
|
99
|
+
:ext => m[4],
|
100
|
+
:traffic_type => (EXTENSION_MAP[m[4]] || EXTENSION_MAP['default']),
|
101
|
+
:bytes => m[5]
|
102
|
+
}
|
103
|
+
end
|
104
|
+
|
105
|
+
def client
|
106
|
+
@client ||= Mysql2::Client.new(
|
107
|
+
:host => options[:mysql_host],
|
108
|
+
:username => options[:mysql_user],
|
109
|
+
:database => options[:mysql_db]
|
110
|
+
)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'sms-logparser/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "sms-logparser"
|
8
|
+
spec.version = SmsLogparser::VERSION
|
9
|
+
spec.authors = ["niwo"]
|
10
|
+
spec.email = ["nik.wolfgramm@gmail.com"]
|
11
|
+
spec.description = %q{SMS Logparser}
|
12
|
+
spec.summary = %q{SMS Logparser}
|
13
|
+
spec.homepage = "https://github.com/niwo/sms-logparser"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
|
24
|
+
spec.add_dependency "thor"
|
25
|
+
spec.add_dependency "mysql2"
|
26
|
+
spec.add_dependency "rest_client"
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sms-logparser
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- niwo
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-02-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: thor
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: mysql2
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rest_client
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: SMS Logparser
|
84
|
+
email:
|
85
|
+
- nik.wolfgramm@gmail.com
|
86
|
+
executables:
|
87
|
+
- sms-logparser
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- .gitignore
|
92
|
+
- Gemfile
|
93
|
+
- LICENSE.txt
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- bin/sms-logparser
|
97
|
+
- lib/sms-logparser.rb
|
98
|
+
- lib/sms-logparser/cli.rb
|
99
|
+
- lib/sms-logparser/version.rb
|
100
|
+
- sms-logparser.gemspec
|
101
|
+
homepage: https://github.com/niwo/sms-logparser
|
102
|
+
licenses:
|
103
|
+
- MIT
|
104
|
+
metadata: {}
|
105
|
+
post_install_message:
|
106
|
+
rdoc_options: []
|
107
|
+
require_paths:
|
108
|
+
- lib
|
109
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - '>='
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - '>='
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
requirements: []
|
120
|
+
rubyforge_project:
|
121
|
+
rubygems_version: 2.0.3
|
122
|
+
signing_key:
|
123
|
+
specification_version: 4
|
124
|
+
summary: SMS Logparser
|
125
|
+
test_files: []
|