mutle-neighborhoodwatch-agent 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 +2 -0
- data/README.markdown +52 -0
- data/bin/neighborhoodwatch-agent +9 -0
- data/lib/neighborhoodwatch-agent.rb +73 -0
- data/neighborhoodwatch-agent.gemspec +37 -0
- metadata +58 -0
data/.gitignore
ADDED
data/README.markdown
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
## What does the NEIGHBORHOODWAT.CH agent do?
|
2
|
+
|
3
|
+
Our agent is a little Ruby program that recieves URL-lists, pings them and reports the results to [NEIGHBORHOODWAT.CH][3]. There we list our user's monitored websites statuses and notify them if something goes wrong.
|
4
|
+
|
5
|
+
## What do I need to run the agent?
|
6
|
+
|
7
|
+
First of all, what you _don't_ need: root privileges. You do need a Unix server running the following software:
|
8
|
+
|
9
|
+
1. Ruby
|
10
|
+
2. Ruby Gems
|
11
|
+
3. Cron
|
12
|
+
4. and a NEIGHBORHOODWAT.CH account
|
13
|
+
|
14
|
+
The agent has so far been tested on Ruby 1.8.6 only but should work on 1.9, too.
|
15
|
+
|
16
|
+
## You got me convinced. How do I install the agent?
|
17
|
+
|
18
|
+
Installing the agent is easy and takes just about 2 minutes.
|
19
|
+
|
20
|
+
_If you're running Ubuntu_, you might have to install Cron. To do this enter the following into your console:
|
21
|
+
|
22
|
+
$ sudo apt-get install cron - on Ubuntu
|
23
|
+
|
24
|
+
Start out by installing the NEIGHBORHOODWAT.CH agent gem.
|
25
|
+
|
26
|
+
$ sudo gem install mutle-neighborhoodwatch-agent --source=http://gems.github.com/
|
27
|
+
|
28
|
+
Before continuing, make sure you have an ID for your agent. He needs this ID to report to the neighborhood watch. To get an ID sign into your NEIGHBORHOODWAT.CH account. Go to your [dashboard][1], click the button "Add an agent" and name him. Now, click "Add agent" and the new agent will apear in the list above. Right beneath the agent name you'll a link "Instructions". Click it and you'll open a modal containing your agent's ID. Copy it.
|
29
|
+
|
30
|
+
Now that you have an agent ID, give it to your agent.
|
31
|
+
|
32
|
+
$ neighborhoodwatch-agent <agent id>
|
33
|
+
|
34
|
+
Your agent is now ready to pick up work and is waiting for you to say the word. Tell him how often to check the servers in his list by configuring Cron.
|
35
|
+
|
36
|
+
$ crontab -e
|
37
|
+
|
38
|
+
This will open your Crontab in a text editor. Now add the following to the bottom of the file:
|
39
|
+
|
40
|
+
*/5 * * * * neighborhoodwatch-agent <agent id>
|
41
|
+
|
42
|
+
What this means is that your agent will check on it's neighborhood every 5 Minutes. Replacing the 5 by 20 will result in a 20 minute interval. Many other intervals are possible. To see how to configure Crontab in more detail, please consult a [Crontab reference][2]. We encourage to use an interval of five minutes, though. _If your agent doesn't report in every 60 minutes we consider him as being down._
|
43
|
+
|
44
|
+
After a couple of minutes, check your NEIGHBORHOODWAT.CH dashboard again, to see whether your agent has successfully picked up his work.
|
45
|
+
|
46
|
+
## Thank you for using and supporting our monitoring network!
|
47
|
+
|
48
|
+
If you have any other issues, please contact us on Twitter [thehoodwatch](https://twitter.com/thehoodwatch) and we'll get back at you.
|
49
|
+
|
50
|
+
[1]: http://neighborhoodwat.ch/dashboard (NEIGHBORHOODWAT.CH dashboard)
|
51
|
+
[2]: http://www.mostlygeek.com/tech-reference/crontab-reference/ (Mostly Geek: Crontab reference)
|
52
|
+
[3]: http://neighborhoodwat.ch/ (Free social website monitoring for you - NEIGHBORHOODWAT.CH)
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'em-http'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module NeighborhoodWatch
|
5
|
+
module Agent
|
6
|
+
|
7
|
+
TIMEOUT = 20
|
8
|
+
SERVER = "beta.neighborhoodwat.ch"
|
9
|
+
|
10
|
+
def self.run
|
11
|
+
EventMachine.run {
|
12
|
+
http = get_list
|
13
|
+
|
14
|
+
http.callback {
|
15
|
+
process_list(http)
|
16
|
+
}
|
17
|
+
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.get_list
|
22
|
+
EventMachine::HttpRequest.new("http://#{SERVER}/ping/#{CLIENT_ID}").get :timeout => TIMEOUT
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.send_response(response)
|
26
|
+
EventMachine::HttpRequest.new("http://#{SERVER}/report/#{CLIENT_ID}").post :timeout => TIMEOUT, :body => {:reports => response}
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.process_list(http)
|
30
|
+
status = http.response_header.status
|
31
|
+
if status == 200
|
32
|
+
sites = JSON.parse(http.response)
|
33
|
+
done if !sites || sites.size == 0
|
34
|
+
|
35
|
+
multi = EventMachine::MultiRequest.new
|
36
|
+
site_requests = []
|
37
|
+
sites.each do |site|
|
38
|
+
req = EventMachine::HttpRequest.new(site['url']).get(:timeout => TIMEOUT)
|
39
|
+
multi.add(req); site_requests << req
|
40
|
+
end
|
41
|
+
multi.callback {
|
42
|
+
status = {}
|
43
|
+
multi.responses[:succeeded].each do |resp|
|
44
|
+
site = sites[site_requests.index(resp)]
|
45
|
+
if resp.response_header.status == 200
|
46
|
+
status[site['id']] = "up"
|
47
|
+
else
|
48
|
+
status[site['id']] = "error-#{resp.response_header.status}"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
multi.responses[:failed].each do |resp|
|
52
|
+
site = sites[site_requests.index(resp)]
|
53
|
+
status[site['id']] = "down"
|
54
|
+
end
|
55
|
+
|
56
|
+
http = send_response(status)
|
57
|
+
http.callback {
|
58
|
+
done
|
59
|
+
}
|
60
|
+
}
|
61
|
+
|
62
|
+
else
|
63
|
+
puts "ERROR: #{http.response}" if status == 403
|
64
|
+
done
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.done
|
69
|
+
EventMachine.stop
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{neighborhoodwatch-agent}
|
5
|
+
s.version = "0.0.1"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Mutwin Kraus"]
|
9
|
+
s.date = %q{2009-08-23}
|
10
|
+
s.email = %q{mutle@redcursor.de}
|
11
|
+
s.executables = ["neighborhoodwatch-agent"]
|
12
|
+
s.extra_rdoc_files = []
|
13
|
+
s.files = [
|
14
|
+
".gitignore",
|
15
|
+
"README.markdown",
|
16
|
+
"bin/neighborhoodwatch-agent",
|
17
|
+
"lib/neighborhoodwatch-agent.rb",
|
18
|
+
"neighborhoodwatch-agent.gemspec"
|
19
|
+
]
|
20
|
+
s.homepage = %q{http://neighborhoodwat.ch/}
|
21
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
22
|
+
s.require_paths = ["lib"]
|
23
|
+
s.rubygems_version = %q{1.3.3}
|
24
|
+
s.summary = %q{Client for the the neighborhoodwat.ch web service}
|
25
|
+
s.test_files = []
|
26
|
+
|
27
|
+
if s.respond_to? :specification_version then
|
28
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
29
|
+
s.specification_version = 3
|
30
|
+
|
31
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
32
|
+
else
|
33
|
+
end
|
34
|
+
else
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
metadata
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mutle-neighborhoodwatch-agent
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mutwin Kraus
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-08-23 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: mutle@redcursor.de
|
18
|
+
executables:
|
19
|
+
- neighborhoodwatch-agent
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- .gitignore
|
26
|
+
- README.markdown
|
27
|
+
- bin/neighborhoodwatch-agent
|
28
|
+
- lib/neighborhoodwatch-agent.rb
|
29
|
+
- neighborhoodwatch-agent.gemspec
|
30
|
+
has_rdoc: false
|
31
|
+
homepage: http://neighborhoodwat.ch/
|
32
|
+
licenses:
|
33
|
+
post_install_message:
|
34
|
+
rdoc_options:
|
35
|
+
- --charset=UTF-8
|
36
|
+
require_paths:
|
37
|
+
- lib
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: "0"
|
43
|
+
version:
|
44
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: "0"
|
49
|
+
version:
|
50
|
+
requirements: []
|
51
|
+
|
52
|
+
rubyforge_project:
|
53
|
+
rubygems_version: 1.3.5
|
54
|
+
signing_key:
|
55
|
+
specification_version: 3
|
56
|
+
summary: Client for the the neighborhoodwat.ch web service
|
57
|
+
test_files: []
|
58
|
+
|