dribbled 0.7.0 → 0.8.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.
- data/lib/dribbled/cli.rb +80 -29
- data/lib/dribbled/drbd.rb +1 -1
- data/lib/dribbled/version.rb +1 -1
- metadata +2 -2
data/lib/dribbled/cli.rb
CHANGED
@@ -11,7 +11,7 @@ module Dribbled
|
|
11
11
|
|
12
12
|
include Senedsa
|
13
13
|
|
14
|
-
COMMANDS = %w(show check snap)
|
14
|
+
COMMANDS = %w(show check snap watch)
|
15
15
|
COMPONENTS = %w(resources)
|
16
16
|
DEFAULT_CONFIG_FILE = File.join(ENV['HOME'],"/.senedsa/config")
|
17
17
|
|
@@ -21,6 +21,7 @@ module Dribbled
|
|
21
21
|
|
22
22
|
@global_options = { :debug => false, :drbdadm => 'drbdadm', :xmldump => nil, :procdrbd => '/proc/drbd', :hostname => nil }
|
23
23
|
@action_options = { :monitor => :nagios, :mode => :active, :suffix => nil, :directory => '/tmp' }
|
24
|
+
@action_arguments = {}
|
24
25
|
@action = nil
|
25
26
|
end
|
26
27
|
|
@@ -56,43 +57,54 @@ module Dribbled
|
|
56
57
|
opts.banner = "Usage: #{ID} [options] <action> [options]"
|
57
58
|
opts.separator ""
|
58
59
|
opts.separator "Actions:"
|
59
|
-
opts.separator " show Displays
|
60
|
+
opts.separator " show Displays resource information"
|
61
|
+
opts.separator " watch Displays resource information at a given interval"
|
60
62
|
opts.separator " check Performs health checks"
|
61
63
|
opts.separator " snap Saves contents of /proc/drbd and 'drbdadm dump-xml'"
|
62
64
|
opts.separator ""
|
63
65
|
opts.separator "General options:"
|
64
|
-
opts.on('-D', '--drbdadm DRBDADM', String, "Path to drbdadm binary")
|
65
|
-
opts.on('-P', '--procdrbd PROCDRBD', String, "Path to /proc/drbd")
|
66
|
-
opts.on('-X', '--xmldump XMLDUMP', String, "Path to output for drbdadm --dump-xml")
|
67
|
-
opts.on('-H', '--hostname HOSTNAME', String, "Hostname")
|
68
|
-
opts.on('-d', '--debug', "Enable debug mode")
|
69
|
-
opts.on('-a', '--about', "Display #{ID} information")
|
70
|
-
opts.on('-V', '--version', "Display #{ID} version")
|
71
|
-
opts.on_tail('--help', "Show this message")
|
66
|
+
opts.on('-D', '--drbdadm DRBDADM', String, "Path to drbdadm binary") { |drbdadm| @global_options[:drbdadm] = drbdadm }
|
67
|
+
opts.on('-P', '--procdrbd PROCDRBD', String, "Path to /proc/drbd") { |procdrbd| @global_options[:procdrbd] = procdrbd }
|
68
|
+
opts.on('-X', '--xmldump XMLDUMP', String, "Path to output for drbdadm --dump-xml") { |xmldump| @global_options[:xmldump] = xmldump}
|
69
|
+
opts.on('-H', '--hostname HOSTNAME', String, "Hostname") { |hostname| @global_options[:hostname] = hostname }
|
70
|
+
opts.on('-d', '--debug', "Enable debug mode") { @global_options[:debug] = true}
|
71
|
+
opts.on('-a', '--about', "Display #{ID} information") { output_message ABOUT, 0 }
|
72
|
+
opts.on('-V', '--version', "Display #{ID} version") { output_message VERSION, 0 }
|
73
|
+
opts.on_tail('--help', "Show this message") { @global_options[:HELP] = true }
|
72
74
|
|
73
75
|
actions = {
|
74
76
|
:show => OptionParser.new do |aopts|
|
75
|
-
aopts.banner = "Usage: #{ID} [options] show
|
76
|
-
aopts.separator ""
|
77
|
-
aopts.separator " <component> is resources|res"
|
77
|
+
aopts.banner = "Usage: #{ID} [options] show [resource]"
|
78
78
|
end,
|
79
79
|
:check => OptionParser.new do |aopts|
|
80
80
|
aopts.banner = "Usage: #{ID} [options] check [check_options]"
|
81
81
|
aopts.separator ""
|
82
82
|
aopts.separator "Check Options"
|
83
|
-
aopts.on('-M', '--monitor [nagios]',
|
84
|
-
aopts.on('-m', '--mode [active|passive]',
|
85
|
-
aopts.on('-H', '--nsca_hostname HOSTNAME',
|
86
|
-
aopts.on('-c', '--config CONFIG',
|
87
|
-
aopts.on('-S', '--svc_descr SVC_DESR',
|
88
|
-
aopts.on('-h', '--hostname HOSTNAME',
|
83
|
+
aopts.on('-M', '--monitor [nagios]', [:nagios], "Monitoring system") { |monitor| @action_options[:monitor] = monitor }
|
84
|
+
aopts.on('-m', '--mode [active|passive]', [:active, :passive], "Monitoring mode") { |mode| @action_options[:mode] = mode }
|
85
|
+
aopts.on('-H', '--nsca_hostname HOSTNAME', String, "NSCA hostname to send passive checks") { |nsca_hostname| @action_options[:nsca_hostname] = nsca_hostname }
|
86
|
+
aopts.on('-c', '--config CONFIG', String, "Path to Senedsa (send_nsca) configuration" ) { |config| @action_options[:senedsa_config] = config }
|
87
|
+
aopts.on('-S', '--svc_descr SVC_DESR', String, "Nagios service description") { |svc_descr| @action_options[:svc_descr] = svc_descr }
|
88
|
+
aopts.on('-h', '--hostname HOSTNAME', String, "Service hostname") { |hostname| @action_options[:svc_hostname] = hostname }
|
89
89
|
end,
|
90
90
|
:snap => OptionParser.new do |aopts|
|
91
91
|
aopts.banner = "Usage: #{ID} [options] snap [snap_options]"
|
92
92
|
aopts.separator ""
|
93
93
|
aopts.separator "Snap Options"
|
94
|
-
aopts.on('-S','--suffix SUFFIX',
|
95
|
-
aopts.on('-D',
|
94
|
+
aopts.on('-S','--suffix SUFFIX', String, "Suffix (defaults to PID)") { |suffix| @action_options[:suffix] = suffix }
|
95
|
+
aopts.on('-D','--directory DIRECTORY', String, "Directory (defaults to /tmp)") { |directory| @action_options[:directory] = directory }
|
96
|
+
end,
|
97
|
+
:watch => OptionParser.new do |aopts|
|
98
|
+
aopts.banner = "Usage: #{ID} [options] watch [watch_options] interval [count]"
|
99
|
+
aopts.separator ""
|
100
|
+
aopts.separator "Watch Arguments"
|
101
|
+
aopts.separator " interval: amount of time in seconds between each report (default: 60)"
|
102
|
+
aopts.separator " count: number of reports to produce"
|
103
|
+
aopts.separator ""
|
104
|
+
aopts.separator "Watch Options"
|
105
|
+
aopts.on('-r', '--resource RESOURCE', String, "Resource") { |resource| @action_options[:resource] = resource }
|
106
|
+
aopts.on('-c', '--cstate CSTATE_RE', String, "CState (partial match)") { |cstate| @action_options[:cstate] = cstate }
|
107
|
+
aopts.on('-d', '--dstate DSTATE_RE', String, "DState (partial match)") { |dstate| @action_options[:dstate] = dstate }
|
96
108
|
end
|
97
109
|
}
|
98
110
|
|
@@ -102,6 +114,13 @@ module Dribbled
|
|
102
114
|
@action = @whoami == :check_drbd ? :check : @arguments.shift.to_sym
|
103
115
|
raise OptionParser::InvalidArgument, "invalid action #@action" if actions[@action].nil?
|
104
116
|
actions[@action].order!(@arguments)
|
117
|
+
case @action
|
118
|
+
when :show
|
119
|
+
@action_arguments[:component] = @arguments.shift
|
120
|
+
when :watch
|
121
|
+
@action_arguments[:interval] = @arguments.shift
|
122
|
+
@action_arguments[:count] = @arguments.shift
|
123
|
+
end
|
105
124
|
end
|
106
125
|
|
107
126
|
def config_options?
|
@@ -131,10 +150,23 @@ module Dribbled
|
|
131
150
|
end
|
132
151
|
|
133
152
|
def process_options
|
153
|
+
case @action
|
154
|
+
when :watch
|
155
|
+
if @action_options[:resource].nil? and @action_options[:cstate].nil? and @action_options[:dstate].nil?
|
156
|
+
@action_options[:cstate] = 'Sync'
|
157
|
+
@action_options[:dstate] = 'Inconsistent'
|
158
|
+
else
|
159
|
+
@action_options[:cstate] = '__NOMATCH__' if @action_options[:cstate].nil?
|
160
|
+
@action_options[:dstate] = '__NOMATCH__' if @action_options[:dstate].nil?
|
161
|
+
end
|
162
|
+
end
|
134
163
|
true
|
135
164
|
end
|
136
165
|
|
137
166
|
def process_arguments
|
167
|
+
@action_arguments[:interval] = 60 if @action_arguments[:interval].nil?
|
168
|
+
@action_arguments[:interval] = @action_arguments[:interval].to_i
|
169
|
+
@action_arguments[:count] = @action_arguments[:count].nil? ? -1 : @action_arguments[:count].to_i
|
138
170
|
true
|
139
171
|
end
|
140
172
|
|
@@ -146,21 +178,21 @@ module Dribbled
|
|
146
178
|
when :show then run_show
|
147
179
|
when :check then run_check
|
148
180
|
when :snap then run_snap
|
181
|
+
when :watch then run_watch
|
149
182
|
end
|
150
183
|
|
151
184
|
end
|
152
185
|
|
153
186
|
def run_show
|
154
|
-
#raise ArgumentError, "missing component" if @arguments.size == 0
|
155
|
-
component = 'res'
|
156
187
|
|
157
|
-
case component
|
158
|
-
when 'resource', 'res'
|
159
|
-
@drbdset.each do |r,resource|
|
160
|
-
puts resource.to_s
|
161
|
-
end
|
188
|
+
case @action_arguments[:component]
|
162
189
|
when 'version'
|
163
190
|
puts @drbdset.version
|
191
|
+
else
|
192
|
+
resource_name_re = @action_arguments[:component].nil? ? /.*/ : /^#{@action_arguments[:component]}$/
|
193
|
+
@drbdset.each do |r,resource|
|
194
|
+
puts resource.to_s if resource.name =~ resource_name_re
|
195
|
+
end
|
164
196
|
end
|
165
197
|
end
|
166
198
|
|
@@ -196,7 +228,7 @@ module Dribbled
|
|
196
228
|
plugin_status = :warning
|
197
229
|
plugin_output += res.percent.nil? ? " #{res.id}:#{po_cstate};#{po_dstate}" : " #{res.id}:#{po_cstate}[#{res.percent}%,#{res.finish}];#{po_dstate}"
|
198
230
|
elsif not res.in_configuration?
|
199
|
-
plugin_status = :
|
231
|
+
plugin_status = :warning
|
200
232
|
plugin_output += " #{res.id}[unconfigured]>#{po_cstate}/;#{po_dstate}"
|
201
233
|
else
|
202
234
|
plugin_output += " #{res.id}>#{po_cstate};#{po_dstate}"
|
@@ -233,6 +265,25 @@ module Dribbled
|
|
233
265
|
File.open(xmldump_file, 'w') {|f| f.write(@drbdset.resources_cfg_raw) }
|
234
266
|
end
|
235
267
|
|
268
|
+
def run_watch
|
269
|
+
begin
|
270
|
+
count = @action_arguments[:count]
|
271
|
+
loop do
|
272
|
+
@drbdset = DrbdSet.new @global_options
|
273
|
+
@drbdset.each do |r,resource|
|
274
|
+
if resource.cstate =~ /#{@action_options[:cstate]}/ or resource.dstate =~ /#{@action_options[:dstate]}/ or resource.name == @action_options[:resource]
|
275
|
+
puts resource
|
276
|
+
end
|
277
|
+
end
|
278
|
+
count -= 1
|
279
|
+
break if count == 0
|
280
|
+
sleep(@action_arguments[:interval])
|
281
|
+
end
|
282
|
+
rescue Interrupt => e
|
283
|
+
exit 0
|
284
|
+
end
|
285
|
+
end
|
286
|
+
|
236
287
|
def output_message(message, exitstatus=nil)
|
237
288
|
m = (! exitstatus.nil? and exitstatus > 0) ? "%s: error: %s" % [ID, message] : message
|
238
289
|
Syslog.open(ID.to_s, Syslog::LOG_PID | Syslog::LOG_CONS) { |s| s.err "error: #{message}" } unless @global_options[:debug]
|
data/lib/dribbled/drbd.rb
CHANGED
data/lib/dribbled/version.rb
CHANGED
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.
|
4
|
+
version: 0.8.0
|
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-
|
12
|
+
date: 2012-11-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: xml-simple
|