openldap_monitor_extractor 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/openldap_monitor_extractor.rb +0 -1
- data/lib/openldap_monitor_extractor/mapper.rb +3 -4
- data/lib/openldap_monitor_extractor/monitor_data.rb +6 -9
- data/lib/openldap_monitor_extractor/version.rb +1 -1
- data/openldap_monitor_extractor.gemspec +1 -0
- data/spec/mapper_spec.rb +93 -0
- data/spec/monitor_data_spec.rb +49 -0
- data/spec/spec_helper.rb +2 -1
- data/spec/{openldap_monitor_extractor_spec.rb → version_spec.rb} +3 -5
- metadata +26 -6
@@ -2,11 +2,10 @@ module OpenldapMonitorExtractor
|
|
2
2
|
|
3
3
|
class Mapper
|
4
4
|
|
5
|
-
private
|
6
5
|
MAPPER = {
|
7
6
|
|
8
|
-
:start_time =>{ :dn =>"cn=Start,cn=Time,cn=Monitor", :attribute =>:
|
9
|
-
:current_time =>{ :dn =>"cn=Current,cn=Time,cn=Monitor", :attribute =>:
|
7
|
+
:start_time =>{ :dn =>"cn=Start,cn=Time,cn=Monitor", :attribute =>:monitortimestamp, :type =>:timestamp },
|
8
|
+
:current_time =>{ :dn =>"cn=Current,cn=Time,cn=Monitor", :attribute =>:monitortimestamp, :type =>:timestamp },
|
10
9
|
|
11
10
|
:total_connections =>{ :dn =>"cn=Total,cn=Connections,cn=Monitor", :attribute =>:monitorcounter, :type =>:counter },
|
12
11
|
|
@@ -33,8 +32,8 @@ module OpenldapMonitorExtractor
|
|
33
32
|
}
|
34
33
|
|
35
34
|
KEYS = MAPPER.keys
|
35
|
+
|
36
36
|
|
37
|
-
public
|
38
37
|
def self.validate_key(key)
|
39
38
|
key == :all || KEYS.include?(key)
|
40
39
|
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require "time"
|
2
2
|
require "ostruct"
|
3
|
+
require "openldap_monitor_extractor/mapper"
|
3
4
|
|
4
5
|
|
5
6
|
module OpenldapMonitorExtractor
|
@@ -14,7 +15,7 @@ module OpenldapMonitorExtractor
|
|
14
15
|
when :counter then data.to_i
|
15
16
|
when :timestamp then Time.parse(data)
|
16
17
|
else
|
17
|
-
ArgumentError.new("Invalid data type: #{type}")
|
18
|
+
raise ArgumentError.new("Invalid data type: #{type}")
|
18
19
|
end
|
19
20
|
end
|
20
21
|
|
@@ -28,19 +29,15 @@ module OpenldapMonitorExtractor
|
|
28
29
|
|
29
30
|
def add(key, entry)
|
30
31
|
|
32
|
+
raise ArgumentError.new("Invalid key: #{key}") unless @mapper.validate_key(key)
|
33
|
+
|
31
34
|
type = @mapper.type(key)
|
32
35
|
value = entry[0][@mapper.attribute(key)][0]
|
33
36
|
t_value = MonitorData.transform(value, type)
|
34
37
|
|
35
38
|
@data.send("#{key}=", t_value)
|
36
|
-
|
37
|
-
|
38
|
-
def inspect()
|
39
|
-
@data.inspect
|
40
|
-
end
|
41
|
-
|
42
|
-
def to_s()
|
43
|
-
"#{inspect()}"
|
39
|
+
|
40
|
+
self
|
44
41
|
end
|
45
42
|
end
|
46
43
|
end
|
data/spec/mapper_spec.rb
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
$:.unshift File.dirname(__FILE__)
|
2
|
+
|
3
|
+
|
4
|
+
require 'spec_helper'
|
5
|
+
require 'openldap_monitor_extractor/monitor_data'
|
6
|
+
|
7
|
+
|
8
|
+
describe OpenldapMonitorExtractor::Mapper do
|
9
|
+
|
10
|
+
describe "#validate_key" do
|
11
|
+
|
12
|
+
it 'should validate keys' do
|
13
|
+
|
14
|
+
OpenldapMonitorExtractor::Mapper::KEYS.each { |k| OpenldapMonitorExtractor::Mapper.validate_key(k).should eq(true) }
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should validate :all as key' do
|
18
|
+
|
19
|
+
OpenldapMonitorExtractor::Mapper.validate_key(:all).should eq(true)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "#keys" do
|
24
|
+
|
25
|
+
it 'should return all the keys' do
|
26
|
+
|
27
|
+
OpenldapMonitorExtractor::Mapper.dns().should eq(OpenldapMonitorExtractor::Mapper::KEYS)
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should return all the keys as an Array' do
|
31
|
+
|
32
|
+
OpenldapMonitorExtractor::Mapper.dns().should be_an_instance_of(Array)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "#dn" do
|
37
|
+
|
38
|
+
it 'should return the DN for a key' do
|
39
|
+
|
40
|
+
OpenldapMonitorExtractor::Mapper::KEYS.each do |k|
|
41
|
+
OpenldapMonitorExtractor::Mapper.dn(k).should eq(OpenldapMonitorExtractor::Mapper::MAPPER[k][:dn])
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should return the DN as a String" do
|
46
|
+
|
47
|
+
OpenldapMonitorExtractor::Mapper::KEYS.each do |k|
|
48
|
+
OpenldapMonitorExtractor::Mapper.dn(k).should be_an_instance_of(String)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should retulr the DN as a base of cn=Monitor" do
|
53
|
+
|
54
|
+
OpenldapMonitorExtractor::Mapper::KEYS.each do |k|
|
55
|
+
OpenldapMonitorExtractor::Mapper.dn(k).should match(/(.+),cn=Monitor/)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "#attribute" do
|
61
|
+
|
62
|
+
it 'should return the attribute for a key' do
|
63
|
+
|
64
|
+
OpenldapMonitorExtractor::Mapper::KEYS.each do |k|
|
65
|
+
OpenldapMonitorExtractor::Mapper.attribute(k).should eq(OpenldapMonitorExtractor::Mapper::MAPPER[k][:attribute])
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'should return the attribute for a key as a Symbol' do
|
70
|
+
|
71
|
+
OpenldapMonitorExtractor::Mapper::KEYS.each do |k|
|
72
|
+
OpenldapMonitorExtractor::Mapper.attribute(k).should be_an_instance_of(Symbol)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe "#type" do
|
78
|
+
|
79
|
+
it 'should return the type for a key' do
|
80
|
+
|
81
|
+
OpenldapMonitorExtractor::Mapper::KEYS.each do |k|
|
82
|
+
OpenldapMonitorExtractor::Mapper.type(k).should eq(OpenldapMonitorExtractor::Mapper::MAPPER[k][:type])
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'should return the type for a key as a Symbol' do
|
87
|
+
|
88
|
+
OpenldapMonitorExtractor::Mapper::KEYS.each do |k|
|
89
|
+
OpenldapMonitorExtractor::Mapper.type(k).should be_an_instance_of(Symbol)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
$:.unshift File.dirname(__FILE__)
|
2
|
+
|
3
|
+
|
4
|
+
require 'spec_helper'
|
5
|
+
require 'openldap_monitor_extractor/monitor_data'
|
6
|
+
|
7
|
+
|
8
|
+
describe OpenldapMonitorExtractor::MonitorData do
|
9
|
+
|
10
|
+
describe "#transform" do
|
11
|
+
|
12
|
+
it '#should transform to an integer' do
|
13
|
+
|
14
|
+
OpenldapMonitorExtractor::MonitorData.transform(10, :counter).should equal(10)
|
15
|
+
OpenldapMonitorExtractor::MonitorData.transform("Fail", :counter).should equal(0)
|
16
|
+
|
17
|
+
expect { OpenldapMonitorExtractor::MonitorData.transform(10, :foo) }.to raise_error(ArgumentError)
|
18
|
+
end
|
19
|
+
|
20
|
+
it '#should transform to a timestamp' do
|
21
|
+
|
22
|
+
OpenldapMonitorExtractor::MonitorData.transform("20130530Z", :timestamp).should be_an_instance_of Time
|
23
|
+
OpenldapMonitorExtractor::MonitorData.transform("20130530Z", :timestamp).should eq(Time.parse("20130530Z"))
|
24
|
+
|
25
|
+
expect { OpenldapMonitorExtractor::MonitorData.transform("fodate", :timestamp) }.to raise_error(ArgumentError)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "#add" do
|
30
|
+
|
31
|
+
it 'should create a valid object whit add method' do
|
32
|
+
|
33
|
+
md = OpenldapMonitorExtractor::MonitorData.new(OpenldapMonitorExtractor::Mapper)
|
34
|
+
|
35
|
+
md.should be_an_instance_of OpenldapMonitorExtractor::MonitorData
|
36
|
+
md.should respond_to :add
|
37
|
+
|
38
|
+
md.add(:total_connections, [{ :monitorcounter =>0, :type =>:counter }]).should be_an_instance_of OpenldapMonitorExtractor::MonitorData
|
39
|
+
md.data.should be_an_instance_of OpenStruct
|
40
|
+
md.data.should respond_to :total_connections
|
41
|
+
md.data.total_connections.should equal(0)
|
42
|
+
|
43
|
+
expect { md.add(:foo, [{ :monitorcounter =>0, :type =>:counter }]) }.to raise_error(ArgumentError)
|
44
|
+
md.data.should be_an_instance_of OpenStruct
|
45
|
+
md.data.should respond_to :total_connections
|
46
|
+
md.data.total_connections.should equal(0)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1 +1,2 @@
|
|
1
|
-
$:.unshift File.
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), %w{.. lib})
|
2
|
+
$:.unshift File.join(File.dirname(__FILE__), %w{.. lib openldap_monitor_extractor})
|
@@ -1,3 +1,6 @@
|
|
1
|
+
$:.unshift File.dirname(__FILE__)
|
2
|
+
|
3
|
+
|
1
4
|
require 'spec_helper'
|
2
5
|
require 'openldap_monitor_extractor/version'
|
3
6
|
|
@@ -8,9 +11,4 @@ describe OpenldapMonitorExtractor do
|
|
8
11
|
|
9
12
|
OpenldapMonitorExtractor::VERSION.should_not be_nil
|
10
13
|
end
|
11
|
-
|
12
|
-
it 'should do something useful' do
|
13
|
-
|
14
|
-
false.should be_true
|
15
|
-
end
|
16
14
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: openldap_monitor_extractor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-06-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: net-ldap
|
@@ -75,6 +75,22 @@ dependencies:
|
|
75
75
|
- - ! '>='
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: syntax
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
78
94
|
description: OpenLDAP stats gem extractor
|
79
95
|
email:
|
80
96
|
- javier.juarez@gmail.com
|
@@ -96,8 +112,10 @@ files:
|
|
96
112
|
- lib/openldap_monitor_extractor/monitor_data.rb
|
97
113
|
- lib/openldap_monitor_extractor/version.rb
|
98
114
|
- openldap_monitor_extractor.gemspec
|
99
|
-
- spec/
|
115
|
+
- spec/mapper_spec.rb
|
116
|
+
- spec/monitor_data_spec.rb
|
100
117
|
- spec/spec_helper.rb
|
118
|
+
- spec/version_spec.rb
|
101
119
|
homepage: http://github.com/jjuarez/openldap_monitor_extractor
|
102
120
|
licenses:
|
103
121
|
- MIT
|
@@ -113,7 +131,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
113
131
|
version: '0'
|
114
132
|
segments:
|
115
133
|
- 0
|
116
|
-
hash: -
|
134
|
+
hash: -1420333256945599315
|
117
135
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
136
|
none: false
|
119
137
|
requirements:
|
@@ -122,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
122
140
|
version: '0'
|
123
141
|
segments:
|
124
142
|
- 0
|
125
|
-
hash: -
|
143
|
+
hash: -1420333256945599315
|
126
144
|
requirements: []
|
127
145
|
rubyforge_project:
|
128
146
|
rubygems_version: 1.8.25
|
@@ -130,5 +148,7 @@ signing_key:
|
|
130
148
|
specification_version: 3
|
131
149
|
summary: OpenLDAP Monitor database handler utility
|
132
150
|
test_files:
|
133
|
-
- spec/
|
151
|
+
- spec/mapper_spec.rb
|
152
|
+
- spec/monitor_data_spec.rb
|
134
153
|
- spec/spec_helper.rb
|
154
|
+
- spec/version_spec.rb
|