zabbixapi 0.6.6 → 2.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.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +11 -6
  3. data/README.md +21 -25
  4. data/lib/zabbixapi.rb +23 -10
  5. data/lib/zabbixapi/{1.8/basic → basic}/basic_alias.rb +0 -0
  6. data/lib/zabbixapi/{1.8/basic → basic}/basic_func.rb +3 -3
  7. data/lib/zabbixapi/{1.8/basic → basic}/basic_init.rb +0 -0
  8. data/lib/zabbixapi/{2.0/basic → basic}/basic_logic.rb +3 -3
  9. data/lib/zabbixapi/{1.8/classes → classes}/applications.rb +0 -0
  10. data/lib/zabbixapi/{1.8/classes → classes}/errors.rb +0 -0
  11. data/lib/zabbixapi/{1.8/classes → classes}/graphs.rb +0 -0
  12. data/lib/zabbixapi/{2.0/classes → classes}/hostgroups.rb +0 -0
  13. data/lib/zabbixapi/{2.0/classes → classes}/hosts.rb +4 -0
  14. data/lib/zabbixapi/{2.0/classes → classes}/items.rb +8 -0
  15. data/lib/zabbixapi/{1.8/classes → classes}/mediatypes.rb +0 -0
  16. data/lib/zabbixapi/{2.0/classes → classes}/proxies.rb +0 -0
  17. data/lib/zabbixapi/{2.0/classes → classes}/screens.rb +1 -19
  18. data/lib/zabbixapi/{1.8/classes → classes}/server.rb +0 -0
  19. data/lib/zabbixapi/{2.0/classes → classes}/templates.rb +4 -4
  20. data/lib/zabbixapi/{1.8/classes → classes}/triggers.rb +0 -0
  21. data/lib/zabbixapi/{1.8/classes → classes}/unusable.rb +0 -0
  22. data/lib/zabbixapi/{2.0/classes → classes}/usergroups.rb +0 -12
  23. data/lib/zabbixapi/{2.0/classes → classes}/usermacros.rb +0 -0
  24. data/lib/zabbixapi/{2.0/classes → classes}/users.rb +2 -2
  25. data/lib/zabbixapi/version.rb +1 -1
  26. data/spec/application.rb +74 -0
  27. data/spec/basic_func.rb +4 -0
  28. data/spec/graph.rb +135 -0
  29. data/spec/host.rb +136 -0
  30. data/spec/hostgroup.rb +55 -0
  31. data/spec/item.rb +132 -0
  32. data/spec/mediatype.rb +47 -0
  33. data/spec/query.rb +13 -0
  34. data/spec/screen.rb +88 -0
  35. data/spec/server.rb +17 -0
  36. data/spec/spec_helper.rb +21 -0
  37. data/spec/template.rb +148 -0
  38. data/spec/trigger.rb +74 -0
  39. data/spec/user.rb +99 -0
  40. data/spec/usergroup.rb +69 -0
  41. data/zabbixapi.gemspec +3 -3
  42. metadata +52 -44
  43. data/lib/zabbixapi/1.8/basic/basic_logic.rb +0 -103
  44. data/lib/zabbixapi/1.8/classes/hostgroups.rb +0 -26
  45. data/lib/zabbixapi/1.8/classes/hosts.rb +0 -58
  46. data/lib/zabbixapi/1.8/classes/items.rb +0 -54
  47. data/lib/zabbixapi/1.8/classes/screens.rb +0 -101
  48. data/lib/zabbixapi/1.8/classes/templates.rb +0 -109
  49. data/lib/zabbixapi/1.8/classes/usergroups.rb +0 -82
  50. data/lib/zabbixapi/1.8/classes/users.rb +0 -32
  51. data/lib/zabbixapi/2.0/basic/basic_alias.rb +0 -21
  52. data/lib/zabbixapi/2.0/basic/basic_func.rb +0 -55
  53. data/lib/zabbixapi/2.0/basic/basic_init.rb +0 -33
  54. data/lib/zabbixapi/2.0/classes/applications.rb +0 -45
  55. data/lib/zabbixapi/2.0/classes/errors.rb +0 -15
  56. data/lib/zabbixapi/2.0/classes/graphs.rb +0 -66
  57. data/lib/zabbixapi/2.0/classes/mediatypes.rb +0 -31
  58. data/lib/zabbixapi/2.0/classes/server.rb +0 -12
  59. data/lib/zabbixapi/2.0/classes/triggers.rb +0 -67
  60. data/lib/zabbixapi/2.0/classes/unusable.rb +0 -10
  61. data/spec/localhost.rb +0 -514
  62. data/spec/run.rb +0 -486
