zabbixapi 0.6.6 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
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/server.rb ADDED
@@ -0,0 +1,17 @@
1
+ #encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe 'server' do
6
+ describe 'version' do
7
+ it "should be string" do
8
+ zbx.server.version.should be_kind_of(String)
9
+ end
10
+
11
+ it "should be 2.0.x" do
12
+ zbx.server.version.should match(/2\.0\.\d+/)
13
+ end
14
+ end
15
+ end
16
+
17
+
@@ -0,0 +1,21 @@
1
+ require 'zabbixapi'
2
+
3
+
4
+ def zbx
5
+ # settings
6
+ @api_url = ENV['ZABBIX_HOST_URL'] || 'http://localhost:7070/api_jsonrpc.php'
7
+ @api_login = 'Admin'
8
+ @api_password = 'zabbix'
9
+
10
+ @zbx ||= ZabbixApi.connect(
11
+ :url => @api_url,
12
+ :user => @api_login,
13
+ :password => @api_password,
14
+ :debug => false
15
+ )
16
+ end
17
+
18
+ def gen_name(prefix)
19
+ suffix = rand(1_000_000_000)
20
+ "#{prefix}_#{suffix}"
21
+ end
data/spec/template.rb ADDED
@@ -0,0 +1,148 @@
1
+ #encoding: utf-8
2
+
3
+ require "spec_helper"
4
+
5
+ describe "template" 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
+ @template = gen_name "template"
14
+ end
15
+
16
+ describe "create" do
17
+ it "should return integer id" do
18
+ templateid = zbx.templates.create(
19
+ :host => @template,
20
+ :groups => [:groupid => @hostgroupid]
21
+ )
22
+ templateid.should be_kind_of(Integer)
23
+ end
24
+ end
25
+
26
+ describe "get_id" do
27
+ it "should return nil" do
28
+ expect(zbx.templates.get_id(:host => @template)).to be_kind_of(NilClass)
29
+ end
30
+ end
31
+ end
32
+
33
+ context "when name exists" do
34
+ before :all do
35
+ @template = gen_name "template"
36
+ @templateid = zbx.templates.create(
37
+ :host => @template,
38
+ :groups => [:groupid => @hostgroupid]
39
+ )
40
+ end
41
+
42
+ describe "get_or_create" do
43
+ it "should return id of template" do
44
+ expect(zbx.templates.get_or_create(
45
+ :host => @template,
46
+ :groups => [:groupid => @hostgroupid]
47
+ )).to eq @templateid
48
+ end
49
+ end
50
+
51
+ describe "get_full_data" do
52
+ it "should contains created template" do
53
+ expect(zbx.templates.get_full_data(:host => @template)[0]).to include("host" => @template)
54
+ end
55
+ end
56
+
57
+ describe "get_id" do
58
+ it "should return id of template" do
59
+ expect(zbx.templates.get_id(:host => @template)).to eq @templateid
60
+ end
61
+ end
62
+
63
+ describe "all" do
64
+ it "should contains template" do
65
+ zbx.templates.all.should include(@template => @templateid.to_s)
66
+ end
67
+ end
68
+
69
+ describe "delete" do
70
+ it "should return id" do
71
+ template = gen_name "template"
72
+ templateid = zbx.templates.create(
73
+ :host => template,
74
+ :groups => [:groupid => @hostgroupid]
75
+ )
76
+ zbx.templates.delete(templateid).should eq templateid
77
+ end
78
+ end
79
+
80
+ context "host related operations" do
81
+ before :all do
82
+ @host = gen_name 'host'
83
+ @hostid = zbx.hosts.create(
84
+ :host => @host,
85
+ :interfaces => [
86
+ {
87
+ :type => 1,
88
+ :main => 1,
89
+ :ip => "10.20.48.88",
90
+ :dns => "",
91
+ :port => 10050,
92
+ :useip => 1
93
+ }
94
+ ],
95
+ :groups => [:groupid => @hostgroupid]
96
+ )
97
+ end
98
+
99
+ context "not linked with host" do
100
+ describe "mass_update" do
101
+ it "should return true" do
102
+ zbx.templates.mass_update(
103
+ :hosts_id => [@hostid],
104
+ :templates_id => [@templateid]
105
+ ).should be_true
106
+ end
107
+ end
108
+ end
109
+
110
+ context "linked with host" do
111
+ before :all do
112
+ zbx.templates.mass_update(
113
+ :hosts_id => [@hostid],
114
+ :templates_id => [@templateid]
115
+ )
116
+ end
117
+
118
+ describe "get_ids_by_host" do
119
+ it "should contains id of linked template" do
120
+ tmpl_array = zbx.templates.get_ids_by_host(
121
+ :hostids => [@hostid]
122
+ )
123
+ tmpl_array.should be_kind_of(Array)
124
+ tmpl_array.should include @templateid.to_s
125
+ end
126
+ end
127
+
128
+ describe "mass_add" do
129
+ it "should return true" do
130
+ zbx.templates.mass_add(
131
+ :hosts_id => [@hostid],
132
+ :templates_id => [@templateid]
133
+ ).should be_kind_of(TrueClass)
134
+ end
135
+ end
136
+
137
+ describe "mass_remove" do
138
+ it "should return true" do
139
+ zbx.templates.mass_remove(
140
+ :hosts_id => [@hostid],
141
+ :templates_id => [@templateid]
142
+ ).should be_true
143
+ end
144
+ end
145
+ end
146
+ end
147
+ end
148
+ end
data/spec/trigger.rb ADDED
@@ -0,0 +1,74 @@
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
+ )
44
+ triggerid.should be_kind_of(Integer)
45
+ end
46
+ end
47
+ end
48
+
49
+ context "when name exists" do
50
+ before :all do
51
+ @trigger = gen_name 'trigger'
52
+ @triggerid = zbx.triggers.create(
53
+ :description => @trigger,
54
+ :expression => "{#{@template}:#{@proc}.last(0)}<1",
55
+ :comments => "Bla-bla is faulty (disaster)",
56
+ :priority => 5,
57
+ :status => 0,
58
+ :type => 0
59
+ )
60
+ end
61
+
62
+ describe "get_id" do
63
+ it "should return id" do
64
+ zbx.triggers.get_id(:description => @trigger).should eq @triggerid
65
+ end
66
+ end
67
+
68
+ describe "delete" do
69
+ it "should return id" do
70
+ zbx.triggers.delete( @triggerid ).should eq @triggerid
71
+ end
72
+ end
73
+ end
74
+ end
data/spec/user.rb ADDED
@@ -0,0 +1,99 @@
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
+ )
17
+ end
18
+
19
+ context 'when not exists' do
20
+ describe 'create' do
21
+ it "should return integer id" do
22
+ user = gen_name 'user'
23
+ userid = zbx.users.create(
24
+ :alias => "Test #{user}",
25
+ :name => user,
26
+ :surname => user,
27
+ :passwd => user,
28
+ :usrgrps => [@usergroupid]
29
+ )
30
+ userid.should be_kind_of(Integer)
31
+ end
32
+ end
33
+
34
+ describe 'get_id' do
35
+ it "should return nil" do
36
+ zbx.users.get_id(:name => "name_____").should be_nil
37
+ end
38
+ end
39
+ end
40
+
41
+ context 'when exists' do
42
+ before :all do
43
+ @user = gen_name 'user'
44
+ @userid = zbx.users.create(
45
+ :alias => @user,
46
+ :name => @user,
47
+ :surname => @user,
48
+ :passwd => @user,
49
+ :usrgrps => [@usergroupid]
50
+ )
51
+ end
52
+
53
+ describe 'create_or_update' do
54
+ it "should return id" do
55
+ zbx.users.create_or_update(
56
+ :alias => @user,
57
+ :name => @user,
58
+ :surname => @user,
59
+ :passwd => @user
60
+ ).should eq @userid
61
+ end
62
+ end
63
+
64
+ describe 'get_full_data' do
65
+ it "should return string name" do
66
+ zbx.users.get_full_data(:name => @user)[0]['name'].should be_kind_of(String)
67
+ end
68
+ end
69
+
70
+ describe 'update' do
71
+ it "should return id" do
72
+ zbx.users.update(:userid => @userid, :name => gen_name('user')).should eq @userid
73
+ end
74
+ end
75
+
76
+ describe 'add_medias' do
77
+ it "should return integer media id" do
78
+ zbx.users.add_medias(
79
+ :userids => [@userid],
80
+ :media => [
81
+ {
82
+ :mediatypeid => @mediatypeid,
83
+ :sendto => "test@test",
84
+ :active => 0,
85
+ :period => "1-7,00:00-24:00",
86
+ :severity => "56"
87
+ }
88
+ ]
89
+ ).should be_kind_of(Integer)
90
+ end
91
+ end
92
+
93
+ describe 'delete' do
94
+ it "should return id" do
95
+ zbx.users.delete(@userid).should eq @userid
96
+ end
97
+ end
98
+ end
99
+ end
data/spec/usergroup.rb ADDED
@@ -0,0 +1,69 @@
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
+ usergroupid.should 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
+ @user2 = gen_name 'user'
28
+
29
+ @userid2 = zbx.users.create(
30
+ :alias => @user2,
31
+ :name => @user2,
32
+ :surname => @user2,
33
+ :passwd => @user2,
34
+ :usrgrps => [zbx.usergroups.create(:name => gen_name('usergroup'))]
35
+ )
36
+ end
37
+
38
+ describe 'get_or_create' do
39
+ it "should return id" do
40
+ zbx.usergroups.get_or_create(:name => @usergroup).should eq @usergroupid
41
+ end
42
+ end
43
+
44
+ describe 'add_user' do
45
+ it "should return id" do
46
+ zbx.usergroups.add_user(
47
+ :usrgrpids => [@usergroupid],
48
+ :userids => [@userid2]
49
+ ).should eq @usergroupid
50
+ end
51
+ end
52
+
53
+ describe 'set_perms' do
54
+ it "should return id" do
55
+ zbx.usergroups.set_perms(
56
+ :usrgrpid => @usergroupid,
57
+ :hostgroupids => zbx.hostgroups.all.values,
58
+ :permission => 3
59
+ ).should eq @usergroupid
60
+ end
61
+ end
62
+
63
+ describe 'delete' do
64
+ it "should return id" do
65
+ zbx.usergroups.delete(@usergroupid).should eq @usergroupid
66
+ end
67
+ end
68
+ end
69
+ end
data/zabbixapi.gemspec CHANGED
@@ -6,13 +6,13 @@ Gem::Specification.new do |s|
6
6
  s.name = "zabbixapi"
7
7
  s.version = ZabbixApi::VERSION
8
8
  s.authors = ["Vasiliev D.V.", "Ivan Evtuhovich"]
9
- s.email = %w(vadv.mkn@gmail.com evtuhovich@gmail.com)
9
+ s.email = %w(vadv.mkn@gmail.com evtuhovich@gmail.com)
10
10
  s.homepage = "https://github.com/express42/zabbixapi"
11
11
  s.summary = %q{Realization for Zabbix API.}
12
12
  s.description = %q{Allows you to work with zabbix api from ruby.}
13
13
  s.licenses = %w(MIT)
14
-
15
- s.add_dependency('json', '~> 1.6', '>= 1.6.0')
14
+
15
+ s.add_dependency('json', '~> 1.6', '>= 1.6.0')
16
16
 
17
17
  s.rubyforge_project = "zabbixapi"
18
18