zabcon 0.0.6 → 0.0.327

Sign up to get free protection for your applications and to get access to all the features.
@@ -18,8 +18,8 @@
18
18
 
19
19
  ##########################################
20
20
  # Subversion information
21
- # $Id: zabcon_globals.rb 272 2011-01-06 21:04:22Z nelsonab $
22
- # $Revision: 272 $
21
+ # $Id: zabcon_globals.rb 325 2011-09-26 08:57:00Z nelsonab $
22
+ # $Revision: 325 $
23
23
  ##########################################
24
24
 
25
25
  #------------------------------------------------------------------------------
@@ -30,11 +30,34 @@
30
30
  #
31
31
  #------------------------------------------------------------------------------
32
32
 
33
- require 'libs/zdebug'
33
+ require 'zbxapi/zdebug'
34
34
 
35
35
  require 'singleton'
36
36
  require 'parseconfig'
37
37
 
38
+ #This class is for containing responses from the Command tree
39
+ class Response
40
+
41
+ class InvalidType < Exception
42
+ end
43
+
44
+ attr_accessor :data #response data
45
+ attr_accessor :message
46
+ attr_reader :type
47
+
48
+ def initialize(val=nil, data_class=nil)
49
+ data=val
50
+ @type=nil
51
+ @message=nil
52
+ end
53
+
54
+ def type=(type)
55
+ raise InvalidType.new("Response.type must be a symbol") if type.class!=Symbol
56
+ @type=type
57
+ end
58
+ end
59
+
60
+
38
61
  # This class is for storing global variables. This is accomplished by inheriting
39
62
  # the singleton class. To use a global variable it must be registered and then
40
63
  # if some part of the program needs to be notified of a change a notifier can
@@ -50,7 +73,7 @@ class GlobalsBase
50
73
 
51
74
  # overload the assignment operator
52
75
  def []=(key,val)
53
- debug(9,[key,val],"Entering []= (key,val)",nil,true)
76
+ debug(9,:var=>[key,val],:msg=>"Entering []= (key,val)",:overload=>true)
54
77
  if val.nil?
55
78
  delete(key) if !@hash[key].nil?
56
79
  else
@@ -70,7 +93,7 @@ class GlobalsBase
70
93
 
71
94
  # overload the array operator
72
95
  def [](key)
73
- debug(9,key,"Entering [] (key)",nil,true)
96
+ debug(9,:var=>key,:msg=>"Entering [] (key)",:overload=>true)
74
97
  if @hash[key].nil?
75
98
  return nil
76
99
  else
@@ -92,7 +115,7 @@ class GlobalsBase
92
115
 
93
116
  # Register a function to be called when the value of key changes.
94
117
  def register_notifier(key,proc)
95
- debug(9,[key,proc],"Entering register_notifier (key,proc)")
118
+ debug(9,:var=>[key,proc],:msg=>"Entering register_notifier (key,proc)")
96
119
  if @callbacks[key].nil?
97
120
  @callbacks[key]=[proc]
98
121
  else
data/zabcon.conf.default CHANGED
@@ -1,6 +1,41 @@
1
1
  server=http://localhost
2
2
  username=admin
3
3
  password=zabbix
4
- lines=24
5
- debug=0
6
- language=english
4
+
5
+ # The following is a list of user editable config file options, the following
6
+ # values are the defaults. These can be changed as needed.
7
+
8
+ # Set the debug level. 0=off
9
+ #debug=0
10
+
11
+ # Attempt to show help for a bad command.
12
+ #show_help=false
13
+
14
+ # How many lines to print when running interactively before pausing output
15
+ #lines=24
16
+
17
+ # The default language
18
+ #language="english"
19
+
20
+ # When debugging api calls, how many characters in the output from the Zabbix
21
+ # server should be displayed before truncation occurs? When the truncation
22
+ # limit is reached the output is split into two. The first n/2 characters
23
+ # are printed followed by " ... " then the last n/2 characters are displayed.
24
+ # 0 = do not truncate
25
+ #truncate_length=5000
26
+
27
+ #output related environment variables
28
+
29
+ # Are we displaying a well formatted table or csv? Zabcon will automatically
30
+ # set this variable to true for intaractive use.
31
+ # true = table false = csv
32
+ #table_output=true
33
+
34
+ # Print the table header?
35
+ #table_header=true
36
+
37
+ # The default seperator character for csv output.
38
+ #table_separator=","
39
+
40
+ # File to store custom commands
41
+ #custom_commands=sample_custom_commands
data/zabcon.rb CHANGED
@@ -20,11 +20,10 @@
20
20
 
21
21
  ##########################################
22
22
  # Subversion information
23
- # $Id: zabcon.rb 281 2011-04-06 18:10:16Z nelsonab $
24
- # $Revision: 281 $
23
+ # $Id: zabcon.rb 325 2011-09-26 08:57:00Z nelsonab $
24
+ # $Revision: 325 $
25
25
  ##########################################
26
26
 
27
-
28
27
  #setup our search path or libraries
29
28
  ZABCON_PATH=File.expand_path(File.join(File.dirname(__FILE__), '.'))