data/spec/host.rb ADDED
@@ -0,0 +1,136 @@
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
+ hostid.should 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
+ end
58
+ end
59
+ end
60
+
61
+ context 'when name exists' do
62
+ before :all do
63
+ @host = gen_name 'host'
64
+ @hostid = zbx.hosts.create(
65
+ :host => @host,
66
+ :interfaces => [
67
+ {
68
+ :type => 1,
69
+ :main => 1,
70
+ :ip => "10.20.48.88",
71
+ :dns => "",
72
+ :port => 10050,
73
+ :useip => 1
74
+ }
75
+ ],
76
+ :groups => [:groupid => @hostgroupid]
77
+ )
78
+ end
79
+
80
+ describe 'get_or_create' do
81
+ it "should return id of host" do
82
+ expect(zbx.hosts.get_or_create(
83
+ :host => @host,
84
+ :groups => [:groupid => @hostgroupid]
85
+ )).to eq @hostid
86
+ end
87
+ end
88
+
89
+ describe 'get_full_data' do
90
+ it "should contains created host" do
91
+ expect(zbx.hosts.get_full_data(:host => @host)[0]).to include("host" => @host)
92
+ end
93
+ end
94
+
95
+ describe 'get_id' do
96
+ it "should return id of host" do
97
+ expect(zbx.hosts.get_id(:host => @host)).to eq @hostid
98
+ end
99
+ end
100
+
101
+ describe 'create_or_update' do
102
+ it "should return id of updated host" do
103
+ zbx.hosts.create_or_update(
104
+ :host => @host,
105
+ :interfaces => [
106
+ {
107
+ :type => 1,
108
+ :main => 1,
109
+ :ip => "10.20.48.89",
110
+ :port => 10050,
111
+ :useip => 1,
112
+ :dns => ''
113
+ }
114
+ ],
115
+ :groups => [:groupid => @hostgroupid]
116
+ ).should eq @hostid
117
+ end
118
+ end
119
+
120
+ describe 'update' do
121
+ it "should return id" do
122
+ zbx.hosts.update(
123
+ :hostid => @hostid,
124
+ :status => 0
125
+ ).should eq @hostid
126
+ end
127
+ end
128
+
129
+ describe 'delete' do
130
+ it "HOST: Delete" do
131
+ zbx.hosts.delete( @hostid ).should eq @hostid
132
+ end
133
+ end
134
+ end
135
+ end
136
+
data/spec/hostgroup.rb ADDED
@@ -0,0 +1,55 @@
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
+ zbx.hostgroups.get_id(:name => @hostgroup).should eq @hostgroupid
24
+ end
25
+
26
+ it "should return nil for not existing group" do
27
+ zbx.hostgroups.get_id(:name => "#{@hostgroup}______").should 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
+ zbx.hostgroups.get_or_create(:name => @hostgroup).should eq @hostgroupid
34
+ end
35
+ end
36
+
37
+ describe 'create_or_update' do
38
+ it "should return id of hostgroup" do
39
+ zbx.hostgroups.create_or_update(:name => @hostgroup).should eq @hostgroupid
40
+ end
41
+ end
42
+
43
+ describe 'all' do
44
+ it "should contains created hostgroup" do
45
+ zbx.hostgroups.all.should include(@hostgroup => @hostgroupid.to_s)
46
+ end
47
+ end
48
+
49
+ describe "delete" do
50
+ it "shold return id" do
51
+ zbx.hostgroups.delete(@hostgroupid).should eq @hostgroupid
52
+ end
53
+ end
54
+ end
55
+ end
data/spec/item.rb ADDED
@@ -0,0 +1,132 @@
1
+ #encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe 'application' 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
+ itemid.should 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(:host => @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
+ describe 'update' do
83
+ it "should return id" do
84
+ zbx.items.update(
85
+ :itemid => zbx.items.get_id(:name => @item),
86
+ :status => 1
87
+ ).should eq @itemid
88
+ end
89
+ end
90
+
91
+ describe 'create_or_update' do
92
+ it "should update existing item" do
93
+ zbx.items.create_or_update(
94
+ :name => @item,
95
+ :key_ => "proc.num[#{gen_name 'proc'}]",
96
+ :status => 0,
97
+ :hostid => @templateid,
98
+ :applications => [@applicationid]
99
+ ).should eq @itemid
100
+ end
101
+
102
+ it "should create item" do
103
+ new_item_id = zbx.items.create_or_update(
104
+ :name => @item + "____1",
105
+ :key_ => "proc.num[#{gen_name 'proc'}]",
106
+ :status => 0,
107
+ :hostid => @templateid,
108
+ :applications => [@applicationid]
109
+ )
110
+
111
+ expect(new_item_id).to be_kind_of(Integer)
112
+ expect(new_item_id).to be > @itemid
113
+ end
114
+ end
115
+
116
+ describe 'delete' do
117
+ before :all do
118
+ @result = zbx.items.delete(@itemid)
119
+ end
120
+
121
+ it "should return deleted id" do
122
+ expect(@result).to eq @itemid
123
+ end
124
+
125
+ it "should delete item from zabbix" do
126
+ expect(zbx.items.get_id(:id => @itemid)).to be_nil
127
+ end
128
+ end
129
+ end
130
+ end
131
+
132
+
data/spec/mediatype.rb ADDED
@@ -0,0 +1,47 @@
1
+ #encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe 'mediatype' do
6
+ before do
7
+ @mediatype = gen_name 'mediatype'
8
+ end
9
+
10
+ context 'when not exists' do
11
+ describe 'create' do
12
+ it "should return integer id" do
13
+ mediatypeid = zbx.mediatypes.create(
14
+ :description => @mediatype,
15
+ :type => 0,
16
+ :smtp_server => "127.0.0.1",
17
+ :smtp_email => "zabbix@test.com"
18
+ )
19
+ mediatypeid.should be_kind_of(Integer)
20
+ end
21
+ end
22
+ end
23
+
24
+ context 'when exists' do
25
+ before do
26
+ @mediatypeid = zbx.mediatypes.create(
27
+ :description => @mediatype,
28
+ :type => 0,
29
+ :smtp_server => "127.0.0.1",
30
+ :smtp_email => "zabbix@test.com"
31
+ )
32
+ end
33
+
34
+ describe 'create_or_update' do
35
+ it "should return id" do
36
+ zbx.mediatypes.create_or_update(
37
+ :description => @mediatype,
38
+ :smtp_email => "zabbix2@test.com"
39
+ ).should eq @mediatypeid
40
+ end
41
+
42
+ it "should return id" do
43
+ expect(@mediatypeid).to eq @mediatypeid
44
+ end
45
+ end
46
+ end
47
+ end
data/spec/query.rb ADDED
@@ -0,0 +1,13 @@
1
+ #encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe "query" do
6
+ it "should works" do
7
+ zbx.query(
8
+ :method => "apiinfo.version",
9
+ :params => {}
10
+ ).should be_kind_of(String)
11
+ end
12
+ end
13
+
data/spec/screen.rb ADDED
@@ -0,0 +1,88 @@
1
+ #encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe 'screen' 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
+ @item = gen_name 'item'
20
+ @itemid = zbx.items.create(
21
+ :name => @item,
22
+ :key_ => "proc.num[#{gen_name 'proc'}]",
23
+ :status => 0,
24
+ :hostid => @templateid,
25
+ :applications => [@applicationid]
26
+ )
27
+
28
+ @color = "123456"
29
+
30
+ @gitems = {
31
+ :itemid => @itemid,
32
+ :calc_fnc => "3",
33
+ :color => @color,
34
+ :type => "0",
35
+ :periods_cnt => "5"
36
+ }
37
+
38
+ @graph = gen_name 'graph'
39
+
40
+ @graphid = zbx.graphs.create(
41
+ :gitems => [@gitems],
42
+ :show_triggers => "0",
43
+ :name => @graph,
44
+ :width => "900",
45
+ :height => "200"
46
+ )
47
+
48
+ @screen_name = gen_name 'screen'
49
+ end
50
+
51
+ context 'when not exists' do
52
+ describe 'get_or_create_for_host' do
53
+ it "should return id" do
54
+ screenid = zbx.screens.get_or_create_for_host(
55
+ :screen_name => @screen_name,
56
+ :graphids => [@graphid]
57
+ )
58
+ screenid.should be_kind_of(Integer)
59
+ end
60
+ end
61
+ end
62
+
63
+ context 'when exists' do
64
+ before do
65
+ @screen_name = gen_name 'screen'
66
+ @screenid = zbx.screens.get_or_create_for_host(
67
+ :screen_name => @screen_name,
68
+ :graphids => [@graphid]
69
+ )
70
+ end
71
+
72
+ describe 'get_or_create_for_host' do
73
+ it "should return id" do
74
+ screenid = zbx.screens.get_or_create_for_host(
75
+ :screen_name => @screen_name,
76
+ :graphids => [@graphid]
77
+ )
78
+ screenid.should eq @screenid
79
+ end
80
+ end
81
+
82
+ describe 'delete' do
83
+ it "should return id" do
84
+ zbx.screens.delete(@screenid).should eq @screenid
85
+ end
86
+ end
87
+ end
88
+ end