sensu-plugins-oracle 0.4.2 → 0.5.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 +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +2 -2
- data/bin/check-oracle-alive.rb +42 -33
- data/bin/check-oracle-query.rb +29 -22
- data/lib/sensu-plugins-oracle/session.rb +27 -0
- data/lib/sensu-plugins-oracle/version.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: efab7ed4b1a29b124c150b526b3e6ba79f4da9ae
|
4
|
+
data.tar.gz: 199db9fcafb5e3bf3f8369aea3b33f0154063028
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 564b180f48f2d26c9e8fec326c55aa09ca1b3581ef49861a76fc7372c2fd858113e3632c76c0e0c0db0ef85c32184525f327a1fb29b1645ef717d843e3ee4124
|
7
|
+
data.tar.gz: 36b1a795d59dcddf89fb2593f2a429e2be6a51e904a7269e65c553f1b294c1615e7adadc94bd339dd5ad56ef5aa42555330a66a0253fb4c4a07bb66356f83c99
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -22,8 +22,8 @@ This sensu plugin provides native Oracle instrumentation.
|
|
22
22
|
```
|
23
23
|
|
24
24
|
```
|
25
|
-
-- check multiple connections as defined in a file
|
26
|
-
check-oracle-alive.rb -f connections.csv
|
25
|
+
-- check multiple connections as defined in a file, use 5 worker threads (-w 5) and verbose output (-v)
|
26
|
+
check-oracle-alive.rb -f connections.csv -w 5 -v
|
27
27
|
|
28
28
|
> cat connections.csv
|
29
29
|
# production connection
|
data/bin/check-oracle-alive.rb
CHANGED
@@ -60,6 +60,20 @@ class CheckOracleAlive < Sensu::Plugin::Check::CLI
|
|
60
60
|
short: '-f FILE',
|
61
61
|
long: '--file FILE'
|
62
62
|
|
63
|
+
option :worker,
|
64
|
+
description: 'Number of worker threads to check for alive connections',
|
65
|
+
short: '-w WORKER',
|
66
|
+
long: '--worker WORKER',
|
67
|
+
default: 1,
|
68
|
+
:proc => Proc.new { |v| v.to_i == 0 ? 1 : v.to_i }
|
69
|
+
|
70
|
+
option :verbose,
|
71
|
+
description: 'Shows console log messages',
|
72
|
+
short: '-v',
|
73
|
+
long: '--verbose',
|
74
|
+
boolean: true,
|
75
|
+
default: false
|
76
|
+
|
63
77
|
def run
|
64
78
|
# handle OCI8 properties
|
65
79
|
::SensuPluginsOracle::Session.set_timeout_properties(config[:timeout])
|
@@ -73,39 +87,6 @@ class CheckOracleAlive < Sensu::Plugin::Check::CLI
|
|
73
87
|
|
74
88
|
private
|
75
89
|
|
76
|
-
def handle_connections_from_file
|
77
|
-
sessions = ::SensuPluginsOracle::Session.parse_from_file(config[:file])
|
78
|
-
|
79
|
-
sessions_total = sessions.size
|
80
|
-
sessions_alive = 0
|
81
|
-
|
82
|
-
thread_group = ThreadGroup.new
|
83
|
-
queue = Queue.new
|
84
|
-
mutex = Mutex.new
|
85
|
-
|
86
|
-
sessions.each do |session|
|
87
|
-
thread_group.add Thread.new {
|
88
|
-
if session.alive?
|
89
|
-
mutex.synchronize do
|
90
|
-
sessions_alive += 1
|
91
|
-
end
|
92
|
-
else
|
93
|
-
queue << session.error_message
|
94
|
-
end
|
95
|
-
}
|
96
|
-
end
|
97
|
-
thread_group.list.map(&:join)
|
98
|
-
sessions_critical = queue.size.times.map { queue.pop }
|
99
|
-
|
100
|
-
if sessions_total == sessions_alive
|
101
|
-
ok "All are alive (#{sessions_alive}/#{sessions_total})"
|
102
|
-
else
|
103
|
-
critical ["#{sessions_alive}/#{sessions_total} are alive", sessions_critical].flatten.join("\n - ")
|
104
|
-
end
|
105
|
-
rescue => e
|
106
|
-
unknown e.to_s
|
107
|
-
end
|
108
|
-
|
109
90
|
def handle_connection
|
110
91
|
session = SensuPluginsOracle::Session.new(
|
111
92
|
username: config[:username],
|
@@ -119,4 +100,32 @@ class CheckOracleAlive < Sensu::Plugin::Check::CLI
|
|
119
100
|
critical session.error_message
|
120
101
|
end
|
121
102
|
end
|
103
|
+
|
104
|
+
def handle_connections_from_file
|
105
|
+
sessions = ::SensuPluginsOracle::Session.parse_from_file(config[:file])
|
106
|
+
::SensuPluginsOracle::Session.handle_multiple(
|
107
|
+
sessions: sessions,
|
108
|
+
method: :alive?,
|
109
|
+
config: config
|
110
|
+
)
|
111
|
+
|
112
|
+
errors = []
|
113
|
+
sessions.each do |session|
|
114
|
+
errors << session.error_message if session.error_message
|
115
|
+
end
|
116
|
+
|
117
|
+
sessions_total = sessions.size
|
118
|
+
errors_total = errors.size
|
119
|
+
|
120
|
+
if errors_total == 0
|
121
|
+
ok "All are alive (#{sessions_total}/#{sessions_total})"
|
122
|
+
else
|
123
|
+
critical ["#{sessions_total - errors_total}/#{sessions_total} are alive", errors].flatten.join("\n - ")
|
124
|
+
end
|
125
|
+
|
126
|
+
rescue => e
|
127
|
+
unknown e.to_s
|
128
|
+
end
|
129
|
+
|
130
|
+
|
122
131
|
end
|
data/bin/check-oracle-query.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
#! /usr/bin/env ruby
|
2
2
|
#
|
3
|
-
# check-oracle-
|
3
|
+
# check-oracle-query
|
4
4
|
#
|
5
5
|
# DESCRIPTION:
|
6
|
-
# This plugin attempts to
|
6
|
+
# This plugin attempts to execute defined query against provided connection credential(s).
|
7
7
|
#
|
8
8
|
# OUTPUT:
|
9
9
|
# plain text
|
@@ -16,7 +16,7 @@
|
|
16
16
|
# gem: ruby-oci8
|
17
17
|
#
|
18
18
|
# USAGE:
|
19
|
-
# ./check-oracle-
|
19
|
+
# ./check-oracle-query.rb -u USERNAME -p PASSWORD -d DATABASE -P PRIVILEGE -T TIMEOUT -f FILE -q 'select foo from bar' -w 'value > 5' -c 'value > 10'
|
20
20
|
#
|
21
21
|
# NOTES:
|
22
22
|
#
|
@@ -93,6 +93,20 @@ class CheckOracleQuery < Sensu::Plugin::Check::CLI
|
|
93
93
|
boolean: true,
|
94
94
|
default: false
|
95
95
|
|
96
|
+
option :worker,
|
97
|
+
description: 'Number of worker threads to execute query against provided connections',
|
98
|
+
short: '-w WORKER',
|
99
|
+
long: '--worker WORKER',
|
100
|
+
default: 1,
|
101
|
+
:proc => Proc.new { |v| v.to_i == 0 ? 1 : v.to_i }
|
102
|
+
|
103
|
+
option :verbose,
|
104
|
+
description: 'Shows console log messages',
|
105
|
+
short: '-v',
|
106
|
+
long: '--verbose',
|
107
|
+
boolean: true,
|
108
|
+
default: false
|
109
|
+
|
96
110
|
def run
|
97
111
|
# handle OCI8 properties
|
98
112
|
::SensuPluginsOracle::Session.set_timeout_properties(config[:timeout])
|
@@ -124,29 +138,22 @@ class CheckOracleQuery < Sensu::Plugin::Check::CLI
|
|
124
138
|
|
125
139
|
def handle_connections_from_file
|
126
140
|
sessions = ::SensuPluginsOracle::Session.parse_from_file(config[:file])
|
141
|
+
::SensuPluginsOracle::Session.handle_multiple(
|
142
|
+
sessions: sessions,
|
143
|
+
method: :query,
|
144
|
+
method_arguments: config[:query].to_s,
|
145
|
+
config: config
|
146
|
+
)
|
127
147
|
|
128
148
|
results = Hash.new { |h, key| h[key] = [] }
|
129
|
-
|
130
|
-
thread_group = ThreadGroup.new
|
131
|
-
mutex = Mutex.new
|
132
|
-
|
133
149
|
sessions.each do |session|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
end
|
141
|
-
else
|
142
|
-
mutex.synchronize do
|
143
|
-
results[:critical] << session.error_message
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
}
|
150
|
+
if session.error_message
|
151
|
+
results[:critical] << session.error_message
|
152
|
+
else
|
153
|
+
method, message = session.handle_query_result(config)
|
154
|
+
results[method] << message
|
155
|
+
end
|
148
156
|
end
|
149
|
-
thread_group.list.map(&:join)
|
150
157
|
|
151
158
|
# return summary plus warning and critical messages
|
152
159
|
method = :ok
|
@@ -95,6 +95,33 @@ module SensuPluginsOracle
|
|
95
95
|
OCI8.properties[:recv_timeout] = timeout
|
96
96
|
end
|
97
97
|
|
98
|
+
def self.handle_multiple(args={})
|
99
|
+
queue_sessions = Queue.new
|
100
|
+
|
101
|
+
# feed the queue with sessions
|
102
|
+
args[:sessions].map{ |session| queue_sessions.push(session) }
|
103
|
+
|
104
|
+
# start worker threads and handle requested sessions
|
105
|
+
worker = (1..args[:config][:worker]).map do
|
106
|
+
Thread.new do
|
107
|
+
begin
|
108
|
+
while session = queue_sessions.pop(true)
|
109
|
+
start = Time.now
|
110
|
+
puts "Processing #{session.name} - Method: #{args[:method]}" if args[:config][:verbose]
|
111
|
+
if args[:method_arguments]
|
112
|
+
session.send(args[:method], args[:method_arguments])
|
113
|
+
else
|
114
|
+
session.send(args[:method])
|
115
|
+
end
|
116
|
+
puts "Done #{session.name}, took #{ '%0.1f' % ((Time.now - start)*1000)} ms" if args[:config][:verbose]
|
117
|
+
end
|
118
|
+
rescue ThreadError
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
worker.map(&:join)
|
123
|
+
end
|
124
|
+
|
98
125
|
private
|
99
126
|
|
100
127
|
def show(show_records=true)
|
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.5.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: 2017-07-
|
11
|
+
date: 2017-07-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sensu-plugin
|