30
29
 
@@ -38,9 +37,60 @@ rescue LoadError
38
37
  exit 1
39
38
  end
40
39
 
40
+ REQUIRED_RUBY_VER="1.8.6"
41
+ DEPENDENCIES={
42
+ "parseconfig"=>true,
43
+ "json"=>true,
44
+ "highline"=>true,
45
+ "zbxapi"=>Gem::Version.new("0.1.294")
46
+ }
47
+
48
+
49
+ required_rev=REQUIRED_RUBY_VER.split('.')
50
+ ruby_rev=RUBY_VERSION.split('.')
51
+ items=ruby_rev.length < required_rev.length ? ruby_rev.length : required_rev.length
52
+
53
+ for i in 0..items-1 do
54
+ if ruby_rev[i].to_i<required_rev[i].to_i
55
+ puts
56
+ puts "Zabcon requires Ruby version #{required_rev.join('.')} or higher."
57
+ puts "you are using Ruby version #{RUBY_VERSION}."
58
+ puts
59
+ exit(1)
60
+ end
61
+ end
62
+
63
+
64
+ depsok=true #assume we will not fail dependencies
65
+
66
+ DEPENDENCIES.each_key {|dep|
67
+ gem=Gem.source_index.find_name(dep)
68
+ if gem.empty?
69
+ puts " #{dep} : Not Installed"
70
+ depsok=false
71
+ break
72
+ end
73
+ gem=gem[0]
74
+ if DEPENDENCIES[dep].class==Gem::Version && gem.version<DEPENDENCIES[dep]
75
+ puts "#{dep} needs to be at least version #{DEPENDENCIES[dep]}, found #{gem.version}"
76
+ depsok=false
77
+ end
78
+ }
79
+ if !depsok
80
+ puts
81
+ puts "One or more dependencies failed"
82
+ puts "Please see the dependencies file for instructions on installing the"
83
+ puts "required dependencies"
84
+ puts
85
+ exit(1)
86
+ end
87
+
88
+ require 'libs/utility_items'
89
+ require 'libs/revision'
41
90
  require 'optparse'
42
91
  require 'ostruct'
43
- require 'libs/zdebug'
92
+ require 'strscan'
93
+ require 'zbxapi/zdebug'
44
94
  require 'libs/zabcon_globals'
45
95
 
46
96
  if RUBY_VERSION=="1.8.6" #Ruby 1.8.6 lacks the each_char function in the string object, so we add it here
@@ -57,7 +107,6 @@ if RUBY_VERSION=="1.8.6" #Ruby 1.8.6 lacks the each_char function in the string
57
107
  end
58
108
  end
59
109
 
60
-
61
110
  class ZabconApp
62
111
 
63
112
  def initialize
@@ -107,7 +156,7 @@ class ZabconApp
107
156
  end
108
157
 
109
158
  def setup_globals
110
- env=EnvVars.instance # we must instantiate a singleton before using it
159
+ # env=EnvVars.instance # we must instantiate a singleton before using it
111
160
  vars=GlobalVars.instance
112
161
 
113
162
  env["debug"]=0
@@ -123,6 +172,7 @@ class ZabconApp
123
172
  env["config_file"]=:default
124
173
  env["load_config"]=true
125
174
  env["truncate_length"]=5000
175
+ env["custom_commands"]=nil
126
176
 
127
177
  #output related environment variables
128
178
  env["table_output"]=STDIN.tty? # Is the output a well formatted table, or csv like?
@@ -135,46 +185,6 @@ class ZabconApp
135
185
  # exit code of 1 if the dependency check fails
136
186
  # * ruby_rev is a string denoting the minimum version of ruby suitable
137
187
  # * *dependencies is an array of libraries which are required
138
- def check_dependencies(required_rev,*dependencies)
139
- puts "Checking dependencies" if EnvVars.instance["echo"]
140
- depsok=true #assume we will not fail dependencies
141
-
142
- required_rev=required_rev.split('.')
143
- ruby_rev=RUBY_VERSION.split('.')
144
- items=ruby_rev.length < required_rev.length ? ruby_rev.length : required_rev.length
145
-
146
- for i in 0..items-1 do
147
- if ruby_rev[i].to_i<required_rev[i].to_i
148
- puts
149
- puts "Zabcon requires Ruby version #{required_rev.join('.')} or higher."
150
- puts "you are using Ruby version #{RUBY_VERSION}."
151
- puts
152
- exit(1)
153
- elsif ruby_rev[i].to_i>required_rev[i].to_i
154
- break
155
- end
156
- end
157
-
158
- #Convert the inbound array to a hash
159
- deps = Hash[*dependencies.collect { |v|
160
- [v,true]
161
- }.flatten]
162
-
163
- deps.each_key {|dep|
164
- val=Gem.source_index.find_name(dep).map {|x| x.name}==[]
165
- puts " #{dep} : Not Installed" if val
166
- depsok=false if val
167
- }
168
- if !depsok
169
- puts
170
- puts "One or more dependencies failed"
171
- puts "Please see the dependencies file for instructions on installing the"
172
- puts "required dependencies"
173
- puts
174
- exit(1)
175
- end
176
- end
177
-
178
188
 
