dribbled 0.8.2 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -15,6 +15,13 @@ module Dribbled
15
15
  COMPONENTS = %w(resources)
16
16
  DEFAULT_CONFIG_FILE = File.join(ENV['HOME'],"/.senedsa/config")
17
17
 
18
+ STATUS = {
19
+ :ok => OpenStruct.new({ :num => 0, :str => "OK", }),
20
+ :warning => OpenStruct.new({ :num => 1, :str => "WARNING", }),
21
+ :critical => OpenStruct.new({ :num => 2, :str => "CRITICAL", }),
22
+ :unknown => OpenStruct.new({ :num => 3, :str => "UNKNOWN" })
23
+ }
24
+
18
25
  def initialize(arguments)
19
26
  @arguments = arguments
20
27
  @whoami = File.basename($PROGRAM_NAME).to_sym
@@ -112,7 +119,7 @@ module Dribbled
112
119
  output_message opts, 0 if (@arguments.size == 0 and @whoami != :check_drbd) or @global_options[:HELP]
113
120
 
114
121
  @action = @whoami == :check_drbd ? :check : @arguments.shift.to_sym
115
- raise OptionParser::InvalidArgument, "invalid action #@action" if actions[@action].nil?
122
+ raise OptionParser::InvalidArgument, "invalid action #{@action}" if actions[@action].nil?
116
123
  actions[@action].order!(@arguments)
117
124
  case @action
118
125
  when :show
@@ -198,8 +205,8 @@ module Dribbled
198
205
 
199
206
  def run_check
200
207
 
201
- plugin_output = ""
202
- plugin_status = ""
208
+ output = ''
209
+ status = :ok
203
210
 
204
211
  # check for configuration vs running resources
205
212
 
@@ -215,41 +222,22 @@ module Dribbled
215
222
  # + dstate should be: UpToDate/UpToDate
216
223
 
217
224
  @drbdset.each do |r,res|
218
- next if res.cstate == 'Unconfigured'
219
-
220
- po_cstate = ""
221
- po_dstate = ""
222
-
223
- po_cstate = "cs:#{res.cstate}" unless res.cstate == "Connected" and res.in_kernel? and res.in_configuration?
224
- po_dstate = "ds:#{res.dstate}" unless res.dstate == "UpToDate/UpToDate" and res.in_kernel? and res.in_configuration?
225
-
226
- unless po_cstate.gsub('cs:','').empty? and po_dstate.gsub('ds:','').empty?
227
- if ['SyncSource','SyncTarget','VerifyS','VerifyT','PausedSyncS','PausedSyncT','StandAlone'].include? res.cstate
228
- plugin_status = :warning
229
- plugin_output += res.percent.nil? ? " #{res.id}:#{po_cstate};#{po_dstate}" : " #{res.id}:#{po_cstate}[#{res.percent}%,#{res.finish}];#{po_dstate}"
230
- elsif not res.in_configuration?
231
- plugin_status = :warning
232
- plugin_output += " #{res.id}[unconfigured]>#{po_cstate}/;#{po_dstate}"
233
- else
234
- plugin_output += " #{res.id}>#{po_cstate};#{po_dstate}"
235
- plugin_status = :critical
236
- end
237
- end
225
+ next if res.cs == 'Unconfigured'
226
+ s,o = res.status
227
+ output << " #{o}"
228
+ status = s if STATUS[s].num > STATUS[status].num
238
229
  end
239
230
 
240
- plugin_output = " all DRBD resources Connected, UpToDate/UpToDate" if plugin_output.empty? and plugin_status.empty?
241
- plugin_status = :ok if plugin_status.empty?
242
-
243
231
  case @action_options[:monitor]
244
232
  when :nagios
245
233
  case @action_options[:mode]
246
234
  when :active
247
- puts "#{plugin_status.to_s.upcase}:#{plugin_output}"
248
- exit SendNsca::STATUS[plugin_status]
235
+ puts "#{status.to_s.upcase}:#{output}"
236
+ exit SendNsca::STATUS[status]
249
237
  when :passive
250
238
  sn = SendNsca.new @action_options
251
239
  begin
252
- sn.send plugin_status, plugin_output
240
+ sn.send status, output
253
241
  rescue SendNsca::SendNscaError => e
254
242
  output_message "send_nsca failed: #{e.message}", 1
255
243
  end
@@ -271,7 +259,7 @@ module Dribbled
271
259
  loop do
272
260
  @drbdset = DrbdSet.new @global_options
273
261
  @drbdset.each do |r,resource|
274
- if resource.cstate =~ /#{@action_options[:cstate]}/ or resource.dstate =~ /#{@action_options[:dstate]}/ or resource.name == @action_options[:resource]
262
+ if resource.cs =~ /#{@action_options[:cstate]}/ or resource.ds =~ /#{@action_options[:dstate]}/ or resource.name == @action_options[:resource]
275
263
  puts resource
276
264
  end
277
265
  end
