zbxapi 0.1 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/libs/api_exceptions.rb +2 -5
- data/libs/exceptions.rb +3 -6
- data/libs/zdebug.rb +1 -1
- data/zbxapi.rb +17 -13
- metadata +4 -3
data/libs/api_exceptions.rb
CHANGED
@@ -29,11 +29,8 @@
|
|
29
29
|
#
|
30
30
|
#------------------------------------------------------------------------------
|
31
31
|
|
32
|
-
|
33
|
-
|
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
|
21
|
-
# $Revision:
|
20
|
+
# $Id: exceptions.rb 258 2010-12-28 22:49:21Z nelsonab $
|
21
|
+
# $Revision: 258 $
|
22
22
|
##########################################
|
23
23
|
|
24
|
-
|
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
data/zbxapi.rb
CHANGED
@@ -19,17 +19,16 @@
|
|
19
19
|
#--
|
20
20
|
##########################################
|
21
21
|
# Subversion information
|
22
|
-
# $Id: zbxapi.rb
|
23
|
-
# $Revision:
|
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
|
-
|
28
|
+
$: << File.expand_path(File.join(File.dirname(__FILE__), '.'))
|
29
29
|
|
30
|
-
|
31
|
-
require
|
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
|
-
|
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",
|
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:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
|
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:
|
18
|
+
date: 2011-04-06 00:00:00 -04:00
|
18
19
|
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|