vidibus-wowza_log_parser 0.1.0

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.
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2013 punkrats
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,75 @@
1
+ # Vidibus::WowzaLogParser [![Build Status](https://travis-ci.org/vidibus/vidibus-wowza_log_parser.png)](https://travis-ci.org/vidibus/vidibus-wowza_log_parser)
2
+
3
+ A simple parser for Wowza access logs.
4
+
5
+ This gem is part of [Vidibus](http://vidibus.org), an open source toolset for building distributed (video) applications.
6
+
7
+
8
+ ## Installation
9
+
10
+ Add `gem 'vidibus-wowza_log_parser'` to the Gemfile of your application. Then call `bundle install` on your console.
11
+
12
+
13
+ ## Usage
14
+
15
+ To parse an access log, provide the path to a file or just the log lines:
16
+
17
+ ```ruby
18
+ parser = Vidibus::WowzaLogParser.new
19
+ parser.parse('path/to/access.log')
20
+ # => [{}, {}, ...]
21
+
22
+ parser.parse('a log line')
23
+ # => [{}, {}, ...]
24
+ ```
25
+
26
+ The parser will use Wowza's default fields to match the logs:
27
+
28
+ ```
29
+ date time tz x-event x-category x-severity x-status x-ctx x-comment x-vhost x-app x-appinst x-duration s-ip s-port s-uri c-ip c-proto c-referrer c-user-agent c-client-id cs-bytes sc-bytes x-stream-id x-spos cs-stream-bytes sc-stream-bytes x-sname x-sname-query x-file-name x-file-ext x-file-size x-file-length x-suri x-suri-stem x-suri-query cs-uri-stem cs-uri-query
30
+ ```
31
+
32
+ Thus each result hash will include all fields with values while omitting the blank entries:
33
+
34
+ ```ruby
35
+ line = '2013-09-17 00:00:04 CEST comment server WARN 200 - LiveMediaStreamReceiver.doWatchdog: streamTimeout - - - 382109.883 - - - - - - - - - - - - - - - - - - - - - - - - -'
36
+ parser = Vidibus::WowzaLogParser.new
37
+ parser.parse(line)
38
+ # => {
39
+ # 'date' => '2013-09-17',
40
+ # 'time' => '00:00:04',
41
+ # 'tz' => 'CEST',
42
+ # 'x-event' => 'comment',
43
+ # 'x-category' => 'server',
44
+ # 'x-severity' => 'WARN',
45
+ # 'x-status' => '200',
46
+ # 'x-comment' => 'LiveMediaStreamReceiver.doWatchdog: streamTimeout',
47
+ # 'x-duration' => '382109.883'
48
+ #}
49
+ ```
50
+
51
+ If you have a different log format or want to group values, you may provide custom fields and matchers:
52
+
53
+ ```ruby
54
+ line = '2013-09-17 00:00:04 CEST comment server WARN 200 - LiveMediaStreamReceiver.doWatchdog: streamTimeout - - - 382109.883 - - - - - - - - - - - - - - - - - - - - - - - - -'
55
+ parser = Vidibus::WowzaLogParser.new
56
+ parser.fields = 'datetime content'
57
+ parser.matchers['datetime'] = '(.+ CEST)'
58
+ parser.matchers['content'] = '(.+)'
59
+ parser.parse(line)
60
+ # => {
61
+ # 'datetime' => '2013-09-17 00:00:04 CEST',
62
+ # 'content' => 'comment server WARN 200 - LiveMediaStreamReceiver.doWatchdog: streamTimeout - - - 382109.883 - - - - - - - - - - - - - - - - - - - - - - - - -',
63
+ #}
64
+ ```
65
+
66
+
67
+ ## Testing
68
+
69
+ To test your gem, call `rspec spec` on your console.
70
+ To imitate the way Travis tests your gem, perform `bundle exec rspec spec --format progress`.
71
+
72
+
73
+ ## Copyright
74
+
75
+ © 2013 punkrats. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,17 @@
1
+ $:.unshift File.expand_path('../lib/', __FILE__)
2
+
3
+ require 'bundler'
4
+ require 'rdoc/task'
5
+ require 'rspec'
6
+ require 'rspec/core/rake_task'
7
+ require 'vidibus/wowza_log_parser'
8
+
9
+ Bundler::GemHelper.install_tasks
10
+
11
+ Rake::RDocTask.new do |rdoc|
12
+ rdoc.rdoc_dir = 'rdoc'
13
+ rdoc.title = "vidibus-wowza_log_parser #{Vidibus::WowzaLogParser::VERSION}"
14
+ rdoc.rdoc_files.include('README*')
15
+ rdoc.rdoc_files.include('lib/**/*.rb')
16
+ rdoc.options << '--charset=utf-8'
17
+ end
@@ -0,0 +1,68 @@
1
+ module Vidibus
2
+ class WowzaLogParser
3
+ VERSION = '0.1.0'
4
+ FIELDS = 'date time tz x-event x-category x-severity x-status x-ctx x-comment x-vhost x-app x-appinst x-duration s-ip s-port s-uri c-ip c-proto c-referrer c-user-agent c-client-id cs-bytes sc-bytes x-stream-id x-spos cs-stream-bytes sc-stream-bytes x-sname x-sname-query x-file-name x-file-ext x-file-size x-file-length x-suri x-suri-stem x-suri-query cs-uri-stem cs-uri-query'
5
+ MATCHERS = {
6
+ '_field' => '([^\s]+)',
7
+ '_space' => '\s+',
8
+ 'x-status' => '((?:\d+|-))',
9
+ 'x-comment' => '(.+)',
10
+ 'x-duration' => '(\d+\.\d+)',
11
+ 'c-proto' => '([^\s]+(?:\s\(.+\))?)',
12
+ 'c-user-agent' => '(.+?)',
13
+ 'c-client-id' => '((?:\d+|-))'
14
+ }
15
+
16
+ def fields
17
+ @fields ||= FIELDS
18
+ end
19
+
20
+ def fields=(input)
21
+ @fields_list = nil
22
+ @fields = input
23
+ end
24
+
25
+ def matchers
26
+ @matchers ||= MATCHERS
27
+ end
28
+
29
+ def matchers=(input)
30
+ @fields_list = nil
31
+ @matchers = input
32
+ end
33
+
34
+ def parse(input, options = {})
35
+ unless input
36
+ raise(ArgumentError, 'No input given')
37
+ end
38
+ if File.file?(input)
39
+ input = File.read(input)
40
+ end
41
+ filter = options[:filter]
42
+ output = []
43
+ input.split(/\n+/).each do |line|
44
+ next if filter && !line.match(filter)
45
+ if match = line.match(regex)
46
+ values = match.to_a[1..-1]
47
+ output << Hash[[keys, values].transpose].reject {|k,v| v == '-'}
48
+ end
49
+ end
50
+ output
51
+ end
52
+
53
+ private
54
+
55
+ def regex
56
+ regex_parts = []
57
+ keys.each do |field|
58
+ regex = matchers[field] || matchers['_field']
59
+ regex_parts << regex
60
+ end
61
+ regex = '^' + regex_parts.join(matchers['_space']) + '$'
62
+ end
63
+
64
+ def keys
65
+ @keys ||= fields.split(Regexp.new(matchers['_space']))
66
+ end
67
+ end
68
+ end
@@ -0,0 +1 @@
1
+ require 'vidibus/wowza_log_parser'
metadata ADDED
@@ -0,0 +1,149 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vidibus-wowza_log_parser
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - punkrats
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-09-18 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 1.0.0
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 1.0.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rdoc
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: simplecov
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rspec
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: rr
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ description: A simple parser for Wowza access logs
111
+ email: andre@webwarelab.com
112
+ executables: []
113
+ extensions: []
114
+ extra_rdoc_files: []
115
+ files:
116
+ - lib/vidibus/wowza_log_parser.rb
117
+ - lib/vidibus-wowza_log_parser.rb
118
+ - LICENSE
119
+ - README.md
120
+ - Rakefile
121
+ homepage: https://github.com/vidibus/vidibus-wowza_log_parser
122
+ licenses:
123
+ - MIT
124
+ post_install_message:
125
+ rdoc_options: []
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ segments:
135
+ - 0
136
+ hash: -672349600621671041
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
+ none: false
139
+ requirements:
140
+ - - ! '>='
141
+ - !ruby/object:Gem::Version
142
+ version: 1.3.6
143
+ requirements: []
144
+ rubyforge_project: vidibus-wowza_log_parser
145
+ rubygems_version: 1.8.24
146
+ signing_key:
147
+ specification_version: 3
148
+ summary: A simple parser for Wowza access logs
149
+ test_files: []