@@ -9,8 +9,8 @@ module Dribbled
9
9
  attr_reader :resources_cfg_raw, :resources_run_raw
10
10
 
11
11
  PROCDRBD_VERSION_RE = /^version:\s+(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)\s+\(api:(?<api>\d+)\/proto:(?<proto>[0-9-]+)/
12
- PROCDRBD_RESOURCE_RE = /^\s*(?<id>\d+):\s+cs:(?<cstate>[\w\/]+)\s+(st|ro):(?<state>[\w\/]+)\s+ds:(?<dstate>[\w\/]+)\s+/
13
- PROCDRBD_URESOURCE_RE = /^\s*(?<id>\d+):\s+cs:(?<cstate>[\w\/]+)/
12
+ PROCDRBD_RESOURCE_RE = /^\s*(?<id>\d+):\s+cs:(?<cs>[\w\/]+)\s+(st|ro):(?<ro>[\w\/]+)\s+ds:(?<ds>[\w\/]+)\s+/
13
+ PROCDRBD_URESOURCE_RE = /^\s*(?<id>\d+):\s+cs:(?<cs>[\w\/]+)/
14
14
  PROCDRBD_ACTIVITY_RE = /^\s+\[[.>=]+\]\s+(?<activity>[a-z']+):\s+(?<percent>[0-9.]+)%\s+\(\d+\/\d+\)M(finish:\s+(?<finish>[0-9:]+)\s+)*/
15
15
  PROCDRBD_ACTIVITY_STATUS_RE = /^\s+finish:\s+(?<finish>[0-9:]+)\s+/
16
16
 
@@ -36,7 +36,7 @@ module Dribbled
36
36
  end
37
37
 
38
38
  def version
39
- "#@version_major.#@version_minor.#@version_path"
39
+ "#{@version_major}.#{@version_minor}.#{@version_path}"
40
40
  end
41
41
 
42
42
  protected
@@ -44,7 +44,7 @@ module Dribbled
44
44
  def _read_procdrbd(resources_run_src)
45
45
  @log.debug "Running configuration source: #{resources_run_src}" unless @log.nil?
46
46
  resources_run = {}
47
- @resources_run_raw = File.open(resources_run_src,"r") { |f| f.read }
47
+ @resources_run_raw = File.open(resources_run_src,'r') { |f| f.read }
48
48
  r = nil
49
49
  @resources_run_raw.each_line do |line|
50
50
  if /^\s*(\d+):/.match(line)
@@ -53,11 +53,11 @@ module Dribbled
53
53
  resources_run[r].in_kernel = true
54
54
  if PROCDRBD_RESOURCE_RE.match(line)
55
55
  m = PROCDRBD_RESOURCE_RE.match(line)
56
- resources_run[r].cstate = m[:cstate]
57
- resources_run[r].state = m[:state]
58
- resources_run[r].dstate = m[:dstate]
56
+ resources_run[r].cs = m[:cs]
57
+ resources_run[r].ro = m[:ro]
58
+ resources_run[r].ds = m[:ds]
59
59
  elsif PROCDRBD_URESOURCE_RE.match(line)
60
- resources_run[r].cstate = PROCDRBD_URESOURCE_RE.match(line)[:cstate]
60
+ resources_run[r].cs = PROCDRBD_URESOURCE_RE.match(line)[:cs]
61
61
  end
62
62
  @log.debug " #{resources_run[r].inspect}" unless @log.nil?
63
63
  elsif PROCDRBD_ACTIVITY_RE.match(line)
@@ -99,14 +99,14 @@ module Dribbled
99
99
  end
100
100
  if self[r].nil?
101
101
  self[r] = DrbdResource.new r, @hostname
102
- self[r].cstate = "StandAlone"
103
- self[r].dstate = "DUnknown"
104
- self[r].state = "Unknown"
102
+ self[r].cs = 'StandAlone'
103
+ self[r].ds = 'DUnknown'
104
+ self[r].ro = 'Unknown'
105
105
  end
106
106
  self[r].name = name
107
107
  self[r].in_configuration = true
108
- @log.debug " resource: #{r}, state: #{self[r].state}"
109
- if self[r].state == 'Primary/Secondary'
108
+ @log.debug " resource: #{r}, state: #{self[r].ro}"
109
+ if self[r].ro == 'Primary/Secondary'
110
110
  if hostname == @hostname
111
111
  @log.debug " resource: #{r}, primary"
112
112
  self[r].primary[:disk] = disk
@@ -118,7 +118,7 @@ module Dribbled
118
118
  self[r].secondary[:device] = device
119
119
  self[r].secondary[:hostname] = hostname
120
120
  end
121
- elsif self[r].state == 'Secondary/Primary' or self[r].state == 'Unknown'
121
+ elsif self[r].ro == 'Secondary/Primary' or self[r].ro == 'Unknown'
122
122
  if hostname == @hostname
123
123
  @log.debug " resource: #{r}, secondary"
124
124
  self[r].secondary[:disk] = disk
@@ -138,15 +138,15 @@ module Dribbled
138
138
  class DrbdResource
139
139
 
140
140
  attr_reader :id
141
- attr_accessor :name, :cstate, :dstate, :state, :config, :primary, :secondary, :activity, :percent, :finish, :in_kernel, :in_configuration
141
+ attr_accessor :name, :cs, :ds, :ro, :config, :primary, :secondary, :activity, :percent, :finish, :in_kernel, :in_configuration
142
142
 
143
143
  def initialize(res,hostname)
144
144
  @id = res
145
145
  @name = nil
146
146
  @config = nil
147
- @dstate = nil
148
- @cstate = nil
149
- @state = nil
147
+ @ds = nil
148
+ @cs = nil
149
+ @ro = nil
150
150
  @activity = nil
151
151
  @percent = nil
152
152
  @finish = nil
@@ -164,11 +164,38 @@ module Dribbled
164
164
  @in_configuration
165
165
  end
166
166
 
167
- def to_s
168
- ph = @primary[:hostname].gsub(/\.[a-z0-9-]+\.[a-z0-9-]+$/,"") unless @primary[:hostname].nil?
169
- sh = @secondary[:hostname].gsub(/\.[a-z0-9-]+\.[a-z0-9-]+$/,"") unless @secondary[:hostname].nil?
167
+ def status
168
+ s = :unknown
169
+ o = 'unable to assert health'
170
170
 
171
- if @state == 'Primary/Secondary'
171
+ if self.cs == 'Unconfigured'
172
+ [:ok,"#{self.id}[unconfigured]"]
173
+ else
174
+ if self.in_kernel? and self.in_configuration?
175
+ if self.cs == 'Connected' and self.ds == 'UpToDate/UpToDate' and (self.ro == 'Primary/Secondary' or self.ro == 'Secondary/Primary')
176
+ s = :ok
177
+ else
178
+ if ['SyncSource','SyncTarget','VerifyS','VerifyT','PausedSyncS','PausedSyncT','StandAlone'].include? self.cs
179
+ s = :warning
180
+ elsif not self.in_configuration?
181
+ s = :warning
182
+ else
183
+ s = :critical
184
+ end
185
+ end
186
+ else
187
+ s = :unknown
188
+ end
189
+ end
190
+
191
+ [s,self.to_s(:concise)]
192
+ end
193
+
194
+ def to_s(mode=:line)
195
+ ph = @primary[:hostname].gsub(/\.[a-z0-9-]+\.[a-z0-9-]+$/,'') unless @primary[:hostname].nil?
196
+ sh = @secondary[:hostname].gsub(/\.[a-z0-9-]+\.[a-z0-9-]+$/,'') unless @secondary[:hostname].nil?
197
+
198
+ if @ro == 'Primary/Secondary'
172
199
  h1 = ph; dev1 = @primary[:device]
173
200
  h2 = sh; dev2 = @secondary[:device]
174
201
  else
@@ -176,13 +203,27 @@ module Dribbled
176
203
  h2 = ph; dev2 = @primary[:device]
177
204
  end
178
205
 
179
- percent_finish = @activity.nil? ? nil : "[%3d%% %8s]" % [@percent,@finish]
206
+ percent_finish = @activity.nil? ? nil : '[%3d%% %8s]' % [@percent,@finish]
207
+
208
+ case mode
209
+ when :line
210
+ fmt_string = '%2d %6s %-13s %15s %-22s %-20s %10s %-11s %10s %-11s'
211
+ percent_finish = @activity.nil? ? nil : '[%3d%% %8s]' % [@percent,@finish]
212
+ when :concise
213
+ fmt_string = '%s>%s:%s%s:%s:%s'
214
+ percent_finish = @activity.nil? ? nil : '[%d%%,%s]' % [@percent,@finish]
215
+ when :verbose
216
+ fmt_string = '%s'
217
+ else
218
+ fmt_string = '%s'
219
+ end
220
+
221
+ fmt_string % [@id,@name,@cs,percent_finish,@ro,@ds,h1,dev1,h2,dev2]
180
222
 
181
- "%2d %6s %-13s %15s %-22s %-20s %10s %-11s %10s %-11s" % [@id,@name,@cstate,percent_finish,@dstate,@state,h1,dev1,h2,dev2]
182
223
  end
183
224
 
184
225
  def inspect
185
- "#{self.class}: #@id[#@name]: #@cstate,#@dstate,#@state"
226
+ "#{self.class}: #{@id}[#{@name}]: #{@cs},#{@ds},#{@ro}"
186
227
  end
187
228
 
188
229
  def check
@@ -1,3 +1,3 @@
1
1
  module Dribbled
2
- VERSION = "0.8.2"
2
+ VERSION = '0.9.2'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dribbled
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.2
4
+ version: 0.9.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-12 00:00:00.000000000 Z
12
+ date: 2013-05-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: xml-simple