netatlas-poller 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +23 -0
- data/Gemfile.lock +58 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +50 -0
- data/VERSION +1 -0
- data/bin/poller.rb +15 -0
- data/bin/poller_ctl +5 -0
- data/lib/netatlas/config.rb +20 -0
- data/lib/netatlas/plugin/base.rb +52 -0
- data/lib/netatlas/plugin/http.rb +36 -0
- data/lib/netatlas/plugin/nagios.rb +67 -0
- data/lib/netatlas/plugin/snmp.rb +34 -0
- data/lib/netatlas/poller.rb +86 -0
- data/lib/netatlas/resource/base.rb +11 -0
- data/lib/netatlas/resource/data_source.rb +14 -0
- data/lib/netatlas/result.rb +11 -0
- data/netatlas-poller.gemspec +94 -0
- data/spec/poller_spec.rb +47 -0
- data/spec/spec_helper.rb +15 -0
- metadata +224 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
|
9
|
+
gem 'eventmachine'
|
10
|
+
gem 'em-synchrony', :require => ['em-synchrony', 'em-synchrony/em-http' ]
|
11
|
+
gem 'activeresource'
|
12
|
+
gem 'amqp'
|
13
|
+
gem 'smi-ffi', :git => 'git://github.com/mixtli/smi-ffi.git'
|
14
|
+
|
15
|
+
group :development do
|
16
|
+
#gem 'spork'
|
17
|
+
#gem 'em-spec', :git => 'https://github.com/mloughran/em-spec.git', :branch =>'rspec2'
|
18
|
+
gem 'amqp-spec'
|
19
|
+
gem "rspec", "~> 2.1.0"
|
20
|
+
gem "bundler", "~> 1.0.0"
|
21
|
+
gem "jeweler", "~> 1.5.1"
|
22
|
+
gem "rcov", ">= 0"
|
23
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
GIT
|
2
|
+
remote: git://github.com/mixtli/smi-ffi.git
|
3
|
+
revision: faa6d4284aed2488d400f9dfd60b47be88e50082
|
4
|
+
specs:
|
5
|
+
smi-ffi (0.0.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: http://rubygems.org/
|
9
|
+
specs:
|
10
|
+
activemodel (3.0.3)
|
11
|
+
activesupport (= 3.0.3)
|
12
|
+
builder (~> 2.1.2)
|
13
|
+
i18n (~> 0.4)
|
14
|
+
activeresource (3.0.3)
|
15
|
+
activemodel (= 3.0.3)
|
16
|
+
activesupport (= 3.0.3)
|
17
|
+
activesupport (3.0.3)
|
18
|
+
amqp (0.6.7)
|
19
|
+
eventmachine (>= 0.12.4)
|
20
|
+
amqp-spec (0.3.4)
|
21
|
+
amqp (~> 0.6.7)
|
22
|
+
bundler (>= 1.0.0)
|
23
|
+
builder (2.1.2)
|
24
|
+
diff-lcs (1.1.2)
|
25
|
+
em-synchrony (0.2.0)
|
26
|
+
eventmachine (>= 0.12.9)
|
27
|
+
eventmachine (0.12.10)
|
28
|
+
git (1.2.5)
|
29
|
+
i18n (0.5.0)
|
30
|
+
jeweler (1.5.1)
|
31
|
+
bundler (~> 1.0.0)
|
32
|
+
git (>= 1.2.5)
|
33
|
+
rake
|
34
|
+
rake (0.8.7)
|
35
|
+
rcov (0.9.9)
|
36
|
+
rspec (2.1.0)
|
37
|
+
rspec-core (~> 2.1.0)
|
38
|
+
rspec-expectations (~> 2.1.0)
|
39
|
+
rspec-mocks (~> 2.1.0)
|
40
|
+
rspec-core (2.1.0)
|
41
|
+
rspec-expectations (2.1.0)
|
42
|
+
diff-lcs (~> 1.1.2)
|
43
|
+
rspec-mocks (2.1.0)
|
44
|
+
|
45
|
+
PLATFORMS
|
46
|
+
ruby
|
47
|
+
|
48
|
+
DEPENDENCIES
|
49
|
+
activeresource
|
50
|
+
amqp
|
51
|
+
amqp-spec
|
52
|
+
bundler (~> 1.0.0)
|
53
|
+
em-synchrony
|
54
|
+
eventmachine
|
55
|
+
jeweler (~> 1.5.1)
|
56
|
+
rcov
|
57
|
+
rspec (~> 2.1.0)
|
58
|
+
smi-ffi!
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Ron McClain
|
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,19 @@
|
|
1
|
+
= netatlas-poller
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Contributing to netatlas-poller
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
9
|
+
* Fork the project
|
10
|
+
* Start a feature/bugfix branch
|
11
|
+
* Commit and push until you are happy with your contribution
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2010 Ron McClain. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'rake'
|
11
|
+
|
12
|
+
require 'jeweler'
|
13
|
+
Jeweler::Tasks.new do |gem|
|
14
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
15
|
+
gem.name = "netatlas-poller"
|
16
|
+
gem.homepage = "http://github.com/mixtli/netatlas-poller"
|
17
|
+
gem.license = "MIT"
|
18
|
+
gem.summary = %Q{Netatlas poller}
|
19
|
+
gem.description = %Q{NetAtlas Poller}
|
20
|
+
gem.email = "ronmcclain75@gmail.com"
|
21
|
+
gem.authors = ["Ron McClain"]
|
22
|
+
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
23
|
+
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
24
|
+
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
25
|
+
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
26
|
+
end
|
27
|
+
Jeweler::RubygemsDotOrgTasks.new
|
28
|
+
|
29
|
+
require 'rspec/core'
|
30
|
+
require 'rspec/core/rake_task'
|
31
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
32
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
33
|
+
end
|
34
|
+
|
35
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
36
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
37
|
+
spec.rcov = true
|
38
|
+
end
|
39
|
+
|
40
|
+
task :default => :spec
|
41
|
+
|
42
|
+
require 'rake/rdoctask'
|
43
|
+
Rake::RDocTask.new do |rdoc|
|
44
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
45
|
+
|
46
|
+
rdoc.rdoc_dir = 'rdoc'
|
47
|
+
rdoc.title = "netatlas-poller #{version}"
|
48
|
+
rdoc.rdoc_files.include('README*')
|
49
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
50
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.0
|
data/bin/poller.rb
ADDED
data/bin/poller_ctl
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
NETATLAS_CONFIG_DIR = ENV['NETATLAS_CONFIG_DIR'] || "/etc/netatlas"
|
3
|
+
NETATLAS_ENVIRONMENT = ENV['NETATLAS_ENVIRONMENT'] || "development"
|
4
|
+
CONFIG = YAML.load(File.open(NETATLAS_CONFIG_DIR + "/netatlas.yml"))[NETATLAS_ENVIRONMENT]
|
5
|
+
NETATLAS_LOG_DIR = ENV['NETATLAS_LOG_DIR'] || ENV['HOME'] + "/.log"
|
6
|
+
|
7
|
+
puts CONFIG.inspect
|
8
|
+
|
9
|
+
$:.unshift File.dirname(__FILE__) + "/../lib"
|
10
|
+
|
11
|
+
require 'eventmachine'
|
12
|
+
require 'em/queue'
|
13
|
+
require 'mq'
|
14
|
+
require 'netatlas/resource/base'
|
15
|
+
require 'netatlas/resource/data_source'
|
16
|
+
require 'netatlas/result'
|
17
|
+
|
18
|
+
require 'netatlas/plugin/base'
|
19
|
+
require 'netatlas/plugin/nagios'
|
20
|
+
require 'netatlas/plugin/http'
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'active_support/core_ext/class/inheritable_attributes'
|
2
|
+
|
3
|
+
|
4
|
+
module NetAtlas::Plugin
|
5
|
+
class Base
|
6
|
+
SEVERITIES = [:ok, :warning, :critical, :unknown, :error]
|
7
|
+
|
8
|
+
class_inheritable_accessor :plugin_args
|
9
|
+
self.plugin_args = {
|
10
|
+
:critical => {:type => Integer, :default => 10},
|
11
|
+
:warning => {:type => Integer, :default => 5}
|
12
|
+
}
|
13
|
+
|
14
|
+
class << self
|
15
|
+
# voodoo
|
16
|
+
def plugin_arguments &block
|
17
|
+
def (self.plugin_args).method_missing(meth, *args)
|
18
|
+
meth = meth.to_s.gsub("=",'').to_sym
|
19
|
+
return self[meth] unless args
|
20
|
+
arg = args.first
|
21
|
+
self[meth] = if arg.kind_of? Class
|
22
|
+
case arg.to_s
|
23
|
+
when 'Integer', 'String'
|
24
|
+
{:type => arg, :default => nil}
|
25
|
+
end
|
26
|
+
else
|
27
|
+
case arg
|
28
|
+
when true, false
|
29
|
+
{:type => 'Boolean', :default => arg}
|
30
|
+
when Integer, String
|
31
|
+
{:type => arg.class, :default => arg}
|
32
|
+
when Array
|
33
|
+
{:type => arg.class, :options => arg}
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
self.plugin_args.instance_eval(&block)
|
39
|
+
end
|
40
|
+
|
41
|
+
def arguments
|
42
|
+
self.plugin_args
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
def poll
|
48
|
+
raise "Must override this method"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module NetAtlas
|
2
|
+
module Plugin
|
3
|
+
class HTTP < Nagios
|
4
|
+
|
5
|
+
def self.check_script
|
6
|
+
"check_http"
|
7
|
+
end
|
8
|
+
|
9
|
+
plugin_arguments do
|
10
|
+
port 80
|
11
|
+
use_ipv4 true
|
12
|
+
use_ipv6 false
|
13
|
+
ssl false
|
14
|
+
certificate Integer
|
15
|
+
expect String
|
16
|
+
string String
|
17
|
+
url String
|
18
|
+
post String
|
19
|
+
method = ['HEAD', 'GET', 'POST', 'PUT', 'TRACE', 'OPTIONS', 'DELETE']
|
20
|
+
no_body false
|
21
|
+
max_age Integer
|
22
|
+
content_type String
|
23
|
+
linespan false
|
24
|
+
regex String
|
25
|
+
erigi String
|
26
|
+
invert_regex false
|
27
|
+
authorization String
|
28
|
+
useragent String
|
29
|
+
header String
|
30
|
+
onredirect ['ok', 'warning', 'critical', 'follow', 'sticky', 'stickyport']
|
31
|
+
pagesize String
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
NAGIOS_CONFIG = YAML.load(File.open(NETATLAS_CONFIG_DIR + "/nagios.yml"))[NETATLAS_ENVIRONMENT]
|
2
|
+
|
3
|
+
require 'netatlas/plugin/base'
|
4
|
+
module NetAtlas::Plugin
|
5
|
+
class Nagios < Base
|
6
|
+
plugin_arguments do
|
7
|
+
critical 10
|
8
|
+
warning 5
|
9
|
+
arguments String
|
10
|
+
end
|
11
|
+
def check_scripts
|
12
|
+
files = Dir.glob("#{NAGIOS_CONFIG['plugin_dir']}/*").collect {|f| f.split("/").last}.sort
|
13
|
+
LOGGER.debug "files = #{files}"
|
14
|
+
files
|
15
|
+
end
|
16
|
+
def poll(data_source, &block)
|
17
|
+
cmd = "#{NAGIOS_CONFIG['plugin_dir']}/#{self.class.check_script || data_source.arguments.check_script} "
|
18
|
+
cmd += build_args(data_source)
|
19
|
+
puts "sending #{cmd}"
|
20
|
+
EM.system(cmd) { |output, status|
|
21
|
+
value = get_value(output, status)
|
22
|
+
puts "in nagios callback"
|
23
|
+
puts "got output = #{output}, status = #{status}"
|
24
|
+
block.call SEVERITIES[status.exitstatus], value
|
25
|
+
}
|
26
|
+
end
|
27
|
+
def cmd_args(data_source)
|
28
|
+
args = []
|
29
|
+
args << "-H #{data_source.interface.ip_address}"
|
30
|
+
args << "-c #{data_source.arguments.critical}" if data_source.arguments.critical.to_f > 0
|
31
|
+
args << "-w #{data_source.arguments.warning}" if data_source.arguments.warning.to_f > 0
|
32
|
+
args << "-p #{data_source.arguments.port}" if data_source.arguments.port.to_i > 0
|
33
|
+
args << data_source.arguments.arguments
|
34
|
+
args.join(" ")
|
35
|
+
end
|
36
|
+
def build_args(data_source)
|
37
|
+
args = ["-H #{data_source.ip_address}"]
|
38
|
+
args << ["-p #{data_source.port}"] if data_source.port
|
39
|
+
arguments = data_source.arguments ? data_source.arguments.attributes : {}
|
40
|
+
arguments.each do |k, v|
|
41
|
+
key = "--" + k.to_s.gsub("_","-")
|
42
|
+
|
43
|
+
if v == true
|
44
|
+
args << key
|
45
|
+
else
|
46
|
+
args << "#{key} #{v}" if v
|
47
|
+
end
|
48
|
+
end
|
49
|
+
args.join(" ")
|
50
|
+
end
|
51
|
+
|
52
|
+
def get_value(output, status)
|
53
|
+
puts "parsing nagios data"
|
54
|
+
puts output
|
55
|
+
output, perfdata = output.split('|')
|
56
|
+
return nil unless perfdata
|
57
|
+
puts "output now #{output}, perfdata = #{perfdata}"
|
58
|
+
metrics = {}
|
59
|
+
stuff = perfdata.scan(/(\w+)=([\d|\.]+)/)
|
60
|
+
stuff.each {|i| metrics[i[0]] = i[1]}
|
61
|
+
metrics['time']
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module NetAtlas
|
2
|
+
module Plugin
|
3
|
+
class SNMP < Base
|
4
|
+
@@sessions = []
|
5
|
+
plugin_arguments do
|
6
|
+
oid String
|
7
|
+
community "public"
|
8
|
+
version "1"
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize(*args)
|
12
|
+
@sessions = {}
|
13
|
+
super *args
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
def poll(data_source, &block)
|
18
|
+
arguments = data_source.arguments ? data_source.arguments.attributes : {:community => "public", :version => "1"}
|
19
|
+
session = @@sessions[data_source.ip_address] ||= SNMP4EM::SNMPv1.new(:host => data_source.ip_address, :community => arguments[:community] || "public", :version => arguments[:version])
|
20
|
+
oid = Smi.translate(data_source.arguments.oid)
|
21
|
+
request = session.get([oid])
|
22
|
+
request.callback { |response|
|
23
|
+
block.call :ok, response[oid]
|
24
|
+
}
|
25
|
+
request.errback {|error|
|
26
|
+
puts "SNMP ERROR: #{error.inspect}"
|
27
|
+
puts data_source.attributes.inspect
|
28
|
+
block.call :error, nil
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
|
2
|
+
module NetAtlas
|
3
|
+
class Poller < Resource::Base
|
4
|
+
|
5
|
+
attr_reader :queue
|
6
|
+
def initialize(*args)
|
7
|
+
@data_sources = {}
|
8
|
+
@queue = EventMachine::Queue.new
|
9
|
+
@queued = {}
|
10
|
+
super
|
11
|
+
end
|
12
|
+
|
13
|
+
def collector_queue
|
14
|
+
@collector_queue ||= MQ.queue("collector")
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
def configure
|
19
|
+
puts "getting data sources"
|
20
|
+
data_sources
|
21
|
+
puts "got data sources"
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
def run
|
26
|
+
#EM.synchrony do
|
27
|
+
EventMachine.add_periodic_timer(1) {
|
28
|
+
do_scheduler
|
29
|
+
}
|
30
|
+
|
31
|
+
loop do
|
32
|
+
next_poll
|
33
|
+
end
|
34
|
+
#end
|
35
|
+
end
|
36
|
+
|
37
|
+
def do_scheduler
|
38
|
+
data_sources.each do |ds|
|
39
|
+
puts "scheduling #{ds}"
|
40
|
+
last_polled = ds.last_result.timestamp rescue Time.at(0)
|
41
|
+
interval = ds.step_interval || 60
|
42
|
+
if (last_polled + interval) < Time.now
|
43
|
+
schedule(ds)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def schedule(ds)
|
49
|
+
if !@queued[ds.id]
|
50
|
+
@queue.push(ds)
|
51
|
+
@queued[ds.id] = true
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
def next_poll
|
57
|
+
@queue.pop do |ds|
|
58
|
+
poll(ds)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def poll(ds)
|
63
|
+
puts "in poll"
|
64
|
+
plugin = ds.get_plugin
|
65
|
+
plugin.poll(ds) do |status, value|
|
66
|
+
result = NetAtlas::Result.new(:timestamp => Time.now, :data_source => ds, :status => status, :value => value)
|
67
|
+
puts "got result #{result.inspect}"
|
68
|
+
collector_queue.publish(result.to_json)
|
69
|
+
puts "done poll"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
def data_sources
|
76
|
+
return @data_sources if @data_sources
|
77
|
+
puts "poller_id = #{id}"
|
78
|
+
Resource::DataSource.find(:all, :params =>{:poller_id => id} ).each do |ds|
|
79
|
+
@data_sources[ds.id] = ds
|
80
|
+
end
|
81
|
+
|
82
|
+
puts @data_sources.inspect
|
83
|
+
@data_sources
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'netatlas/resource/base'
|
2
|
+
module NetAtlas
|
3
|
+
class Resource::DataSource < Resource::Base
|
4
|
+
self.prefix = "/pollers/:poller_id/"
|
5
|
+
attr_accessor :last_result
|
6
|
+
|
7
|
+
def get_plugin
|
8
|
+
puts "plugin = #{plugin}"
|
9
|
+
@real_plugin ||= eval "NetAtlas::Plugin::#{plugin}.new"
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{netatlas-poller}
|
8
|
+
s.version = "0.0.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Ron McClain"]
|
12
|
+
s.date = %q{2010-12-29}
|
13
|
+
s.description = %q{NetAtlas Poller}
|
14
|
+
s.email = %q{ronmcclain75@gmail.com}
|
15
|
+
s.executables = ["poller.rb", "poller_ctl"]
|
16
|
+
s.extra_rdoc_files = [
|
17
|
+
"LICENSE.txt",
|
18
|
+
"README.rdoc"
|
19
|
+
]
|
20
|
+
s.files = [
|
21
|
+
".document",
|
22
|
+
".rspec",
|
23
|
+
"Gemfile",
|
24
|
+
"Gemfile.lock",
|
25
|
+
"LICENSE.txt",
|
26
|
+
"README.rdoc",
|
27
|
+
"Rakefile",
|
28
|
+
"VERSION",
|
29
|
+
"bin/poller.rb",
|
30
|
+
"bin/poller_ctl",
|
31
|
+
"lib/netatlas/config.rb",
|
32
|
+
"lib/netatlas/plugin/base.rb",
|
33
|
+
"lib/netatlas/plugin/http.rb",
|
34
|
+
"lib/netatlas/plugin/nagios.rb",
|
35
|
+
"lib/netatlas/plugin/snmp.rb",
|
36
|
+
"lib/netatlas/poller.rb",
|
37
|
+
"lib/netatlas/resource/base.rb",
|
38
|
+
"lib/netatlas/resource/data_source.rb",
|
39
|
+
"lib/netatlas/result.rb",
|
40
|
+
"netatlas-poller.gemspec",
|
41
|
+
"spec/poller_spec.rb",
|
42
|
+
"spec/spec_helper.rb"
|
43
|
+
]
|
44
|
+
s.homepage = %q{http://github.com/mixtli/netatlas-poller}
|
45
|
+
s.licenses = ["MIT"]
|
46
|
+
s.require_paths = ["lib"]
|
47
|
+
s.rubygems_version = %q{1.3.7}
|
48
|
+
s.summary = %q{Netatlas poller}
|
49
|
+
s.test_files = [
|
50
|
+
"spec/poller_spec.rb",
|
51
|
+
"spec/spec_helper.rb"
|
52
|
+
]
|
53
|
+
|
54
|
+
if s.respond_to? :specification_version then
|
55
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
56
|
+
s.specification_version = 3
|
57
|
+
|
58
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
59
|
+
s.add_runtime_dependency(%q<eventmachine>, [">= 0"])
|
60
|
+
s.add_runtime_dependency(%q<em-synchrony>, [">= 0"])
|
61
|
+
s.add_runtime_dependency(%q<activeresource>, [">= 0"])
|
62
|
+
s.add_runtime_dependency(%q<amqp>, [">= 0"])
|
63
|
+
s.add_runtime_dependency(%q<smi-ffi>, [">= 0"])
|
64
|
+
s.add_development_dependency(%q<amqp-spec>, [">= 0"])
|
65
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.1.0"])
|
66
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
67
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.1"])
|
68
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
69
|
+
else
|
70
|
+
s.add_dependency(%q<eventmachine>, [">= 0"])
|
71
|
+
s.add_dependency(%q<em-synchrony>, [">= 0"])
|
72
|
+
s.add_dependency(%q<activeresource>, [">= 0"])
|
73
|
+
s.add_dependency(%q<amqp>, [">= 0"])
|
74
|
+
s.add_dependency(%q<smi-ffi>, [">= 0"])
|
75
|
+
s.add_dependency(%q<amqp-spec>, [">= 0"])
|
76
|
+
s.add_dependency(%q<rspec>, ["~> 2.1.0"])
|
77
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
78
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
|
79
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
80
|
+
end
|
81
|
+
else
|
82
|
+
s.add_dependency(%q<eventmachine>, [">= 0"])
|
83
|
+
s.add_dependency(%q<em-synchrony>, [">= 0"])
|
84
|
+
s.add_dependency(%q<activeresource>, [">= 0"])
|
85
|
+
s.add_dependency(%q<amqp>, [">= 0"])
|
86
|
+
s.add_dependency(%q<smi-ffi>, [">= 0"])
|
87
|
+
s.add_dependency(%q<amqp-spec>, [">= 0"])
|
88
|
+
s.add_dependency(%q<rspec>, ["~> 2.1.0"])
|
89
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
90
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
|
91
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
data/spec/poller_spec.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
require 'amqp'
|
3
|
+
require "amqp-spec/rspec"
|
4
|
+
|
5
|
+
describe NetAtlas::Poller do
|
6
|
+
#include EM::SpecHelper
|
7
|
+
include AMQP::SpecHelper
|
8
|
+
default_options = {:host => "localhost", :user => "guest", :pass => "guest", :vhost => "netatlas"}
|
9
|
+
default_timeout = 1
|
10
|
+
it "should schedule data sources" do
|
11
|
+
amqp do
|
12
|
+
poller = NetAtlas::Poller.new
|
13
|
+
poller.should_receive(:data_sources).twice.and_return(make_data_sources)
|
14
|
+
poller.do_scheduler
|
15
|
+
# sleep 1
|
16
|
+
poller.queue.size.should == 2
|
17
|
+
poller.do_scheduler
|
18
|
+
poller.queue.size.should == 2
|
19
|
+
done
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should poll data sources" do
|
24
|
+
amqp do
|
25
|
+
poller = NetAtlas::Poller.new(:id => 1)
|
26
|
+
poller.should_receive(:data_sources).and_return(make_data_sources)
|
27
|
+
poller.do_scheduler
|
28
|
+
#poller.should_receive(:poll)
|
29
|
+
poller.collector_queue.should_receive(:publish)
|
30
|
+
poller.next_poll
|
31
|
+
EM.add_timer(3) do
|
32
|
+
done
|
33
|
+
end
|
34
|
+
#res1.value.should be_gt(1)
|
35
|
+
#done
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
def make_data_sources
|
42
|
+
[
|
43
|
+
{:id => 1, :ip_address => '127.0.0.1', :plugin => 'HTTP', :step_interval => 10, :port => 80, :arguments => {}},
|
44
|
+
{:id => 2, :ip_address => '127.0.0.1', :plugin => 'SNMP', :step_interval => 10}
|
45
|
+
].map {|d| NetAtlas::Resource::DataSource.new(d)}
|
46
|
+
end
|
47
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
#require 'em-spec/rspec'
|
5
|
+
|
6
|
+
require 'netatlas/config'
|
7
|
+
require 'netatlas/poller'
|
8
|
+
|
9
|
+
# Requires supporting files with custom matchers and macros, etc,
|
10
|
+
# in ./support/ and its subdirectories.
|
11
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
12
|
+
|
13
|
+
RSpec.configure do |config|
|
14
|
+
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,224 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: netatlas-poller
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
version: 0.0.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Ron McClain
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-12-29 00:00:00 -06:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: eventmachine
|
22
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
version: "0"
|
30
|
+
type: :runtime
|
31
|
+
prerelease: false
|
32
|
+
version_requirements: *id001
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: em-synchrony
|
35
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
36
|
+
none: false
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
segments:
|
41
|
+
- 0
|
42
|
+
version: "0"
|
43
|
+
type: :runtime
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: *id002
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: activeresource
|
48
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
segments:
|
54
|
+
- 0
|
55
|
+
version: "0"
|
56
|
+
type: :runtime
|
57
|
+
prerelease: false
|
58
|
+
version_requirements: *id003
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: amqp
|
61
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
segments:
|
67
|
+
- 0
|
68
|
+
version: "0"
|
69
|
+
type: :runtime
|
70
|
+
prerelease: false
|
71
|
+
version_requirements: *id004
|
72
|
+
- !ruby/object:Gem::Dependency
|
73
|
+
name: smi-ffi
|
74
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
segments:
|
80
|
+
- 0
|
81
|
+
version: "0"
|
82
|
+
type: :runtime
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: *id005
|
85
|
+
- !ruby/object:Gem::Dependency
|
86
|
+
name: amqp-spec
|
87
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
88
|
+
none: false
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
segments:
|
93
|
+
- 0
|
94
|
+
version: "0"
|
95
|
+
type: :development
|
96
|
+
prerelease: false
|
97
|
+
version_requirements: *id006
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: rspec
|
100
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
101
|
+
none: false
|
102
|
+
requirements:
|
103
|
+
- - ~>
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
segments:
|
106
|
+
- 2
|
107
|
+
- 1
|
108
|
+
- 0
|
109
|
+
version: 2.1.0
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: *id007
|
113
|
+
- !ruby/object:Gem::Dependency
|
114
|
+
name: bundler
|
115
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
116
|
+
none: false
|
117
|
+
requirements:
|
118
|
+
- - ~>
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
segments:
|
121
|
+
- 1
|
122
|
+
- 0
|
123
|
+
- 0
|
124
|
+
version: 1.0.0
|
125
|
+
type: :development
|
126
|
+
prerelease: false
|
127
|
+
version_requirements: *id008
|
128
|
+
- !ruby/object:Gem::Dependency
|
129
|
+
name: jeweler
|
130
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
131
|
+
none: false
|
132
|
+
requirements:
|
133
|
+
- - ~>
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
segments:
|
136
|
+
- 1
|
137
|
+
- 5
|
138
|
+
- 1
|
139
|
+
version: 1.5.1
|
140
|
+
type: :development
|
141
|
+
prerelease: false
|
142
|
+
version_requirements: *id009
|
143
|
+
- !ruby/object:Gem::Dependency
|
144
|
+
name: rcov
|
145
|
+
requirement: &id010 !ruby/object:Gem::Requirement
|
146
|
+
none: false
|
147
|
+
requirements:
|
148
|
+
- - ">="
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
segments:
|
151
|
+
- 0
|
152
|
+
version: "0"
|
153
|
+
type: :development
|
154
|
+
prerelease: false
|
155
|
+
version_requirements: *id010
|
156
|
+
description: NetAtlas Poller
|
157
|
+
email: ronmcclain75@gmail.com
|
158
|
+
executables:
|
159
|
+
- poller.rb
|
160
|
+
- poller_ctl
|
161
|
+
extensions: []
|
162
|
+
|
163
|
+
extra_rdoc_files:
|
164
|
+
- LICENSE.txt
|
165
|
+
- README.rdoc
|
166
|
+
files:
|
167
|
+
- .document
|
168
|
+
- .rspec
|
169
|
+
- Gemfile
|
170
|
+
- Gemfile.lock
|
171
|
+
- LICENSE.txt
|
172
|
+
- README.rdoc
|
173
|
+
- Rakefile
|
174
|
+
- VERSION
|
175
|
+
- bin/poller.rb
|
176
|
+
- bin/poller_ctl
|
177
|
+
- lib/netatlas/config.rb
|
178
|
+
- lib/netatlas/plugin/base.rb
|
179
|
+
- lib/netatlas/plugin/http.rb
|
180
|
+
- lib/netatlas/plugin/nagios.rb
|
181
|
+
- lib/netatlas/plugin/snmp.rb
|
182
|
+
- lib/netatlas/poller.rb
|
183
|
+
- lib/netatlas/resource/base.rb
|
184
|
+
- lib/netatlas/resource/data_source.rb
|
185
|
+
- lib/netatlas/result.rb
|
186
|
+
- netatlas-poller.gemspec
|
187
|
+
- spec/poller_spec.rb
|
188
|
+
- spec/spec_helper.rb
|
189
|
+
has_rdoc: true
|
190
|
+
homepage: http://github.com/mixtli/netatlas-poller
|
191
|
+
licenses:
|
192
|
+
- MIT
|
193
|
+
post_install_message:
|
194
|
+
rdoc_options: []
|
195
|
+
|
196
|
+
require_paths:
|
197
|
+
- lib
|
198
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
199
|
+
none: false
|
200
|
+
requirements:
|
201
|
+
- - ">="
|
202
|
+
- !ruby/object:Gem::Version
|
203
|
+
hash: -3775198721526403474
|
204
|
+
segments:
|
205
|
+
- 0
|
206
|
+
version: "0"
|
207
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
208
|
+
none: false
|
209
|
+
requirements:
|
210
|
+
- - ">="
|
211
|
+
- !ruby/object:Gem::Version
|
212
|
+
segments:
|
213
|
+
- 0
|
214
|
+
version: "0"
|
215
|
+
requirements: []
|
216
|
+
|
217
|
+
rubyforge_project:
|
218
|
+
rubygems_version: 1.3.7
|
219
|
+
signing_key:
|
220
|
+
specification_version: 3
|
221
|
+
summary: Netatlas poller
|
222
|
+
test_files:
|
223
|
+
- spec/poller_spec.rb
|
224
|
+
- spec/spec_helper.rb
|