sensu-plugins-oracle 0.1.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +19 -6
- data/bin/check-oracle-alive.rb +2 -2
- data/bin/check-oracle-query.rb +184 -0
- data/lib/sensu-plugins-oracle/session.rb +66 -8
- data/lib/sensu-plugins-oracle/version.rb +1 -1
- metadata +35 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3870e038023cfb7baa04fdaeb18d24e1cf5d620a
|
4
|
+
data.tar.gz: 374295249f2a24d15736fcfbf6c70b791b0ef8ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f40c0f3d54c7d5d007c10ae1783d0f6c67cdc0ad11b930b9bacf6216a7220303031cbc5575a0c686f049a5e1d449ff572975d9b29167e1216bc9eb929277bf6
|
7
|
+
data.tar.gz: bbffaeac68eef29e2da04fcbf82d1a81f05b8869beb7c02ee5feaae5e88a857843049d63f59d964934d01de65c4fbb33cd7c8146a121f86e4584e035c98f2d08
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
|
2
|
+
[![Gem Version](https://badge.fury.io/rb/sensu-plugins-oracle.svg)](https://badge.fury.io/rb/sensu-plugins-oracle)
|
2
3
|
[![Code Climate](https://codeclimate.com/github/thomis/sensu-plugins-oracle/badges/gpa.svg)](https://codeclimate.com/github/thomis/sensu-plugins-oracle)
|
3
4
|
[![Dependency Status](https://gemnasium.com/badges/github.com/thomis/sensu-plugins-oracle.svg)](https://gemnasium.com/github.com/thomis/sensu-plugins-oracle)
|
4
5
|
|
@@ -7,25 +8,37 @@
|
|
7
8
|
This sensu plugin provides native Oracle instrumentation.
|
8
9
|
|
9
10
|
## Files
|
10
|
-
|
11
|
+
* bin/check-oracle-alive.rb
|
12
|
+
* bin/check-oracle-query.rb
|
11
13
|
|
12
14
|
## Usage
|
13
15
|
|
14
16
|
```
|
17
|
+
-- check a single connection
|
15
18
|
check-oracle-alive.rb -u scott -p tiger -d hr
|
16
19
|
|
17
|
-
check
|
20
|
+
-- check a single connection with timeout
|
21
|
+
check-oracle-alive.rb -u scott -p tiger -d hr -T 30
|
18
22
|
```
|
19
23
|
|
20
24
|
```
|
25
|
+
-- check multiple connections as defined in a file
|
21
26
|
check-oracle-alive.rb -f connections.csv
|
22
27
|
|
23
28
|
> cat connections.csv
|
24
|
-
|
25
|
-
|
29
|
+
# production connection
|
30
|
+
example_connection_1,scott/tiger@hr
|
26
31
|
|
27
|
-
|
28
|
-
|
32
|
+
# test connection
|
33
|
+
example_connection_2,scott/tiger@hr_test
|
34
|
+
```
|
35
|
+
|
36
|
+
```
|
37
|
+
-- check for invalid objects in a schema, show type and name if there are invalid objects (-s), define a ciritical boundary only (-c)
|
38
|
+
check-oracle-query.rb -u scott -p tiger -d hr -t -s -query "select object_type, object_name from user_objects where status = 'INVALID'" -c 'value > 0'
|
39
|
+
|
40
|
+
-- same as above but check for all connections in a file
|
41
|
+
check-oracle-query.rb -f connections.csv -t -s -query "select object_type, object_name from user_objects where status = 'INVALID'" -c 'value > 0'
|
29
42
|
|
30
43
|
```
|
31
44
|
|
data/bin/check-oracle-alive.rb
CHANGED
@@ -17,7 +17,7 @@
|
|
17
17
|
# gem: ruby-oci8
|
18
18
|
#
|
19
19
|
# USAGE:
|
20
|
-
# ./check-oracle-alive.rb -u
|
20
|
+
# ./check-oracle-alive.rb -u USERNAME -p PASSWORD -d DATABASE -P PRIVILEGE -T TIMEOUT -f FILE
|
21
21
|
#
|
22
22
|
# NOTES:
|
23
23
|
#
|
@@ -30,7 +30,7 @@
|
|
30
30
|
require 'sensu-plugins-oracle'
|
31
31
|
require 'sensu-plugin/check/cli'
|
32
32
|
|
33
|
-
class
|
33
|
+
class CheckOracleAlive < Sensu::Plugin::Check::CLI
|
34
34
|
option :username,
|
35
35
|
description: 'Oracle Username',
|
36
36
|
short: '-u USERNAME',
|
@@ -0,0 +1,184 @@
|
|
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 USERNAME -p PASSWORD -d DATABASE -P PRIVILEGE -T TIMEOUT -f FILE -q 'select foo from bar' -w 'value > 5' -c 'value > 10'
|
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
|
+
# Check Oracle Query
|
34
|
+
class CheckOracleQuery < Sensu::Plugin::Check::CLI
|
35
|
+
option :username,
|
36
|
+
description: 'Oracle Username',
|
37
|
+
short: '-u USERNAME',
|
38
|
+
long: '--username USERNAME'
|
39
|
+
|
40
|
+
option :password,
|
41
|
+
description: 'Oracle Password',
|
42
|
+
short: '-p PASSWORD',
|
43
|
+
long: '--password PASSWORD'
|
44
|
+
|
45
|
+
option :database,
|
46
|
+
description: 'Database schema to connect to',
|
47
|
+
short: '-d DATABASE',
|
48
|
+
long: '--database DATABASE'
|
49
|
+
|
50
|
+
option :privilege,
|
51
|
+
description: 'Connect to Oracle database by optional priviledge (SYSDBA, SYSOPER, SYSASM, , SYSDG or SYSKM)',
|
52
|
+
short: '-P PRIVILEGE',
|
53
|
+
long: '--privilege PRIVILEGE'
|
54
|
+
|
55
|
+
option :timeout,
|
56
|
+
description: 'Connection timeout (seconds)',
|
57
|
+
short: '-T TIMEOUT',
|
58
|
+
long: '--timeout TIMEOUT'
|
59
|
+
|
60
|
+
option :file,
|
61
|
+
description: 'File with connection strings to check',
|
62
|
+
short: '-f FILE',
|
63
|
+
long: '--file FILE'
|
64
|
+
|
65
|
+
option :query,
|
66
|
+
description: 'Database query to execute',
|
67
|
+
short: '-q QUERY',
|
68
|
+
long: '--query QUERY',
|
69
|
+
required: true
|
70
|
+
|
71
|
+
option :warning,
|
72
|
+
description: 'Warning threshold expression',
|
73
|
+
short: '-w WARNING',
|
74
|
+
long: '--warning WARNING',
|
75
|
+
default: nil
|
76
|
+
|
77
|
+
option :critical,
|
78
|
+
description: 'Critical threshold expression',
|
79
|
+
short: '-c CRITICAL',
|
80
|
+
long: '--critical CRITICAL',
|
81
|
+
default: nil
|
82
|
+
|
83
|
+
option :tuples,
|
84
|
+
description: 'Count the number of tuples (rows) returned by the query',
|
85
|
+
short: '-t',
|
86
|
+
long: '--tuples',
|
87
|
+
boolean: true,
|
88
|
+
default: false
|
89
|
+
|
90
|
+
option :show,
|
91
|
+
description: 'Show result records',
|
92
|
+
short: '-s',
|
93
|
+
long: '--show',
|
94
|
+
boolean: true,
|
95
|
+
default: false
|
96
|
+
|
97
|
+
def run
|
98
|
+
# handle OCI8 properties
|
99
|
+
OCI8.properties[:connect_timeout] = config[:timeout].to_i if config[:timeout]
|
100
|
+
|
101
|
+
if config[:file]
|
102
|
+
handle_connections_from_file
|
103
|
+
else
|
104
|
+
handle_connection
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
private
|
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.query(config[:query].to_s)
|
118
|
+
method, message = session.handle_query_result(config)
|
119
|
+
self.send(method, message)
|
120
|
+
else
|
121
|
+
# issue with the query
|
122
|
+
critical session.error_message
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def handle_connections_from_file
|
127
|
+
sessions = ::SensuPluginsOracle::Session.parse_from_file(config[:file])
|
128
|
+
|
129
|
+
sessions_total = sessions.size
|
130
|
+
results = Hash.new { |h, key| h[key] = [] }
|
131
|
+
|
132
|
+
thread_group = ThreadGroup.new
|
133
|
+
mutex = Mutex.new
|
134
|
+
|
135
|
+
sessions.each do |session|
|
136
|
+
thread_group.add Thread.new {
|
137
|
+
|
138
|
+
if session.query(config[:query].to_s)
|
139
|
+
method, message = session.handle_query_result(config)
|
140
|
+
mutex.synchronize do
|
141
|
+
results[method] << message
|
142
|
+
end
|
143
|
+
else
|
144
|
+
mutex.synchronize do
|
145
|
+
results[:critical] << session.error_message
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
}
|
150
|
+
end
|
151
|
+
thread_group.list.map(&:join)
|
152
|
+
|
153
|
+
# return summary plus warning and critical messages
|
154
|
+
sessions_ok = results[:ok].size
|
155
|
+
|
156
|
+
# default values
|
157
|
+
method = :ok
|
158
|
+
header = ["Total: #{sessions.size}"]
|
159
|
+
header << "Ok: #{results[:ok].size}" if results[:ok].size > 0
|
160
|
+
header << "Warning: #{results[:warning].size}" if results[:warning].size > 0
|
161
|
+
header << "Critical: #{results[:critical].size}" if results[:critical].size > 0
|
162
|
+
|
163
|
+
messages = [header.join(', ')]
|
164
|
+
|
165
|
+
if results[:warning].size > 0
|
166
|
+
method = :warning
|
167
|
+
messages << nil
|
168
|
+
messages << 'WARNING'
|
169
|
+
messages << results[:warning].compact.sort.join("\n\n")
|
170
|
+
end
|
171
|
+
|
172
|
+
if results[:critical].size > 0
|
173
|
+
method = :critical
|
174
|
+
messages << nil
|
175
|
+
messages << 'CRITICAL'
|
176
|
+
messages << results[:critical].compact.sort.join("\n\n")
|
177
|
+
end
|
178
|
+
|
179
|
+
send(method, messages.join("\n"))
|
180
|
+
rescue => e
|
181
|
+
unknown e.to_s
|
182
|
+
end
|
183
|
+
|
184
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'dentaku'
|
2
|
+
|
1
3
|
module SensuPluginsOracle
|
2
4
|
class Session
|
3
5
|
|
@@ -7,11 +9,14 @@ module SensuPluginsOracle
|
|
7
9
|
|
8
10
|
attr_reader :server_version
|
9
11
|
|
12
|
+
attr_accessor :rows
|
13
|
+
|
10
14
|
PRIVILEDGES = [:SYSDBA, :SYSOPER, :SYSASM, :SYSBACKUP, :SYSDG, :SYSKM]
|
11
15
|
|
12
16
|
def initialize(args)
|
13
17
|
@name = args[:name]
|
14
18
|
@error_message = nil
|
19
|
+
@rows = []
|
15
20
|
|
16
21
|
@connect_string = args[:connect_string]
|
17
22
|
|
@@ -19,6 +24,8 @@ module SensuPluginsOracle
|
|
19
24
|
@password = args[:password]
|
20
25
|
@database = args[:database]
|
21
26
|
@priviledge = args[:priviledge].upcase.to_sym if args[:priviledge] && PRIVILEDGES.include?(args[:priviledge].upcase.to_sym)
|
27
|
+
|
28
|
+
@provide_name_in_result = args[:provide_name_in_result] || false
|
22
29
|
end
|
23
30
|
|
24
31
|
def self.parse_from_file(file)
|
@@ -29,7 +36,7 @@ module SensuPluginsOracle
|
|
29
36
|
line.strip!
|
30
37
|
next if line.size == 0 || line =~ /^#/
|
31
38
|
a = line.split(/:|,|;/)
|
32
|
-
sessions << Session.new(name: a[0], connect_string: a[1])
|
39
|
+
sessions << Session.new(name: a[0], connect_string: a[1], provide_name_in_result: true)
|
33
40
|
end
|
34
41
|
end
|
35
42
|
|
@@ -37,17 +44,68 @@ module SensuPluginsOracle
|
|
37
44
|
end
|
38
45
|
|
39
46
|
def alive?
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
@server_version = connection.oracle_server_version
|
44
|
-
|
47
|
+
connect
|
48
|
+
@server_version = @connection.oracle_server_version
|
45
49
|
true
|
46
|
-
rescue OCIError => e
|
50
|
+
rescue StandardError, OCIError => e
|
47
51
|
@error_message = [@name, e.message.split("\n").first].compact.join(": ")
|
48
52
|
false
|
49
53
|
ensure
|
50
|
-
|
54
|
+
disconnect
|
55
|
+
end
|
56
|
+
|
57
|
+
def query(query_string)
|
58
|
+
connect
|
59
|
+
@rows = []
|
60
|
+
|
61
|
+
cursor = @connection.exec(query_string)
|
62
|
+
|
63
|
+
@rows = []
|
64
|
+
while row = cursor.fetch
|
65
|
+
@rows << row
|
66
|
+
end
|
67
|
+
cursor.close
|
68
|
+
|
69
|
+
return true
|
70
|
+
rescue StandardError, OCIError => e
|
71
|
+
@error_message = [@name, e.message.split("\n").first].compact.join(": ")
|
72
|
+
return false
|
73
|
+
end
|
74
|
+
|
75
|
+
def handle_query_result(config={})
|
76
|
+
# check if query is ok, warning, or critical
|
77
|
+
value = @rows.size
|
78
|
+
value = @rows[0][0].to_f if @rows[0] && !config[:tuples]
|
79
|
+
|
80
|
+
calc = Dentaku::Calculator.new
|
81
|
+
return :critical, show(config[:show]) if config[:critical] && calc.evaluate(config[:critical], value: value)
|
82
|
+
return :warning, show(config[:show]) if config[:warning] && calc.evaluate(config[:warning], value: value)
|
83
|
+
return :ok, show(config[:show])
|
84
|
+
end
|
85
|
+
|
86
|
+
private
|
87
|
+
|
88
|
+
def show(show_records=true)
|
89
|
+
return nil unless show_records
|
90
|
+
buffer = []
|
91
|
+
buffer << "#{@name} (#{@rows.size})" if @provide_name_in_result
|
92
|
+
buffer += @rows.map{ |row| '- ' + row.join(', ')}
|
93
|
+
buffer.join("\n")
|
94
|
+
end
|
95
|
+
|
96
|
+
def connect
|
97
|
+
return if @connection
|
98
|
+
|
99
|
+
if @username
|
100
|
+
@connection = OCI8.new(@username.to_s, @password.to_s, @database.to_s)
|
101
|
+
else
|
102
|
+
@connection = OCI8.new(@connect_string.to_s)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def disconnect
|
107
|
+
@connection.logoff if @connection
|
108
|
+
@connection = nil
|
51
109
|
end
|
52
110
|
|
53
111
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sensu-plugins-oracle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sensu-Plugins and contributors
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-10-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sensu-plugin
|
@@ -28,16 +28,30 @@ dependencies:
|
|
28
28
|
name: ruby-oci8
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 2.2.2
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 2.2.2
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: dentaku
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 2.0.9
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.0.9
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: bundler
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,12 +108,27 @@ dependencies:
|
|
94
108
|
- - "~>"
|
95
109
|
- !ruby/object:Gem::Version
|
96
110
|
version: '3.1'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: codeclimate-test-reporter
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 0.6.0
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 0.6.0
|
97
125
|
description: |-
|
98
126
|
This plugin provides native Oracle
|
99
127
|
instrumentation.
|
100
128
|
email: "<thomas.steiner@ikey.ch>"
|
101
129
|
executables:
|
102
130
|
- check-oracle-alive.rb
|
131
|
+
- check-oracle-query.rb
|
103
132
|
extensions: []
|
104
133
|
extra_rdoc_files: []
|
105
134
|
files:
|
@@ -107,6 +136,7 @@ files:
|
|
107
136
|
- LICENSE
|
108
137
|
- README.md
|
109
138
|
- bin/check-oracle-alive.rb
|
139
|
+
- bin/check-oracle-query.rb
|
110
140
|
- lib/sensu-plugins-oracle.rb
|
111
141
|
- lib/sensu-plugins-oracle/session.rb
|
112
142
|
- lib/sensu-plugins-oracle/version.rb
|
@@ -114,7 +144,7 @@ homepage: https://github.com/thomis/sensu-plugins-oracle
|
|
114
144
|
licenses:
|
115
145
|
- MIT
|
116
146
|
metadata:
|
117
|
-
maintainer:
|
147
|
+
maintainer: thomis
|
118
148
|
development_status: active
|
119
149
|
production_status: unstable - testing recommended
|
120
150
|
release_draft: 'false'
|