zbxapi 0.1.294 → 0.1.324

Sign up to get free protection for your applications and to get access to all the features.
@@ -46,7 +46,7 @@ require "api_classes/subclass_base"
46
46
 
47
47
  class ZbxAPI_Application < ZbxAPI_Sub
48
48
  def get(options={})
49
- debug(8, "Application.get Start")
49
+ debug(8, :msg=>"Application.get Start")
50
50
  checkauth
51
51
  checkversion(1,1)
52
52
 
@@ -55,7 +55,7 @@ class ZbxAPI_Application < ZbxAPI_Sub
55
55
  end
56
56
 
57
57
  def create(options={})
58
- debug(8, "Application.create Start")
58
+ debug(8, :msg=>"Application.create Start")
59
59
  checkauth
60
60
  checkversion(1,1)
61
61
 
@@ -70,7 +70,7 @@ class ZbxAPI_Application < ZbxAPI_Sub
70
70
  end
71
71
 
72
72
  def getid(options={})
73
- debug(8, "Application.getid Start")
73
+ debug(8, :msg=>"Application.getid Start")
74
74
  checkauth
75
75
  checkversion(1,1)
76
76
 
@@ -47,7 +47,7 @@ require "api_classes/subclass_base"
47
47
 
48
48
  class ZbxAPI_HostGroup < ZbxAPI_Sub
49
49
  def create(options={})
50
- debug(8, "HostGroup.create Start")
50
+ debug(8, :msg=>"HostGroup.create Start")
51
51
  checkauth
52
52
  checkversion(1,1)
53
53
 
@@ -62,7 +62,7 @@ class ZbxAPI_HostGroup < ZbxAPI_Sub
62
62
  end
63
63
 
64
64
  def get(options={})
65
- debug(8, "HostGroup.get Start")
65
+ debug(8, :msg=>"HostGroup.get Start")
66
66
  checkauth
67
67
  checkversion(1,1)
68
68
 
@@ -76,7 +76,7 @@ class ZbxAPI_HostGroup < ZbxAPI_Sub
76
76
  end
77
77
 
78
78
  def getObjects(name)
79
- debug(8, "HostGroup.getId Start")
79
+ debug(8, :msg=>"HostGroup.getId Start")
80
80
  checkauth
81
81
  checkversion(1,1)
82
82
 
data/api_classes/item.rb CHANGED
@@ -59,7 +59,7 @@ class ZbxAPI_Item < ZbxAPI_Sub
59
59
  end
60
60
 
61
61
  def create(options)
62
- debug(8,options)
62
+ debug(8,:var=>options)
63
63
  checkauth
64
64
  checkversion(1,1)
65
65
 
@@ -53,7 +53,7 @@ class ZbxAPI_Sub < ZabbixAPI #:nodoc: all
53
53
  return @parent.json_obj(method, param)
54
54
  end
55
55
 
56
- def debug(level,param="",message=nil)
57
- @parent.debug(level,param,message)
56
+ def debug(level,args={})
57
+ @parent.debug(level,args)
58
58
  end
59
59
  end
@@ -39,7 +39,7 @@ require "api_classes/subclass_base"
39
39
 
40
40
  class ZbxAPI_Sysmap < ZbxAPI_Sub
41
41
  def create(options={})
42
- debug(8, "Sysmap.create Start")
42
+ debug(8, :msg=>"Sysmap.create Start")
43
43
  checkauth
44
44
  checkversion(1,1)
45
45
 
@@ -54,7 +54,7 @@ class ZbxAPI_Sysmap < ZbxAPI_Sub
54
54
  end
55
55
 
56
56
  def addelement(options={})
57
- debug(8, "Sysmap.addelement Start")
57
+ debug(8, :msg=>"Sysmap.addelement Start")
58
58
  checkauth
59
59
  checkversion(1,1)
60
60
 
@@ -63,7 +63,7 @@ class ZbxAPI_Sysmap < ZbxAPI_Sub
63
63
  end
64
64
 
65
65
  def addlink(options={})
66
- debug(8, "Sysmap.addlink Start")
66
+ debug(8, :msg=>"Sysmap.addlink Start")
67
67
  checkauth
68
68
  checkversion(1,1)
69
69
 
@@ -72,7 +72,7 @@ class ZbxAPI_Sysmap < ZbxAPI_Sub
72
72
  end
73
73
 
74
74
  def getseid(options={})
75
- debug(8, "Sysmap.getseid Start")
75
+ debug(8, :msg=>"Sysmap.getseid Start")
76
76
  checkauth
77
77
  checkversion(1,1)
78
78
 
