zabbixapi 3.1.0 → 3.2.1

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.
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,176 +0,0 @@
1
- #encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe 'host' do
6
- before :all do
7
- @hostgroup = gen_name 'hostgroup'
8
- @hostgroupid = zbx.hostgroups.create(:name => @hostgroup)
9
- end
10
-
11
- context 'when name not exists' do
12
- before do
13
- @host = gen_name 'host'
14
- end
15
-
16
- describe 'create' do
17
- it "should return integer id" do
18
- hostid = zbx.hosts.create(
19
- :host => @host,
20
- :interfaces => [
21
- {
22
- :type => 1,
23
- :main => 1,
24
- :ip => "10.20.48.88",
25
- :dns => "",
26
- :port => 10050,
27
- :useip => 1
28
- }
29
- ],
30
- :groups => [:groupid => @hostgroupid]
31
- )
32
- expect(hostid).to be_kind_of(Integer)
33
- end
34
-
35
- it "should create host in multiple groups" do
36
- @hostgroupid2 = zbx.hostgroups.create(:name => gen_name('hostgroup'))
37
- host = gen_name('host')
38
- hostid = zbx.hosts.create(
39
- host: host,
40
- interfaces: [{ type: 1, main: 1, ip: '192.168.0.1', dns: 'server.example.org', port: 10050, useip: 0 }],
41
- groups: [
42
- {groupid: @hostgroupid},
43
- {groupid: @hostgroupid2}
44
- ])
45
-
46
- expect(hostid).to be_kind_of Integer
47
- host = zbx.query(method: 'host.get', params: { hostids: [hostid], selectGroups: 'extend' }).first
48
-
49
- expect(host['hostid'].to_i).to eq hostid
50
- expect(host['groups'].size).to eq 2
51
- end
52
- end
53
-
54
- describe 'get_id' do
55
- it "should return nil" do
56
- expect(zbx.hosts.get_id(:host => @host)).to be_kind_of(NilClass)
57
- expect(zbx.hosts.get_id('host' => @host)).to be_kind_of(NilClass)
58
- end
59
- end
60
- end
61
-
62
- context 'when name exists' do
63
- before :all do
64
- @host = gen_name 'host'
65
- @hostid = zbx.hosts.create(
66
- :host => @host,
67
- :interfaces => [
68
- {
69
- :type => 1,
70
- :main => 1,
71
- :ip => "10.20.48.88",
72
- :dns => "",
73
- :port => 10050,
74
- :useip => 1
75
- }
76
- ],
77
- :groups => [:groupid => @hostgroupid]
78
- )
79
- end
80
-
81
- describe 'get_or_create' do
82
- it "should return id of host" do
83
- expect(zbx.hosts.get_or_create(
84
- :host => @host,
85
- :groups => [:groupid => @hostgroupid]
86
- )).to eq @hostid
87
- end
88
- end
89
-
90
- describe 'get_full_data' do
91
- it "should contains created host" do
92
- expect(zbx.hosts.get_full_data(:host => @host)[0]).to include("host" => @host)
93
- end
94
- end
95
-
96
- describe 'get_id' do
97
- it "should return id of host" do
98
- expect(zbx.hosts.get_id(:host => @host)).to eq @hostid
99
- expect(zbx.hosts.get_id('host' => @host)).to eq @hostid
100
- end
101
- end
102
-
103
- describe 'create_or_update' do
104
- it "should return id of updated host" do
105
- expect(zbx.hosts.create_or_update(
106
- :host => @host,
107
- :interfaces => [
108
- {
109
- :type => 1,
110
- :main => 1,
111
- :ip => "10.20.48.89",
112
- :port => 10050,
113
- :useip => 1,
114
- :dns => ''
115
- }
116
- ],
117
- :groups => [:groupid => @hostgroupid]
118
- )).to eq @hostid
119
- end
120
- end
121
-
122
- describe 'update' do
123
- it "should return id" do
124
- expect(zbx.hosts.update(
125
- :hostid => @hostid,
126
- :status => 0
127
- )).to eq @hostid
128
- end
129
-
130
- it "should update groups" do
131
- @hostgroupid2 = zbx.hostgroups.create(:name => gen_name('hostgroup'))
132
-
133
- expect(zbx.hosts.update(
134
- :hostid => @hostid,
135
- :groups => [ :groupid => @hostgroupid2]
136
- )).to eq @hostid
137
-
138
- expect(zbx.hosts.dump_by_id(:hostid => @hostid).first['groups'].first["groupid"]).to eq @hostgroupid2.to_s
139
-
140
- end
141
-
142
- it "should update interfaces when use with force: true" do
143
- new_ip = '1.2.3.4'
144
- zbx.hosts.update(
145
- {:hostid => @hostid,
146
- :interfaces => [
147
- {
148
- :type => 1,
149
- :main => 1,
150
- :ip => new_ip,
151
- :port => 10050,
152
- :useip => 1,
153
- :dns => ''
154
- }
155
- ]}, true)
156
-
157
- h = zbx.query(
158
- method: 'host.get',
159
- params: {
160
- hostids: @hostid,
161
- selectInterfaces: 'extend'
162
- }
163
- ).first
164
-
165
- expect(h['interfaces'].first['ip']).to eq new_ip
166
- end
167
-
168
- end
169
-
170
- describe 'delete' do
171
- it "HOST: Delete" do
172
- expect(zbx.hosts.delete( @hostid )).to eq @hostid
173
- end
174
- end
175
- end
176
- end
@@ -1,55 +0,0 @@
1
- #encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe 'hostgroup' do
6
- context 'when not exists' do
7
- describe 'create' do
8
- it "should return integer id after creation" do
9
- hostgroupid = zbx.hostgroups.create(:name => "hostgroup_#{rand(1_000_000)}")
10
- expect(hostgroupid).to be_kind_of(Integer)
11
- end
12
- end
13
- end
14
-
15
- context 'when exists' do
16
- before :all do
17
- @hostgroup = gen_name('hostgroup')
18
- @hostgroupid = zbx.hostgroups.create(:name => @hostgroup)
19
- end
20
-
21
- describe 'get_id' do
22
- it "should return id" do
23
- expect(zbx.hostgroups.get_id(:name => @hostgroup)).to eq @hostgroupid
24
- end
25
-
26
- it "should return nil for not existing group" do
27
- expect(zbx.hostgroups.get_id(:name => "#{@hostgroup}______")).to be_kind_of(NilClass)
28
- end
29
- end
30
-
31
- describe 'get_or_create' do
32
- it "should return id of existing hostgroup" do
33
- expect(zbx.hostgroups.get_or_create(:name => @hostgroup)).to eq @hostgroupid
34
- end
35
- end
36
-
37
- describe 'create_or_update' do
38
- it "should return id of hostgroup" do
39
- expect(zbx.hostgroups.create_or_update(:name => @hostgroup)).to eq @hostgroupid
40
- end
41
- end
42
-
43
- describe 'all' do
44
- it "should contains created hostgroup" do
45
- expect(zbx.hostgroups.all).to include(@hostgroup => @hostgroupid.to_s)
46
- end
47
- end
48
-
49
- describe "delete" do
50
- it "shold return id" do
51
- expect(zbx.hostgroups.delete(@hostgroupid)).to eq @hostgroupid
52
- end
53
- end
54
- end
55
- end
@@ -1,136 +0,0 @@
1
- #encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe 'httptest' 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 name not exists' do
17
- before do
18
- @httptest_name = gen_name 'httptest_name'
19
- @step_name = gen_name 'step_name'
20
- end
21
-
22
- describe 'create' do
23
- it "should return integer id" do
24
- httptestid = zbx.httptests.create(
25
- :name => @httptest_name,
26
- :hostid => @templateid,
27
- :steps => [
28
- {
29
- :name => @step_name,
30
- :url => "http://localhost/zabbix/",
31
- :status_codes => 200,
32
- :no => 1
33
- }
34
- ]
35
- )
36
- expect(httptestid).to be_kind_of(Integer)
37
- end
38
- end
39
-
40
- describe 'get_id' do
41
- it "should return nil" do
42
- expect(zbx.httptests.get_id(:name => @httptest_name)).to be_kind_of(NilClass)
43
- expect(zbx.httptests.get_id('name' => @httptest_name)).to be_kind_of(NilClass)
44
- end
45
- end
46
- end
47
-
48
- context 'when name exists' do
49
- before :all do
50
- @httptest_name = gen_name 'httptest_name'
51
- @step_name = gen_name 'step_name'
52
- @httptestid = zbx.httptests.create(
53
- :name => @httptest_name,
54
- :hostid => @templateid,
55
- :steps => [
56
- {
57
- :name => @step_name,
58
- :url => "http://localhost/zabbix/",
59
- :status_codes => 200,
60
- :no => 1
61
- }
62
- ]
63
- )
64
- end
65
-
66
- describe 'get_or_create' do
67
- it "should return id of httptest" do
68
- expect(zbx.httptests.get_or_create(
69
- :name => @httptest_name,
70
- :hostid => @templateid,
71
- :steps => [
72
- {
73
- :name => @step_name,
74
- :url => "http://localhost/zabbix/",
75
- :status_codes => 200,
76
- :no => 1
77
- }
78
- ]
79
- )).to eq @httptestid
80
- end
81
- end
82
-
83
- describe 'get_full_data' do
84
- it "should contain created httptest" do
85
- expect(zbx.httptests.get_full_data(:name => @httptest_name)[0]).to include("name" => @httptest_name)
86
- end
87
- end
88
-
89
- describe 'get_id' do
90
- it "should return id of httptest" do
91
- expect(zbx.httptests.get_id(:name => @httptest_name)).to eq @httptestid
92
- expect(zbx.httptests.get_id('name' => @httptest_name)).to eq @httptestid
93
- end
94
- end
95
-
96
- describe 'create_or_update' do
97
- it "should return id of updated httptest" do
98
- expect(zbx.httptests.create_or_update(
99
- :name => @httptest_name,
100
- :hostid => @templateid,
101
- :steps => [
102
- {
103
- :name => @step_name,
104
- :url => "http://localhost/zabbix/",
105
- :status_codes => 200,
106
- :no => 1
107
- }
108
- ]
109
- )).to eq @httptestid
110
- end
111
- end
112
-
113
- describe 'update' do
114
- it "should return id" do
115
- expect(zbx.httptests.update(
116
- :httptestid => @httptestid,
117
- :status => 0,
118
- :steps => [
119
- {
120
- :name => @step_name,
121
- :url => "http://localhost/zabbix/",
122
- :status_codes => 200,
123
- :no => 1
124
- }
125
- ]
126
- )).to eq @httptestid
127
- end
128
- end
129
-
130
- describe 'delete' do
131
- it "HTTPTEST: Delete" do
132
- expect(zbx.httptests.delete( @httptestid )).to eq @httptestid
133
- end
134
- end
135
- end
136
- end
@@ -1,134 +0,0 @@
1
- #encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe 'item' 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
- @application = gen_name 'application'
15
- @applicationid = zbx.applications.create(
16
- :name => @application,
17
- :hostid => @templateid
18
- )
19
- end
20
-
21
- context 'when name not exists' do
22
- before do
23
- @item = gen_name 'item'
24
- end
25
-
26
- describe 'create' do
27
- it "should return integer id" do
28
- itemid = zbx.items.create(
29
- :name => @item,
30
- :key_ => "proc.num[#{gen_name 'proc'}]",
31
- :status => 0,
32
- :hostid => @templateid,
33
- :applications => [@applicationid]
34
- )
35
- expect(itemid).to be_kind_of(Integer)
36
- end
37
- end
38
-
39
- describe 'get_id' do
40
- it "should return nil" do
41
- expect(zbx.items.get_id(:name => @item)).to be_kind_of(NilClass)
42
- end
43
- end
44
- end
45
-
46
- context 'when name exists' do
47
- before :all do
48
- @item = gen_name 'item'
49
- @itemid = zbx.items.create(
50
- :name => @item,
51
- :key_ => "proc.num[aaa]",
52
- :status => 0,
53
- :hostid => @templateid,
54
- :applications => [@applicationid]
55
- )
56
- end
57
-
58
- describe 'get_or_create' do
59
- it "should return id of item" do
60
- expect(zbx.items.get_or_create(
61
- :name => @item,
62
- :key_ => "proc.num[#{gen_name 'proc'}]",
63
- :status => 0,
64
- :hostid => @templateid,
65
- :applications => [@applicationid]
66
- )).to eq @itemid
67
- end
68
- end
69
-
70
- describe 'get_full_data' do
71
- it "should contains created item" do
72
- expect(zbx.items.get_full_data(:name => @item)[0]).to include("name" => @item)
73
- end
74
- end
75
-
76
- describe 'get_id' do
77
- it "should return id of item" do
78
- expect(zbx.items.get_id(:name => @item)).to eq @itemid
79
- end
80
- end
81
-
82
- it "should raise error on no identity given" do
83
- expect { zbx.items.get_id({}) }.to raise_error(ZabbixApi::ApiError)
84
- end
85
-
86
- describe 'update' do
87
- it "should return id" do
88
- expect(zbx.items.update(
89
- :itemid => zbx.items.get_id(:name => @item),
90
- :status => 1
91
- )).to eq @itemid
92
- end
93
- end
94
-
95
- describe 'create_or_update' do
96
- it "should update existing item" do
97
- expect(zbx.items.create_or_update(
98
- :name => @item,
99
- :key_ => "proc.num[#{gen_name 'proc'}]",
100
- :status => 0,
101
- :hostid => @templateid,
102
- :applications => [@applicationid]
103
- )).to eq @itemid
104
- end
105
-
106
- it "should create item" do
107
- new_item_id = zbx.items.create_or_update(
108
- :name => @item + "____1",
109
- :key_ => "proc.num[#{gen_name 'proc'}]",
110
- :status => 0,
111
- :hostid => @templateid,
112
- :applications => [@applicationid]
113
- )
114
-
115
- expect(new_item_id).to be_kind_of(Integer)
116
- expect(new_item_id).to be > @itemid
117
- end
118
- end
119
-
120
- describe 'delete' do
121
- before :all do
122
- @result = zbx.items.delete(@itemid)
123
- end
124
-
125
- it "should return deleted id" do
126
- expect(@result).to eq @itemid
127
- end
128
-
129
- it "should delete item from zabbix" do
130
- expect(zbx.items.get_id(:name => @item)).to be_nil
131
- end
132
- end
133
- end
134
- end