zabbixapi 3.1.0 → 3.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +9 -0
  3. data/CHANGELOG.md +5 -0
  4. data/{LICENSE → LICENSE.md} +1 -1
  5. data/README.md +53 -569
  6. data/lib/zabbixapi.rb +102 -65
  7. data/lib/zabbixapi/basic/basic_alias.rb +21 -4
  8. data/lib/zabbixapi/basic/basic_func.rb +56 -23
  9. data/lib/zabbixapi/basic/basic_init.rb +21 -4
  10. data/lib/zabbixapi/basic/basic_logic.rb +75 -18
  11. data/lib/zabbixapi/classes/actions.rb +8 -4
  12. data/lib/zabbixapi/classes/applications.rb +20 -6
  13. data/lib/zabbixapi/classes/configurations.rb +23 -17
  14. data/lib/zabbixapi/classes/errors.rb +2 -4
  15. data/lib/zabbixapi/classes/graphs.rb +65 -15
  16. data/lib/zabbixapi/classes/hostgroups.rb +12 -4
  17. data/lib/zabbixapi/classes/hosts.rb +36 -10
  18. data/lib/zabbixapi/classes/httptests.rb +24 -4
  19. data/lib/zabbixapi/classes/items.rb +24 -5
  20. data/lib/zabbixapi/classes/maintenance.rb +8 -4
  21. data/lib/zabbixapi/classes/mediatypes.rb +20 -13
  22. data/lib/zabbixapi/classes/proxies.rb +29 -8
  23. data/lib/zabbixapi/classes/screens.rb +41 -25
  24. data/lib/zabbixapi/classes/server.rb +8 -4
  25. data/lib/zabbixapi/classes/templates.rb +46 -43
  26. data/lib/zabbixapi/classes/triggers.rb +43 -16
  27. data/lib/zabbixapi/classes/unusable.rb +0 -2
  28. data/lib/zabbixapi/classes/usergroups.rb +33 -26
  29. data/lib/zabbixapi/classes/usermacros.rb +137 -31
  30. data/lib/zabbixapi/classes/users.rb +32 -10
  31. data/lib/zabbixapi/classes/valuemaps.rb +50 -0
  32. data/lib/zabbixapi/client.rb +61 -22
  33. data/lib/zabbixapi/version.rb +1 -1
  34. data/zabbixapi.gemspec +26 -23
  35. metadata +25 -73
  36. data/.gitignore +0 -7
  37. data/.rspec +0 -1
  38. data/.travis.yml +0 -41
  39. data/Gemfile +0 -3
  40. data/Gemfile.lock +0 -36
  41. data/Rakefile +0 -1
  42. data/json-1.x.Gemfile +0 -4
  43. data/json-1.x.Gemfile.lock +0 -28
  44. data/spec/action.rb +0 -89
  45. data/spec/application.rb +0 -83
  46. data/spec/basic_func.rb +0 -4
  47. data/spec/configuration.rb +0 -122
  48. data/spec/graph.rb +0 -135
  49. data/spec/host.rb +0 -176
  50. data/spec/hostgroup.rb +0 -55
  51. data/spec/httptest.rb +0 -136
  52. data/spec/item.rb +0 -134
  53. data/spec/maintenance.rb +0 -81
  54. data/spec/mediatype.rb +0 -50
  55. data/spec/query.rb +0 -18
  56. data/spec/screen.rb +0 -88
  57. data/spec/script.rb +0 -123
  58. data/spec/server.rb +0 -15
  59. data/spec/spec_helper.rb +0 -21
  60. data/spec/template.rb +0 -148
  61. data/spec/trigger.rb +0 -103
  62. data/spec/user.rb +0 -116
  63. data/spec/usergroup.rb +0 -85
  64. data/spec/usermacro.rb +0 -190
