openldap_monitor_extractor 0.0.4 → 0.0.6

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.
@@ -16,4 +16,4 @@ end
16
16
 
17
17
 
18
18
  config = YAML.load_file(ARGV[0])
19
- puts OpenldapMonitorExtractor.configure(config).get(:all).inspect
19
+ puts OpenldapMonitorExtractor::Core.new(config).get(:all).inspect
@@ -1,82 +1,8 @@
1
- require "ostruct"
2
1
  require "openldap_monitor_extractor/version"
3
- require "openldap_monitor_extractor/connection"
2
+ require "openldap_monitor_extractor/core"
4
3
 
5
4
 
6
5
  module OpenldapMonitorExtractor
7
- extend self
8
-
9
- class ExtractorError < StandardError
10
- end
11
6
 
12
- MAPPER = {
13
- :total_connections =>{ :dn =>"cn=Total,cn=Connections,cn=Monitor", :attribute =>:monitorcounter },
14
- :referals_statistics =>{ :dn =>"cn=Referrals,cn=Statistics,cn=Monitor",:attribute =>:monitorcounter },
15
- :bytes_statistics =>{ :dn =>"cn=Bytes,cn=Statistics,cn=Monitor", :attribute =>:monitorcounter },
16
- :entries_statistics =>{ :dn =>"cn=Entries,cn=Statistics,cn=Monitor", :attribute =>:monitorcounter },
17
- :initiated_operations =>{ :dn =>"cn=Operations,cn=Monitor", :attribute =>:monitoropinitiated },
18
- :completed_operations =>{ :dn =>"cn=Operations,cn=Monitor", :attribute =>:monitoropcompleted },
19
- :bind_operations =>{ :dn =>"cn=Bind,cn=Operations,cn=Monitor", :attribute =>:monitoropcompleted },
20
- :unbind_operations =>{ :dn =>"cn=Unbind,cn=Operations,cn=Monitor", :attribute =>:monitoropcompleted },
21
- :search_operations =>{ :dn =>"cn=Search,cn=Operations,cn=Monitor", :attribute =>:monitoropcompleted },
22
- :compare_operations =>{ :dn =>"cn=Compare,cn=Operations,cn=Monitor", :attribute =>:monitoropcompleted },
23
- :modify_operations =>{ :dn =>"cn=Modify,cn=Operations,cn=Monitor", :attribute =>:monitoropcompleted },
24
- :modrdn_operations =>{ :dn =>"cn=Modrdn,cn=Operations,cn=Monitor", :attribute =>:monitoropcompleted },
25
- :add_operations =>{ :dn =>"cn=Add,cn=Operations,cn=Monitor", :attribute =>:monitoropcompleted },
26
- :delete_operations =>{ :dn =>"cn=Delete,cn=Operations,cn=Monitor", :attribute =>:monitoropcompleted },
27
- :abandon_operations =>{ :dn =>"cn=Abandon,cn=Operations,cn=Monitor", :attribute =>:monitoropcompleted },
28
- :extended_operations =>{ :dn =>"cn=Extended,cn=Operations,cn=Monitor", :attribute =>:monitoropcompleted },
29
- :write_waiters =>{ :dn =>"cn=Write,cn=Waiters,cn=Monitor", :attribute =>:monitorcounter },
30
- :read_waiters =>{ :dn =>"cn=Read,cn=Waiters,cn=Monitor", :attribute =>:monitorcounter }
31
- }
32
-
33
- KEYS = MAPPER.keys
34
-
35
- private
36
- def get_monitor_parameter(dn, attribute)
37
-
38
- @connection.search(
39
- :filter =>Net::LDAP::Filter.eq("objectClass", "*"),
40
- :base =>dn,
41
- :attributes =>[attribute])
42
- end
43
-
44
-
45
- public
46
- def configure(config)
47
-
48
- @connection ||= Connection.new(config).connection
49
- self
50
- end
51
-
52
-
53
- def validate_key(key)
54
-
55
- key == :all || KEYS.include?(key)
56
- end
57
-
58
-
59
- def get(key=:all)
60
-
61
- raise ExtractorError.new("You need to configure a valid LDAP connection") unless @connection
62
- raise ArgumentError.new("Invalid key: #{key}, valid keys are: #{KEYS.inspect}") unless validate_key(key)
63
-
64
- result = OpenStruct.new()
65
- keys = (key == :all ? KEYS : [key])
66
-
67
- keys.each do |k|
68
-
69
- dn = MAPPER[k][:dn]
70
- attr = MAPPER[k][:attribute]
71
- entry = get_monitor_parameter(dn, attr)
72
-
73
- raise ExtractorError.new("Problems getting #{dn} data") unless entry
74
-
75
- result.send("#{k}=", entry[0][attr][0].to_i)
76
- end
77
-
78
- result
79
- rescue Exception => exc
80
- raise ExtractorError.new(exc.message)
81
- end
7
+ # Other stuffs goes here... may be
82
8
  end
