zabbixapi 2.4.7 → 2.4.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +13 -10
- data/CHANGELOG.md +4 -0
- data/README.md +7 -5
- data/lib/zabbixapi.rb +5 -0
- data/lib/zabbixapi/basic/basic_logic.rb +33 -11
- data/lib/zabbixapi/classes/actions.rb +13 -0
- data/lib/zabbixapi/client.rb +1 -1
- data/lib/zabbixapi/version.rb +1 -1
- data/spec/action.rb +79 -0
- data/spec/application.rb +2 -2
- data/spec/graph.rb +9 -9
- data/spec/host.rb +10 -9
- data/spec/hostgroup.rb +6 -6
- data/spec/item.rb +12 -10
- data/spec/maintenance.rb +6 -6
- data/spec/mediatype.rb +3 -3
- data/spec/query.rb +2 -2
- data/spec/screen.rb +3 -3
- data/spec/server.rb +2 -4
- data/spec/spec_helper.rb +2 -2
- data/spec/template.rb +11 -11
- data/spec/trigger.rb +3 -3
- data/spec/user.rb +10 -10
- data/spec/usergroup.rb +9 -9
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9993377c6f344fef920fc248798eec2d010ba7ec
|
4
|
+
data.tar.gz: 96bb61c40517a55efd1f0ca1c2dde18c7d24677b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 482de14774541ede7972c80dd4b082539412f5b7bfa08ccf9b2fedcc066b415319e6226665c691f4688417b2b1647256af08751c7d70ec8c59c50932ae558f46
|
7
|
+
data.tar.gz: 246494db24bc2cc0527459d6874f2054e58259910f9f21db23375b82ea064c3aeef882993a9e68ae4e901fa725fa3d5e2aab7c2ad4b0aa380fbd7a254958850f
|
data/.travis.yml
CHANGED
@@ -6,22 +6,25 @@ rvm:
|
|
6
6
|
- 1.9.3
|
7
7
|
- 2.0
|
8
8
|
- 2.1
|
9
|
+
- 2.2
|
10
|
+
dist: trusty
|
11
|
+
sudo: required
|
12
|
+
|
9
13
|
before_script:
|
10
|
-
- sudo apt-get purge postgresql-9.1 postgresql-9.2 postgresql-9.3 postgresql-9.4
|
11
|
-
- wget -qO - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
|
12
|
-
- echo "deb http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg main" | sudo tee /etc/apt/sources.list.d/postgresql.list
|
14
|
+
- sudo apt-get purge postgresql-9.1 postgresql-9.2 postgresql-9.3 postgresql-9.4 -y
|
15
|
+
# - wget -qO - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
|
16
|
+
# - echo "deb http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg main" | sudo tee /etc/apt/sources.list.d/postgresql.list
|
13
17
|
- wget -qO - http://repo.zabbix.com/zabbix-official-repo.key | sudo apt-key add -
|
14
18
|
- echo "deb http://repo.zabbix.com/zabbix/3.0/ubuntu/ trusty main" | sudo tee /etc/apt/sources.list.d/zabbix.list
|
15
19
|
- sudo apt-get update
|
16
20
|
- sudo dpkg-reconfigure locales
|
17
|
-
- sudo apt-get install curl
|
18
|
-
- sudo apt-get install apache2
|
19
|
-
- sudo apt-get install libiodbc2
|
20
|
-
- sudo apt-get install
|
21
|
-
- sudo apt-get install zabbix-frontend-php
|
21
|
+
- sudo apt-get install curl -y
|
22
|
+
- sudo apt-get install apache2 -y
|
23
|
+
- sudo apt-get install libiodbc2 -y
|
24
|
+
- sudo apt-get install zabbix-frontend-php -y
|
22
25
|
- sudo useradd -r zabbix
|
23
|
-
- sudo apt-get install zabbix-server-pgsql
|
24
|
-
- sudo apt-get install php5-pgsql
|
26
|
+
- sudo apt-get install zabbix-server-pgsql -y
|
27
|
+
- sudo apt-get install php5-pgsql -y
|
25
28
|
- sudo sed -i "s,;date.timezone =,date.timezone = 'US/Eastern'," /etc/php5/apache2/php.ini
|
26
29
|
- 'echo -e "local all postgres trust\nlocal all all trust\nhost all all 127.0.0.1/32 trust\nhost all all ::1/128 trust" | sudo tee /etc/postgresql/9.5/main/pg_hba.conf'
|
27
30
|
- sudo /etc/init.d/postgresql restart
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -9,9 +9,10 @@ Simple and lightweight ruby module for work with zabbix api
|
|
9
9
|
* 1.8.9 (api version 1.3) /zabbixapi 0.6.x [branch zabbix1.8](https://github.com/express42/zabbixapi/tree/zabbix1.8)
|
10
10
|
* 2.0.x (api version 1.4 -> 2.0.10) /zabbixapi 2.0.x [branch zabbix2.0](https://github.com/express42/zabbixapi/tree/zabbix2.0)
|
11
11
|
* 2.2.x (api version 2.2.x) /zabbixapi 2.2.x [branch zabbix2.2](https://github.com/express42/zabbixapi/tree/zabbix2.2)
|
12
|
-
* 2.4.x (api version 2.2.x) /zabbixapi 2.4.x [master
|
12
|
+
* 2.4.x (api version 2.2.x) /zabbixapi 2.4.x [master](https://github.com/express42/zabbixapi/)
|
13
|
+
* 3.0.x (api version 3.0.x) /zabbixapi 2.4.x [master](https://github.com/express42/zabbixapi/)
|
13
14
|
|
14
|
-
Because Zabbix
|
15
|
+
Because Zabbix 3.0 is a main branch of Zabbix, so master of zabbixapi supports this version of zabbix.
|
15
16
|
|
16
17
|
## Version policy
|
17
18
|
|
@@ -20,15 +21,16 @@ Zabbixapi has next version policy:
|
|
20
21
|
* for zabbix 2.0.x you should use zabbixapi 2.0.y
|
21
22
|
* for zabbix 2.2.x you should use zabbixapi 2.2.y
|
22
23
|
* for zabbix 2.4.x you should use zabbixapi 2.4.y
|
24
|
+
* for zabbix 3.0.x you should use zabbixapi 2.4.y (>= 2.4.7)
|
23
25
|
|
24
26
|
The PATCH (third digit) version of zabbixapi should not correspond to PATCH version of zabbix, for example
|
25
27
|
zabbixapi-2.0.x should works with all version of zabbix 2.0.y
|
26
28
|
|
27
|
-
We support only two last versions of zabbix (2.
|
29
|
+
We support only two last versions of zabbix (2.4 and 3.0), so you should consider zabbixapi 0.6.x, 2.0.x and 2.2.x depricated.
|
28
30
|
|
29
31
|
## Installation
|
30
32
|
```
|
31
|
-
gem install zabbixapi -v 2.4.
|
33
|
+
gem install zabbixapi -v 2.4.7
|
32
34
|
```
|
33
35
|
|
34
36
|
## Getting Started
|
@@ -455,4 +457,4 @@ zbx.query(
|
|
455
457
|
## Zabbix documentation
|
456
458
|
|
457
459
|
* [Zabbix Project Homepage](http://zabbix.com/)
|
458
|
-
* [Zabbix Api docs](https://www.zabbix.com/documentation/
|
460
|
+
* [Zabbix Api docs](https://www.zabbix.com/documentation/3.0/manual/api/reference)
|
data/lib/zabbixapi.rb
CHANGED
@@ -24,6 +24,7 @@ require "zabbixapi/classes/usergroups"
|
|
24
24
|
require "zabbixapi/classes/usermacros"
|
25
25
|
require "zabbixapi/classes/users"
|
26
26
|
require "zabbixapi/classes/configurations"
|
27
|
+
require "zabbixapi/classes/actions"
|
27
28
|
|
28
29
|
class ZabbixApi
|
29
30
|
|
@@ -109,4 +110,8 @@ class ZabbixApi
|
|
109
110
|
@configurations ||= Configurations.new(@client)
|
110
111
|
end
|
111
112
|
|
113
|
+
def actions
|
114
|
+
@actions ||= Actions.new(@client)
|
115
|
+
end
|
116
|
+
|
112
117
|
end
|
@@ -2,7 +2,7 @@ class ZabbixApi
|
|
2
2
|
class Basic
|
3
3
|
|
4
4
|
def create(data)
|
5
|
-
log "[DEBUG] Call create with
|
5
|
+
log "[DEBUG] Call create with parameters: #{data.inspect}"
|
6
6
|
|
7
7
|
data_with_default = default_options.empty? ? data : merge_params(default_options, data)
|
8
8
|
data_create = [data_with_default]
|
@@ -11,7 +11,7 @@ class ZabbixApi
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def delete(data)
|
14
|
-
log "[DEBUG] Call delete with
|
14
|
+
log "[DEBUG] Call delete with parameters: #{data.inspect}"
|
15
15
|
|
16
16
|
data_delete = [data]
|
17
17
|
result = @client.api_request(:method => "#{method_name}.delete", :params => data_delete)
|
@@ -19,14 +19,14 @@ class ZabbixApi
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def create_or_update(data)
|
22
|
-
log "[DEBUG] Call create_or_update with
|
22
|
+
log "[DEBUG] Call create_or_update with parameters: #{data.inspect}"
|
23
23
|
|
24
24
|
id = get_id(indentify.to_sym => data[indentify.to_sym])
|
25
25
|
id ? update(data.merge(key.to_sym => id.to_s)) : create(data)
|
26
26
|
end
|
27
27
|
|
28
28
|
def update(data, force=false)
|
29
|
-
log "[DEBUG] Call update with
|
29
|
+
log "[DEBUG] Call update with parameters: #{data.inspect}"
|
30
30
|
|
31
31
|
dump = {}
|
32
32
|
item_id = data[key.to_sym].to_i
|
@@ -46,7 +46,7 @@ class ZabbixApi
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def get_full_data(data)
|
49
|
-
log "[DEBUG] Call get_full_data with
|
49
|
+
log "[DEBUG] Call get_full_data with parameters: #{data.inspect}"
|
50
50
|
|
51
51
|
@client.api_request(
|
52
52
|
:method => "#{method_name}.get",
|
@@ -59,8 +59,17 @@ class ZabbixApi
|
|
59
59
|
)
|
60
60
|
end
|
61
61
|
|
62
|
+
def get_raw(data)
|
63
|
+
log "[DEBUG] Call get_raw with parameters: #{data.inspect}"
|
64
|
+
|
65
|
+
@client.api_request(
|
66
|
+
:method => "#{method_name}.get",
|
67
|
+
:params => data
|
68
|
+
)
|
69
|
+
end
|
70
|
+
|
62
71
|
def dump_by_id(data)
|
63
|
-
log "[DEBUG] Call dump_by_id with
|
72
|
+
log "[DEBUG] Call dump_by_id with parameters: #{data.inspect}"
|
64
73
|
|
65
74
|
@client.api_request(
|
66
75
|
:method => "#{method_name}.get",
|
@@ -82,16 +91,29 @@ class ZabbixApi
|
|
82
91
|
end
|
83
92
|
|
84
93
|
def get_id(data)
|
85
|
-
log "[DEBUG] Call get_id with
|
86
|
-
|
87
|
-
|
94
|
+
log "[DEBUG] Call get_id with parameters: #{data.inspect}"
|
95
|
+
|
96
|
+
# symbolize keys if the user used string keys instead of symbols
|
97
|
+
data = symbolize_keys(data) if data.key?(indentify)
|
98
|
+
# raise an error if indentify name was not supplied
|
99
|
+
name = data[indentify.to_sym]
|
100
|
+
raise ApiError.new("#{indentify} not supplied in call to get_id") if name == nil
|
101
|
+
result = @client.api_request(
|
102
|
+
:method => "#{method_name}.get",
|
103
|
+
:params => {
|
104
|
+
:filter => {
|
105
|
+
indentify.to_sym => name
|
106
|
+
},
|
107
|
+
:output => [key, indentify]
|
108
|
+
}
|
109
|
+
)
|
88
110
|
id = nil
|
89
|
-
result.each { |item| id = item[key
|
111
|
+
result.each { |item| id = item[key].to_i if item[indentify] == data[indentify.to_sym] }
|
90
112
|
id
|
91
113
|
end
|
92
114
|
|
93
115
|
def get_or_create(data)
|
94
|
-
log "[DEBUG] Call get_or_create with
|
116
|
+
log "[DEBUG] Call get_or_create with parameters: #{data.inspect}"
|
95
117
|
|
96
118
|
unless (id = get_id(data))
|
97
119
|
id = create(data)
|
data/lib/zabbixapi/client.rb
CHANGED
@@ -27,7 +27,7 @@ class ZabbixApi
|
|
27
27
|
|
28
28
|
def initialize(options = {})
|
29
29
|
@options = options
|
30
|
-
|
30
|
+
if ENV['http_proxy'] != nil && options[:no_proxy] != true
|
31
31
|
@proxy_uri = URI.parse(ENV['http_proxy'])
|
32
32
|
@proxy_host = @proxy_uri.host
|
33
33
|
@proxy_port = @proxy_uri.port
|
data/lib/zabbixapi/version.rb
CHANGED
data/spec/action.rb
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe 'action' do
|
6
|
+
before do
|
7
|
+
@actionname = gen_name 'action'
|
8
|
+
@usergroupid = zbx.usergroups.create(:name => gen_name('usergroup'))
|
9
|
+
@actiondata = {
|
10
|
+
:name => @actionname,
|
11
|
+
:eventsource => '0', # event source is a triggerid
|
12
|
+
:status => '0', # action is enabled
|
13
|
+
:esc_period => '120', # how long each step should take
|
14
|
+
:def_shortdata => "Email header",
|
15
|
+
:def_longdata => "Email content",
|
16
|
+
:filter => {
|
17
|
+
:evaltype => '1', # perform 'and' between the conditions
|
18
|
+
:conditions => [
|
19
|
+
{
|
20
|
+
:conditiontype => '3', # trigger name
|
21
|
+
:operator => '2', # like
|
22
|
+
:value => 'pattern' # the pattern
|
23
|
+
},
|
24
|
+
{
|
25
|
+
:conditiontype => '5', # trigger value
|
26
|
+
:operator => '0', # equal
|
27
|
+
:value => '1' # 'on'
|
28
|
+
},
|
29
|
+
{
|
30
|
+
:conditiontype => '4', # trigger severity
|
31
|
+
:operator => '5', # >=
|
32
|
+
:value => '3' # average
|
33
|
+
}
|
34
|
+
]
|
35
|
+
},
|
36
|
+
:operations => [
|
37
|
+
{
|
38
|
+
:operationtype => '0', # send message
|
39
|
+
:opmessage_grp => [ # who the message will be sent to
|
40
|
+
{
|
41
|
+
:usrgrpid => @usergroupid
|
42
|
+
}
|
43
|
+
],
|
44
|
+
:opmessage => {
|
45
|
+
:default_msg => '0', # use default message
|
46
|
+
:mediatypeid => '1' # email id
|
47
|
+
}
|
48
|
+
}
|
49
|
+
]
|
50
|
+
}
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'when not exists' do
|
54
|
+
describe 'create' do
|
55
|
+
it "should return integer id" do
|
56
|
+
actionid = zbx.actions.create(@actiondata)
|
57
|
+
expect(actionid).to be_kind_of(Integer)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context 'when exists' do
|
63
|
+
before do
|
64
|
+
@actionid = zbx.actions.create(@actiondata)
|
65
|
+
end
|
66
|
+
|
67
|
+
describe 'create_or_update' do
|
68
|
+
it "should return id" do
|
69
|
+
expect(zbx.actions.create_or_update(@actiondata)).to eq @actionid
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe 'delete' do
|
74
|
+
it "should return id" do
|
75
|
+
expect(zbx.actions.delete(@actionid)).to eq @actionid
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
data/spec/application.rb
CHANGED
@@ -24,7 +24,7 @@ describe 'application' do
|
|
24
24
|
:name => @application,
|
25
25
|
:hostid => @templateid
|
26
26
|
)
|
27
|
-
applicationid.
|
27
|
+
expect(applicationid).to be_kind_of(Integer)
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
@@ -67,7 +67,7 @@ describe 'application' do
|
|
67
67
|
|
68
68
|
describe "delete" do
|
69
69
|
it "should return id" do
|
70
|
-
zbx.applications.delete(@applicationid).
|
70
|
+
expect(zbx.applications.delete(@applicationid)).to eq @applicationid
|
71
71
|
end
|
72
72
|
end
|
73
73
|
end
|
data/spec/graph.rb
CHANGED
@@ -66,13 +66,13 @@ describe 'graph' do
|
|
66
66
|
|
67
67
|
describe 'get_or_create' do
|
68
68
|
it "should return id of existing graph" do
|
69
|
-
zbx.graphs.get_or_create(
|
69
|
+
expect(zbx.graphs.get_or_create(
|
70
70
|
:gitems => [gitems],
|
71
71
|
:show_triggers => "0",
|
72
72
|
:name => @graph,
|
73
73
|
:width => "900",
|
74
74
|
:height => "200"
|
75
|
-
).
|
75
|
+
)).to eq @graphid
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
@@ -92,37 +92,37 @@ describe 'graph' do
|
|
92
92
|
|
93
93
|
describe 'get_id' do
|
94
94
|
it "should return id" do
|
95
|
-
zbx.graphs.get_id( :name => @graph ).
|
95
|
+
expect(zbx.graphs.get_id( :name => @graph )).to eq @graphid
|
96
96
|
end
|
97
97
|
end
|
98
98
|
|
99
99
|
describe 'get_ids_by_host' do
|
100
100
|
it "should contains id of graph" do
|
101
101
|
graph_array = zbx.graphs.get_ids_by_host( :host => @host )
|
102
|
-
graph_array.
|
103
|
-
graph_array.
|
102
|
+
expect(graph_array).to be_kind_of(Array)
|
103
|
+
expect(graph_array).to include(@graphid.to_s)
|
104
104
|
end
|
105
105
|
end
|
106
106
|
|
107
107
|
describe 'update' do
|
108
108
|
it "should return id" do
|
109
|
-
zbx.graphs.update(
|
109
|
+
expect(zbx.graphs.update(
|
110
110
|
:graphid => @graphid,
|
111
111
|
:gitems => [gitems],
|
112
112
|
:ymax_type => 1
|
113
|
-
).
|
113
|
+
)).to eq @graphid
|
114
114
|
end
|
115
115
|
end
|
116
116
|
|
117
117
|
describe 'create_or_update' do
|
118
118
|
it "should return existing id" do
|
119
|
-
zbx.graphs.create_or_update(
|
119
|
+
expect(zbx.graphs.create_or_update(
|
120
120
|
:gitems => [gitems],
|
121
121
|
:show_triggers => "1",
|
122
122
|
:name => @graph,
|
123
123
|
:width => "900",
|
124
124
|
:height => "200"
|
125
|
-
).
|
125
|
+
)).to eq @graphid
|
126
126
|
end
|
127
127
|
end
|
128
128
|
|
data/spec/host.rb
CHANGED
@@ -29,7 +29,7 @@ describe 'host' do
|
|
29
29
|
],
|
30
30
|
:groups => [:groupid => @hostgroupid]
|
31
31
|
)
|
32
|
-
hostid.
|
32
|
+
expect(hostid).to be_kind_of(Integer)
|
33
33
|
end
|
34
34
|
|
35
35
|
it "should create host in multiple groups" do
|
@@ -54,6 +54,7 @@ describe 'host' do
|
|
54
54
|
describe 'get_id' do
|
55
55
|
it "should return nil" do
|
56
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)
|
57
58
|
end
|
58
59
|
end
|
59
60
|
end
|
@@ -95,12 +96,13 @@ describe 'host' do
|
|
95
96
|
describe 'get_id' do
|
96
97
|
it "should return id of host" do
|
97
98
|
expect(zbx.hosts.get_id(:host => @host)).to eq @hostid
|
99
|
+
expect(zbx.hosts.get_id('host' => @host)).to eq @hostid
|
98
100
|
end
|
99
101
|
end
|
100
102
|
|
101
103
|
describe 'create_or_update' do
|
102
104
|
it "should return id of updated host" do
|
103
|
-
zbx.hosts.create_or_update(
|
105
|
+
expect(zbx.hosts.create_or_update(
|
104
106
|
:host => @host,
|
105
107
|
:interfaces => [
|
106
108
|
{
|
@@ -113,25 +115,25 @@ describe 'host' do
|
|
113
115
|
}
|
114
116
|
],
|
115
117
|
:groups => [:groupid => @hostgroupid]
|
116
|
-
).
|
118
|
+
)).to eq @hostid
|
117
119
|
end
|
118
120
|
end
|
119
121
|
|
120
122
|
describe 'update' do
|
121
123
|
it "should return id" do
|
122
|
-
zbx.hosts.update(
|
124
|
+
expect(zbx.hosts.update(
|
123
125
|
:hostid => @hostid,
|
124
126
|
:status => 0
|
125
|
-
).
|
127
|
+
)).to eq @hostid
|
126
128
|
end
|
127
129
|
|
128
130
|
it "should update groups" do
|
129
131
|
@hostgroupid2 = zbx.hostgroups.create(:name => gen_name('hostgroup'))
|
130
132
|
|
131
|
-
zbx.hosts.update(
|
133
|
+
expect(zbx.hosts.update(
|
132
134
|
:hostid => @hostid,
|
133
135
|
:groups => [ :groupid => @hostgroupid2]
|
134
|
-
).
|
136
|
+
)).to eq @hostid
|
135
137
|
|
136
138
|
expect(zbx.hosts.dump_by_id(:hostid => @hostid).first['groups'].first["groupid"]).to eq @hostgroupid2.to_s
|
137
139
|
|
@@ -167,9 +169,8 @@ describe 'host' do
|
|
167
169
|
|
168
170
|
describe 'delete' do
|
169
171
|
it "HOST: Delete" do
|
170
|
-
zbx.hosts.delete( @hostid ).
|
172
|
+
expect(zbx.hosts.delete( @hostid )).to eq @hostid
|
171
173
|
end
|
172
174
|
end
|
173
175
|
end
|
174
176
|
end
|
175
|
-
|
data/spec/hostgroup.rb
CHANGED
@@ -20,35 +20,35 @@ describe 'hostgroup' do
|
|
20
20
|
|
21
21
|
describe 'get_id' do
|
22
22
|
it "should return id" do
|
23
|
-
zbx.hostgroups.get_id(:name => @hostgroup).
|
23
|
+
expect(zbx.hostgroups.get_id(:name => @hostgroup)).to eq @hostgroupid
|
24
24
|
end
|
25
25
|
|
26
26
|
it "should return nil for not existing group" do
|
27
|
-
zbx.hostgroups.get_id(:name => "#{@hostgroup}______").
|
27
|
+
expect(zbx.hostgroups.get_id(:name => "#{@hostgroup}______")).to be_kind_of(NilClass)
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
31
|
describe 'get_or_create' do
|
32
32
|
it "should return id of existing hostgroup" do
|
33
|
-
zbx.hostgroups.get_or_create(:name => @hostgroup).
|
33
|
+
expect(zbx.hostgroups.get_or_create(:name => @hostgroup)).to eq @hostgroupid
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
37
|
describe 'create_or_update' do
|
38
38
|
it "should return id of hostgroup" do
|
39
|
-
zbx.hostgroups.create_or_update(:name => @hostgroup).
|
39
|
+
expect(zbx.hostgroups.create_or_update(:name => @hostgroup)).to eq @hostgroupid
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
43
|
describe 'all' do
|
44
44
|
it "should contains created hostgroup" do
|
45
|
-
zbx.hostgroups.all.
|
45
|
+
expect(zbx.hostgroups.all).to include(@hostgroup => @hostgroupid.to_s)
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
49
|
describe "delete" do
|
50
50
|
it "shold return id" do
|
51
|
-
zbx.hostgroups.delete(@hostgroupid).
|
51
|
+
expect(zbx.hostgroups.delete(@hostgroupid)).to eq @hostgroupid
|
52
52
|
end
|
53
53
|
end
|
54
54
|
end
|
data/spec/item.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
|
-
describe '
|
5
|
+
describe 'item' do
|
6
6
|
before :all do
|
7
7
|
@hostgroup = gen_name 'hostgroup'
|
8
8
|
@hostgroupid = zbx.hostgroups.create(:name => @hostgroup)
|
@@ -32,13 +32,13 @@ describe 'application' do
|
|
32
32
|
:hostid => @templateid,
|
33
33
|
:applications => [@applicationid]
|
34
34
|
)
|
35
|
-
itemid.
|
35
|
+
expect(itemid).to be_kind_of(Integer)
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
39
|
describe 'get_id' do
|
40
40
|
it "should return nil" do
|
41
|
-
expect(zbx.items.get_id(:
|
41
|
+
expect(zbx.items.get_id(:name => @item)).to be_kind_of(NilClass)
|
42
42
|
end
|
43
43
|
end
|
44
44
|
end
|
@@ -79,24 +79,28 @@ describe 'application' do
|
|
79
79
|
end
|
80
80
|
end
|
81
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
|
+
|
82
86
|
describe 'update' do
|
83
87
|
it "should return id" do
|
84
|
-
zbx.items.update(
|
88
|
+
expect(zbx.items.update(
|
85
89
|
:itemid => zbx.items.get_id(:name => @item),
|
86
90
|
:status => 1
|
87
|
-
).
|
91
|
+
)).to eq @itemid
|
88
92
|
end
|
89
93
|
end
|
90
94
|
|
91
95
|
describe 'create_or_update' do
|
92
96
|
it "should update existing item" do
|
93
|
-
zbx.items.create_or_update(
|
97
|
+
expect(zbx.items.create_or_update(
|
94
98
|
:name => @item,
|
95
99
|
:key_ => "proc.num[#{gen_name 'proc'}]",
|
96
100
|
:status => 0,
|
97
101
|
:hostid => @templateid,
|
98
102
|
:applications => [@applicationid]
|
99
|
-
).
|
103
|
+
)).to eq @itemid
|
100
104
|
end
|
101
105
|
|
102
106
|
it "should create item" do
|
@@ -123,10 +127,8 @@ describe 'application' do
|
|
123
127
|
end
|
124
128
|
|
125
129
|
it "should delete item from zabbix" do
|
126
|
-
expect(zbx.items.get_id(:
|
130
|
+
expect(zbx.items.get_id(:name => @item)).to be_nil
|
127
131
|
end
|
128
132
|
end
|
129
133
|
end
|
130
134
|
end
|
131
|
-
|
132
|
-
|
data/spec/maintenance.rb
CHANGED
@@ -41,35 +41,35 @@ describe 'maintenance' do
|
|
41
41
|
|
42
42
|
describe 'get_id' do
|
43
43
|
it "should return id" do
|
44
|
-
zbx.maintenance.get_id(:name => @maintenance).
|
44
|
+
expect(zbx.maintenance.get_id(:name => @maintenance)).to eq @maintenanceid
|
45
45
|
end
|
46
46
|
|
47
47
|
it "should return nil for not existing group" do
|
48
|
-
zbx.maintenance.get_id(:name => "#{@maintenance}______").
|
48
|
+
expect(zbx.maintenance.get_id(:name => "#{@maintenance}______")).to be_kind_of(NilClass)
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
52
|
describe 'get_or_create' do
|
53
53
|
it "should return id of existing maintenance" do
|
54
|
-
zbx.maintenance.get_or_create(:name => @maintenance).
|
54
|
+
expect(zbx.maintenance.get_or_create(:name => @maintenance)).to eq @maintenanceid
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
58
|
describe 'create_or_update' do
|
59
59
|
it "should return id of maintenance" do
|
60
|
-
zbx.maintenance.create_or_update(:name => @maintenance).
|
60
|
+
expect(zbx.maintenance.create_or_update(:name => @maintenance)).to eq @maintenanceid
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
64
|
describe 'all' do
|
65
65
|
it "should contains created maintenance" do
|
66
|
-
zbx.maintenance.all.
|
66
|
+
expect(zbx.maintenance.all).to include(@maintenance => @maintenanceid.to_s)
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
70
|
describe "delete" do
|
71
71
|
it "shold return id" do
|
72
|
-
zbx.maintenance.delete(@maintenanceid).
|
72
|
+
expect(zbx.maintenance.delete(@maintenanceid)).to eq @maintenanceid
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
data/spec/mediatype.rb
CHANGED
@@ -17,7 +17,7 @@ describe 'mediatype' do
|
|
17
17
|
:smtp_email => "zabbix@test.com",
|
18
18
|
:smtp_helo => "test.com"
|
19
19
|
)
|
20
|
-
mediatypeid.
|
20
|
+
expect(mediatypeid).to be_kind_of(Integer)
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
@@ -35,11 +35,11 @@ describe 'mediatype' do
|
|
35
35
|
|
36
36
|
describe 'create_or_update' do
|
37
37
|
it "should return id" do
|
38
|
-
zbx.mediatypes.create_or_update(
|
38
|
+
expect(zbx.mediatypes.create_or_update(
|
39
39
|
:description => @mediatype,
|
40
40
|
:smtp_email => "zabbix2@test.com",
|
41
41
|
:smtp_helo => "test.com"
|
42
|
-
).
|
42
|
+
)).to eq @mediatypeid
|
43
43
|
end
|
44
44
|
|
45
45
|
it "should return id" do
|
data/spec/query.rb
CHANGED
@@ -4,7 +4,7 @@ require 'spec_helper'
|
|
4
4
|
|
5
5
|
describe "query" do
|
6
6
|
it "should works" do
|
7
|
-
zbx.query(
|
7
|
+
expect(zbx.query(
|
8
8
|
method: 'host.get',
|
9
9
|
params: {
|
10
10
|
filter: {
|
@@ -12,7 +12,7 @@ describe "query" do
|
|
12
12
|
},
|
13
13
|
selectInterfaces: 'refer'
|
14
14
|
}
|
15
|
-
).
|
15
|
+
)).to be_kind_of(Array)
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
data/spec/screen.rb
CHANGED
@@ -55,7 +55,7 @@ describe 'screen' do
|
|
55
55
|
:screen_name => @screen_name,
|
56
56
|
:graphids => [@graphid]
|
57
57
|
)
|
58
|
-
screenid.
|
58
|
+
expect(screenid).to be_kind_of(Integer)
|
59
59
|
end
|
60
60
|
end
|
61
61
|
end
|
@@ -75,13 +75,13 @@ describe 'screen' do
|
|
75
75
|
:screen_name => @screen_name,
|
76
76
|
:graphids => [@graphid]
|
77
77
|
)
|
78
|
-
screenid.
|
78
|
+
expect(screenid).to eq @screenid
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
82
82
|
describe 'delete' do
|
83
83
|
it "should return id" do
|
84
|
-
zbx.screens.delete(@screenid).
|
84
|
+
expect(zbx.screens.delete(@screenid)).to eq @screenid
|
85
85
|
end
|
86
86
|
end
|
87
87
|
end
|
data/spec/server.rb
CHANGED
@@ -5,13 +5,11 @@ require 'spec_helper'
|
|
5
5
|
describe 'server' do
|
6
6
|
describe 'version' do
|
7
7
|
it "should be string" do
|
8
|
-
zbx.server.version.
|
8
|
+
expect(zbx.server.version).to be_kind_of(String)
|
9
9
|
end
|
10
10
|
|
11
11
|
it "should be 2.4.x or 3.0.x or 3.2.x" do
|
12
|
-
zbx.server.version.
|
12
|
+
expect(zbx.server.version).to match(/(2\.4|3\.[02])\.\d+/)
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
16
|
-
|
17
|
-
|
data/spec/spec_helper.rb
CHANGED
@@ -4,8 +4,8 @@ require 'zabbixapi'
|
|
4
4
|
def zbx
|
5
5
|
# settings
|
6
6
|
@api_url = ENV['ZABBIX_HOST_URL'] || 'http://10.211.55.6/api_jsonrpc.php'
|
7
|
-
@api_login = 'Admin'
|
8
|
-
@api_password = 'zabbix'
|
7
|
+
@api_login = ENV['ZABBIX_USERNAME'] || 'Admin'
|
8
|
+
@api_password = ENV['ZABBIX_PASSWORD'] || 'zabbix'
|
9
9
|
|
10
10
|
@zbx ||= ZabbixApi.connect(
|
11
11
|
:url => @api_url,
|
data/spec/template.rb
CHANGED
@@ -19,7 +19,7 @@ describe "template" do
|
|
19
19
|
:host => @template,
|
20
20
|
:groups => [:groupid => @hostgroupid]
|
21
21
|
)
|
22
|
-
templateid.
|
22
|
+
expect(templateid).to be_kind_of(Integer)
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -62,7 +62,7 @@ describe "template" do
|
|
62
62
|
|
63
63
|
describe "all" do
|
64
64
|
it "should contains template" do
|
65
|
-
zbx.templates.all.
|
65
|
+
expect(zbx.templates.all).to include(@template => @templateid.to_s)
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
@@ -73,7 +73,7 @@ describe "template" do
|
|
73
73
|
:host => template,
|
74
74
|
:groups => [:groupid => @hostgroupid]
|
75
75
|
)
|
76
|
-
zbx.templates.delete(templateid).
|
76
|
+
expect(zbx.templates.delete(templateid)).to eq templateid
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
@@ -99,10 +99,10 @@ describe "template" do
|
|
99
99
|
context "not linked with host" do
|
100
100
|
describe "mass_update" do
|
101
101
|
it "should return true" do
|
102
|
-
zbx.templates.mass_update(
|
102
|
+
expect(zbx.templates.mass_update(
|
103
103
|
:hosts_id => [@hostid],
|
104
104
|
:templates_id => [@templateid]
|
105
|
-
).
|
105
|
+
)).to be true
|
106
106
|
end
|
107
107
|
end
|
108
108
|
end
|
@@ -120,26 +120,26 @@ describe "template" do
|
|
120
120
|
tmpl_array = zbx.templates.get_ids_by_host(
|
121
121
|
:hostids => [@hostid]
|
122
122
|
)
|
123
|
-
tmpl_array.
|
124
|
-
tmpl_array.
|
123
|
+
expect(tmpl_array).to be_kind_of(Array)
|
124
|
+
expect(tmpl_array).to include @templateid.to_s
|
125
125
|
end
|
126
126
|
end
|
127
127
|
|
128
128
|
describe "mass_add" do
|
129
129
|
it "should return true" do
|
130
|
-
zbx.templates.mass_add(
|
130
|
+
expect(zbx.templates.mass_add(
|
131
131
|
:hosts_id => [@hostid],
|
132
132
|
:templates_id => [@templateid]
|
133
|
-
).
|
133
|
+
)).to be_kind_of(TrueClass)
|
134
134
|
end
|
135
135
|
end
|
136
136
|
|
137
137
|
describe "mass_remove" do
|
138
138
|
it "should return true" do
|
139
|
-
zbx.templates.mass_remove(
|
139
|
+
expect(zbx.templates.mass_remove(
|
140
140
|
:hosts_id => [@hostid],
|
141
141
|
:templates_id => [@templateid]
|
142
|
-
).
|
142
|
+
)).to be true
|
143
143
|
end
|
144
144
|
end
|
145
145
|
end
|
data/spec/trigger.rb
CHANGED
@@ -41,7 +41,7 @@ describe "trigger" do
|
|
41
41
|
:status => 0,
|
42
42
|
:type => 0
|
43
43
|
)
|
44
|
-
triggerid.
|
44
|
+
expect(triggerid).to be_kind_of(Integer)
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
@@ -61,13 +61,13 @@ describe "trigger" do
|
|
61
61
|
|
62
62
|
describe "get_id" do
|
63
63
|
it "should return id" do
|
64
|
-
zbx.triggers.get_id(:description => @trigger).
|
64
|
+
expect(zbx.triggers.get_id(:description => @trigger)).to eq @triggerid
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
68
|
describe "delete" do
|
69
69
|
it "should return id" do
|
70
|
-
zbx.triggers.delete( @triggerid ).
|
70
|
+
expect(zbx.triggers.delete( @triggerid )).to eq @triggerid
|
71
71
|
end
|
72
72
|
end
|
73
73
|
end
|
data/spec/user.rb
CHANGED
@@ -38,13 +38,13 @@ describe 'user' do
|
|
38
38
|
:passwd => user,
|
39
39
|
:usrgrps => [@usergroupid]
|
40
40
|
)
|
41
|
-
userid.
|
41
|
+
expect(userid).to be_kind_of(Integer)
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
45
|
describe 'get_id' do
|
46
46
|
it "should return nil" do
|
47
|
-
zbx.users.get_id(:alias => "name_____").
|
47
|
+
expect(zbx.users.get_id(:alias => "name_____")).to be_nil
|
48
48
|
end
|
49
49
|
end
|
50
50
|
end
|
@@ -63,33 +63,33 @@ describe 'user' do
|
|
63
63
|
|
64
64
|
describe 'create_or_update' do
|
65
65
|
it "should return id" do
|
66
|
-
zbx.users.create_or_update(
|
66
|
+
expect(zbx.users.create_or_update(
|
67
67
|
:alias => @user,
|
68
68
|
:name => @user,
|
69
69
|
:surname => @user,
|
70
70
|
:passwd => @user
|
71
|
-
).
|
71
|
+
)).to eq @userid
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
75
|
describe 'get_full_data' do
|
76
76
|
it "should return string name" do
|
77
|
-
zbx.users.get_full_data(:alias => @user)[0]['name'].
|
77
|
+
expect(zbx.users.get_full_data(:alias => @user)[0]['name']).to be_kind_of(String)
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
81
81
|
describe 'update' do
|
82
82
|
it "should return id" do
|
83
|
-
zbx.users.update(:userid => @userid, :name => gen_name('user')).
|
83
|
+
expect(zbx.users.update(:userid => @userid, :name => gen_name('user'))).to eq @userid
|
84
84
|
end
|
85
85
|
end
|
86
86
|
|
87
87
|
describe 'add_medias' do
|
88
88
|
it "should return integer media id" do
|
89
|
-
zbx.users.add_medias(
|
89
|
+
expect(zbx.users.add_medias(
|
90
90
|
:userids => [@userid],
|
91
91
|
:media => [media]
|
92
|
-
).
|
92
|
+
)).to be_kind_of(Integer)
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
@@ -102,14 +102,14 @@ describe 'user' do
|
|
102
102
|
:media => [media]
|
103
103
|
)
|
104
104
|
|
105
|
-
returned_userid.
|
105
|
+
expect(returned_userid).to eq @userid
|
106
106
|
end
|
107
107
|
end
|
108
108
|
end
|
109
109
|
|
110
110
|
describe 'delete' do
|
111
111
|
it "should return id" do
|
112
|
-
zbx.users.delete(@userid).
|
112
|
+
expect(zbx.users.delete(@userid)).to eq @userid
|
113
113
|
end
|
114
114
|
end
|
115
115
|
end
|
data/spec/usergroup.rb
CHANGED
@@ -7,7 +7,7 @@ describe 'usergroup' do
|
|
7
7
|
context 'when not exists' do
|
8
8
|
it "should be integer id" do
|
9
9
|
usergroupid = zbx.usergroups.create(:name => gen_name('usergroup'))
|
10
|
-
usergroupid.
|
10
|
+
expect(usergroupid).to be_kind_of(Integer)
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
@@ -37,41 +37,41 @@ describe 'usergroup' do
|
|
37
37
|
|
38
38
|
describe 'get_or_create' do
|
39
39
|
it "should return id" do
|
40
|
-
zbx.usergroups.get_or_create(:name => @usergroup).
|
40
|
+
expect(zbx.usergroups.get_or_create(:name => @usergroup)).to eq @usergroupid
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
44
|
describe 'add_user' do
|
45
45
|
it "should return id" do
|
46
|
-
zbx.usergroups.add_user(
|
46
|
+
expect(zbx.usergroups.add_user(
|
47
47
|
:usrgrpids => [@usergroupid],
|
48
48
|
:userids => [@userid2]
|
49
|
-
).
|
49
|
+
)).to eq @usergroupid
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
53
|
describe 'update_users' do
|
54
54
|
it "should return id" do
|
55
|
-
zbx.usergroups.update_users(
|
55
|
+
expect(zbx.usergroups.update_users(
|
56
56
|
:usrgrpids => [@usergroupid],
|
57
57
|
:userids => [@userid2]
|
58
|
-
).
|
58
|
+
)).to eq @usergroupid
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
62
|
describe 'set_perms' do
|
63
63
|
it "should return id" do
|
64
|
-
zbx.usergroups.set_perms(
|
64
|
+
expect(zbx.usergroups.set_perms(
|
65
65
|
:usrgrpid => @usergroupid,
|
66
66
|
:hostgroupids => zbx.hostgroups.all.values,
|
67
67
|
:permission => 3
|
68
|
-
).
|
68
|
+
)).to eq @usergroupid
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
72
72
|
describe 'delete' do
|
73
73
|
it "should raise error when has users with only one group" do
|
74
|
-
expect { zbx.usergroups.delete(@usergroupid) }.to raise_error
|
74
|
+
expect { zbx.usergroups.delete(@usergroupid) }.to raise_error(ZabbixApi::ApiError)
|
75
75
|
end
|
76
76
|
|
77
77
|
it "should return id of deleted group" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zabbixapi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.4.
|
4
|
+
version: 2.4.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vasiliev D.V.
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-08-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|
@@ -53,6 +53,7 @@ files:
|
|
53
53
|
- lib/zabbixapi/basic/basic_func.rb
|
54
54
|
- lib/zabbixapi/basic/basic_init.rb
|
55
55
|
- lib/zabbixapi/basic/basic_logic.rb
|
56
|
+
- lib/zabbixapi/classes/actions.rb
|
56
57
|
- lib/zabbixapi/classes/applications.rb
|
57
58
|
- lib/zabbixapi/classes/configurations.rb
|
58
59
|
- lib/zabbixapi/classes/errors.rb
|
@@ -73,6 +74,7 @@ files:
|
|
73
74
|
- lib/zabbixapi/classes/users.rb
|
74
75
|
- lib/zabbixapi/client.rb
|
75
76
|
- lib/zabbixapi/version.rb
|
77
|
+
- spec/action.rb
|
76
78
|
- spec/application.rb
|
77
79
|
- spec/basic_func.rb
|
78
80
|
- spec/configuration.rb
|
@@ -116,6 +118,7 @@ signing_key:
|
|
116
118
|
specification_version: 4
|
117
119
|
summary: Realization for Zabbix API.
|
118
120
|
test_files:
|
121
|
+
- spec/action.rb
|
119
122
|
- spec/application.rb
|
120
123
|
- spec/basic_func.rb
|
121
124
|
- spec/configuration.rb
|