zbxapi 0.1 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -29,11 +29,8 @@
29
29
  #
30
30
  #------------------------------------------------------------------------------
31
31
 
32
- #setup our search path or libraries
33
- path=File.expand_path(File.dirname(__FILE__) + "/./")+"/"
34
-
35
- require path+'zdebug'
36
- require path+'exceptions'
32
+ require 'libs/zdebug'
33
+ require 'libs/exceptions'
37
34
 
38
35
  #------------------------------------------------------------------------------
39
36
  #
data/libs/exceptions.rb CHANGED
@@ -17,14 +17,11 @@
17
17
 
18
18
  ##########################################
19
19
  # Subversion information
20
- # $Id: exceptions.rb 254 2010-12-27 19:45:42Z nelsonab $
21
- # $Revision: 254 $
20
+ # $Id: exceptions.rb 258 2010-12-28 22:49:21Z nelsonab $
21
+ # $Revision: 258 $
22
22
  ##########################################
23
23
 
24
- #setup our search path or libraries
25
- path=File.expand_path(File.dirname(__FILE__) + "/./")+"/"
26
-
27
- require path+'zdebug'
24
+ require 'libs/zdebug'
28
25
 
29
26
  #------------------------------------------------------------------------------
30
27
  #
data/libs/zdebug.rb CHANGED
@@ -76,7 +76,7 @@ module ZDebug
76
76
  strval="nil"
77
77
  elsif variable.class==String
78
78
  strval=variable
79
- if !truncate.nil?
79
+ if !truncate.nil? && truncate>0
80
80
  if truncate<strval.length then
81
81
  o_strval=strval
82
82
  strval=o_strval[0..(truncate/2)]
data/zbxapi.rb CHANGED
@@ -19,17 +19,16 @@
19
19
  #--
20
20
  ##########################################
21
21
  # Subversion information
22
- # $Id: zbxapi.rb 254 2010-12-27 19:45:42Z nelsonab $
23
- # $Revision: 254 $
22
+ # $Id: zbxapi.rb 268 2011-01-02 18:52:37Z nelsonab $
23
+ # $Revision: 268 $
24
24
  ##########################################
25
25
  #++
26
26
 
27
27
  #setup our search path or libraries
28
- path=File.expand_path(File.dirname(__FILE__) + "/./")+"/"
28
+ $: << File.expand_path(File.join(File.dirname(__FILE__), '.'))
29
29
 
30
-
31
- require path+'libs/zdebug'
32
- require path+'libs/api_exceptions.rb'
30
+ require 'libs/zdebug'
31
+ require 'libs/api_exceptions.rb'
33
32
  require 'uri'
34
33
  #require 'net/http'
35
34
  require 'net/https'
@@ -236,7 +235,9 @@ class ZabbixAPI
236
235
  end
237
236
 
238
237
  #Sends JSON encoded string to server
239
- def do_request(json_obj)
238
+ #truncate_length determines how many characters at maximum should be displayed while debugging before
239
+ #truncation should occur.
240
+ def do_request(json_obj,truncate_length=5000)
240
241
  #puts json_obj
241
242
  redirects=0
242
243
  begin # This is here for redirects
@@ -250,13 +251,16 @@ class ZabbixAPI
250
251
  'User-Agent'=>'Zbx Ruby CLI'}
251
252
  debug(4,"Sending: #{json_obj}")
252
253
  response = http.post(@url.path, json_obj,headers)
253
- if response.code=="301"
254
- puts "Redirecting to #{response['location']}"
255
- @url=URI.parse(response['location'])
256
- raise Redirect
257
- end
258
254
  debug(4,"Response Code: #{response.code}")
259
- debug(4,response.body,"Response Body",5000)
255
+ debug(4,response.body,"Response Body",truncate_length)
256
+ case response.code.to_i
257
+ when 301
258
+ puts "Redirecting to #{response['location']}"
259
+ @url=URI.parse(response['location'])
260
+ raise Redirect
261
+ when 500
262
+ raise ZbxAPI_GeneralError.new("Zabbix server returned an internal error\n Call: #{json_obj}", :retry=>true)
263
+ end
260
264
  # end
261
265
 
262
266
  @id+=1 # increment the ID value for the API call
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zbxapi
3
3
  version: !ruby/object:Gem::Version
4
- hash: 9
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- version: "0.1"
9
+ - 1
10
+ version: 0.1.1
10
11
  platform: ruby
11
12
  authors:
12
13
  - A. Nelson
@@ -14,7 +15,7 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-12-28 00:00:00 -05:00
18
+ date: 2011-04-06 00:00:00 -04:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency