zabbixapi 2.4.9 → 3.0.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3b0c4d39286a5204648a76628cc643fb5155ed4a
4
- data.tar.gz: a8076c8cd8f418d0dd40828ac430cd7409285f54
3
+ metadata.gz: 491a14fb3d69c78a072b5f67a72fa1410835a7c6
4
+ data.tar.gz: 4f19756c236c435d6f253943182e8d123442e7c1
5
5
  SHA512:
6
- metadata.gz: 9ceb26cc5e2ddff7674a0f5beefe99bcdf91639eb280d39862daf110d652b05aa40433ec77c8c709d37ffb19153f27529140f54bcad60ce885369bbbd9b761e0
7
- data.tar.gz: 1628507b889ce7cb58b72218fb3205f41e219276a0195669f73146408b000c5037d1729ff1687e085dc20efdafa9b7140dc5e1f15586df2ee2e4b72079c50b61
6
+ metadata.gz: 36562b8555de03cff58f5e7d1b73daa12e5c3d3dfd990ddff49077b6f47470b915ccaa389c8b719f4f8681ed5cf1cf8b319ca892a6d234d183e633d0c71db04c
7
+ data.tar.gz: bf90b9d74bde43345caf3e66cb36f9bd059e2595e0e4fa454ec1395752b7b59e6d5d70640db1a110702b8faa0ca35e6504c34313e39f60c77f55443f983d4c03
@@ -17,6 +17,10 @@ rvm:
17
17
  - 2.0
18
18
  - 2.1
19
19
  - 2.2
20
+ - 2.3
21
+ gemfile:
22
+ - Gemfile
23
+ - json-1.x.Gemfile
20
24
  dist: trusty
21
25
  sudo: required
22
26
 
@@ -29,3 +33,9 @@ before_script:
29
33
  - echo "$(curl -fsSL https://gist.githubusercontent.com/evtuhovich/9544441/raw/d661863063b76cc8e2599bc44d8595b1f86ece38/zabbix)" | sudo tee /etc/zabbix/web/zabbix.conf.php
30
34
  - sudo service apache2 restart
31
35
  script: "ZABBIX_HOST_URL=http://localhost/zabbix/api_jsonrpc.php bundle exec rspec spec/*"
36
+
37
+ matrix:
38
+ exclude:
39
+ # json 2.x requires ruby 2.x
40
+ - rvm: 1.9.3
41
+ gemfile: json-1.x.Gemfile
data/Gemfile CHANGED
@@ -1,5 +1,3 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem "rspec"
4
- gem "rake"
5
- gem "json"
3
+ gemspec
@@ -1,22 +1,36 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ zabbixapi (3.0.0)
5
+ json
6
+
1
7
  GEM
2
8
  remote: https://rubygems.org/
3
9
  specs:
4
- diff-lcs (1.1.3)
5
- json (1.8.3)
6
- rake (0.9.2.2)
7
- rspec (2.12.0)
8
- rspec-core (~> 2.12.0)
9
- rspec-expectations (~> 2.12.0)
10
- rspec-mocks (~> 2.12.0)
11
- rspec-core (2.12.0)
12
- rspec-expectations (2.12.0)
13
- diff-lcs (~> 1.1.3)
14
- rspec-mocks (2.12.0)
10
+ diff-lcs (1.2.5)
11
+ json (2.0.3)
12
+ rake (12.0.0)
13
+ rspec (3.5.0)
14
+ rspec-core (~> 3.5.0)
15
+ rspec-expectations (~> 3.5.0)
16
+ rspec-mocks (~> 3.5.0)
17
+ rspec-core (3.5.4)
18
+ rspec-support (~> 3.5.0)
19
+ rspec-expectations (3.5.0)
20
+ diff-lcs (>= 1.2.0, < 2.0)
21
+ rspec-support (~> 3.5.0)
22
+ rspec-mocks (3.5.0)
23
+ diff-lcs (>= 1.2.0, < 2.0)
24
+ rspec-support (~> 3.5.0)
25
+ rspec-support (3.5.0)
15
26
 
