openldap_monitor_extractor 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ .rvmrc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ config
12
+ doc/
13
+ pkg
14
+ rdoc
15
+ tmp
16
+ lib/bundler/man
17
+ spec/reports
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Javier Juarez
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Open LDAP Monitor Extractor
2
+
3
+ This is a simple utility to dig in the Open LDAP Monitor meta-data
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'openldap_monitor_extractor'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install openldap_monitor_extractor
18
+
19
+ ## Usage
20
+
21
+ You can take a look to the examples directory
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), %w{.. lib})
4
+
5
+
6
+ require 'rubygems'
7
+ require 'yaml'
8
+ require 'openldap_monitor_extractor'
9
+
10
+
11
+ config = YAML.load_file(ARGV[0])
12
+
13
+ OpenldapMonitorExtractor.configure(config)
14
+ puts OpenldapMonitorExtractor.get(:total_connections)
@@ -0,0 +1,5 @@
1
+ ---
2
+ :url: 'ldaps://ldap.example.com'
3
+ :username: 'cn=admin,dc=example,dc=com'
4
+ :password: 'supersecret'
5
+ :base: 'cn=Monitor'
@@ -0,0 +1,54 @@
1
+ require "ostruct"
2
+ require "openldap_monitor_extractor/version"
3
+ require "openldap_monitor_extractor/connection"
4
+
5
+
6
+ module OpenldapMonitorExtractor
7
+ extend self
8
+
9
+
10
+ MAPPER = {
11
+ :total_connections =>{ :dn =>"cn=Total,cn=Connections,cn=Monitor", :attribute =>:monitorcounter },
12
+ :referals_statistics =>{ :dn =>"cn=Referrals,cn=Statistics,cn=Monitor",:attribute =>:monitorcounter },
13
+ :bytes_statistics =>{ :dn =>"cn=Bytes,cn=Statistics,cn=Monitor", :attribute =>:monitorcounter },
14
+ :entries_statistics =>{ :dn =>"cn=Entries,cn=Statistics,cn=Monitor", :attribute =>:monitorcounter },
15
+ :initiated_operations =>{ :dn =>"cn=Operations,cn=Monitor", :attribute =>:monitoropinitiated },
16
+ :completed_operations =>{ :dn =>"cn=Operations,cn=Monitor", :attribute =>:monitoropcompleted },
17
+ :bind_operations =>{ :dn =>"cn=Bind,cn=Operations,cn=Monitor", :attribute =>:monitoropcompleted },
18
+ :unbind_operations =>{ :dn =>"cn=Unbind,cn=Operations,cn=Monitor", :attribute =>:monitoropcompleted },
19
+ :search_operations =>{ :dn =>"cn=Search,cn=Operations,cn=Monitor", :attribute =>:monitoropcompleted },
20
+ :compare_operations =>{ :dn =>"cn=Compare,cn=Operations,cn=Monitor", :attribute =>:monitoropcompleted },
21
+ :modify_operations =>{ :dn =>"cn=Modify,cn=Operations,cn=Monitor", :attribute =>:monitoropcompleted },
22
+ :modrdn_operations =>{ :dn =>"cn=Modrdn,cn=Operations,cn=Monitor", :attribute =>:monitoropcompleted },
23
+ :add_operations =>{ :dn =>"cn=Add,cn=Operations,cn=Monitor", :attribute =>:monitoropcompleted },
24
+ :delete_operations =>{ :dn =>"cn=Delete,cn=Operations,cn=Monitor", :attribute =>:monitoropcompleted },
25
+ :abandon_operations =>{ :dn =>"cn=Abandon,cn=Operations,cn=Monitor", :attribute =>:monitoropcompleted },
26
+ :extended_operations =>{ :dn =>"cn=Extended,cn=Operations,cn=Monitor", :attribute =>:monitoropcompleted },
27
+ :write_waiters =>{ :dn =>"cn=Write,cn=Waiters,cn=Monitor", :attribute =>:monitorcounter },
28
+ :read_waiters =>{ :dn =>"cn=Read,cn=Waiters,cn=Monitor", :attribute =>:monitorcounter }
29
+ }
30
+
31
+ KEYS = MAPPER.keys
32
+
33
+ def configure(config)
34
+ @connection ||= Connection.new(config).connection
35
+ end
36
+
37
+ def get(key)
38
+
39
+ dn = MAPPER[key][:dn]
40
+ attribute = MAPPER[key][:attribute]
41
+
42
+ raise ArgumentError.new("You need to configure a valid LDAP connection before call this") unless @connection
43
+ raise ArgumentError.new("Invalid key: #{key}") unless KEYS.include?(key)
44
+
45
+ entry = @connection.search(
46
+ :filter =>Net::LDAP::Filter.eq("objectClass", "*"),
47
+ :base =>dn,
48
+ :attributes =>[attribute])
49
+
50
+ raise StandardError.new("Problems getting information: #{dn} from Monitor backend") unless entry
51
+
52
+ entry[0][attribute][0]
53
+ end
54
+ end
@@ -0,0 +1,40 @@
1
+ require 'rubygems'
2
+ require 'net/ldap'
3
+ require 'uri'
4
+
5
+
6
+ module OpenldapMonitorExtractor
7
+
8
+ class Connection
9
+
10
+ attr_reader :connection
11
+
12
+ def self.builder(parameters={ })
13
+
14
+ uri = URI.parse(parameters[:url])
15
+ auth = {
16
+ :method =>:simple,
17
+ :username =>parameters[:username],
18
+ :password =>parameters[:password]
19
+ }
20
+
21
+ cparameters = {
22
+ :host =>uri.host,
23
+ :port =>uri.port,
24
+ :base =>parameters[:base],
25
+ :auth =>auth
26
+ }
27
+
28
+ cparameters[:encryption] = { :method =>:simple_tls } if uri.scheme == "ldaps"
29
+
30
+ Net::LDAP.new(cparameters)
31
+ end
32
+
33
+ def initialize(parameters={ })
34
+
35
+ @connection = Connection::builder(parameters)
36
+
37
+ self
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,4 @@
1
+ module OpenldapMonitorExtractor
2
+
3
+ VERSION = "0.0.2"
4
+ end
@@ -0,0 +1,28 @@
1
+ # encoding: utf-8
2
+ $:.unshift File.join(File.dirname(__FILE__), 'lib')
3
+
4
+
5
+ require 'openldap_monitor_extractor/version'
6
+
7
+
8
+ Gem::Specification.new do |spec|
9
+
10
+ spec.name = "openldap_monitor_extractor"
11
+ spec.version = OpenldapMonitorExtractor::VERSION
12
+ spec.authors = ["Javier Juarez"]
13
+ spec.email = ["javier.juarez@gmail.com"]
14
+ spec.description = %q{OpenLDAP stats gem extractor}
15
+ spec.summary = %q{OpenLDAP Monitor database handler utility}
16
+ spec.homepage = ""
17
+ spec.license = "MIT"
18
+
19
+ spec.files = `git ls-files`.split($/)
20
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_dependency "net-ldap"
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.3"
26
+ spec.add_development_dependency "rake"
27
+ spec.add_development_dependency "rspec"
28
+ end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+ require 'openldap_monitor_extractor/version'
3
+
4
+
5
+ describe OpenldapMonitorExtractor do
6
+
7
+ it 'should have a version number' do
8
+
9
+ OpenldapMonitorExtractor::VERSION.should_not be_nil
10
+ end
11
+
12
+ it 'should do something useful' do
13
+
14
+ false.should be_true
15
+ end
16
+ end
@@ -0,0 +1 @@
1
+ $:.unshift File.expand_path(File.join(%w{.. .. lib}, __FILE__))
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: openldap_monitor_extractor
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Javier Juarez
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-25 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: net-ldap
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: bundler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '1.3'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '1.3'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: OpenLDAP stats gem extractor
79
+ email:
80
+ - javier.juarez@gmail.com
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - .gitignore
86
+ - Gemfile
87
+ - LICENSE.txt
88
+ - README.md
89
+ - Rakefile
90
+ - examples/get_totalconnections.rb
91
+ - examples/sample_settings.yml
92
+ - lib/openldap_monitor_extractor.rb
93
+ - lib/openldap_monitor_extractor/connection.rb
94
+ - lib/openldap_monitor_extractor/version.rb
95
+ - openldap_monitor_extractor.gemspec
96
+ - spec/openldap_monitor_extractor_spec.rb
97
+ - spec/spec_helper.rb
98
+ homepage: ''
99
+ licenses:
100
+ - MIT
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ segments:
112
+ - 0
113
+ hash: -1701931666641725521
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ none: false
116
+ requirements:
117
+ - - ! '>='
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ segments:
121
+ - 0
122
+ hash: -1701931666641725521
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 1.8.25
126
+ signing_key:
127
+ specification_version: 3
128
+ summary: OpenLDAP Monitor database handler utility
129
+ test_files:
130
+ - spec/openldap_monitor_extractor_spec.rb
131
+ - spec/spec_helper.rb