@@ -0,0 +1,53 @@
1
+ require "openldap_monitor_extractor/connection"
2
+ require "openldap_monitor_extractor/mapper"
3
+ require "openldap_monitor_extractor/monitor_data"
4
+
5
+
6
+ module OpenldapMonitorExtractor
7
+
8
+ class Core
9
+
10
+ def initialize(config, options={ })
11
+
12
+ options = { :mapper =>Mapper }.merge(options)
13
+
14
+ @connection = Connection.new(config).connection
15
+ @mapper = options[:mapper]
16
+
17
+ self
18
+ end
19
+
20
+
21
+ def get_monitor_parameter(dn, attribute, options={ })
22
+
23
+ options = { :filter =>Net::LDAP::Filter.eq("objectClass", "*") }.merge(options)
24
+
25
+ @connection.search(
26
+ :filter =>options[:filter],
27
+ :base =>dn,
28
+ :attributes =>[attribute])
29
+ end
30
+
31
+
32
+ def get(key=:all)
33
+
34
+ raise ArgumentError.new("Monitor invalid key: #{key}") unless @mapper.validate_key(key)
35
+
36
+ result = MonitorData.new()
37
+ key_list = (key == :all) ? @mapper::dns() : [key]
38
+
39
+ key_list.each do |k|
40
+
41
+ dn = @mapper.dn(k)
42
+ attribute = @mapper.attribute(k)
43
+ entry = get_monitor_parameter(dn, attribute)
44
+
45
+ raise StandardError.new("Problems getting Monitor for data: #{dn}") unless entry
46
+
47
+ result.add(k, entry)
48
+ end
49
+
50
+ result
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,58 @@
1
+ module OpenldapMonitorExtractor
2
+
3
+ class Mapper
4
+
5
+ private
6
+ MAPPER = {
7
+
8
+ :start_time =>{ :dn =>"cn=Start,cn=Time,cn=Monitor", :attribute =>:monitorTimestamp, :type =>:timestamp },
9
+ :current_time =>{ :dn =>"cn=Current,cn=Time,cn=Monitor", :attribute =>:monitorTimestamp, :type =>:timestamp },
10
+
11
+ :total_connections =>{ :dn =>"cn=Total,cn=Connections,cn=Monitor", :attribute =>:monitorcounter, :type =>:counter },
12
+
13
+ :pdu_statistics =>{ :dn =>"cn=PDU,cn=Statistics,cn=Monitor", :attribute =>:monitorcounter, :type =>:counter },
14
+ :referals_statistics =>{ :dn =>"cn=Referrals,cn=Statistics,cn=Monitor",:attribute =>:monitorcounter, :type =>:counter },
15
+ :bytes_statistics =>{ :dn =>"cn=Bytes,cn=Statistics,cn=Monitor", :attribute =>:monitorcounter, :type =>:counter },
16
+ :entries_statistics =>{ :dn =>"cn=Entries,cn=Statistics,cn=Monitor", :attribute =>:monitorcounter, :type =>:counter },
17
+
18
+ :initiated_operations =>{ :dn =>"cn=Operations,cn=Monitor", :attribute =>:monitoropinitiated, :type =>:counter },
19
+ :completed_operations =>{ :dn =>"cn=Operations,cn=Monitor", :attribute =>:monitoropcompleted, :type =>:counter },
20
+ :bind_operations =>{ :dn =>"cn=Bind,cn=Operations,cn=Monitor", :attribute =>:monitoropcompleted, :type =>:counter },
21
+ :unbind_operations =>{ :dn =>"cn=Unbind,cn=Operations,cn=Monitor", :attribute =>:monitoropcompleted, :type =>:counter },
22
+ :search_operations =>{ :dn =>"cn=Search,cn=Operations,cn=Monitor", :attribute =>:monitoropcompleted, :type =>:counter },
23
+ :compare_operations =>{ :dn =>"cn=Compare,cn=Operations,cn=Monitor", :attribute =>:monitoropcompleted, :type =>:counter },
24
+ :modify_operations =>{ :dn =>"cn=Modify,cn=Operations,cn=Monitor", :attribute =>:monitoropcompleted, :type =>:counter },
25
+ :modrdn_operations =>{ :dn =>"cn=Modrdn,cn=Operations,cn=Monitor", :attribute =>:monitoropcompleted, :type =>:counter },
26
+ :add_operations =>{ :dn =>"cn=Add,cn=Operations,cn=Monitor", :attribute =>:monitoropcompleted, :type =>:counter },
27
+ :delete_operations =>{ :dn =>"cn=Delete,cn=Operations,cn=Monitor", :attribute =>:monitoropcompleted, :type =>:counter },
28
+ :abandon_operations =>{ :dn =>"cn=Abandon,cn=Operations,cn=Monitor", :attribute =>:monitoropcompleted, :type =>:counter },
29
+ :extended_operations =>{ :dn =>"cn=Extended,cn=Operations,cn=Monitor", :attribute =>:monitoropcompleted, :type =>:counter },
30
+
31
+ :write_waiters =>{ :dn =>"cn=Write,cn=Waiters,cn=Monitor", :attribute =>:monitorcounter, :type =>:counter },
32
+ :read_waiters =>{ :dn =>"cn=Read,cn=Waiters,cn=Monitor", :attribute =>:monitorcounter, :type =>:counter }
33
+ }
34
+
35
+ KEYS = MAPPER.keys
36
+
37
+ public
38
+ def self.validate_key(key)
39
+ key == :all || KEYS.include?(key)
40
+ end
41
+
42
+ def self.dns()
43
+ KEYS
44
+ end
45
+
46
+ def self.dn(key)
47
+ MAPPER[key][:dn]
48
+ end
49
+
50
+ def self.attribute(key)
51
+ MAPPER[key][:attribute]
52
+ end
53
+
54
+ def self.type(key)
55
+ MAPPER[key][:type]
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,46 @@
1
+ require "time"
2
+ require "ostruct"
3
+
4
+
5
+ module OpenldapMonitorExtractor
6
+
7
+ class MonitorData
8
+
9
+ attr_reader :data
10
+
11
+ def self.transform(data, type)
12
+
13
+ case type
14
+ when :counter then data.to_i
15
+ when :timestamp then Time.parse(data)
16
+ else
17
+ ArgumentError.new("Invalid data type: #{type}")
18
+ end
19
+ end
20
+
21
+ def initialize(mapper=Mapper)
22
+
23
+ @data = OpenStruct.new
24
+ @mapper = mapper
25
+
26
+ self
27
+ end
28
+
29
+ def add(key, entry)
30
+
31
+ type = @mapper.type(key)
32
+ value = entry[0][@mapper.attribute(key)][0]
33
+ t_value = MonitorData.transform(value, type)
34
+
35
+ @data.send("#{key}=", t_value)
36
+ end
37
+
38
+ def inspect()
39
+ @data.inspect
40
+ end
41
+
42
+ def to_s()
43
+ "#{inspect()}"
44
+ end
45
+ end
46
+ end
@@ -1,4 +1,4 @@
1
1
  module OpenldapMonitorExtractor
2
2
 
3
- VERSION = "0.0.4"
4
- end
3
+ VERSION = "0.0.6"
4
+ end
@@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
13
13
  spec.email = ["javier.juarez@gmail.com"]
14
14
  spec.description = %q{OpenLDAP stats gem extractor}
15
15
  spec.summary = %q{OpenLDAP Monitor database handler utility}
16
- spec.homepage = ""
16
+ spec.homepage = "http://github.com/jjuarez/openldap_monitor_extractor"
17
17
  spec.license = "MIT"
18
18
 
19
19
  spec.files = `git ls-files`.split($/)
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
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -91,11 +91,14 @@ files:
91
91
  - examples/sample_settings.yml
92
92
  - lib/openldap_monitor_extractor.rb
93
93
  - lib/openldap_monitor_extractor/connection.rb
94
+ - lib/openldap_monitor_extractor/core.rb
95
+ - lib/openldap_monitor_extractor/mapper.rb
96
+ - lib/openldap_monitor_extractor/monitor_data.rb
94
97
  - lib/openldap_monitor_extractor/version.rb
95
98
  - openldap_monitor_extractor.gemspec
96
99
  - spec/openldap_monitor_extractor_spec.rb
97
100
  - spec/spec_helper.rb
98
- homepage: ''
101
+ homepage: http://github.com/jjuarez/openldap_monitor_extractor
99
102
  licenses:
100
103
  - MIT
101
104
  post_install_message:
@@ -110,7 +113,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
110
113
  version: '0'
111
114
  segments:
112
115
  - 0
113
- hash: 720276235540630360
116
+ hash: -2902660141660861386
114
117
  required_rubygems_version: !ruby/object:Gem::Requirement
115
118
  none: false
116
119
  requirements:
@@ -119,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
122
  version: '0'
120
123
  segments:
121
124
  - 0
122
- hash: 720276235540630360
125
+ hash: -2902660141660861386
123
126
  requirements: []
124
127
  rubyforge_project:
125
128
  rubygems_version: 1.8.25