16
27
  PLATFORMS
17
28
  ruby
18
29
 
19
30
  DEPENDENCIES
20
- json
21
31
  rake
22
32
  rspec
33
+ zabbixapi!
34
+
35
+ BUNDLED WITH
36
+ 1.14.3
data/README.md CHANGED
@@ -22,7 +22,7 @@ Zabbixapi has next version policy:
22
22
  * for zabbix 2.0.x you should use zabbixapi 2.0.y
23
23
  * for zabbix 2.2.x you should use zabbixapi 2.2.y
24
24
  * for zabbix 2.4.x you should use zabbixapi 2.4.y
25
- * for zabbix 3.0.x you should use zabbixapi 2.4.y (>= 2.4.7)
25
+ * for zabbix 3.0.x you should use zabbixapi 3.0.y and ruby >= 2
26
26
 
27
27
  The PATCH (third digit) version of zabbixapi should not correspond to PATCH version of zabbix, for example
28
28
  zabbixapi-2.0.x should works with all version of zabbix 2.0.y
@@ -190,7 +190,8 @@ zbx.graphs.create(
190
190
  :show_triggers => "0",
191
191
  :name => "graph",
192
192
  :width => "900",
193
- :height => "200"
193
+ :height => "200",
194
+ :hostid => zbx.templates.get_id(:host => "template")
194
195
  )
195
196
  ```
196
197
 
@@ -212,7 +213,8 @@ zbx.graphs.create_or_update(
212
213
  :show_triggers => "1",
213
214
  :name => graph,
214
215
  :width => "900",
215
- :height => "200"
216
+ :height => "200",
217
+ :hostid => zbx.templates.get_id(:host => "template")
216
218
  )
217
219
  ```
218
220
  ### Get ids by host ###
