logstomp 0.0.1
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/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +46 -0
- data/Rakefile +2 -0
- data/bin/logstomp +5 -0
- data/lib/logstomp.rb +84 -0
- data/lib/logstomp/version.rb +3 -0
- data/logstomp.gemspec +20 -0
- metadata +87 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Craig R Webster
|
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,46 @@
|
|
1
|
+
# Logstomp
|
2
|
+
|
3
|
+
Broadcast logs via Stomp.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
$ gem install logstomp
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
I had this in mind to be used as a log processor for `svlogd` logs where you've
|
12
|
+
told `svlogd` to use tai64n labels in the logs.
|
13
|
+
|
14
|
+
In `/service/$foo/log/config` add a line like this:
|
15
|
+
|
16
|
+
!/usr/bin/logstomp log_tag stomp://yourmq.com:61613/topic/logs.service_name
|
17
|
+
|
18
|
+
Whenever `svlogd` rotates the logs you'll now get an event in the following
|
19
|
+
format on `/topic/logs.service_name`:
|
20
|
+
|
21
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
22
|
+
<event>
|
23
|
+
<time tai64n="@4000000050a17673000001f4" iso8601="2012-11-12T22:21:29Z"/>
|
24
|
+
<meta>
|
25
|
+
<tag>
|
26
|
+
<![CDATA[log_tag]]>
|
27
|
+
</tag>
|
28
|
+
<hostname>
|
29
|
+
<![CDATA[zuu.local]]>
|
30
|
+
</hostname>
|
31
|
+
<batch_id>zuu.local-l8s-mdec37-55y3hhr9</batch_id>
|
32
|
+
</meta>
|
33
|
+
<entry>
|
34
|
+
<text>
|
35
|
+
<![CDATA[The logged line will appear here]]>
|
36
|
+
</text>
|
37
|
+
</entry>
|
38
|
+
</event>
|
39
|
+
|
40
|
+
## Contributing
|
41
|
+
|
42
|
+
1. Fork it
|
43
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
44
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
45
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
46
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/bin/logstomp
ADDED
data/lib/logstomp.rb
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
require "uri"
|
2
|
+
require "tai64"
|
3
|
+
require "stomp"
|
4
|
+
require "logstomp/version"
|
5
|
+
|
6
|
+
module Logstomp
|
7
|
+
class Command
|
8
|
+
attr_accessor :argv
|
9
|
+
private :argv=, :argv
|
10
|
+
|
11
|
+
attr_accessor :start_at
|
12
|
+
private :start_at=, :start_at
|
13
|
+
|
14
|
+
def initialize argv
|
15
|
+
self.argv = argv
|
16
|
+
self.start_at = Time.now
|
17
|
+
end
|
18
|
+
|
19
|
+
def connection_string
|
20
|
+
return "stomp://127.0.0.1:61613/topic/logs.#{tag}" unless argv[1]
|
21
|
+
argv[1]
|
22
|
+
end
|
23
|
+
|
24
|
+
def uri
|
25
|
+
URI.parse connection_string
|
26
|
+
end
|
27
|
+
|
28
|
+
def destination
|
29
|
+
uri.path
|
30
|
+
end
|
31
|
+
|
32
|
+
def tag
|
33
|
+
argv[0] || "default"
|
34
|
+
end
|
35
|
+
|
36
|
+
def hostname
|
37
|
+
@hostname ||= %x[hostname].strip.split(/\./)[0]
|
38
|
+
end
|
39
|
+
|
40
|
+
def client
|
41
|
+
@client ||= Stomp::Client.new connection_string
|
42
|
+
end
|
43
|
+
|
44
|
+
def broadcast event
|
45
|
+
puts [ uri.to_s, event.to_s ].join("\n") if $DEBUG
|
46
|
+
client.publish destination, event
|
47
|
+
end
|
48
|
+
|
49
|
+
def disconnect
|
50
|
+
client.close
|
51
|
+
end
|
52
|
+
|
53
|
+
def batch_id
|
54
|
+
@batch_id ||= [
|
55
|
+
"h#{hostname}",
|
56
|
+
"p#{Process.pid.to_s(36)}",
|
57
|
+
"t#{Time.now.to_i.to_s(36)}",
|
58
|
+
"r#{rand(1_000_000_000_000).to_s(36)}"
|
59
|
+
].join('.')
|
60
|
+
end
|
61
|
+
|
62
|
+
def execute
|
63
|
+
m = %Q(<?xml version="1.0" encoding="UTF-8"?>
|
64
|
+
<event>
|
65
|
+
<meta>
|
66
|
+
<tag>%s</tag>
|
67
|
+
<hostname>%s</hostname>
|
68
|
+
<batch_id>%s</batch_id>
|
69
|
+
</meta>
|
70
|
+
<entry>
|
71
|
+
<time tai64n="%s"/>
|
72
|
+
<text><![CDATA[%s]]></text>
|
73
|
+
</entry>
|
74
|
+
</event>)
|
75
|
+
|
76
|
+
STDIN.each_line do |l|
|
77
|
+
label, line = l.split(/ /, 2)
|
78
|
+
line.strip!
|
79
|
+
broadcast m % [ label, tag, hostname, batch_id, line ]
|
80
|
+
end
|
81
|
+
disconnect
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
data/logstomp.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/logstomp/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Craig R Webster"]
|
6
|
+
gem.email = ["craig@barkingiguana.com"]
|
7
|
+
gem.description = %q{svlogd processor to send logs to Stomp destination}
|
8
|
+
gem.summary = gem.description
|
9
|
+
gem.homepage = ""
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "logstomp"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Logstomp::VERSION
|
17
|
+
|
18
|
+
gem.add_runtime_dependency 'tai64', '~> 0.0.3'
|
19
|
+
gem.add_runtime_dependency 'stomp'
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: logstomp
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Craig R Webster
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-11-12 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: tai64
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.0.3
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.0.3
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: stomp
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
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
|
+
description: svlogd processor to send logs to Stomp destination
|
47
|
+
email:
|
48
|
+
- craig@barkingiguana.com
|
49
|
+
executables:
|
50
|
+
- logstomp
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- .gitignore
|
55
|
+
- Gemfile
|
56
|
+
- LICENSE
|
57
|
+
- README.md
|
58
|
+
- Rakefile
|
59
|
+
- bin/logstomp
|
60
|
+
- lib/logstomp.rb
|
61
|
+
- lib/logstomp/version.rb
|
62
|
+
- logstomp.gemspec
|
63
|
+
homepage: ''
|
64
|
+
licenses: []
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options: []
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ! '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
none: false
|
77
|
+
requirements:
|
78
|
+
- - ! '>='
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
requirements: []
|
82
|
+
rubyforge_project:
|
83
|
+
rubygems_version: 1.8.24
|
84
|
+
signing_key:
|
85
|
+
specification_version: 3
|
86
|
+
summary: svlogd processor to send logs to Stomp destination
|
87
|
+
test_files: []
|