zabcon 0.0.4 → 0.0.5

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/command_help.rb CHANGED
@@ -36,7 +36,7 @@ class CommandHelp
36
36
  include ZDebug
37
37
 
38
38
  def initialize(language)
39
- @file = File.new("libs/help.xml")
39
+ @file = File.new(ZABCON_PATH+"/libs/help.xml")
40
40
 
41
41
  @doc=REXML::Document.new(@file).elements["//help[@language='#{language}']"]
42
42
  # puts @doc.root.attributes
data/libs/printer.rb CHANGED
@@ -19,8 +19,8 @@
19
19
 
20
20
  ##########################################
21
21
  # Subversion information
22
- # $Id: printer.rb 258 2010-12-28 22:49:21Z nelsonab $
23
- # $Revision: 258 $
22
+ # $Id: printer.rb 269 2011-01-02 19:14:58Z richlv $
23
+ # $Revision: 269 $
24
24
  ##########################################
25
25
 
26
26
  require 'libs/zdebug'
@@ -357,7 +357,7 @@ class OutputPrinter
357
357
  elsif dataset[:result].class==Hash then
358
358
  print_hash(dataset,cols_to_show)
359
359
  elsif dataset[:result].class!=NilClass then
360
- puts "Unknown object received by the print routint"
360
+ puts "Unknown object received by the print routine"
361
361
  puts "Class type: #{dataset[:result].class}"
362
362
  puts "Data:"
363
363
  p dataset[:result]
data/libs/zabcon_core.rb CHANGED
@@ -31,7 +31,7 @@ require 'libs/zbxcliserver'
31
31
  require 'libs/printer'
32
32
  require 'libs/zdebug'
33
33
  require 'libs/input'
34
- require 'libs/defines'
34
+ #require 'libs/defines'
35
35
  require 'libs/command_tree'
36
36
  require 'libs/argument_processor'
37
37
  require 'libs/command_help'
data/zabcon.rb CHANGED
@@ -20,13 +20,13 @@
20
20
 
21
21
  ##########################################
22
22
  # Subversion information
23
- # $Id: zabcon.rb 264 2010-12-30 07:21:01Z nelsonab $
24
- # $Revision: 264 $
23
+ # $Id: zabcon.rb 272 2011-01-06 21:04:22Z nelsonab $
24
+ # $Revision: 272 $
25
25
  ##########################################
26
26
 
27
27
 
28
28
  #setup our search path or libraries
29
- $: << File.expand_path(File.join(File.dirname(__FILE__), '.'))
29
+ ZABCON_PATH=File.expand_path(File.join(File.dirname(__FILE__), '.'))
30
30
 
31
31
  begin
32
32
  require 'rubygems'
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: 23
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 4
10
- version: 0.0.4
9
+ - 5
10
+ version: 0.0.5
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-01-06 00:00:00 -05:00
18
+ date: 2011-01-09 00:00:00 -05:00
19
19
  default_executable: zabcon
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -76,8 +76,6 @@ files:
76
76
  - libs/argument_processor.rb
77
77
  - libs/command_help.rb
78
78
  - libs/command_tree.rb
79
- - libs/defines.rb
80
- - libs/exceptions.rb
81
79
  - libs/help.xml
82
80
  - libs/input.rb
83
81
  - libs/printer.rb
@@ -85,7 +83,6 @@ files:
85
83
  - libs/zabcon_exceptions.rb
86
84
  - libs/zabcon_globals.rb
87
85
  - libs/zbxcliserver.rb
88
- - libs/zdebug.rb
89
86
  - ./zabcon.rb
90
87
  has_rdoc: true
91
88
  homepage: http://trac.red-tux.net/
