zobbix 0.0.4 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fe780a7edc0dcaf9a8330101a6b6cabda2390a92
4
- data.tar.gz: 3c5b511db823535493b7b7ab5a3bbab8c1bfd6be
3
+ metadata.gz: 32104052200babb6cd6287f873dfdf4a6e63c78f
4
+ data.tar.gz: a2f3ae52af02afee02380dabb7ebbd280ea265e4
5
5
  SHA512:
6
- metadata.gz: 4e2b8fb63c46c2ce26507fdcc1bc295050d98ff5885f380102abef9f5535404fcf9c6a337b93681611cd92b3d4ed6cfac02f5f99308bfbbdd34fd47943941090
7
- data.tar.gz: 07e44b487a16eb17e5459480c8ea2adacbb41808c1336653358c3240d5e73903cf20bbd6c13ddb3e2f03225b154cc00a34e6ac566177a25248f80a67fd058975
6
+ metadata.gz: f86193cfadffdd44a567c5dc2c5a1b68a5c6954a78e87c3aa7293d9a712338dd8da2248640d4ce97d012593c1fa706647660da71cab8275f770d8c14c326a36f
7
+ data.tar.gz: 0c533422068a92555b61e0b1c4258a3b311a296788b31cfbc298e2b0faf7cfd0a2c6e56754672e45c2989e02d936ee1d904e9b013030a1ee2d8efcb2cdbcd095
data/lib/zobbix.rb CHANGED
@@ -43,8 +43,9 @@ class Zobbix
43
43
  .tap(&:authenticate!)
44
44
  end
45
45
 
46
- def self.supported_version?(zabbix_version)
47
- zabbix_version.to_s =~ /^2\.4\./
46
+ def self.supported_version?(version)
47
+ version = Gem::Version.new(version)
48
+ ZABBIX_VERSION_REQUIREMENT.satisfied_by?(version)
48
49
  end
49
50
 
50
51
  attr_reader :credentials, :auth
@@ -66,8 +67,7 @@ class Zobbix
66
67
  raise ConnectionError.new(credentials)
67
68
  end
68
69
 
69
- version = Gem::Version.new(version)
70
- unless ZABBIX_VERSION_REQUIREMENT.satisfied_by?(version)
70
+ unless self.class.supported_version?(version)
71
71
  raise UnsupportedVersionError.new(version)
72
72
  end
73
73
  end
@@ -98,9 +98,10 @@ class Zobbix
98
98
  #
99
99
  # @see https://www.zabbix.com/documentation/2.4/manual/api/reference
100
100
  def request(method, params = {})
101
- params = params.merge(auth: @auth) if requires_auth?(method)
101
+ args = [credentials.uri, method, params]
102
+ args << @auth if requires_auth?(method)
102
103
 
103
- response = ApiRequest.perform(credentials.uri, method, params)
104
+ response = ApiRequest.perform(*args)
104
105
  response.raise_exception if @raise_exceptions && response.error?
105
106
  response
106
107
  end
@@ -23,10 +23,11 @@ class Zobbix
23
23
  # @param [String] uri Zabbix Server uri
24
24
  # @param [String] method API method
25
25
  # @param [Hash] params API method params
26
- def initialize(uri, method, params)
26
+ # @param [String] auth Auth token
27
+ def initialize(uri, method, params, auth = nil)
27
28
  @uri = uri.sub(/\/$/, '')
28
29
  @method = method
29
- @auth = params.delete(:auth)
30
+ @auth = auth
30
31
  @params = params
31
32
  end
32
33
 
@@ -1,3 +1,3 @@
1
1
  class Zobbix
2
- VERSION = '0.0.4'
2
+ VERSION = '0.1.0'
3
3
  end
