ropian 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/LICENSE +20 -0
- data/README.rdoc +7 -0
- data/Rakefile +60 -0
- data/VERSION.yml +4 -0
- data/lib/ropian.rb +33 -0
- data/lib/ropian/control/apc.rb +12 -0
- data/lib/ropian/control/generic.rb +35 -0
- data/lib/ropian/control/raritan.rb +12 -0
- data/lib/ropian/meter/apc.rb +22 -0
- data/lib/ropian/meter/generic.rb +17 -0
- data/lib/ropian/meter/raritan.rb +28 -0
- data/ropian.gemspec +55 -0
- data/test/ropian_test.rb +7 -0
- data/test/test_helper.rb +10 -0
- metadata +95 -0
data/.document
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Geoff Garside
|
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
data/Rakefile
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
begin
|
6
|
+
require 'jeweler'
|
7
|
+
Jeweler::Tasks.new do |gem|
|
8
|
+
gem.name = "ropian"
|
9
|
+
gem.summary = %Q{Suite of tools for working with network power units}
|
10
|
+
gem.email = "geoff@geoffgarside.co.uk"
|
11
|
+
gem.homepage = "http://github.com/geoffgarside/ropian"
|
12
|
+
gem.authors = ["Geoff Garside"]
|
13
|
+
gem.add_dependency('snmp', '>= 1.0.2')
|
14
|
+
|
15
|
+
gem.files.exclude 'doc/*.mib'
|
16
|
+
|
17
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
18
|
+
end
|
19
|
+
rescue LoadError
|
20
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
21
|
+
end
|
22
|
+
|
23
|
+
require 'rake/testtask'
|
24
|
+
Rake::TestTask.new(:test) do |test|
|
25
|
+
test.libs << 'lib' << 'test'
|
26
|
+
test.pattern = 'test/**/*_test.rb'
|
27
|
+
test.verbose = true
|
28
|
+
end
|
29
|
+
|
30
|
+
begin
|
31
|
+
require 'rcov/rcovtask'
|
32
|
+
Rcov::RcovTask.new do |test|
|
33
|
+
test.libs << 'test'
|
34
|
+
test.pattern = 'test/**/*_test.rb'
|
35
|
+
test.verbose = true
|
36
|
+
end
|
37
|
+
rescue LoadError
|
38
|
+
task :rcov do
|
39
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
task :default => :test
|
45
|
+
|
46
|
+
require 'rake/rdoctask'
|
47
|
+
Rake::RDocTask.new do |rdoc|
|
48
|
+
if File.exist?('VERSION.yml')
|
49
|
+
config = YAML.load(File.read('VERSION.yml'))
|
50
|
+
version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
|
51
|
+
else
|
52
|
+
version = ""
|
53
|
+
end
|
54
|
+
|
55
|
+
rdoc.rdoc_dir = 'rdoc'
|
56
|
+
rdoc.title = "ropian #{version}"
|
57
|
+
rdoc.rdoc_files.include('README*')
|
58
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
59
|
+
end
|
60
|
+
|
data/VERSION.yml
ADDED
data/lib/ropian.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'snmp'
|
2
|
+
|
3
|
+
require 'ropian/control/generic'
|
4
|
+
require 'ropian/control/raritan'
|
5
|
+
require 'ropian/control/apc'
|
6
|
+
|
7
|
+
require 'ropian/meter/generic'
|
8
|
+
require 'ropian/meter/raritan'
|
9
|
+
require 'ropian/meter/apc'
|
10
|
+
|
11
|
+
# :stopdoc:
|
12
|
+
class SNMP::Manager
|
13
|
+
attr_reader :host, :community, :version
|
14
|
+
end
|
15
|
+
class SNMP::ObjectId
|
16
|
+
def +(val)
|
17
|
+
current = self.to_a
|
18
|
+
unless val.kind_of?(Array)
|
19
|
+
current << val.to_i
|
20
|
+
return self.class.new(current)
|
21
|
+
else
|
22
|
+
return self.class.new(current + val.to_a)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
# :startdoc:
|
27
|
+
|
28
|
+
module Ropian # :nodoc:
|
29
|
+
module Control # :nodoc:
|
30
|
+
end
|
31
|
+
module Meter # :nodoc:
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Ropian
|
2
|
+
module Control
|
3
|
+
class Generic
|
4
|
+
States = [:on, :off, :reboot]
|
5
|
+
def inspect
|
6
|
+
"#<#{self.class} #{@manager.host}@#{@manager.community}>"
|
7
|
+
end
|
8
|
+
def initialize(ip_addr, community, version = :SNMPv2c)
|
9
|
+
@manager = SNMP::Manager.new(:Host => ip_addr,
|
10
|
+
:Community => community, :Version => version)
|
11
|
+
end
|
12
|
+
def turn_on(port_index)
|
13
|
+
set_state(:on, port_index)
|
14
|
+
end
|
15
|
+
def turn_off(port_index)
|
16
|
+
set_state(:off, port_index)
|
17
|
+
end
|
18
|
+
def reboot(port_index)
|
19
|
+
set_state(:reboot, port_index)
|
20
|
+
end
|
21
|
+
def set_state(state, port_index)
|
22
|
+
raise ArgumentError, "invalid state" unless States.include?(state)
|
23
|
+
@manager.set(SNMP::VarBind.new(base_oid + port_index,
|
24
|
+
SNMP::Integer.new(state_order.index(state))))
|
25
|
+
end
|
26
|
+
protected
|
27
|
+
def base_oid
|
28
|
+
raise NotImplementedError, "method must be overridden"
|
29
|
+
end
|
30
|
+
def state_order
|
31
|
+
States
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Ropian
|
2
|
+
module Meter
|
3
|
+
class APC < Generic
|
4
|
+
UnitCurrent = SNMP::ObjectId.new('1.3.6.1.4.1.318.1.1.12.2.3.1.1.2.1')
|
5
|
+
|
6
|
+
def collect # :yields: total_amps, hash_of_outlet_amps
|
7
|
+
yield total_amps, {}
|
8
|
+
end
|
9
|
+
# Amps in total on whole bar
|
10
|
+
def total_amps
|
11
|
+
amps_for_oid(UnitCurrent)
|
12
|
+
end
|
13
|
+
def outlet_amps(outlet_index)
|
14
|
+
raise NotImplementedError, "APC Power Bars do not support per outlet power stats"
|
15
|
+
end
|
16
|
+
protected
|
17
|
+
def amps_for_oid(oid)
|
18
|
+
@manager.get(oid).varbind_list.first.value.to_f / 10
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Ropian
|
2
|
+
module Meter
|
3
|
+
class Generic
|
4
|
+
def inspect
|
5
|
+
"#<#{self.class} #{@manager.host}@#{@manager.community}>"
|
6
|
+
end
|
7
|
+
def initialize(ip_addr, community, version = :SNMPv2c)
|
8
|
+
@manager = SNMP::Manager.new(:Host => ip_addr,
|
9
|
+
:Community => community, :Version => version)
|
10
|
+
end
|
11
|
+
protected
|
12
|
+
def amps_for_oid(oid)
|
13
|
+
@manager.get(oid).varbind_list.first.value.to_f / 1000
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Ropian
|
2
|
+
module Meter
|
3
|
+
class Raritan < Generic
|
4
|
+
UnitCurrent = SNMP::ObjectId.new("1.3.6.1.4.1.13742.4.1.4.2.1.3.1")
|
5
|
+
OutletCurrent = SNMP::ObjectId.new("1.3.6.1.4.1.13742.4.1.2.2.1.4")
|
6
|
+
|
7
|
+
def collect # :yields: total_amps, hash_of_outlet_amps
|
8
|
+
results = Hash.new
|
9
|
+
|
10
|
+
@manager.walk(OutletCurrent) do |r|
|
11
|
+
r.each do |varbind|
|
12
|
+
results[varbind.name.index(OutletCurrent)] = varbind.value.to_f / 1000
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
yield total_amps, results
|
17
|
+
end
|
18
|
+
# Amps in total on whole bar
|
19
|
+
def total_amps
|
20
|
+
amps_for_oid(UnitCurrent)
|
21
|
+
end
|
22
|
+
# Amps per outlet
|
23
|
+
def outlet_amps(outlet_index)
|
24
|
+
amps_for_oid(OutletCurrent + outlet_index)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/ropian.gemspec
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{ropian}
|
5
|
+
s.version = "0.1.1"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Geoff Garside"]
|
9
|
+
s.date = %q{2009-06-11}
|
10
|
+
s.email = %q{geoff@geoffgarside.co.uk}
|
11
|
+
s.extra_rdoc_files = [
|
12
|
+
"LICENSE",
|
13
|
+
"README.rdoc"
|
14
|
+
]
|
15
|
+
s.files = [
|
16
|
+
".document",
|
17
|
+
".gitignore",
|
18
|
+
"LICENSE",
|
19
|
+
"README.rdoc",
|
20
|
+
"Rakefile",
|
21
|
+
"VERSION.yml",
|
22
|
+
"lib/ropian.rb",
|
23
|
+
"lib/ropian/control/apc.rb",
|
24
|
+
"lib/ropian/control/generic.rb",
|
25
|
+
"lib/ropian/control/raritan.rb",
|
26
|
+
"lib/ropian/meter/apc.rb",
|
27
|
+
"lib/ropian/meter/generic.rb",
|
28
|
+
"lib/ropian/meter/raritan.rb",
|
29
|
+
"ropian.gemspec",
|
30
|
+
"test/ropian_test.rb",
|
31
|
+
"test/test_helper.rb"
|
32
|
+
]
|
33
|
+
s.homepage = %q{http://github.com/geoffgarside/ropian}
|
34
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
35
|
+
s.require_paths = ["lib"]
|
36
|
+
s.rubygems_version = %q{1.3.4}
|
37
|
+
s.summary = %q{Suite of tools for working with network power units}
|
38
|
+
s.test_files = [
|
39
|
+
"test/ropian_test.rb",
|
40
|
+
"test/test_helper.rb"
|
41
|
+
]
|
42
|
+
|
43
|
+
if s.respond_to? :specification_version then
|
44
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
45
|
+
s.specification_version = 3
|
46
|
+
|
47
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
48
|
+
s.add_runtime_dependency(%q<snmp>, [">= 1.0.2"])
|
49
|
+
else
|
50
|
+
s.add_dependency(%q<snmp>, [">= 1.0.2"])
|
51
|
+
end
|
52
|
+
else
|
53
|
+
s.add_dependency(%q<snmp>, [">= 1.0.2"])
|
54
|
+
end
|
55
|
+
end
|
data/test/ropian_test.rb
ADDED
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ropian
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 25
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Geoff Garside
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-06-02 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: snmp
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 19
|
29
|
+
segments:
|
30
|
+
- 1
|
31
|
+
- 0
|
32
|
+
- 2
|
33
|
+
version: 1.0.2
|
34
|
+
type: :runtime
|
35
|
+
version_requirements: *id001
|
36
|
+
description:
|
37
|
+
email: geoff@geoffgarside.co.uk
|
38
|
+
executables: []
|
39
|
+
|
40
|
+
extensions: []
|
41
|
+
|
42
|
+
extra_rdoc_files:
|
43
|
+
- LICENSE
|
44
|
+
- README.rdoc
|
45
|
+
files:
|
46
|
+
- .document
|
47
|
+
- LICENSE
|
48
|
+
- README.rdoc
|
49
|
+
- Rakefile
|
50
|
+
- VERSION.yml
|
51
|
+
- lib/ropian.rb
|
52
|
+
- lib/ropian/control/apc.rb
|
53
|
+
- lib/ropian/control/generic.rb
|
54
|
+
- lib/ropian/control/raritan.rb
|
55
|
+
- lib/ropian/meter/apc.rb
|
56
|
+
- lib/ropian/meter/generic.rb
|
57
|
+
- lib/ropian/meter/raritan.rb
|
58
|
+
- ropian.gemspec
|
59
|
+
- test/ropian_test.rb
|
60
|
+
- test/test_helper.rb
|
61
|
+
homepage: http://github.com/geoffgarside/ropian
|
62
|
+
licenses: []
|
63
|
+
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
|
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
|
+
hash: 3
|
75
|
+
segments:
|
76
|
+
- 0
|
77
|
+
version: "0"
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
hash: 3
|
84
|
+
segments:
|
85
|
+
- 0
|
86
|
+
version: "0"
|
87
|
+
requirements: []
|
88
|
+
|
89
|
+
rubyforge_project:
|
90
|
+
rubygems_version: 1.8.4
|
91
|
+
signing_key:
|
92
|
+
specification_version: 3
|
93
|
+
summary: Suite of tools for working with network power units
|
94
|
+
test_files: []
|
95
|
+
|