@@ -257,7 +259,7 @@ zbx.triggers.create(
257
259
  :comments => "Bla-bla is faulty (disaster)",
258
260
  :priority => 5,
259
261
  :status => 0,
260
- :templateid => 0,
262
+ :hostid => zbx.templates.get_id(:host => "template"),
261
263
  :type => 0,
262
264
  :tags => [
263
265
  {
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'json', '~> 1.8'
4
+ gem 'rspec'
@@ -0,0 +1,28 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.2.5)
5
+ json (1.8.5)
6
+ rspec (3.5.0)
7
+ rspec-core (~> 3.5.0)
8
+ rspec-expectations (~> 3.5.0)
9
+ rspec-mocks (~> 3.5.0)
10
+ rspec-core (3.5.4)
11
+ rspec-support (~> 3.5.0)
12
+ rspec-expectations (3.5.0)
13
+ diff-lcs (>= 1.2.0, < 2.0)
14
+ rspec-support (~> 3.5.0)
15
+ rspec-mocks (3.5.0)
16
+ diff-lcs (>= 1.2.0, < 2.0)
17
+ rspec-support (~> 3.5.0)
18
+ rspec-support (3.5.0)
19
+
20
+ PLATFORMS
21
+ ruby
22
+
23
+ DEPENDENCIES
24
+ json (~> 1.8)
25
+ rspec
26
+
27
+ BUNDLED WITH
28
+ 1.12.5
@@ -101,9 +101,7 @@ class ZabbixApi
101
101
  result = @client.api_request(
102
102
  :method => "#{method_name}.get",
103
103
  :params => {
104
- :filter => {
105
- indentify.to_sym => name
106
- },
104
+ :filter => data,
107
105
  :output => [key, indentify]
108
106
  }
109
107
  )
@@ -115,7 +113,7 @@ class ZabbixApi
115
113
  def get_or_create(data)
116
114
  log "[DEBUG] Call get_or_create with parameters: #{data.inspect}"
117
115
 
118
- unless (id = get_id(data))
116
+ unless (id = get_id(indentify.to_sym => data[indentify.to_sym]))
119
117
  id = create(data)
120
118
  end
121
119
  id
@@ -1,50 +1,28 @@
1
1
  class ZabbixApi
2
- class Applications
2
+ class Applications < Basic
3
3
 
4
4
  API_PARAMETERS = %w(applicationids groupids hostids inherited itemids templated templateids selectItems)
5
5
 
6
- def initialize(client)
7
- @client = client
6
+ def method_name
7
+ "application"
8
8
  end
9
9
 
10
- def create(data)
11
- result = @client.api_request(:method => "application.create", :params => [data])
12
- result.empty? ? nil : result['applicationids'][0].to_i
13
- end
14
-
15
- def add(data)
16
- create(data)
17
- end
18
-
19
- def delete(data)
20
- result = @client.api_request(:method => "application.delete", :params => [data])
21
- result.empty? ? nil : result['applicationids'][0].to_i
10
+ def indentify
11
+ "name"
22
12
  end
23
13
 
24
14
  def get_or_create(data)
25
- unless (appid = get_id(data))
26
- appid = create(data)
27
- end
28
- appid
29
- end
30
-
31
- def destroy(data)
32
- delete(data)
33
- end
15
+ log "[DEBUG] Call get_or_create with parameters: #{data.inspect}"
34
16
 
35
- def get_full_data(data)
36
- filter_params = {}
37
- request_data = data.dup # Duplicate data, as we modify it. Otherwise methods that use data after calling get_full_data (such as get_id) will fail.
38
-
39
- request_data.each { |key, value| filter_params[key] = request_data.delete(key) unless API_PARAMETERS.include?(key) }
40
- @client.api_request(:method => "application.get", :params => request_data.merge({:filter => filter_params, :output => "extend"}))
17
+ unless (id = get_id(:name => data[:name], :hostid => data[:hostid]))
18
+ id = create(data)
19
+ end
20
+ id
41
21
  end
42
22
 
43
- def get_id(data)
44
- result = get_full_data(data)
45
- applicationid = nil
46
- result.each { |app| applicationid = app['applicationid'].to_i if app['name'] == data[:name] }
47
- applicationid
23
+ def create_or_update(data)
24
+ applicationid = get_id(:name => data[:name], :hostid => data[:hostid])
25
+ applicationid ? update(data.merge(:applicationid => applicationid)) : create(data)
48
26
  end
49
27
 
50
28
  end
@@ -48,6 +48,15 @@ class ZabbixApi
48
48
  @client.api_request(:method => "graphitem.get", :params => { :graphids => [data], :output => "extend" } )
49
49
  end
50
50
 
51
+ def get_or_create(data)
52
+ log "[DEBUG] Call get_or_create with parameters: #{data.inspect}"
53
+
54
+ unless (id = get_id(:name => data[:name], :templateid => data[:templateid]))
55
+ id = create(data)
56
+ end
57
+ id
58
+ end
59
+
51
60
  def create_or_update(data)
52
61
  graphid = get_id(:name => data[:name], :templateid => data[:templateid])
53
62
  graphid ? _update(data.merge(:graphid => graphid)) : create(data)
@@ -17,8 +17,17 @@ class ZabbixApi
17
17
  }
18
18
  end
19
19
 
20
+ def get_or_create(data)
21
+ log "[DEBUG] Call get_or_create with parameters: #{data.inspect}"
22
+
23
+ unless (id = get_id(:name => data[:name], :hostid => data[:hostid]))
24
+ id = create(data)
25
+ end
26
+ id
27
+ end
28
+
20
29
  def create_or_update(data)
21
- httptestid = get_id(:name => data[:name])
30
+ httptestid = get_id(:name => data[:name], :hostid => data[:hostid])
22
31
  httptestid ? update(data.merge(:httptestid => httptestid)) : create(data)
23
32
  end
24
33
  end
@@ -45,5 +45,20 @@ class ZabbixApi
45
45
  :ipmi_sensor => ''
46
46
  }
