zabcon 0.0.5 → 0.0.6
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/libs/argument_processor.rb +42 -27
- data/libs/command_help.rb +2 -2
- data/libs/command_tree.rb +2 -2
- data/libs/help.xml +13 -2
- data/libs/input.rb +2 -2
- data/libs/printer.rb +2 -2
- data/libs/zabcon_core.rb +18 -19
- data/libs/zabcon_exceptions.rb +2 -2
- data/libs/zabcon_globals.rb +2 -2
- data/libs/zbxcliserver.rb +18 -3
- data/zabcon.rb +3 -2
- metadata +7 -6
data/libs/argument_processor.rb
CHANGED
@@ -18,8 +18,8 @@
|
|
18
18
|
|
19
19
|
##########################################
|
20
20
|
# Subversion information
|
21
|
-
# $Id: argument_processor.rb
|
22
|
-
# $Revision:
|
21
|
+
# $Id: argument_processor.rb 281 2011-04-06 18:10:16Z nelsonab $
|
22
|
+
# $Revision: 281 $
|
23
23
|
##########################################
|
24
24
|
|
25
25
|
require 'libs/zdebug'
|
@@ -315,7 +315,7 @@ class ArgumentProcessor
|
|
315
315
|
debug(7,args,"default helper")
|
316
316
|
api_params = args
|
317
317
|
show_params = {}
|
318
|
-
if !args["show"].nil?
|
318
|
+
if args.class!=Array && !args["show"].nil?
|
319
319
|
show_params={:show=>args["show"]}
|
320
320
|
api_params.delete("show")
|
321
321
|
api_params.merge({"extendoutput"=>true})
|
@@ -328,28 +328,52 @@ class ArgumentProcessor
|
|
328
328
|
# The default processor also checks the incoming parameters against a list of valid arguments, and merges
|
329
329
|
# the user variables with the inbound arguments with the inbound arguments taking precedence, raises an
|
330
330
|
# exception if there is an error
|
331
|
+
# If :use_array_processor is passed as an option the array processor will be used
|
332
|
+
# In :num_args is passed with a value, and error will be returned if more than that many args are passed
|
333
|
+
|
331
334
|
def default_processor(help_func,valid_args,args,user_vars,*options)
|
332
|
-
debug(
|
335
|
+
debug(5,args,"default_processor args")
|
336
|
+
debug(5,options,"default_processor options")
|
333
337
|
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
338
|
+
#if the intersection of options and [:array] is not empty then we will return an array
|
339
|
+
return_array = !(options[0] & [:use_array_processor]).empty?
|
340
|
+
check_not_empty = !(options[0] & [:not_empty]).empty?
|
341
|
+
|
342
|
+
num_args=options[0].map { |i|
|
343
|
+
i[:num_args] if i.class==Hash
|
344
|
+
}.compact[0] # will be nil if :num_args not found
|
345
|
+
|
346
|
+
if check_not_empty
|
347
|
+
raise ParameterError.new("No arguments",:retry=>true, :help_func=>help_func) if args==""
|
340
348
|
end
|
341
349
|
|
342
|
-
|
350
|
+
if return_array
|
351
|
+
args=safe_split(args)
|
352
|
+
else
|
353
|
+
args=substitute_vars(args)
|
354
|
+
args=params_to_hash(args)
|
355
|
+
if !(invalid=check_parameters(args, valid_args)).empty?
|
356
|
+
msg="Invalid parameters:\n"
|
357
|
+
msg+=invalid.join(", ")
|
358
|
+
raise ParameterError_Invalid.new(msg,:retry=>true, :help_func=>help_func)
|
359
|
+
end
|
343
360
|
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
361
|
+
valid_user_vars = {}
|
362
|
+
|
363
|
+
if !valid_args.nil?
|
364
|
+
valid_args.each {|item|
|
365
|
+
valid_user_vars[item]=user_vars[item] if !user_vars[item].nil?
|
366
|
+
}
|
367
|
+
end
|
368
|
+
args = valid_user_vars.merge(args)
|
369
|
+
end
|
370
|
+
|
371
|
+
if !num_args.nil?
|
372
|
+
eval_exp="#{args.length}#{num_args}"
|
373
|
+
raise ParameterError.new("Too many arguments (#{args.length})",:retry=>true, :help_func=>help_func) if !eval(eval_exp)
|
348
374
|
end
|
349
|
-
args = valid_user_vars.merge(args)
|
350
|
-
|
351
|
-
default_helper(args)
|
352
375
|
|
376
|
+
default_helper(args)
|
353
377
|
end
|
354
378
|
|
355
379
|
# This processor does not do anything fancy. All items passed in via args are passed back in api_params
|
@@ -437,15 +461,6 @@ class ArgumentProcessor
|
|
437
461
|
end
|
438
462
|
end
|
439
463
|
|
440
|
-
# array_process is a helper function which takes the incoming arguments
|
441
|
-
# and puts them into an array and returns that result.
|
442
|
-
# empty input results in an empty array
|
443
|
-
# does not perform variable substitution
|
444
|
-
def array_processor(help_func,valid_args,args,user_vars,*options)
|
445
|
-
|
446
|
-
return_helper(safe_split(args))
|
447
|
-
end
|
448
|
-
|
449
464
|
##############################################################################################
|
450
465
|
# End of default and helper functions
|
451
466
|
##############################################################################################
|
data/libs/command_help.rb
CHANGED
@@ -18,8 +18,8 @@
|
|
18
18
|
|
19
19
|
##########################################
|
20
20
|
# Subversion information
|
21
|
-
# $Id: command_help.rb
|
22
|
-
# $Revision:
|
21
|
+
# $Id: command_help.rb 274 2011-01-10 01:01:31Z nelsonab $
|
22
|
+
# $Revision: 274 $
|
23
23
|
##########################################
|
24
24
|
|
25
25
|
require 'libs/zdebug'
|
data/libs/command_tree.rb
CHANGED
@@ -18,8 +18,8 @@
|
|
18
18
|
|
19
19
|
##########################################
|
20
20
|
# Subversion information
|
21
|
-
# $Id: command_tree.rb
|
22
|
-
# $Revision:
|
21
|
+
# $Id: command_tree.rb 272 2011-01-06 21:04:22Z nelsonab $
|
22
|
+
# $Revision: 272 $
|
23
23
|
##########################################
|
24
24
|
|
25
25
|
require 'libs/zdebug'
|
data/libs/help.xml
CHANGED
@@ -21,8 +21,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
21
21
|
|
22
22
|
##########################################
|
23
23
|
Subversion information
|
24
|
-
$Id: help.xml
|
25
|
-
$Revision:
|
24
|
+
$Id: help.xml 281 2011-04-06 18:10:16Z nelsonab $
|
25
|
+
$Revision: 281 $
|
26
26
|
##########################################
|
27
27
|
|
28
28
|
Zabcon help file
|
@@ -246,6 +246,17 @@ syntax: delete item itemid=num
|
|
246
246
|
itemid must be a number
|
247
247
|
</item>
|
248
248
|
|
249
|
+
<!-- 80 Col Marker ######################################################## -->
|
250
|
+
|
251
|
+
<item command="import">
|
252
|
+
import
|
253
|
+
syntax: import <filename>
|
254
|
+
|
255
|
+
Import an XML file into Zabbix. Requires one file name to be passed.
|
256
|
+
An error will be returned for 0 or 2+ arguments passed.
|
257
|
+
</item>
|
258
|
+
|
259
|
+
|
249
260
|
<!-- 80 Col Marker ######################################################## -->
|
250
261
|
|
251
262
|
<item command="raw_api">
|
data/libs/input.rb
CHANGED
@@ -18,8 +18,8 @@
|
|
18
18
|
|
19
19
|
##########################################
|
20
20
|
# Subversion information
|
21
|
-
# $Id: input.rb
|
22
|
-
# $Revision:
|
21
|
+
# $Id: input.rb 272 2011-01-06 21:04:22Z nelsonab $
|
22
|
+
# $Revision: 272 $
|
23
23
|
##########################################
|
24
24
|
|
25
25
|
require 'readline'
|
data/libs/printer.rb
CHANGED
@@ -19,8 +19,8 @@
|
|
19
19
|
|
20
20
|
##########################################
|
21
21
|
# Subversion information
|
22
|
-
# $Id: printer.rb
|
23
|
-
# $Revision:
|
22
|
+
# $Id: printer.rb 272 2011-01-06 21:04:22Z nelsonab $
|
23
|
+
# $Revision: 272 $
|
24
24
|
##########################################
|
25
25
|
|
26
26
|
require 'libs/zdebug'
|
data/libs/zabcon_core.rb
CHANGED
@@ -21,7 +21,7 @@
|
|
21
21
|
##########################################
|
22
22
|
# Subversion information
|
23
23
|
# $Id: $
|
24
|
-
# $Revision:
|
24
|
+
# $Revision: 281 $
|
25
25
|
##########################################
|
26
26
|
|
27
27
|
require 'parseconfig'
|
@@ -123,16 +123,17 @@ class ZabconCore
|
|
123
123
|
@commands.insert ["set","pause"], self.method(:set_pause),no_args,no_help,no_verify,:suppress_printer
|
124
124
|
@commands.insert ["set","var"], self.method(:set_var), no_args, no_help, @arg_processor.method(:simple_processor),:suppress_printer
|
125
125
|
@commands.insert ["set","env"], self.method(:set_env), no_args, no_help, @arg_processor.method(:simple_processor), :suppress_printer
|
126
|
-
@commands.insert ["show","var"], self.method(:show_var), no_args, no_help, @arg_processor.
|
127
|
-
@commands.insert ["show","env"], self.method(:show_env), no_args, no_help, @arg_processor.
|
128
|
-
@commands.insert ["unset","var"], self.method(:unset_var), no_args, no_help, @arg_processor.
|
126
|
+
@commands.insert ["show","var"], self.method(:show_var), no_args, no_help, @arg_processor.default, :use_array_processor, :suppress_printer
|
127
|
+
@commands.insert ["show","env"], self.method(:show_env), no_args, no_help, @arg_processor.default, :use_array_processor, :suppress_printer
|
128
|
+
@commands.insert ["unset","var"], self.method(:unset_var), no_args, no_help, @arg_processor.default, :use_array_processor, :suppress_printer
|
129
129
|
|
130
130
|
|
131
131
|
if loggedin then
|
132
132
|
debug(5,"Inserting commands which require login")
|
133
133
|
# This command tree is for a valid login
|
134
134
|
@commands.insert ["get"], no_cmd, no_args, @cmd_help.method(:get)
|
135
|
-
|
135
|
+
#Import commented out until fixed
|
136
|
+
#@commands.insert ["import"], self.method(:do_import),no_args,@cmd_help.method(:import),@arg_processor.default,:not_empty, :use_array_processor, :num_args=>"==1"
|
136
137
|
|
137
138
|
@commands.insert ["add","app"], @server.method(:addapp),no_args,no_help,no_verify
|
138
139
|
@commands.insert ["add","app","id"], @server.method(:getappid),no_args,no_help,no_verify
|
@@ -265,7 +266,7 @@ class ZabconCore
|
|
265
266
|
puts "A fatal error occurred."
|
266
267
|
end
|
267
268
|
e.show_message
|
268
|
-
e.show_backtrace
|
269
|
+
# e.show_backtrace
|
269
270
|
retry if e.retry?
|
270
271
|
end #end of exception block
|
271
272
|
end # def
|
@@ -441,31 +442,29 @@ class ZabconCore
|
|
441
442
|
# Import config from an XML file:
|
442
443
|
#
|
443
444
|
def do_import(input)
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
end
|
445
|
+
debug(5,input,"args")
|
446
|
+
|
447
|
+
input=input[0]
|
448
448
|
|
449
449
|
begin
|
450
|
-
xml_import = REXML::Document.new
|
450
|
+
xml_import = REXML::Document.new(File.new(input)).root
|
451
451
|
rescue Errno::ENOENT
|
452
|
-
|
453
|
-
return
|
452
|
+
raise ZabconError.new("Failed to open import file #{input}.",:retry=>true)
|
454
453
|
end
|
455
454
|
|
456
455
|
if xml_import.nil?
|
457
|
-
|
458
|
-
return
|
456
|
+
raise ZabconError.new("Failed to parse import file #{input}.",:retry=>true)
|
459
457
|
end
|
460
458
|
|
461
|
-
|
462
|
-
|
463
|
-
|
459
|
+
p hosts=xml_import.elements.to_a("//hosts")[0]
|
460
|
+
p hosts = hosts.elements.to_a("//host")
|
461
|
+
if !hosts.empty?
|
462
|
+
host = hosts[0]
|
464
463
|
end
|
465
464
|
|
466
465
|
# Loop for the host tags:
|
467
466
|
while !host.nil?
|
468
|
-
host_params = { 'host' => host.attributes["name"],
|
467
|
+
p host_params = { 'host' => host.attributes["name"],
|
469
468
|
'port' => host.elements["port"].text }
|
470
469
|
if host.elements["useip"].text.to_i == 0 # This is broken in Zabbix export (always 0).
|
471
470
|
host_params['dns']=host.elements["dns"].text
|
data/libs/zabcon_exceptions.rb
CHANGED
@@ -18,8 +18,8 @@
|
|
18
18
|
|
19
19
|
##########################################
|
20
20
|
# Subversion information
|
21
|
-
# $Id: zabcon_exceptions.rb
|
22
|
-
# $Revision:
|
21
|
+
# $Id: zabcon_exceptions.rb 272 2011-01-06 21:04:22Z nelsonab $
|
22
|
+
# $Revision: 272 $
|
23
23
|
##########################################
|
24
24
|
|
25
25
|
#------------------------------------------------------------------------------
|
data/libs/zabcon_globals.rb
CHANGED
@@ -18,8 +18,8 @@
|
|
18
18
|
|
19
19
|
##########################################
|
20
20
|
# Subversion information
|
21
|
-
# $Id: zabcon_globals.rb
|
22
|
-
# $Revision:
|
21
|
+
# $Id: zabcon_globals.rb 272 2011-01-06 21:04:22Z nelsonab $
|
22
|
+
# $Revision: 272 $
|
23
23
|
##########################################
|
24
24
|
|
25
25
|
#------------------------------------------------------------------------------
|
data/libs/zbxcliserver.rb
CHANGED
@@ -18,14 +18,29 @@
|
|
18
18
|
|
19
19
|
##########################################
|
20
20
|
# Subversion information
|
21
|
-
# $Id: zbxcliserver.rb
|
22
|
-
# $Revision:
|
21
|
+
# $Id: zbxcliserver.rb 281 2011-04-06 18:10:16Z nelsonab $
|
22
|
+
# $Revision: 281 $
|
23
23
|
##########################################
|
24
24
|
|
25
25
|
require 'zbxapi'
|
26
26
|
require 'libs/zdebug'
|
27
27
|
require 'libs/zabcon_globals'
|
28
28
|
|
29
|
+
class ZabbixServer < ZabbixAPI
|
30
|
+
alias zbxapi_initialize initialize
|
31
|
+
alias zbxapi_do_request do_request
|
32
|
+
|
33
|
+
def initialize(url,debug_level=0)
|
34
|
+
@env = EnvVars.instance
|
35
|
+
zbxapi_initialize(url,debug_level)
|
36
|
+
end
|
37
|
+
|
38
|
+
#truncate_length is set to the symbol :not_used as do_request is passed a different variable
|
39
|
+
def do_request(json_obj,truncate_length=:not_used)
|
40
|
+
zbxapi_do_request(json_obj,@env["truncate_length"])
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
29
44
|
class ZbxCliServer
|
30
45
|
|
31
46
|
include ZDebug
|
@@ -38,7 +53,7 @@ class ZbxCliServer
|
|
38
53
|
@password=password
|
39
54
|
@debuglevel=debuglevel
|
40
55
|
# *Note* Do not rescue errors here, rescue in function that calls this block
|
41
|
-
@server=
|
56
|
+
@server=ZabbixServer.new(@server_url,@debuglevel)
|
42
57
|
@server.login(@user, @password)
|
43
58
|
GlobalVars.instance["auth"]=@server.auth
|
44
59
|
end
|
data/zabcon.rb
CHANGED
@@ -20,8 +20,8 @@
|
|
20
20
|
|
21
21
|
##########################################
|
22
22
|
# Subversion information
|
23
|
-
# $Id: zabcon.rb
|
24
|
-
# $Revision:
|
23
|
+
# $Id: zabcon.rb 281 2011-04-06 18:10:16Z nelsonab $
|
24
|
+
# $Revision: 281 $
|
25
25
|
##########################################
|
26
26
|
|
27
27
|
|
@@ -122,6 +122,7 @@ class ZabconApp
|
|
122
122
|
env["echo"]=STDIN.tty? ? true: false
|
123
123
|
env["config_file"]=:default
|
124
124
|
env["load_config"]=true
|
125
|
+
env["truncate_length"]=5000
|
125
126
|
|
126
127
|
#output related environment variables
|
127
128
|
env["table_output"]=STDIN.tty? # Is the output a well formatted table, or csv like?
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zabcon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 6
|
10
|
+
version: 0.0.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- A. Nelson
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: .
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-04-06 00:00:00 -04:00
|
19
19
|
default_executable: zabcon
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -26,11 +26,12 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
hash:
|
29
|
+
hash: 25
|
30
30
|
segments:
|
31
31
|
- 0
|
32
32
|
- 1
|
33
|
-
|
33
|
+
- 1
|
34
|
+
version: 0.1.1
|
34
35
|
type: :runtime
|
35
36
|
version_requirements: *id001
|
36
37
|
- !ruby/object:Gem::Dependency
|