@@ -0,0 +1,77 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://localhost/zabbix/api_jsonrpc.php
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"jsonrpc":"2.0","method":"user.login","params":{"user":"Admin","password":"zabbix"},"auth":null,"id":8212}'
9
+ headers:
10
+ Content-Type:
11
+ - application/json-rpc
12
+ response:
13
+ status:
14
+ code: 200
15
+ message: OK
16
+ headers:
17
+ Date:
18
+ - Mon, 26 Oct 2015 10:48:39 GMT
19
+ Server:
20
+ - Apache/2.4.7 (Ubuntu)
21
+ X-Powered-By:
22
+ - PHP/5.5.9-1ubuntu4.13
23
+ Access-Control-Allow-Origin:
24
+ - "*"
25
+ Access-Control-Allow-Headers:
26
+ - Content-Type
27
+ Access-Control-Allow-Methods:
28
+ - POST
29
+ Access-Control-Max-Age:
30
+ - '1000'
31
+ Content-Length:
32
+ - '71'
33
+ Content-Type:
34
+ - application/json
35
+ body:
36
+ encoding: UTF-8
37
+ string: '{"jsonrpc":"2.0","result":"cf58cfe673d0f5cd4c5985610c1413c0","id":8212}'
38
+ http_version:
39
+ recorded_at: Mon, 26 Oct 2015 10:48:39 GMT
40
+ - request:
41
+ method: post
42
+ uri: http://localhost/zabbix/api_jsonrpc.php
43
+ body:
44
+ encoding: UTF-8
45
+ string: '{"jsonrpc":"2.0","method":"host.delete","params":[10123],"auth":"cf58cfe673d0f5cd4c5985610c1413c0","id":7044}'
46
+ headers:
47
+ Content-Type:
48
+ - application/json-rpc
49
+ response:
50
+ status:
51
+ code: 200
52
+ message: OK
53
+ headers:
54
+ Date:
55
+ - Mon, 26 Oct 2015 10:48:39 GMT
56
+ Server:
57
+ - Apache/2.4.7 (Ubuntu)
58
+ X-Powered-By:
59
+ - PHP/5.5.9-1ubuntu4.13
60
+ Access-Control-Allow-Origin:
61
+ - "*"
62
+ Access-Control-Allow-Headers:
63
+ - Content-Type
64
+ Access-Control-Allow-Methods:
65
+ - POST
66
+ Access-Control-Max-Age:
67
+ - '1000'
68
+ Content-Length:
69
+ - '56'
70
+ Content-Type:
71
+ - application/json
72
+ body:
73
+ encoding: UTF-8
74
+ string: '{"jsonrpc":"2.0","result":{"hostids":[10123]},"id":7044}'
75
+ http_version:
76
+ recorded_at: Mon, 26 Oct 2015 10:48:39 GMT
77
+ recorded_with: VCR 2.9.3
data/test/zobbix_test.rb CHANGED
@@ -41,4 +41,14 @@ class ZobbixTest < Minitest::Test
41
41
  end
42
42
  end
43
43
  end
44
+
45
+ def test_params_as_array
46
+ VCR.use_cassette('array_params') do
47
+ z = zbx
48
+ z.authenticate!
49
+ response = z.request('host.delete', [10123])
50
+ assert_success(response)
51
+ pass
52
+ end
53
+ end
44
54
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zobbix
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Lutsiuk
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-21 00:00:00.000000000 Z
11
+ date: 2015-10-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -118,6 +118,7 @@ files:
118
118
  - test/credentials_test.rb
119
119
  - test/fixtures/vcr_casettes/api_request.yml
120
120
  - test/fixtures/vcr_casettes/apiinfo_version.yml
121
+ - test/fixtures/vcr_casettes/array_params.yml
121
122
  - test/fixtures/vcr_casettes/authentication.yml
122
123
  - test/fixtures/vcr_casettes/bad_authentication.yml
123
124
  - test/fixtures/vcr_casettes/check_version/high_version.yml
@@ -159,6 +160,7 @@ test_files:
159
160
  - test/credentials_test.rb
160
161
  - test/fixtures/vcr_casettes/api_request.yml
161
162
  - test/fixtures/vcr_casettes/apiinfo_version.yml
163
+ - test/fixtures/vcr_casettes/array_params.yml
162
164
  - test/fixtures/vcr_casettes/authentication.yml
163
165
  - test/fixtures/vcr_casettes/bad_authentication.yml
164
166
  - test/fixtures/vcr_casettes/check_version/high_version.yml