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,81 +0,0 @@
1
- #encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe 'maintenance' do
6
- context 'when not exists' do
7
- before :all do
8
- @hostgroupid = zbx.hostgroups.create(:name => "hostgroup_#{rand(1_000_000)}")
9
- end
10
-
11
- describe 'create' do
12
- it "should return integer id after creation" do
13
- maintenanceid = zbx.maintenance.create(:name => "maintenance_#{rand(1_000_000)}",
14
- :groupids => [ @hostgroupid ],
15
- :active_since => 1358844540,
16
- :active_till => 1390466940,
17
- :timeperiods => [ :timeperiod_type => 3, :every => 1, :dayofweek => 64, :start_time => 64800, :period => 3600 ]
18
- )
19
- expect(maintenanceid).to be_kind_of(Integer)
20
- zbx.maintenance.delete(maintenanceid)
21
- end
22
- end
23
-
24
- after :all do
25
- zbx.hostgroups.delete(@hostgroupid)
26
- end
27
-
28
- end
29
-
30
- context 'when exists' do
31
- before :all do
32
- @hostgroupid_when_exists = zbx.hostgroups.create(:name => "hostgroup_#{rand(1_000_000)}")
33
- @maintenance = gen_name('maintenance')
34
- @maintenanceid = zbx.maintenance.create(:name => @maintenance,
35
- :groupids => [ @hostgroupid_when_exists ],
36
- :active_since => 1358844540,
37
- :active_till => 1390466940,
38
- :timeperiods => [ :timeperiod_type => 3, :every => 1, :dayofweek => 64, :start_time => 64800, :period => 3600 ]
39
- )
40
- end
41
-
42
- describe 'get_id' do
43
- it "should return id" do
44
- expect(zbx.maintenance.get_id(:name => @maintenance)).to eq @maintenanceid
45
- end
46
-
47
- it "should return nil for not existing group" do
48
- expect(zbx.maintenance.get_id(:name => "#{@maintenance}______")).to be_kind_of(NilClass)
49
- end
50
- end
51
-
52
- describe 'get_or_create' do
53
- it "should return id of existing maintenance" do
54
- expect(zbx.maintenance.get_or_create(:name => @maintenance)).to eq @maintenanceid
55
- end
56
- end
57
-
58
- describe 'create_or_update' do
59
- it "should return id of maintenance" do
60
- expect(zbx.maintenance.create_or_update(:name => @maintenance)).to eq @maintenanceid
61
- end
62
- end
63
-
64
- describe 'all' do
65
- it "should contains created maintenance" do
66
- expect(zbx.maintenance.all).to include(@maintenance => @maintenanceid.to_s)
67
- end
68
- end
69
-
70
- describe "delete" do
71
- it "shold return id" do
72
- expect(zbx.maintenance.delete(@maintenanceid)).to eq @maintenanceid
73
- end
74
- end
75
-
76
- after :all do
77
- zbx.hostgroups.delete(@hostgroupid_when_exists)
78
- end
79
-
80
- end
81
- end
@@ -1,50 +0,0 @@
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
- :smtp_helo => "test.com"
19
- )
20
- expect(mediatypeid).to be_kind_of(Integer)
21
- end
22
- end
23
- end
24
-
25
- context 'when exists' do
26
- before do
27
- @mediatypeid = zbx.mediatypes.create(
28
- :description => @mediatype,
29
- :type => 0,
30
- :smtp_server => "127.0.0.1",
31
- :smtp_email => "zabbix@test.com",
32
- :smtp_helo => "test.com"
33
- )
34
- end
35
-
36
- describe 'create_or_update' do
37
- it "should return id" do
38
- expect(zbx.mediatypes.create_or_update(
39
- :description => @mediatype,
40
- :smtp_email => "zabbix2@test.com",
41
- :smtp_helo => "test.com"
42
- )).to eq @mediatypeid
43
- end
44
-
45
- it "should return id" do
46
- expect(@mediatypeid).to eq @mediatypeid
47
- end
48
- end
49
- end
50
- end
@@ -1,18 +0,0 @@
1
- #encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe "query" do
6
- it "should works" do
7
- expect(zbx.query(
8
- method: 'host.get',
9
- params: {
10
- filter: {
11
- host: 'asdf'
12
- },
13
- selectInterfaces: 'refer'
14
- }
15
- )).to be_kind_of(Array)
16
- end
17
- end
18
-
@@ -1,88 +0,0 @@
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
- expect(screenid).to 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
- expect(screenid).to eq @screenid
79
- end
80
- end
81
-
82
- describe 'delete' do
83
- it "should return id" do
84
- expect(zbx.screens.delete(@screenid)).to eq @screenid
85
- end
86
- end
87
- end
88
- end
@@ -1,123 +0,0 @@
1
- #encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe 'script' do
6
- before :all do
7
- @hostid = zbx.hosts.get_id(:host => 'Zabbix server')
8
- end
9
-
10
- context 'when name not exists' do
11
- before do
12
- @script = gen_name 'script'
13
- end
14
-
15
- describe 'create' do
16
- it "should return integer id" do
17
- scriptid = zbx.scripts.create(
18
- :name => @script,
19
- :command => 'hostname',
20
- )
21
- expect(scriptid).to be_kind_of(Integer)
22
- end
23
- end
24
-
25
- describe 'get_id' do
26
- it "should return nil" do
27
- expect(zbx.scripts.get_id(:name => @script)).to be_kind_of(NilClass)
28
- end
29
- end
30
- end
31
-
32
- context 'when name exists' do
33
- before :all do
34
- @script = gen_name 'script'
35
- @scriptid = zbx.scripts.create(
36
- :name => @script,
37
- :command => 'hostname',
38
- )
39
- end
40
-
41
- describe 'get_or_create' do
42
- it "should return id of script" do
43
- expect(zbx.scripts.get_or_create(
44
- :name => @script,
45
- :command => 'hostname',
46
- )).to eq @scriptid
47
- end
48
- end
49
-
50
- describe 'get_full_data' do
51
- it "should contains created script" do
52
- expect(zbx.scripts.get_full_data(:name => @script)[0]).to include("name" => @script)
53
- end
54
- end
55
-
56
- describe 'get_id' do
57
- it "should return id of script" do
58
- expect(zbx.scripts.get_id(:name => @script)).to eq @scriptid
59
- end
60
- end
61
-
62
- it "should raise error on no identity given" do
63
- expect { zbx.scripts.get_id({}) }.to raise_error(ZabbixApi::ApiError)
64
- end
65
-
66
- describe 'update' do
67
- it "should return id" do
68
- expect(zbx.scripts.update(
69
- :scriptid => zbx.scripts.get_id(:name => @script),
70
- :enable_confirmation => 1,
71
- :confirmation => 'Are you sure you would like to show the system hostname?'
72
- )).to eq @scriptid
73
- end
74
- end
75
-
76
- describe 'create_or_update' do
77
- it "should update existing script" do
78
- expect(zbx.scripts.get_or_create(
79
- :name => @script,
80
- :command => 'hostname',
81
- )).to eq @scriptid
82
- end
83
-
84
- it "should create script" do
85
- new_script_id = zbx.scripts.get_or_create(
86
- :name => @script + "____1",
87
- :command => 'hostname',
88
- )
89
-
90
- expect(new_script_id).to be_kind_of(Integer)
91
- expect(new_script_id).to be > @scriptid
92
- end
93
- end
94
-
95
- # TODO: see if we can get this test working with travis ci (passes on standalone zabbix server)
96
- #describe 'execute' do
97
- # it "should return success response" do
98
- # expect(zbx.scripts.execute(:scriptid => @scriptid, :hostid => @hostid)).to include("response" => "success")
99
- # end
100
- #end
101
-
102
- describe 'getscriptsbyhost' do
103
- it "should return object with hostid and script" do
104
- expect(zbx.scripts.getscriptsbyhost([@hostid])[@hostid.to_s].select { |script| script[:name] == @script}).to_not be_nil
105
- end
106
- end
107
-
108
- describe 'delete' do
109
- before :all do
110
- @result = zbx.scripts.delete(@scriptid)
111
- end
112
-
113
- it "should return deleted id" do
114
- expect(@result).to eq @scriptid
115
- end
116
-
117
- it "should delete script from zabbix" do
118
- expect(zbx.scripts.get_id(:name => @script)).to be_nil
119
- end
120
- end
121
-
122
- end
123
- end
@@ -1,15 +0,0 @@
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
- expect(zbx.server.version).to be_kind_of(String)
9
- end
10
-
11
- it "should be 2.4.x or 3.0.x or 3.2.x" do
12
- expect(zbx.server.version).to match(/(2\.4|3\.[02])\.\d+/)
13
- end
14
- end
15
- end
@@ -1,21 +0,0 @@
1
- require 'zabbixapi'
2
-
3
-
4
- def zbx
5
- # settings
6
- @api_url = ENV['ZABBIX_HOST_URL'] || 'http://10.211.55.6/api_jsonrpc.php'
7
- @api_login = ENV['ZABBIX_USERNAME'] || 'Admin'
8
- @api_password = ENV['ZABBIX_PASSWORD'] || 'zabbix'
9
-
10
- @zbx ||= ZabbixApi.connect(
11
- :url => @api_url,
12
- :user => @api_login,
13
- :password => @api_password,
14
- :debug => ENV['ZABBIX_DEBUG']? true : false
15
- )
16
- end
17
-
18
- def gen_name(prefix)
19
- suffix = rand(1_000_000_000)
20
- "#{prefix}_#{suffix}"
21
- end
@@ -1,148 +0,0 @@
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
- expect(templateid).to 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
- expect(zbx.templates.all).to 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
- expect(zbx.templates.delete(templateid)).to 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
- expect(zbx.templates.mass_update(
103
- :hosts_id => [@hostid],
104
- :templates_id => [@templateid]
105
- )).to 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
- expect(tmpl_array).to be_kind_of(Array)
124
- expect(tmpl_array).to include @templateid.to_s
125
- end
126
- end
127
-
128
- describe "mass_add" do
129
- it "should return true" do
130
- expect(zbx.templates.mass_add(
131
- :hosts_id => [@hostid],
132
- :templates_id => [@templateid]
133
- )).to be_kind_of(TrueClass)
134
- end
135
- end
136
-
137
- describe "mass_remove" do
138
- it "should return true" do
139
- expect(zbx.templates.mass_remove(
140
- :hosts_id => [@hostid],
141
- :templates_id => [@templateid]
142
- )).to be true
143
- end
144
- end
145
- end
146
- end
147
- end
148
- end