warcorrespondent 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +17 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/bin/warcorrespondent +11 -0
- data/lib/warcorrespondent.rb +47 -0
- data/lib/warcorrespondent/reporter.rb +31 -0
- data/lib/warcorrespondent/uplink.rb +46 -0
- data/test/helper.rb +10 -0
- data/test/test_warcorrespondent.rb +7 -0
- metadata +86 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Stefan Maier
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
= warcorrespondent
|
2
|
+
|
3
|
+
warcorrespondent reports to the warroom.
|
4
|
+
|
5
|
+
== Note on Patches/Pull Requests
|
6
|
+
|
7
|
+
* Fork the project.
|
8
|
+
* Make your feature addition or bug fix.
|
9
|
+
* Add tests for it. This is important so I don't break it in a
|
10
|
+
future version unintentionally.
|
11
|
+
* Commit, do not mess with rakefile, version, or history.
|
12
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
13
|
+
* Send me a pull request. Bonus points for topic branches.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2010 Stefan Maier. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "warcorrespondent"
|
8
|
+
gem.summary = %Q{warcorrespondent reports to the warroom.}
|
9
|
+
gem.description = %Q{warcorrespondent collects data and reports it back to warroom.}
|
10
|
+
gem.email = "stefanmaier@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/tliff/warcorrespondent"
|
12
|
+
gem.authors = ["Stefan Maier"]
|
13
|
+
gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
|
14
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
|
+
end
|
16
|
+
Jeweler::GemcutterTasks.new
|
17
|
+
rescue LoadError
|
18
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'rake/testtask'
|
22
|
+
Rake::TestTask.new(:test) do |test|
|
23
|
+
test.libs << 'lib' << 'test'
|
24
|
+
test.pattern = 'test/**/test_*.rb'
|
25
|
+
test.verbose = true
|
26
|
+
end
|
27
|
+
|
28
|
+
begin
|
29
|
+
require 'rcov/rcovtask'
|
30
|
+
Rcov::RcovTask.new do |test|
|
31
|
+
test.libs << 'test'
|
32
|
+
test.pattern = 'test/**/test_*.rb'
|
33
|
+
test.verbose = true
|
34
|
+
end
|
35
|
+
rescue LoadError
|
36
|
+
task :rcov do
|
37
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
task :test => :check_dependencies
|
42
|
+
|
43
|
+
task :default => :test
|
44
|
+
|
45
|
+
require 'rake/rdoctask'
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
47
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
+
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.title = "warcorrespondent #{version}"
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'warcorrespondent/reporter.rb'
|
2
|
+
require 'warcorrespondent/uplink.rb'
|
3
|
+
require 'json'
|
4
|
+
require 'pp'
|
5
|
+
|
6
|
+
module WarCorrespondent
|
7
|
+
CONFIG_FILE = '/etc/warcorrespondent/warcorrespondent.yml'
|
8
|
+
REPORTERS_DIRECTORIES = '/etc/warcorrespondent/reporters'
|
9
|
+
|
10
|
+
def self.setup
|
11
|
+
@@uplink = Uplink.new
|
12
|
+
begin
|
13
|
+
@@config = YAML.load_file(CONFIG_FILE)
|
14
|
+
@@uplink.url = @@config['url']
|
15
|
+
@@uplink.secret = @@config['secret']
|
16
|
+
rescue
|
17
|
+
puts "Could not load config file #{CONFIG_FILE}"
|
18
|
+
exit
|
19
|
+
end
|
20
|
+
Dir.glob("#{REPORTERS_DIRECTORIES}/*.rb").each do |i|
|
21
|
+
require i
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.run
|
26
|
+
Thread.new do
|
27
|
+
@@uplink.run
|
28
|
+
end
|
29
|
+
@@reporters.each do |reporter|
|
30
|
+
Thread.new do
|
31
|
+
reporter.run
|
32
|
+
end
|
33
|
+
end
|
34
|
+
loop do
|
35
|
+
sleep 1
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.register_reporter(reporter)
|
40
|
+
@@reporters ||= []
|
41
|
+
@@reporters << reporter
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.update(message)
|
45
|
+
@@uplink.add(message)
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module WarCorrespondent
|
2
|
+
class Reporter
|
3
|
+
attr_accessor :timeout
|
4
|
+
attr_accessor :identifier
|
5
|
+
def initialize(args, &block)
|
6
|
+
@timeout = 5
|
7
|
+
[:timeout, :identifier].each do |key|
|
8
|
+
if args[key] && self.respond_to?("#{key}=")
|
9
|
+
self.send("#{key}=",args[key])
|
10
|
+
end
|
11
|
+
end
|
12
|
+
@block = block
|
13
|
+
WarCorrespondent::register_reporter(self)
|
14
|
+
end
|
15
|
+
|
16
|
+
def update
|
17
|
+
WarCorrespondent::update({:payload => @block.call, :identifier => identifier, :timestamp => Time.now.to_i})
|
18
|
+
end
|
19
|
+
|
20
|
+
def run
|
21
|
+
loop do
|
22
|
+
update
|
23
|
+
sleep timeout
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
module WarCorrespondent
|
3
|
+
class Uplink
|
4
|
+
|
5
|
+
attr_accessor :url
|
6
|
+
attr_accessor :secret
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@@messages = []
|
10
|
+
end
|
11
|
+
|
12
|
+
def add(message)
|
13
|
+
@@messages << message
|
14
|
+
end
|
15
|
+
|
16
|
+
def sync
|
17
|
+
return if @@messages.size == 0
|
18
|
+
begin
|
19
|
+
message = @@messages.shift
|
20
|
+
post(encode(message))
|
21
|
+
rescue
|
22
|
+
add(message)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def run
|
27
|
+
loop do
|
28
|
+
sync
|
29
|
+
sleep 1
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def encode(message)
|
36
|
+
message.to_json
|
37
|
+
end
|
38
|
+
|
39
|
+
def post(message)
|
40
|
+
res = Net::HTTP.post_form(URI.parse(url),
|
41
|
+
{'secret'=>secret, 'data'=>message})
|
42
|
+
raise if res.code == 200
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
data/test/helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: warcorrespondent
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Stefan Maier
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-04-11 00:00:00 +02:00
|
18
|
+
default_executable: warcorrespondent
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: thoughtbot-shoulda
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
version: "0"
|
30
|
+
type: :development
|
31
|
+
version_requirements: *id001
|
32
|
+
description: warcorrespondent collects data and reports it back to warroom.
|
33
|
+
email: stefanmaier@gmail.com
|
34
|
+
executables:
|
35
|
+
- warcorrespondent
|
36
|
+
extensions: []
|
37
|
+
|
38
|
+
extra_rdoc_files:
|
39
|
+
- LICENSE
|
40
|
+
- README.rdoc
|
41
|
+
files:
|
42
|
+
- .document
|
43
|
+
- .gitignore
|
44
|
+
- LICENSE
|
45
|
+
- README.rdoc
|
46
|
+
- Rakefile
|
47
|
+
- VERSION
|
48
|
+
- bin/warcorrespondent
|
49
|
+
- lib/warcorrespondent.rb
|
50
|
+
- lib/warcorrespondent/reporter.rb
|
51
|
+
- lib/warcorrespondent/uplink.rb
|
52
|
+
- test/helper.rb
|
53
|
+
- test/test_warcorrespondent.rb
|
54
|
+
has_rdoc: true
|
55
|
+
homepage: http://github.com/tliff/warcorrespondent
|
56
|
+
licenses: []
|
57
|
+
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options:
|
60
|
+
- --charset=UTF-8
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
segments:
|
68
|
+
- 0
|
69
|
+
version: "0"
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
segments:
|
75
|
+
- 0
|
76
|
+
version: "0"
|
77
|
+
requirements: []
|
78
|
+
|
79
|
+
rubyforge_project:
|
80
|
+
rubygems_version: 1.3.6
|
81
|
+
signing_key:
|
82
|
+
specification_version: 3
|
83
|
+
summary: warcorrespondent reports to the warroom.
|
84
|
+
test_files:
|
85
|
+
- test/helper.rb
|
86
|
+
- test/test_warcorrespondent.rb
|