179
189
  def run
180
190
  begin
@@ -208,8 +218,6 @@ class ZabconApp
208
218
 
209
219
  puts RUBY_PLATFORM if EnvVars.instance["echo"]
210
220
 
211
- check_dependencies("1.8.6","parseconfig", "json", "highline")
212
-
213
221
  begin
214
222
  require 'readline'
215
223
  rescue LoadError
@@ -235,5 +243,19 @@ class ZabconApp
235
243
  end
236
244
  end
237
245
 
238
- zabconapp=ZabconApp.new()
239
- zabconapp.run()
246
+ begin
247
+ zabconapp=ZabconApp.new()
248
+ zabconapp.run()
249
+ rescue Exception => e
250
+ puts "Runtime error detected"
251
+ puts "(#{e.class}): #{e.message}"
252
+ puts
253
+ puts "Top 10 items in backtrace"
254
+ n=1
255
+ e.backtrace.first(10).each {|i|
256
+ puts "#{n}: #{i}"
257
+ n+=1
258
+ }
259
+ end
260
+
261
+
metadata CHANGED
@@ -1,13 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zabcon
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 0
9
- - 6
10
- version: 0.0.6
4
+ version: 0.0.327
11
5
  platform: ruby
12
6
  authors:
13
7
  - A. Nelson
@@ -15,53 +9,39 @@ autorequire:
15
9
  bindir: .
16
10
  cert_chain: []
17
11
 
18
- date: 2011-04-06 00:00:00 -04:00
12
+ date: 2011-09-26 00:00:00 -04:00
19
13
  default_executable: zabcon
20
14
  dependencies:
21
15
  - !ruby/object:Gem::Dependency
22
16
  name: zbxapi
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
25
- none: false
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
26
20
  requirements:
27
21
  - - ">="
28
22
  - !ruby/object:Gem::Version
29
- hash: 25
30
- segments:
31
- - 0
32
- - 1
33
- - 1
34
- version: 0.1.1
35
- type: :runtime
36
- version_requirements: *id001
23
+ version: 0.1.324
24
+ version:
37
25
  - !ruby/object:Gem::Dependency
38
26
  name: parseconfig
39
- prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
41
- none: false
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
42
30
  requirements:
43
31
  - - ">="
44
32
  - !ruby/object:Gem::Version
45
- hash: 3
46
- segments:
47
- - 0
48
33
  version: "0"
49
- type: :runtime
50
- version_requirements: *id002
34
+ version:
51
35
  - !ruby/object:Gem::Dependency
52
36
  name: highline
53
- prerelease: false
54
- requirement: &id003 !ruby/object:Gem::Requirement
55
- none: false
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
56
40
  requirements:
57
41
  - - ">="
58
42
  - !ruby/object:Gem::Version
59
- hash: 3
60
- segments:
61
- - 0
62
43
  version: "0"
63
- type: :runtime
64
- version_requirements: *id003
44
+ version:
65
45
  description: Zabcon is a command line interface for Zabbix written in Ruby
66
46
  email: nelsonab@red-tux.net
67
47
  executables:
@@ -75,16 +55,19 @@ files:
75
55
  - zabcon.conf.default
76
56
  - README
77
57
  - libs/argument_processor.rb
58
+ - libs/revision.rb
78
59
  - libs/command_help.rb
79
60
  - libs/command_tree.rb
80
61
  - libs/help.xml
81
62
  - libs/input.rb
63
+ - libs/lexer.rb
82
64
  - libs/printer.rb
65
+ - libs/zabcon_commands.rb
83
66
  - libs/zabcon_core.rb
84
67
  - libs/zabcon_exceptions.rb
85
68
  - libs/zabcon_globals.rb
86
- - libs/zbxcliserver.rb
87
- - ./zabcon.rb
69
+ - libs/zabbix_server.rb
70
+ - libs/utility_items.rb
88
71
  has_rdoc: true
89
72
  homepage: http://trac.red-tux.net/
90
73
  licenses:
@@ -95,29 +78,21 @@ rdoc_options: []
95
78
  require_paths:
96
79
  - .
97
80
  required_ruby_version: !ruby/object:Gem::Requirement
98
- none: false
99
81
  requirements:
100
82
  - - ">="
101
83
  - !ruby/object:Gem::Version
102
- hash: 59
103
- segments:
104
- - 1
105
- - 8
106
- - 6
107
84
  version: 1.8.6
85
+ version:
108
86
  required_rubygems_version: !ruby/object:Gem::Requirement
109
- none: false
110
87
  requirements:
111
88
  - - ">="
112
89
  - !ruby/object:Gem::Version
113
- hash: 3
114
- segments:
115
- - 0
116
90
  version: "0"
91
+ version:
117
92
  requirements:
118
93
  - Requires zbxapi, parseconfig and highline
119
94
  rubyforge_project: zabcon
120
- rubygems_version: 1.3.7
95
+ rubygems_version: 1.3.5
121
96
  signing_key:
122
97
  specification_version: 3
123
98
  summary: Zabcon command line interface for Zabbix