sensu-plugins-oracle 0.1.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e05bc65c5bf93831644ccdebae43ecc27f7a35ab
4
+ data.tar.gz: 853e25216e18f24f0ec94d2c357f805dcfc1e228
5
+ SHA512:
6
+ metadata.gz: 95dbd868e884e2aa3692de4a8d8d37320f946c5b2b2fd62fd57745307653ba555d3d5a8dc082111a3182e9c74193c7cc5dd505440575cb8f2f5499451c8682a2
7
+ data.tar.gz: 6e26c529fb09bb2c330d09155011b393e7327b12b4de2d2844d001dfc2ad25cd807490f886fbe77920ad0ed9b721bd7be4032e9c23546e989029bac770ff939a
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ## 0.0.1 - 2016-08-03
2
+ ### Added
3
+ - initial release based on sensu-plugins-postgres (https://github.com/sensu-plugins/sensu-plugins-postgres)
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2016 thomis
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,34 @@
1
+
2
+ [![Code Climate](https://codeclimate.com/github/thomis/sensu-plugins-oracle/badges/gpa.svg)](https://codeclimate.com/github/thomis/sensu-plugins-oracle)
3
+ [![Dependency Status](https://gemnasium.com/badges/github.com/thomis/sensu-plugins-oracle.svg)](https://gemnasium.com/github.com/thomis/sensu-plugins-oracle)
4
+
5
+ # sensu-plugins-oracle
6
+
7
+ This sensu plugin provides native Oracle instrumentation.
8
+
9
+ ## Files
10
+ * bin/check-oracle-alive.rb
11
+
12
+ ## Usage
13
+
14
+ ```
15
+ check-oracle-alive.rb -u scott -p tiger -d hr
16
+
17
+ check-oracle-alive.rb -u scott -p tiger -d ht -T 30
18
+ ```
19
+
20
+ ```
21
+ check-oracle-alive.rb -f connections.csv
22
+
23
+ > cat connections.csv
24
+ # production connection
25
+ example_connection_1,scott/tiger@hr
26
+
27
+ # test connection
28
+ example_connection_2,scott/tiger@hr_test
29
+
30
+ ```
31
+
32
+ ## Installation
33
+
34
+ [Installation and Setup](http://sensu-plugins.io/docs/installation_instructions.html)
@@ -0,0 +1,123 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # check-oracle-alive
4
+ #
5
+ # DESCRIPTION:
6
+ #
7
+ # This plugin attempts to login to oracle with provided credentials.
8
+ #
9
+ # OUTPUT:
10
+ # plain text
11
+ #
12
+ # PLATFORMS:
13
+ # Linux
14
+ #
15
+ # DEPENDENCIES:
16
+ # gem: sensu-plugin
17
+ # gem: ruby-oci8
18
+ #
19
+ # USAGE:
20
+ # ./check-oracle-alive.rb -u db_user -p db_pass -h db_host -d db
21
+ #
22
+ # NOTES:
23
+ #
24
+ # LICENSE:
25
+ # Copyright (c) 2016 Thomas Steiner
26
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
27
+ # for details.
28
+ #
29
+
30
+ require 'sensu-plugins-oracle'
31
+ require 'sensu-plugin/check/cli'
32
+
33
+ class CheckOracle < Sensu::Plugin::Check::CLI
34
+ option :username,
35
+ description: 'Oracle Username',
36
+ short: '-u USERNAME',
37
+ long: '--username USERNAME'
38
+
39
+ option :password,
40
+ description: 'Oracle Password',
41
+ short: '-p PASSWORD',
42
+ long: '--password PASSWORD'
43
+
44
+ option :database,
45
+ description: 'Database schema to connect to',
46
+ short: '-d DATABASE',
47
+ long: '--database DATABASE'
48
+
49
+ option :privilege,
50
+ description: 'Connect to Oracle database by optional priviledge (SYSDBA, SYSOPER, SYSASM, , SYSDG or SYSKM)',
51
+ short: '-P PRIVILEGE',
52
+ long: '--privilege PRIVILEGE'
53
+
54
+ option :timeout,
55
+ description: 'Connection timeout (seconds)',
56
+ short: '-T TIMEOUT',
57
+ long: '--timeout TIMEOUT'
58
+
59
+ option :file,
60
+ description: 'File with connection strings to check',
61
+ short: '-f FILE',
62
+ long: '--file FILE'
63
+
64
+ def run
65
+ # handle OCI8 properties
66
+ OCI8.properties[:connect_timeout] = config[:timeout].to_i if config[:timeout]
67
+
68
+ if config[:file]
69
+ handle_connections_from_file
70
+ else
71
+ handle_connection
72
+ end
73
+ end
74
+
75
+ private
76
+
77
+ def handle_connections_from_file
78
+ sessions = ::SensuPluginsOracle::Session.parse_from_file(config[:file])
79
+
80
+ sessions_total = sessions.size
81
+ sessions_alive = 0
82
+
83
+ thread_group = ThreadGroup.new
84
+ queue = Queue.new
85
+ mutex = Mutex.new
86
+
87
+ sessions.each do |session|
88
+ thread_group.add Thread.new {
89
+ if session.alive?
90
+ mutex.synchronize do
91
+ sessions_alive += 1
92
+ end
93
+ else
94
+ queue << session.error_message
95
+ end
96
+ }
97
+ end
98
+ thread_group.list.map(&:join)
99
+ sessions_critical = queue.size.times.map { queue.pop }
100
+
101
+ if sessions_total == sessions_alive
102
+ ok "All are alive (#{sessions_alive}/#{sessions_total})"
103
+ else
104
+ critical ["#{sessions_alive}/#{sessions_total} are alive", sessions_critical].flatten.join("\n - ")
105
+ end
106
+ rescue => e
107
+ unknown e.to_s
108
+ end
109
+
110
+ def handle_connection
111
+ session = SensuPluginsOracle::Session.new(
112
+ username: config[:username],
113
+ password: config[:password],
114
+ database: config[:database],
115
+ privilege: config[:privilege])
116
+
117
+ if session.alive?
118
+ ok "Server version: #{session.server_version}"
119
+ else
120
+ critical session.error_message
121
+ end
122
+ end
123
+ end
@@ -0,0 +1,4 @@
1
+ require 'sensu-plugins-oracle/version'
2
+ require 'sensu-plugins-oracle/session'
3
+
4
+ require 'oci8'
@@ -0,0 +1,54 @@
1
+ module SensuPluginsOracle
2
+ class Session
3
+
4
+ attr_reader :name, :error_message
5
+ attr_reader :connect_string
6
+ attr_reader :username, :password, :database, :priviledge
7
+
8
+ attr_reader :server_version
9
+
10
+ PRIVILEDGES = [:SYSDBA, :SYSOPER, :SYSASM, :SYSBACKUP, :SYSDG, :SYSKM]
11
+
12
+ def initialize(args)
13
+ @name = args[:name]
14
+ @error_message = nil
15
+
16
+ @connect_string = args[:connect_string]
17
+
18
+ @username = args[:username]
19
+ @password = args[:password]
20
+ @database = args[:database]
21
+ @priviledge = args[:priviledge].upcase.to_sym if args[:priviledge] && PRIVILEDGES.include?(args[:priviledge].upcase.to_sym)
22
+ end
23
+
24
+ def self.parse_from_file(file)
25
+ sessions = []
26
+
27
+ File.open(file) do |input|
28
+ input.each_line do |line|
29
+ line.strip!
30
+ next if line.size == 0 || line =~ /^#/
31
+ a = line.split(/:|,|;/)
32
+ sessions << Session.new(name: a[0], connect_string: a[1])
33
+ end
34
+ end
35
+
36
+ return sessions
37
+ end
38
+
39
+ def alive?
40
+ connection = OCI8.new(@connect_string) if @connect_string
41
+ connection = OCI8.new(@username, @password, @database) if @username
42
+
43
+ @server_version = connection.oracle_server_version
44
+
45
+ true
46
+ rescue OCIError => e
47
+ @error_message = [@name, e.message.split("\n").first].compact.join(": ")
48
+ false
49
+ ensure
50
+ connection.logoff if connection
51
+ end
52
+
53
+ end
54
+ end
@@ -0,0 +1,9 @@
1
+ module SensuPluginsOracle
2
+ module Version
3
+ MAJOR = 0
4
+ MINOR = 1
5
+ PATCH = 0
6
+
7
+ VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.')
8
+ end
9
+ end
metadata ADDED
@@ -0,0 +1,143 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sensu-plugins-oracle
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sensu-Plugins and contributors
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-09-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sensu-plugin
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: ruby-oci8
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 2.2.2
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 2.2.2
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.7'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '11.2'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '11.2'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.10'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.10'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.1'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.1'
97
+ description: |-
98
+ This plugin provides native Oracle
99
+ instrumentation.
100
+ email: "<thomas.steiner@ikey.ch>"
101
+ executables:
102
+ - check-oracle-alive.rb
103
+ extensions: []
104
+ extra_rdoc_files: []
105
+ files:
106
+ - CHANGELOG.md
107
+ - LICENSE
108
+ - README.md
109
+ - bin/check-oracle-alive.rb
110
+ - lib/sensu-plugins-oracle.rb
111
+ - lib/sensu-plugins-oracle/session.rb
112
+ - lib/sensu-plugins-oracle/version.rb
113
+ homepage: https://github.com/thomis/sensu-plugins-oracle
114
+ licenses:
115
+ - MIT
116
+ metadata:
117
+ maintainer: "@tas50"
118
+ development_status: active
119
+ production_status: unstable - testing recommended
120
+ release_draft: 'false'
121
+ release_prerelease: 'false'
122
+ post_install_message: You can use the embedded Ruby by setting EMBEDDED_RUBY=true
123
+ in /etc/default/sensu
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: 1.9.3
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ requirements: []
138
+ rubyforge_project:
139
+ rubygems_version: 2.2.2
140
+ signing_key:
141
+ specification_version: 4
142
+ summary: Sensu plugins for oracle
143
+ test_files: []