@@ -81,7 +81,7 @@ class ZbxAPI_Sysmap < ZbxAPI_Sub
81
81
  end
82
82
 
83
83
  def addlinktrigger(options={})
84
- debug(8, "Sysmap.addlinktrigger Start")
84
+ debug(8, :msg=>"Sysmap.addlinktrigger Start")
85
85
  checkauth
86
86
  checkversion(1,1)
87
87
 
@@ -45,7 +45,7 @@ require "api_classes/subclass_base"
45
45
 
46
46
  class ZbxAPI_Trigger < ZbxAPI_Sub
47
47
  def get(options={})
48
- debug(8, "Trigger.get Start")
48
+ debug(8, :msg=>"Trigger.get Start")
49
49
  checkauth
50
50
  checkversion(1,1)
51
51
 
@@ -55,7 +55,7 @@ class ZbxAPI_Trigger < ZbxAPI_Sub
55
55
 
56
56
  # Function name changed to reflect 1.1 API changes
57
57
  def create(options={})
58
- debug(8, "Trigger.create Start")
58
+ debug(8, :msg=>"Trigger.create Start")
59
59
  checkauth
60
60
  checkversion(1,1)
61
61
 
data/api_classes/user.rb CHANGED
@@ -109,7 +109,7 @@ class ZbxAPI_User < ZbxAPI_Sub
109
109
  # addmedia expects a hash of the following variables
110
110
  # userid, mediatypeid, sendto, severity, active, period
111
111
  def addmedia(options)
112
- debug(8, "User.addmedia Start")
112
+ debug(8, :msg=>"User.addmedia Start")
113
113
  checkauth
114
114
  checkversion(1,1)
115
115
 
@@ -17,8 +17,8 @@
17
17
 
18
18
  ##########################################
19
19
  # Subversion information
20
- # $Id: $
21
- # $Revision: $
20
+ # $Id: api_exceptions.rb 319 2011-09-25 21:53:30Z nelsonab $
21
+ # $Revision: 319 $
22
22
  ##########################################
23
23
 
24
24
  #------------------------------------------------------------------------------
@@ -29,8 +29,8 @@
29
29
  #
30
30
  #------------------------------------------------------------------------------
31
31
 
32
- require 'libs/zdebug'
33
- require 'libs/exceptions'
32
+ require 'zbxapi/zdebug'
33
+ require 'zbxapi/exceptions'
34
34
 
35
35
  #------------------------------------------------------------------------------
36
36
  #
@@ -40,7 +40,7 @@ require 'libs/exceptions'
40
40
  #
41
41
  #------------------------------------------------------------------------------
42
42
 
43
- class ZbxAPI_ExceptionBadAuth < RuntimeError
43
+ class ZbxAPI_ExceptionBadAuth < ZError
44
44
  end
45
45
 
46
46
  #------------------------------------------------------------------------------
@@ -97,7 +97,7 @@ end
97
97
  #------------------------------------------------------------------------------
98
98
 
99
99
  class ZbxAPI_ExceptionLoginPermission < ZError
100
- def initialize(message=nil, params=nil)
100
+ def initialize(message=nil, params={})
101
101
  super(message, params)
102
102
  @local_msg="This is also a general Zabbix API error number (Your error may not be a login error).\nTell the Zabbix devs to honor section 5.1 of the JSON-RPC 2.0 Spec."
103
103
  end
@@ -17,11 +17,12 @@
17
17
 
18
18
  ##########################################
19
19
  # Subversion information
20
- # $Id: exceptions.rb 258 2010-12-28 22:49:21Z nelsonab $
21
- # $Revision: 258 $
20
+ # $Id: exceptions.rb 319 2011-09-25 21:53:30Z nelsonab $
21
+ # $Revision: 319 $
22
22
  ##########################################
23
23
 
24
- require 'libs/zdebug'
24
+ require 'zbxapi/utils'
25
+ require 'zbxapi/zdebug'
25
26
 
26
27
  #------------------------------------------------------------------------------
27
28
  #
@@ -34,18 +35,17 @@ class ZError < RuntimeError
34
35
 
35
36
  include ZDebug
36
37
 
37
- attr_accessor :help_func, :message, :retry
38
+ attr_accessor :help_func, :message, :retry, :error_code
38
39
 
39
40
  # list of valid params
40
41
  # :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
- raise "Exception not called correctly" if params.class!=Hash if !params.nil?
44
- params={} if params.nil?
42
+ # : retry, is the exception eligible for retry?
43
+ def initialize(message=nil, params={})
45
44
  @help_func=params[:help_func]
46
45
  @message=message