47
47
  end
48
+
49
+ def get_or_create(data)
50
+ log "[DEBUG] Call get_or_create with parameters: #{data.inspect}"
51
+
52
+ unless (id = get_id(:name => data[:name], :hostid => data[:hostid]))
53
+ id = create(data)
54
+ end
55
+ id
56
+ end
57
+
58
+ def create_or_update(data)
59
+ itemid = get_id(:name => data[:name], :hostid => data[:hostid])
60
+ itemid ? update(data.merge(:itemid => itemid)) : create(data)
61
+ end
62
+
48
63
  end
49
64
  end
@@ -59,5 +59,19 @@ class ZabbixApi
59
59
 
60
60
  end
61
61
 
62
+ def get_or_create(data)
63
+ log "[DEBUG] Call get_or_create with parameters: #{data.inspect}"
64
+
65
+ unless (id = get_id(:description => data[:description], :hostid => data[:hostid]))
66
+ id = create(data)
67
+ end
68
+ id
69
+ end
70
+
71
+ def create_or_update(data)
72
+ triggerid = get_id(:description => data[:description], :hostid => data[:hostid])
73
+ triggerid ? update(data.merge(:triggerid => triggerid)) : create(data)
74
+ end
75
+
62
76
  end
63
77
  end
@@ -13,20 +13,6 @@ class ZabbixApi
13
13
  "name"
14
14
  end
15
15
 
16
- # Return usrgrpid
17
- #
18
- # * *Args* :
19
- # - +data+ -> Hash with :name => "UserGroup"
20
- # * *Returns* :
21
- # - Integer
22
- def get_or_create(data)
23
- usrgrpid = get_id(data)
24
- if usrgrpid.nil?
25
- usrgrpid = create(data)
26
- end
27
- usrgrpid
28
- end
29
-
30
16
  # Set permission for usrgrp on some hostgroup
31
17
  #
32
18
  # * *Args* :
@@ -8,6 +8,46 @@ class ZabbixApi
8
8
  "usermacro"
9
9
  end
10
10
 
11
+ def get_id(data)
12
+ log "[DEBUG] Call get_id with parameters: #{data.inspect}"
13
+
14
+ # symbolize keys if the user used string keys instead of symbols
15
+ data = symbolize_keys(data) if data.key?(indentify)
16
+ # raise an error if indentify name was not supplied
17
+ name = data[indentify.to_sym]
18
+ raise ApiError.new("#{indentify} not supplied in call to get_id") if name == nil
19
+
20
+ result = request(data, "usermacro.get", "hostmacroid")
21
+
22
+ result.length > 0 && result[0].key?("hostmacroid") ? result[0]["hostmacroid"].to_i : nil
23
+ end
24
+
25
+ def get_id_global(data)
26
+ log "[DEBUG] Call get_id_global with parameters: #{data.inspect}"
27
+
28
+ # symbolize keys if the user used string keys instead of symbols
29
+ data = symbolize_keys(data) if data.key?(indentify)
30
+ # raise an error if indentify name was not supplied
31
+ name = data[indentify.to_sym]
32
+ raise ApiError.new("#{indentify} not supplied in call to get_id") if name == nil
33
+
34
+ result = request(data, "usermacro.get", "globalmacroid")
35
+
36
+ result.length > 0 && result[0].key?("globalmacroid") ? result[0]["globalmacroid"].to_i : nil
37
+ end
38
+
39
+ def get_full_data(data)
40
+ log "[DEBUG] Call get_full_data with parameters: #{data.inspect}"
41
+
42
+ request(data, "usermacro.get", "hostmacroid")
43
+ end
44
+
45
+ def get_full_data_global(data)
46
+ log "[DEBUG] Call get_full_data_global with parameters: #{data.inspect}"
47
+
48
+ request(data, "usermacro.get", "globalmacroid")
49
+ end
50
+
11
51
  def create(data)