data/libs/defines.rb DELETED
@@ -1,46 +0,0 @@
1
- #!/usr/bin/ruby
2
-
3
- #GPL 2.0 http://www.gnu.org/licenses/gpl-2.0.html
4
- #Zabbix CLI Tool and associated files
5
- #Copyright (C) 2009,2010 Andrew Nelson nelsonab(at)red-tux(dot)net
6
- #
7
- #This program is free software; you can redistribute it and/or
8
- #modify it under the terms of the GNU General Public License
9
- #as published by the Free Software Foundation; either version 2
10
- #of the License, or (at your option) any later version.
11
- #
12
- #This program is distributed in the hope that it will be useful,
13
- #but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
- #GNU General Public License for more details.
16
- #
17
- #You should have received a copy of the GNU General Public License
18
- #along with this program; if not, write to the Free Software
19
- #Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
-
21
- ##########################################
22
- # Subversion information
23
- # $Id: defines.rb 215 2010-09-25 21:22:37Z richlv $
24
- # $Revision: 215 $
25
- ##########################################
26
-
27
- # Zabbix constants
28
-
29
- # Sysmap elements (Create Element Type drop down menu):
30
- ME_HOST=0
31
- ME_MAP=1
32
- ME_TRIGGER=2
33
- ME_HOSTGROUP=3
34
- ME_IMAGE=4
35
-
36
- # Sysmap connection draw type
37
- MC_DT_LINE=1
38
- MC_DT_BOLD=2
39
- MC_DT_DOT=3
40
- MC_DT_DASHED=4
41
-
42
- # Sysmap label location
43
- ML_BOTTOM=0
44
- ML_LEFT=1
45
- ML_RIGHT=2
46
- ML_TOP=3
data/libs/exceptions.rb DELETED
@@ -1,119 +0,0 @@
1
- #License:: LGPL 2.1 http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
2
- #Copyright:: Copyright (C) 2009,2010 Andrew Nelson nelsonab(at)red-tux(dot)net
3
- #
4
- #This library is free software; you can redistribute it and/or
5
- #modify it under the terms of the GNU Lesser General Public
6
- #License as published by the Free Software Foundation; either
7
- #version 2.1 of the License, or (at your option) any later version.
8
- #
9
- #This library is distributed in the hope that it will be useful,
10
- #but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
- #Lesser General Public License for more details.
13
- #
14
- #You should have received a copy of the GNU Lesser General Public
15
- #License along with this library; if not, write to the Free Software
16
- #Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
-
18
- ##########################################
19
- # Subversion information
20
- # $Id: exceptions.rb 258 2010-12-28 22:49:21Z nelsonab $
21
- # $Revision: 258 $
22
- ##########################################
23
-
24
- require 'libs/zdebug'
25
-
26
- #------------------------------------------------------------------------------
27
- #
28
- # Class ZError
29
- #
30
- # This is the superclass for all Zabcon and ZabbixAPI exceptions.
31
- #
32
- #------------------------------------------------------------------------------
33
- class ZError < RuntimeError
34
-
35
- include ZDebug
36
-
37
- attr_reader :help_func, :message, :retry
38
-
39
- # list of valid params
40
- # :help_func, the help function with more information for the exception
41
- # : retry, is the exception eligable for retry?
42
- def initialize(message=nil, params=nil)
43
- debug(2,self.class,"Exception raised")
44
- debug(2,params,"params")
45
- raise "Exception not called correctly" if params.class!=Hash if !params.nil?
46
- params={} if params.nil?
47
- @help_func=params[:help_func]
48
- @message=message
49
- @local_msg="Error"
50
- @retry = params[:retry]
51
- super(message)
52
- end
53
-
54
- def show_message
55
- puts "** #{self.class}"
56
- if @message.nil? && @help_func.nil?
57
- puts "** #{@local_msg}"
58
- puts
59
- else
60
- if !@message.nil?
61
- @message.each_line {|line|
62
- puts "** #{line}"
63
- }
64
- puts
65
- puts "---" if !@help_func.nil?
66
- end
67
- @help_func.call if !@help_func.nil?
68
- end
69
- end
70
-
71
- #show the backtrace, if override is true it will be shown even if there is a help function
72
- def show_backtrace(override=false)
73
- if @help_func.nil? || override
74
- puts "Backtrace:"
75
- puts backtrace.join("\n")
76
- end
77
- end
78
- def retry?
79
- #the following may be worthy of a sig on "The Daily WTF", but this guarantees a boolean gets returned.
80
- #@retry is not guaranteed to be a boolean.
81
- if @retry
82
- return true
83
- else
84
- return false
85
- end
86
- end
87
- end
88
-
89
- class ParameterError < ZError
90
- def initialize(message=nil, params=nil)
91
- super(message, params)
92
- @local_msg="Parameter Error"
93
- end
94
- end
95
-
96
- #----------------------------------------------------------
97
-
98
- class ParameterError_Invalid < ZError
99
- def initialize(message=nil, params=nil)
100
- super(message, params)
101
- @local_msg="Invalid Parameters"
102
- end
103
- end
104
-
105
- class ParameterError_Missing < ZError
106
- def initialize(message=nil, params=nil)
107
- super(message, params)
108
- @local_msg="Missing required parameters"
109
- end
110
- end
111
-
112
- #----------------------------------------------------------
113
-
114
- class ParseError < ZError
115
- def initialize(message=nil, params=nil)
116
- super(message, params)
117
- @local_msg="Parse Error"
118
- end
119
- end
data/libs/zdebug.rb DELETED
@@ -1,163 +0,0 @@
1
- #License:: LGPL 2.1 http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
2
- #Copyright:: Copyright (C) 2009,2010 Andrew Nelson nelsonab(at)red-tux(dot)net
3
- #
4
- #This library is free software; you can redistribute it and/or
5
- #modify it under the terms of the GNU Lesser General Public
6
- #License as published by the Free Software Foundation; either
7
- #version 2.1 of the License, or (at your option) any later version.
8
- #
9
- #This library is distributed in the hope that it will be useful,
10
- #but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
- #Lesser General Public License for more details.
13
- #
14
- #You should have received a copy of the GNU Lesser General Public
15
- #License along with this library; if not, write to the Free Software
16
- #Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
-
18
- ##########################################
19
- # Subversion information
20
- # $Id: zdebug.rb 222 2010-10-07 14:25:08Z nelsonab $
21
- # $Revision: 222 $
22
- ##########################################
23
-
24
- module ZDebug
25
-
26
- # Either set_debug_level or set_facility_debug_level must be called before
27
- # the debug functions can be used.
28
- def set_debug_level(level) # sets the current debug level for printing messages
29
- @@debug_level=level
30
-
31
- # Create faciltiy_level if it's not created already
32
- @@facility_level= {} if !defined?(@@facility_level)
33
- end
34
-
35
- # facility is a symbol, level is an integer
36
- def set_facility_debug_level(facility,level)
37
- # Create faciltiy_level if it's not created already
38
- @@facility_level= {} if !defined?(@@facility_level)
39
-
40
- @@facility_level[facility]=level
41
-
42
- # Create debug level if it's not already created
43
- @@debug_level=0 if !defined?(@@debug_level)
44
- end
45
-
46
- def debug_level
47
- @@debug_level
48
- end
49
-
50
- # level - level to show message (Integer)
51
- # variable - variable to show (Object)
52
- # message - message to be prepended before variable (String)
53
- # overload - do show or error if debug_level is not set
54
- def debug(level,variable="",message=nil,truncate=nil,overload=false)
55
- return if overload
56
- raise "Call set_debug before using debug" if !defined?(@@debug_level)
57
- if level<=@@debug_level
58
- #parse the caller array to determine who called us, what line, and what file
59
- caller[0]=~/(.*):(\d+):.*`(.*?)'/
60
-
61
- #sometimes the debug function gets called from within an exception block, in which cases the backtrace is not
62
- #available.
63
- file_tmp=$1.nil? ? "n/a" : $1
64
- debug_line=$2.nil? ? "" : $2
65
- debug_func=$3.nil? ? "" : $3
66
- tmp_split=file_tmp.split("/")
67
-
68
- if (len=tmp_split.length)>2
69
- debug_file=".../#{tmp_split[len-2]}/#{tmp_split[len-1]}"
70
- else
71
- debug_file=file_tmp
72
- end
73
-
74
- strval=""
75
- if variable.nil?
76
- strval="nil"
77
- elsif variable.class==String
78
- strval=variable
79
- if !truncate.nil?
80
- if truncate<strval.length then
81
- o_strval=strval
82
- strval=o_strval[0..(truncate/2)]
83
- strval+= " ..... "
84
- strval+=o_strval[(o_strval.length-(truncate/2))..o_strval.length]
85
- end
86
- end
87
- else
88
- strval=variable.inspect
89
- if !truncate.nil?
90
- if truncate<strval.length then
91
- o_strval=strval
92
- strval=o_strval[0..(truncate/2)]
93
- strval+= " ..... "
94
- strval+=o_strval[(o_strval.length-(truncate/2))..o_strval.length]
95
- end
96
- end
97
- end
98
-
99
- if !message.nil?
100
- strval = message + ": " + strval
101
- end
102
- puts "D#{level} #{debug_file}:#{debug_func}:#{debug_line} #{strval}"
103
- end
104
- end
105
-
106
- # Debug_facility is a copy of the above function in an effort to shorten
107
- # code path.
108
- # facility - symbol denoting logging facility
109
- # level - level to show message (Integer)
110
- # variable - variable to show (Object)
111
- # message - message to be prepended before variable (String)
112
- def debug_facility(facility,level,variable="",message=nil,truncate=nil)
113
- facility_level=@@facility_level[facility]
114
- raise "Call set_debug before using debug" if !defined?(@@debug_level)
115
- raise "Unknown facility type: #{facility.to_s}" if facility_level.nil?
116
- if level<=facility_level
117
- #parse the caller array to determine who called us, what line, and what file
118
- caller[0]=~/(.*):(\d+):.*`(.*?)'/
119
-
120
- file_tmp=$1
121
- debug_line=$2
122
- debug_func=$3
123
- tmp_split=file_tmp.split("/")
124
-
125
- if (len=tmp_split.length)>2
126
- debug_file=".../#{tmp_split[len-2]}/#{tmp_split[len-1]}"
127
- else
128
- debug_file=file_tmp
129
- end
130
-
131
- strval=""
132
- if variable.nil?
133
- strval="nil"
134
- elsif variable.class==String
135
- strval=variable
136
- if !truncate.nil?
137
- if truncate<strval.length then
138
- o_strval=strval
139
- strval=o_strval[0..(truncate/2)]
140
- strval+= " ..... "
141
- strval+=o_strval[(o_strval.length-(truncate/2))..o_strval.length]
142
- end
143
- end
144
- else
145
- strval=variable.inspect
146
- if !truncate.nil?
147
- if truncate<strval.length then
148
- o_strval=strval
149
- strval=o_strval[0..(truncate/2)]
150
- strval+= " ..... "
151
- strval+=o_strval[(o_strval.length-(truncate/2))..o_strval.length]
152
- end
153
- end
154
- end
155
-
156
- if !message.nil?
157
- strval = message + ": " + strval
158
- end
159
- puts "D#{level}(#{facility.to_s}) #{debug_file}:#{debug_func}:#{debug_line} #{strval}"
160
- end
161
- end
162
-
163
- end # end Debug module