47
46
  @local_msg="Error"
48
47
  @retry = params[:retry]
48
+ @error_code= params[:error_code]
49
49
  super(message)
50
50
  end
51
51
 
@@ -0,0 +1,7 @@
1
+ #CHANGES TO THIS FILE WILL AUTOMATICALLY BE OVERWRITTEN
2
+ #This file is autogenerated by the zbxapi rakefile.
3
+ #This file contains the latest SVN revision number at the time
4
+ #the rakefile was run
5
+
6
+ ZBXAPI_VERSION="0.1"
7
+ ZBXAPI_REVISION="324"
data/zbxapi/utils.rb ADDED
@@ -0,0 +1,38 @@
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: utils.rb 319 2011-09-25 21:53:30Z nelsonab $
21
+ # $Revision: 319 $
22
+ ##########################################
23
+
24
+
25
+ class Object
26
+ #self.class_of?
27
+ #Ruby's is_a? or kind_of? will only tell you the hierarchy of classes which
28
+ #have been instantiated.
29
+ def self.class_of?(obj)
30
+ raise RuntimeError.new("Obj must be an uninstantiated class, often calling method \".class\" works") if obj.class!=Class
31
+ return true if self==obj
32
+ if self.superclass.respond_to?(:class_of?)
33
+ self.superclass.class_of?(obj)
34
+ else
35
+ false
36
+ end
37
+ end
38
+ end
data/zbxapi/zdebug.rb ADDED
@@ -0,0 +1,165 @@
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 324 2011-09-26 08:53:11Z nelsonab $
21
+ # $Revision: 324 $
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
+ # :var - variable to show (Object)
52
+ # :msg - message to be prepended before variable (String)
53
+ # :truncate - truncate var if it is over N characters
54
+ # :overload - do not show or error if debug_level is not set
55
+ # :facility - Which debug facility level should also be used
56
+ # :stack_pos - Stack position to use for calling function information (0==last function)
57
+ # :trace_depth - Show a backtrace of :trace_depth starting at :stack_pos
58
+ def debug(level,args={})
59
+ variable=args[:var] || :zzempty
60
+ message=args[:msg] || nil
61
+ facility=args[:facility] || nil
62
+ raise "Facility must be a symbol" if facility && facility.class!=Symbol
63
+ truncate=args[:truncate] || 0
64
+ raise "Truncate must be an Integer" if truncate.class!=Fixnum
65
+ overload=(!args[:overload].nil? && args[:overload]==true) || false
66
+ stack_pos=args[:stack_pos] || 0
67
+ raise ":stack_pos must be an Integer" if stack_pos.class!=Fixnum
68
+ backtrace_depth=args[:trace_depth] || 0
69
+
70
+ return if overload
71
+ raise "Call set_debug before using debug" if !defined?(@@debug_level)
72
+
73
+ if facility
74
+ facility_level=@@facility_level[facility]
75
+ raise("Unknown facility type: #{facility.to_s}") if facility_level.nil?
76
+ show_debug=level<=facility_level
77
+ else
78
+ show_debug=level<=@@debug_level
79
+ end
80
+
81
+ if show_debug
82
+
83
+ if facility
84
+ header="D#{level}(#{facility.to_s})"
85
+ else
86
+ header="D#{level}"
87
+ end
88
+
89
+ #Example: "./libs/lexer.rb:650:in `item'"
90
+ #parse the caller array to determine who called us, what line, and what file
91
+ caller[stack_pos]=~/(.*):(\d+):.*`(.*?)'/
92
+
93
+ if $1
94
+ #sometimes the debug function gets called from within an exception block, in which cases the backtrace is not
95
+ #available.
96
+ path=$1
97
+ debug_line=$2
98
+ debug_func=$3
99
+ path=path.split("/")
100
+
101
+ if (len=path.length)>2
102
+ debug_file=".../#{path[len-2]}/#{path[len-1]}"
103
+ else
104
+ debug_file=path
105
+ end
106
+
107
+ header+=" #{debug_file}:#{debug_func}:#{debug_line}"
108
+ else
109
+ header+=" --from exception--"
110
+ end
111
+
112
+ if variable.nil?
113
+ strval="nil"
114
+ elsif variable==:zzempty || variable==""
115
+ strval=""
116
+ elsif variable.class==String
117
+ strval=variable
118
+ else
119
+ strval=variable.inspect
120
+ end
121
+
122
+ if truncate>0 && truncate<strval.length
123
+ o_strval=strval
124
+ strval=o_strval[0..(truncate/2)]
125
+ strval+= " ..... "
126
+ strval+=o_strval[(o_strval.length-(truncate/2))..o_strval.length]
127
+ end
128
+
129
+ if message
130
+ strval = variable==:zzempty ?
131
+ message :
132
+ message + ": " + strval
133
+ end
134
+ puts "#{header} #{strval}"
135
+
136
+ if backtrace_depth>0
137
+ backtrace=[]
138
+ (stack_pos..stack_pos+backtrace_depth-1).each do |pos|
139
+ pos+=2 #Need to offset current block
140
+ next if pos>=caller.length
141
+
142
+ caller[pos]=~/(.*):(\d+):.*`(.*?)'/
143
+ if $1
144
+ #sometimes the debug function gets called from within an exception block, in which cases the backtrace is not
145
+ #available.
146
+ debug_line=$2
147
+ debug_func=$3
148
+ path=$1.split("/") #global vars are changed by split
149
+
150
+ path= (len=path.length)>2 ? ".../#{path[len-2]}/#{path[len-1]}" : path
151
+ backtrace<<"#{path}:#{debug_func}:#{debug_line}"
152
+ else
153
+ backtrace<<"Unknown"
154
+ end
155
+ end
156
+ puts " Backtrace(#{stack_pos}..#{stack_pos+backtrace_depth-1}):["+backtrace.join("],[")+"]"
157
+ end
158
+ end
159
+ end
160
+
161
+ def debug_facility(facility,level,variable="",message=nil,truncate=nil)
162
+ debug(level, :var=>variable, :msg=>message, :truncate=>truncate, :stack_pos=>1)
163
+ end
164
+
165
+ end # end Debug module
data/zbxapi.rb CHANGED
@@ -19,8 +19,8 @@
19
19
  #--