12
52
  request(data, "usermacro.create", "hostmacroids")
13
53
  end
@@ -17,25 +57,65 @@ class ZabbixApi
17
57
  end
18
58
 
19
59
  def delete(data)
20
- request(data, "usermacro.delete", "hostmacroids")
60
+ data_delete = [data]
61
+ request(data_delete, "usermacro.delete", "hostmacroids")
21
62
  end
22
63
 
23
64
  def delete_global(data)
24
- request(data, "usermacro.deleteglobal", "globalmacroids")
65
+ data_delete = [data]
66
+ request(data_delete, "usermacro.deleteglobal", "globalmacroids")
25
67
  end
26
68
 
27
- def update
69
+ def update(data)
28
70
  request(data, "usermacro.update", "hostmacroids")
29
71
  end
30
72
 
31
- def update_global
73
+ def update_global(data)
32
74
  request(data, "usermacro.updateglobal", "globalmacroids")
33
75
  end
34
76
 
77
+ def get_or_create(data)
78
+ log "[DEBUG] Call get_or_create with parameters: #{data.inspect}"
79
+
80
+ unless (id = get_id(:macro => data[:macro], :hostid => data[:hostid]))
81
+ id = create(data)
82
+ end
83
+ id
84
+ end
85
+
86
+ def get_or_create_global(data)
87
+ log "[DEBUG] Call get_or_create_global with parameters: #{data.inspect}"
88
+
89
+ unless (id = get_id_global(:macro => data[:macro], :hostid => data[:hostid]))
90
+ id = create_global(data)
91
+ end
92
+ id
93
+ end
94
+
95
+ def create_or_update(data)
96
+ hostmacroid = get_id(:macro => data[:macro], :hostid => data[:hostid])
97
+ hostmacroid ? update(data.merge(:hostmacroid => hostmacroid)) : create(data)
98
+ end
99
+
100
+ def create_or_update_global(data)
101
+ hostmacroid = get_id_global(:macro => data[:macro], :hostid => data[:hostid])
102
+ hostmacroid ? update_global(data.merge(:globalmacroid => globalmacroid)) : create_global(data)
103
+ end
104
+
35
105
  private
36
106
  def request(data, method, result_key)
37
- result = @client.api_request(:method => method, :params => data)
38
- result.empty? ? nil : result[result_key][0].to_i
107
+ # Zabbix has different result formats for gets vs updates
108
+ if method.include?(".get")
109
+ if result_key.include?("global")
110
+ result = @client.api_request(:method => method, :params => { :globalmacro => true, :filter => data })
111
+ else
112
+ result = @client.api_request(:method => method, :params => { :filter => data })
113
+ end
114
+ else
115
+ result = @client.api_request(:method => method, :params => data)
116
+
117
+ result.key?(result_key) && result[result_key].length > 0 ? result[result_key][0].to_i : nil
118
+ end
39
119
  end
40
120
 
41
121
  end
@@ -1,3 +1,3 @@
1
1
  class ZabbixApi
2
- VERSION = "2.4.9"
2
+ VERSION = "3.0.0"
3
3
  end
@@ -30,7 +30,7 @@ describe 'application' do
30
30
 
31
31
  describe 'get_id' do
32
32
  it "should return nil" do
33
- expect(zbx.applications.get_id(:host => @application)).to be_kind_of(NilClass)
33
+ expect(zbx.applications.get_id(:name => @application)).to be_kind_of(NilClass)
34
34
  end
35
35
  end
36
36
  end
@@ -65,6 +65,15 @@ describe 'application' do
65
65
  end
66
66
  end
67
67
 
68
+ describe 'create_or_update' do
69
+ it "should return id of updated application" do
70
+ expect(zbx.applications.create_or_update(
71
+ :name => @application,
72
+ :hostid => @templateid
73
+ )).to eq @applicationid
74
+ end
75
+ end
76
+
68
77
  describe "delete" do