@@ -1,103 +0,0 @@
1
-
2
- #encoding: utf-8
3
-
4
- require "spec_helper"
5
-
6
- describe "trigger" do
7
- before :all do
8
- @hostgroup = gen_name "hostgroup"
9
- @hostgroupid = zbx.hostgroups.create(:name => @hostgroup)
10
- @template = gen_name "template"
11
- @templateid = zbx.templates.create(
12
- :host => @template,
13
- :groups => [:groupid => @hostgroupid]
14
- )
15
- @application = gen_name 'application'
16
- @applicationid = zbx.applications.create(
17
- :name => @application,
18
- :hostid => @templateid
19
- )
20
- @item = gen_name 'item'
21
- @proc = "proc.num[#{gen_name 'proc'}]"
22
- @itemid = zbx.items.create(
23
- :name => @item,
24
- :key_ => @proc,
25
- :status => 0,
26
- :hostid => @templateid,
27
- :applications => [@applicationid]
28
- )
29
-
30
- end
31
-
32
- context "when name not exists" do
33
- describe "create" do
34
- it "should return integer id" do
35
- @trigger = gen_name 'trigger'
36
- triggerid = zbx.triggers.create(
37
- :description => @trigger,
38
- :expression => "{#{@template}:#{@proc}.last(0)}<1",
39
- :comments => "Bla-bla is faulty (disaster)",
40
- :priority => 5,
41
- :status => 0,
42
- :type => 0,
43
- :tags => [
44
- {
45
- :tag => "proc",
46
- :value => "#{@proc}"
47
- },
48
- {
49
- :tag => "error",
50
- :value => ""
51
- }
52
- ]
53
- )
54
- expect(triggerid).to be_kind_of(Integer)
55
- end
56
- end
57
- end
58
-
59
- context "when name exists" do
60
- before :all do
61
- @trigger = gen_name 'trigger'
62
- @triggerid = zbx.triggers.create(
63
- :description => @trigger,
64
- :expression => "{#{@template}:#{@proc}.last(0)}<1",
65
- :comments => "Bla-bla is faulty (disaster)",
66
- :priority => 5,
67
- :status => 0,
68
- :type => 0,
69
- :tags => [
70
- {
71
- :tag => "proc",
72
- :value => "#{@proc}"
73
- },
74
- {
75
- :tag => "error",
76
- :value => ""
77
- }
78
- ]
79
- )
80
- end
81
-
82
- describe "get_id" do
83
- it "should return id" do
84
- expect(zbx.triggers.get_id(:description => @trigger)).to eq @triggerid
85
- end
86
- end
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
-
97
- describe "delete" do
98
- it "should return id" do
99
- expect(zbx.triggers.delete( @triggerid )).to eq @triggerid
100
- end
101
- end
102
- end
103
- end
@@ -1,116 +0,0 @@
1
- #encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe 'user' do
6
- before :all do
7
- @usergroup = gen_name 'usergroup'
8
- @usergroupid = zbx.usergroups.create(:name => @usergroup)
9
-
10
- @mediatype = gen_name 'mediatype'
11
- @mediatypeid = zbx.mediatypes.create(
12
- :description => @mediatype,
13
- :type => 0,
14
- :smtp_server => "127.0.0.1",
15
- :smtp_email => "zabbix@test.com",
16
- :smtp_helo => "test.com"
17
- )
18
- end
19
-
20
- def media
21
- {
22
- :mediatypeid => @mediatypeid,
23
- :sendto => "test@test",
24
- :active => 0,
25
- :period => "1-7,00:00-24:00",
26
- :severity => "56"
27
- }
28
- end
29
-
30
- context 'when not exists' do
31
- describe 'create' do
32
- it "should return integer id" do
33
- user = gen_name 'user'
34
- userid = zbx.users.create(
35
- :alias => user,
36
- :name => user,
37
- :surname => user,
38
- :passwd => user,
39
- :usrgrps => [@usergroupid]
40
- )
41
- expect(userid).to be_kind_of(Integer)
42
- end
43
- end
44
-
45
- describe 'get_id' do
46
- it "should return nil" do
47
- expect(zbx.users.get_id(:alias => "name_____")).to be_nil
48
- end
49
- end
50
- end
51
-
52
- context 'when exists' do
53
- before :all do
54
- @user = gen_name 'user'
55
- @userid = zbx.users.create(
56
- :alias => @user,
57
- :name => @user,
58
- :surname => @user,
59
- :passwd => @user,
60
- :usrgrps => [@usergroupid]
61
- )
62
- end
63
-
64
- describe 'create_or_update' do
65
- it "should return id" do
66
- expect(zbx.users.create_or_update(
67
- :alias => @user,
68
- :name => @user,
69
- :surname => @user,
70
- :passwd => @user
71
- )).to eq @userid
72
- end
73
- end
74
-
75
- describe 'get_full_data' do
76
- it "should return string name" do
77
- expect(zbx.users.get_full_data(:alias => @user)[0]['name']).to be_kind_of(String)
78
- end
79
- end
80
-
81
- describe 'update' do
82
- it "should return id" do
83
- expect(zbx.users.update(:userid => @userid, :name => gen_name('user'))).to eq @userid
84
- end
85
- end
86
-
87
- describe 'add_medias' do
88
- it "should return integer media id" do
89
- expect(zbx.users.add_medias(
90
- :userids => [@userid],
91
- :media => [media]
92
- )).to be_kind_of(Integer)
93
- end
94
- end
95
-
96
- describe 'update_medias' do
97
- it "should return the user id" do
98
- # Call twice to ensure update_medias first successfully creates the media, then updates it
99
- 2.times do
100
- returned_userid = zbx.users.update_medias(
101
- :userids => [@userid],
102
- :media => [media]
103
- )
104
-
105
- expect(returned_userid).to eq @userid
106
- end
107
- end
108
- end
109
-
110
- describe 'delete' do
111
- it "should return id" do
112
- expect(zbx.users.delete(@userid)).to eq @userid
113
- end
114
- end
115
- end
116
- end
@@ -1,85 +0,0 @@
1
- #encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe 'usergroup' do
6
-
7
- context 'when not exists' do
8
- it "should be integer id" do
9
- usergroupid = zbx.usergroups.create(:name => gen_name('usergroup'))
10
- expect(usergroupid).to be_kind_of(Integer)
11
- end
12
- end
13
-
14
- context 'when exists' do
15
- before do
16
- @usergroup = gen_name 'usergroup'
17
- @usergroupid = zbx.usergroups.create(:name => @usergroup)
18
- @user = gen_name 'user'
19
- @userid = zbx.users.create(
20
- :alias => @user,
21
- :name => @user,
22
- :surname => @user,
23
- :passwd => @user,
24
- :usrgrps => [@usergroupid]
25
- )
26
-
27
- @usergroup2 = gen_name 'usergroup'
28
- @usergroupid2 = zbx.usergroups.create(:name => @usergroup2)
29
- @user2 = gen_name 'user'
30
- @userid2 = zbx.users.create(
31
- :alias => @user2,
32
- :name => @user2,
33
- :surname => @user2,
34
- :passwd => @user2,
35
- :usrgrps => [@usergroupid2]
36
- )
37
- end
38
-
39
- describe 'get_or_create' do
40
- it "should return id" do
41
- expect(zbx.usergroups.get_or_create(:name => @usergroup)).to eq @usergroupid
42
- end
43
- end
44
-
45
- describe 'add_user' do
46
- it "should return id" do
47
- expect(zbx.usergroups.add_user(
48
- :usrgrpids => [@usergroupid],
49
- :userids => [@userid2]
50
- )).to eq @usergroupid
51
- end
52
- end
53
-
54
- describe 'update_users' do
55
- it "should return id" do
56
- expect(zbx.usergroups.update_users(
57
- :usrgrpids => [@usergroupid2],
58
- :userids => [@userid2]
59
- )).to eq @usergroupid2
60
- end
61
- end
62
-
63
- describe 'set_perms' do
64
- it "should return id" do
65
- expect(zbx.usergroups.set_perms(
66
- :usrgrpid => @usergroupid,
67
- :hostgroupids => zbx.hostgroups.all.values,
68
- :permission => 3
69
- )).to eq @usergroupid
70
- end
71
- end
72
-
73
- describe 'delete' do
74
- it "should raise error when has users with only one group" do
75
- expect { zbx.usergroups.delete(@usergroupid) }.to raise_error(ZabbixApi::ApiError)
76
- end
77
-
78
- it "should return id of deleted group" do
79
- usergroupid = zbx.usergroups.create(:name => gen_name('usergroup'))
80
-
81
- expect(zbx.usergroups.delete(usergroupid)).to eq usergroupid
82
- end
83
- end
84
- end
85
- end
@@ -1,190 +0,0 @@
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