20
20
  ##########################################
21
21
  # Subversion information
22
- # $Id: zbxapi.rb 294 2011-07-08 08:27:45Z nelsonab $
23
- # $Revision: 294 $
22
+ # $Id: zbxapi.rb 319 2011-09-25 21:53:30Z nelsonab $
23
+ # $Revision: 319 $
24
24
  ##########################################
25
25
  #++
26
26
 
@@ -32,8 +32,9 @@ end
32
32
  #setup our search path or libraries
33
33
  $: << File.expand_path(File.join(File.dirname(__FILE__), '.'))
34
34
 
35
- require 'libs/zdebug'
36
- require 'libs/api_exceptions.rb'
35
+ require 'zbxapi/revision'
36
+ require 'zbxapi/zdebug'
37
+ require 'zbxapi/api_exceptions.rb'
37
38
  require 'uri'
38
39
  #require 'net/http'
39
40
  require 'net/https'
@@ -105,9 +106,13 @@ class ZabbixAPI
105
106
  @history = ZbxAPI_History.new(self)
106
107
  @id=0
107
108
 
108
- debug(6,"protocol: #{@url.scheme}, host: #{@url.host}")
109
- debug(6,"port: #{@url.port}, path: #{@url.path}")
110
- debug(6,"query: #{@url.query}, fragment: #{@url.fragment}")
109
+ debug(6,:msg=>"protocol: #{@url.scheme}, host: #{@url.host}")
110
+ debug(6,:msg=>"port: #{@url.port}, path: #{@url.path}")
111
+ debug(6,:msg=>"query: #{@url.query}, fragment: #{@url.fragment}")
112
+ end
113
+
114
+ def self.get_version
115
+ "#{ZBXAPI_VERSION}.#{ZBXAPI_REVISION}"
111
116
  end
112
117
 
113
118
  #wraps the given information into the appropriate JSON object
@@ -123,7 +128,7 @@ class ZabbixAPI
123
128
  'auth'=>@auth,
124
129
  'id'=>@id
125
130
  }
126
- debug(10, "json_obj: #{obj}")
131
+ debug(10, :msg=>"json_obj: #{obj}")
127
132
  return obj.to_json
128
133
  end
129
134
 
@@ -177,7 +182,7 @@ class ZabbixAPI
177
182
  if !login_methods.empty?
178
183
  retry
179
184
  else
180
- raise e
185
+ raise ZbxAPI_ExceptionBadAuth.new('Invalid User or Password',:error_code=>e.error_code)
181
186
  end
182
187
  rescue SocketError
183
188
  raise ZbxAPI_ExceptionBadServerUrl
@@ -230,8 +235,8 @@ class ZabbixAPI
230
235
  # _params_ are the parameters to be passed to the call
231
236
  # returns a hash of the results from the server
232
237
  def raw_api(method,params=nil)