69
78
  it "should return id" do
70
79
  expect(zbx.applications.delete(@applicationid)).to eq @applicationid
@@ -85,6 +85,15 @@ describe "trigger" do
85
85
  end
86
86
  end
87
87
 
88
+ describe 'create_or_update' do
89
+ it "should return id of updated trigger" do
90
+ expect(zbx.triggers.create_or_update(
91
+ :description => @trigger,
92
+ :hostid => @templateid
93
+ )).to eq @triggerid
94
+ end
95
+ end
96
+
88
97
  describe "delete" do
89
98
  it "should return id" do
90
99
  expect(zbx.triggers.delete( @triggerid )).to eq @triggerid
@@ -24,14 +24,15 @@ describe 'usergroup' do
24
24
  :usrgrps => [@usergroupid]
25
25
  )
26
26
 
27
+ @usergroup2 = gen_name 'usergroup'
28
+ @usergroupid2 = zbx.usergroups.create(:name => @usergroup2)
27
29
  @user2 = gen_name 'user'
28
-
29
30
  @userid2 = zbx.users.create(
30
31
  :alias => @user2,
31
32
  :name => @user2,
32
33
  :surname => @user2,
33
34
  :passwd => @user2,
34
- :usrgrps => [zbx.usergroups.create(:name => gen_name('usergroup'))]
35
+ :usrgrps => [@usergroupid2]
35
36
  )
36
37
  end
37
38
 
@@ -53,9 +54,9 @@ describe 'usergroup' do
53
54
  describe 'update_users' do
54
55
  it "should return id" do
55
56
  expect(zbx.usergroups.update_users(
56
- :usrgrpids => [@usergroupid],
57
+ :usrgrpids => [@usergroupid2],
57
58
  :userids => [@userid2]
58
- )).to eq @usergroupid
59
+ )).to eq @usergroupid2
59
60
  end
60
61
  end
61
62
 