233
- debug(6,method,"method")
234
- debug(6,params,"Parameters")
238
+ debug(6,:var=>method,:msg=>"method")
239
+ debug(6,:var=>params,:msg=>"Parameters")
235
240
 
236
241
  checkauth
237
242
  checkversion(1,1)
@@ -269,10 +274,10 @@ class ZabbixAPI
269
274
  # http.start do |http|
270
275
  headers={'Content-Type'=>'application/json-rpc',
271
276
  'User-Agent'=>'Zbx Ruby CLI'}
272
- debug(4,"Sending: #{json_obj}")
277
+ debug(4,:msg=>"Sending: #{json_obj}")
273
278
  response = http.post(@url.path, json_obj,headers)
274
- debug(4,"Response Code: #{response.code}")
275
- debug(4,response.body,"Response Body",truncate_length)
279
+ debug(4,:msg=>"Response Code: #{response.code}")
280
+ debug(4,:var=>response.body,:msg=>"Response Body",:truncate=>truncate_length)
276
281
  case response.code.to_i
277
282
  when 301
278
283
  puts "Redirecting to #{response['location']}"
@@ -291,9 +296,9 @@ class ZabbixAPI
291
296
  errcode=resp["error"]["code"].to_i
292
297
  case errcode
293
298
  when -32602 then
294
- raise ZbxAPI_ExceptionLoginPermission.new(resp["error"],:retry=>true)
299
+ raise ZbxAPI_ExceptionLoginPermission.new(resp["error"],:error_code=>errcode,:retry=>true)
295
300
  when -32500 then
296
- raise ZbxAPI_ExceptionPermissionError.new(resp["error"],:retry=>true)
301
+ raise ZbxAPI_ExceptionPermissionError.new(resp["error"],:error_code=>errcode,:retry=>true)
297
302
  else
298
303
  puts "other error"
299
304
  raise ZbxAPI_GeneralError, resp["error"]
metadata CHANGED
@@ -1,13 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zbxapi
3
3
  version: !ruby/object:Gem::Version
4
- hash: 599
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 1
9
- - 294
10
- version: 0.1.294
4
+ version: 0.1.324
11
5
  platform: ruby
12
6
  authors:
13
7
  - A. Nelson
@@ -15,23 +9,19 @@ autorequire:
15
9
  bindir: bin
16
10
  cert_chain: []
17
11
 
18
- date: 2011-07-08 00:00:00 -04:00
12
+ date: 2011-09-26 00:00:00 -04:00
19
13
  default_executable:
20
14
  dependencies:
21
15
  - !ruby/object:Gem::Dependency
22
16
  name: json
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: 3
30
- segments:
31
- - 0
32
23
  version: "0"
33
- type: :runtime
34
- version_requirements: *id001
24
+ version:
35
25
  description: Provides a straight forward interface to manipulate Zabbix servers using the Zabbix API.
36
26
  email: nelsonab@red-tux.net
37
27
  executables: []
@@ -42,9 +32,11 @@ extra_rdoc_files: []
42
32
 
43
33
  files:
44
34
  - zbxapi.rb
45
- - libs/zdebug.rb
46
- - libs/api_exceptions.rb
47
- - libs/exceptions.rb
35
+ - zbxapi/zdebug.rb
36
+ - zbxapi/api_exceptions.rb
37
+ - zbxapi/exceptions.rb
38
+ - zbxapi/revision.rb
39
+ - zbxapi/utils.rb
48
40
  - api_classes/application.rb
49
41
  - api_classes/history.rb
50
42
  - api_classes/host.rb
@@ -65,27 +57,21 @@ rdoc_options: []
65
57
  require_paths:
66
58
  - .
67
59
  required_ruby_version: !ruby/object:Gem::Requirement
68
- none: false
69
60
  requirements:
70
61
  - - ">="
71
62
  - !ruby/object:Gem::Version
72
- hash: 3
73
- segments:
74
- - 0
75
63
  version: "0"
64
+ version:
76
65
  required_rubygems_version: !ruby/object:Gem::Requirement
77
- none: false
78
66
  requirements:
79
67
  - - ">="
80
68
  - !ruby/object:Gem::Version
81
- hash: 3
82
- segments:
83
- - 0
84
69
  version: "0"
70
+ version:
85
71
  requirements:
86
72
  - Requires json
87
73
  rubyforge_project: zbxapi
88
- rubygems_version: 1.3.7
74
+ rubygems_version: 1.3.5
89
75
  signing_key:
90
76
  specification_version: 3
91
77
  summary: Ruby wrapper to the Zabbix API
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 281 2011-04-06 18:10:16Z nelsonab $
21
- # $Revision: 281 $
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? && truncate>0
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