@@ -0,0 +1,190 @@
1
+ #encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe 'usermacro' do
6
+ before :all do
7
+ @hostgroup = gen_name 'hostgroup'
8
+ @hostgroupid = zbx.hostgroups.create(:name => @hostgroup)
9
+ @template = gen_name 'template'
10
+ @templateid = zbx.templates.create(
11
+ :host => @template,
12
+ :groups => [:groupid => @hostgroupid]
13
+ )
14
+ end
15
+
16
+ context 'when hostmacro not exists' do
17
+ before do
18
+ @hostmacro = '{$' + gen_name('HOSTMACRO') + '}'
19
+ end
20
+
21
+ describe 'create' do
22
+ it "should return integer id" do
23
+ hostmacroid = zbx.usermacros.create(
24
+ :macro => @hostmacro,
25
+ :value => "public",
26
+ :hostid => @templateid
27
+ )
28
+ expect(hostmacroid).to be_kind_of(Integer)
29
+ end
30
+ end
31
+
32
+ describe 'get_id' do
33
+ it "should return nil" do
34
+ expect(zbx.usermacros.get_id(:macro => @hostmacro)).to be_kind_of(NilClass)
35
+ end
36
+ end
37
+ end
38
+
39
+ context 'when hostmacro exists' do
40
+ before :all do
41
+ @hostmacro = '{$' + gen_name('HOSTMACRO') + '}'
42
+ @hostmacroid = zbx.usermacros.create(
43
+ :macro => @hostmacro,
44
+ :value => "public",
45
+ :hostid => @templateid
46
+ )
47
+ end
48
+
49
+ describe 'get_or_create' do
50
+ it "should return id of hostmacro" do
51
+ expect(zbx.usermacros.get_or_create(
52
+ :macro => @hostmacro,
53
+ :value => "public",
54
+ :hostid => @templateid
55
+ )).to eq @hostmacroid
56
+ end
57
+ end
58
+
59
+ describe 'get_full_data' do
60
+ it "should contains created hostmacro" do
61
+ expect(zbx.usermacros.get_full_data(:macro => @hostmacro)[0]).to include("macro" => @hostmacro)
62
+ end
63
+ end
64
+
65
+ describe 'get_id' do
66
+ it "should return id of hostmacro" do
67
+ expect(zbx.usermacros.get_id(:macro => @hostmacro)).to eq @hostmacroid
68
+ end
69
+ end
70
+
71
+ it "should raise error on no identity given" do
72
+ expect { zbx.usermacros.get_id({}) }.to raise_error(ZabbixApi::ApiError)
73
+ end
74
+
75
+ describe 'update' do
76
+ it "should return id" do
77
+ expect(zbx.usermacros.update(
78
+ :hostmacroid => zbx.usermacros.get_id(:macro => @hostmacro),
79
+ :value => "private",
80
+ )).to eq @hostmacroid
81
+ end
82
+ end
83
+
84
+ describe 'create_or_update' do
85
+ it "should update existing usermacro" do
86
+ expect(zbx.usermacros.create_or_update(
87
+ :macro => @hostmacro,
88
+ :value => "public",
89
+ :hostid => @templateid
90
+ )).to eq @hostmacroid
91
+ end
92
+
93
+ it "should create usermacro" do
94
+ new_hostmacro_id = zbx.usermacros.create_or_update(
95
+ :macro => @hostmacro.gsub(/}/, "____1}"),
96
+ :value => "public",
97
+ :hostid => @templateid
98
+ )
99
+
100
+ expect(new_hostmacro_id).to be_kind_of(Integer)
101
+ expect(new_hostmacro_id).to be > @hostmacroid
102
+ end
103
+ end
104
+
105
+ describe 'delete' do
106
+ before :all do
107
+ @result = zbx.usermacros.delete(@hostmacroid)
108
+ end
109
+
110
+ it "should return deleted id" do
111
+ expect(@result).to eq @hostmacroid
112
+ end
113
+
114
+ it "should delete item from zabbix" do
115
+ expect(zbx.usermacros.get_id(:macro => @hostmacro)).to be_nil
116
+ end
117
+ end
118
+ end
119
+
120
+ context 'when globalmacro not exists' do
121
+ before do
122
+ @globalmacro = '{$' + gen_name('GLOBALMACRO') + '}'
123
+ end
124
+
125
+ describe 'create_global' do
126
+ it "should return integer id" do
127
+ globalmacroid = zbx.usermacros.create_global(
128
+ :macro => @globalmacro,
129
+ :value => "public"
130
+ )
131
+ expect(globalmacroid).to be_kind_of(Integer)
132
+ end
133
+ end
134
+
135
+ describe 'get_id_global' do
136
+ it "should return nil" do
137
+ expect(zbx.usermacros.get_id_global(:macro => @globalmacro)).to be_kind_of(NilClass)
138
+ end
139
+ end
140
+ end
141
+
142
+ context 'when globalmacro exists' do
143
+ before :all do
144
+ @globalmacro = '{$' + gen_name('GLOBALMACRO') + '}'
145
+ @globalmacroid = zbx.usermacros.create_global(
146
+ :macro => @globalmacro,
147
+ :value => "public"
148
+ )
149
+ end
150
+
151
+ describe 'get_full_data_global' do
152
+ it "should contains created globalmacro" do
153
+ expect(zbx.usermacros.get_full_data_global(:macro => @globalmacro)[0]).to include("macro" => @globalmacro)
154
+ end
155
+ end
156
+
157
+ describe 'get_id_global' do
158
+ it "should return id of globalmacro" do
159
+ expect(zbx.usermacros.get_id_global(:macro => @globalmacro)).to eq @globalmacroid
160
+ end
161
+ end
162
+
163
+ it "should raise error on no identity given" do
164
+ expect { zbx.usermacros.get_id_global({}) }.to raise_error(ZabbixApi::ApiError)
165
+ end
166
+
167
+ describe 'update_global' do
168
+ it "should return id" do
169
+ expect(zbx.usermacros.update_global(
170
+ :globalmacroid => zbx.usermacros.get_id_global(:macro => @globalmacro),
171
+ :value => "private",
172
+ )).to eq @globalmacroid
173
+ end
174
+ end
175
+
176
+ describe 'delete_global' do
177
+ before :all do
178
+ @result = zbx.usermacros.delete_global(@globalmacroid)
179
+ end
180
+
181
+ it "should return deleted id" do
182
+ expect(@result).to eq @globalmacroid
183
+ end
184
+
185
+ it "should delete item from zabbix" do
186
+ expect(zbx.usermacros.get_id_global(:macro => @globalmacro)).to be_nil
187
+ end
188
+ end
189
+ end
190
+ end
@@ -12,7 +12,10 @@ Gem::Specification.new do |s|
12
12
  s.description = %q{Allows you to work with zabbix api from ruby.}
13
13
  s.licenses = %w(MIT)
14
14
 
15
- s.add_dependency('json', '~> 1.6', '>= 1.6.0')
15
+ s.add_runtime_dependency 'json'
16
+ s.required_ruby_version = Gem::Requirement.new(">= 2".freeze)
17
+ s.add_development_dependency 'rake'
18
+ s.add_development_dependency 'rspec'
16
19
 
17
20
  s.rubyforge_project = "zabbixapi"
18
21
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zabbixapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.9
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vasiliev D.V.
@@ -9,28 +9,50 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-11-14 00:00:00.000000000 Z
12
+ date: 2017-01-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - "~>"
19
- - !ruby/object:Gem::Version
20
- version: '1.6'
21
18
  - - ">="
22
19
  - !ruby/object:Gem::Version
23
- version: 1.6.0
20
+ version: '0'
24
21
  type: :runtime
25
22
  prerelease: false
26
23
  version_requirements: !ruby/object:Gem::Requirement
27
24
  requirements:
28
- - - "~>"
25
+ - - ">="
29
26
  - !ruby/object:Gem::Version
30
- version: '1.6'
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
31
32
  - - ">="
32
33
  - !ruby/object:Gem::Version
33
- version: 1.6.0
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rspec
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
34
56
  description: Allows you to work with zabbix api from ruby.
35
57
  email:
36
58
  - vadv.mkn@gmail.com
@@ -48,6 +70,8 @@ files:
48
70
  - LICENSE
49
71
  - README.md
50
72
  - Rakefile
73
+ - json-1.x.Gemfile
74
+ - json-1.x.Gemfile.lock
51
75
  - lib/zabbixapi.rb
52
76
  - lib/zabbixapi/basic/basic_alias.rb
53
77
  - lib/zabbixapi/basic/basic_func.rb
@@ -94,6 +118,7 @@ files:
94
118
  - spec/trigger.rb
95
119
  - spec/user.rb
96
120
  - spec/usergroup.rb
121
+ - spec/usermacro.rb
97
122
  - zabbixapi.gemspec
98
123
  homepage: https://github.com/express42/zabbixapi
99
124
  licenses:
@@ -107,7 +132,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
107
132
  requirements:
108
133
  - - ">="
109
134
  - !ruby/object:Gem::Version
110
- version: '0'
135
+ version: '2'
111
136
  required_rubygems_version: !ruby/object:Gem::Requirement
112
137
  requirements:
113
138
  - - ">="
@@ -115,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
140
  version: '0'
116
141
  requirements: []
117
142
  rubyforge_project: zabbixapi
118
- rubygems_version: 2.4.3
143
+ rubygems_version: 2.5.2
119
144
  signing_key:
120
145
  specification_version: 4
121
146
  summary: Realization for Zabbix API.
@@ -139,3 +164,4 @@ test_files:
139
164
  - spec/trigger.rb
140
165
  - spec/user.rb
141
166
  - spec/usergroup.rb
167
+ - spec/usermacro.rb