zabbixapi 2.4.2 → 2.4.3
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.
- checksums.yaml +4 -4
- data/.travis.yml +14 -4
- data/LICENSE +20 -0
- data/README.md +40 -10
- data/lib/zabbixapi/basic/basic_func.rb +15 -1
- data/lib/zabbixapi/classes/hosts.rb +15 -0
- data/lib/zabbixapi/classes/templates.rb +1 -1
- data/lib/zabbixapi/classes/users.rb +11 -0
- data/lib/zabbixapi/client.rb +1 -1
- data/lib/zabbixapi/version.rb +1 -1
- data/spec/host.rb +12 -0
- data/spec/user.rb +25 -9
- metadata +13 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4a430b3b9e7367023a5a75e19414e842eb791a3c
|
4
|
+
data.tar.gz: 0f78b7cfbbecbb96223ed5e5fc43fc6babc63c05
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2fa71a223935015b12a3c319bc649a4e6a5ee12c676305f18a25de690cc0feb0e1da86bb31b716dae402f4637a61d0afa80feb9c2ed30fc791c7260c373b4870
|
7
|
+
data.tar.gz: e23d53427667a09bf898a5e6c5b17acd59fa5d77df155e0a480045abb4a565c5c1000ca4e21dc1562b5e081cda412477ac7139ea5986d53f35dea4c05f7e6a55
|
data/.travis.yml
CHANGED
@@ -1,14 +1,24 @@
|
|
1
1
|
language:
|
2
2
|
- ruby
|
3
|
+
addons:
|
4
|
+
postgresql: "9.4"
|
3
5
|
rvm:
|
4
6
|
- 1.9.3
|
5
|
-
- 2.0
|
7
|
+
- 2.0
|
6
8
|
- 2.1
|
7
9
|
before_script:
|
8
|
-
-
|
9
|
-
-
|
10
|
+
- sudo apt-get purge postgresql-9.1 postgresql-9.2 postgresql-9.3
|
11
|
+
- wget -qO - http://repo.zabbix.com/zabbix-official-repo.key | sudo apt-key add -
|
12
|
+
- echo "deb http://repo.zabbix.com/zabbix/2.4/ubuntu/ precise main" | sudo tee /etc/apt/sources.list.d/zabbix.list
|
10
13
|
- sudo apt-get update
|
11
14
|
- sudo apt-get install libiodbc2
|
12
|
-
- sudo apt-get install
|
15
|
+
- sudo apt-get install postgresql
|
16
|
+
- sudo apt-get install zabbix-frontend-php
|
17
|
+
- sudo useradd -r zabbix
|
18
|
+
- sudo apt-get install zabbix-server-pgsql
|
19
|
+
- sudo apt-get install php5-pgsql
|
20
|
+
- sudo service apache2 restart
|
21
|
+
- 'echo -e "local all all trust\nhost all all 127.0.0.1/32 trust\nhost all all ::1/128 trust" | sudo tee /etc/postgresql/9.4/main/pg_hba.conf'
|
22
|
+
- sudo pg_ctlcluster 9.4 main reload
|
13
23
|
- echo "$(curl -fsSL https://gist.githubusercontent.com/evtuhovich/9544441/raw/d661863063b76cc8e2599bc44d8595b1f86ece38/zabbix)" | sudo tee /etc/zabbix/web/zabbix.conf.php
|
14
24
|
script: "ZABBIX_HOST_URL=http://localhost/zabbix/api_jsonrpc.php bundle exec rspec spec/*"
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Express 42
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -8,10 +8,10 @@ Simple and lightweight ruby module for work with zabbix api
|
|
8
8
|
* 1.8.2 (api version 1.2) /zabbixapi 0.6.x [branch zabbix1.8](https://github.com/express42/zabbixapi/tree/zabbix1.8)
|
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
|
-
* 2.2.x (api version 2.2.x) /zabbixapi 2.2.x [
|
12
|
-
* 2.4.x (api version 2.2.x) /zabbixapi 2.4.x [branch zabbix2.4](https://github.com/express42/zabbixapi/
|
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 or branch zabbix2.4](https://github.com/express42/zabbixapi/)
|
13
13
|
|
14
|
-
Because Zabbix 2.
|
14
|
+
Because Zabbix 2.4 is a main branch of Zabbix, so master of zabbixapi supports this version of zabbix.
|
15
15
|
|
16
16
|
## Version policy
|
17
17
|
|
@@ -24,7 +24,7 @@ Zabbixapi has next version policy:
|
|
24
24
|
The PATCH (third digit) version of zabbixapi should not correspond to PATCH version of zabbix, for example
|
25
25
|
zabbixapi-2.0.x should works with all version of zabbix 2.0.y
|
26
26
|
|
27
|
-
We support only
|
27
|
+
We support only two last versions of zabbix (2.2 and 2.4), so you should consider zabbixapi 0.6.x and 2.0.x depricated.
|
28
28
|
|
29
29
|
## Installation
|
30
30
|
```
|
@@ -98,11 +98,11 @@ zbx.items.create_or_update(
|
|
98
98
|
### Update Item
|
99
99
|
```ruby
|
100
100
|
zbx.items.update(
|
101
|
-
:itemid => zbx.items.get_id(:
|
101
|
+
:itemid => zbx.items.get_id(:name => "item"),
|
102
102
|
:status => 0
|
103
103
|
)
|
104
104
|
#You can check item:
|
105
|
-
puts zbx.items.get_full_data(:
|
105
|
+
puts zbx.items.get_full_data(:name => "item")
|
106
106
|
```
|
107
107
|
|
108
108
|
### Create host
|
@@ -157,7 +157,7 @@ zbx.hosts.delete zbx.hosts.get_id(:host => "hostname")
|
|
157
157
|
### Create graph
|
158
158
|
```ruby
|
159
159
|
gitems = {
|
160
|
-
:itemid => zbx.items.get_id(:
|
160
|
+
:itemid => zbx.items.get_id(:name => "item"),
|
161
161
|
:calc_fnc => "2",
|
162
162
|
:type => "0",
|
163
163
|
:periods_cnt => "5"
|
@@ -175,12 +175,12 @@ zbx.graphs.create(
|
|
175
175
|
### Update graph
|
176
176
|
```ruby
|
177
177
|
zbx.graphs.update(
|
178
|
-
:graphid => zbx.graphs.get_id(
|
178
|
+
:graphid => zbx.graphs.get_id(:name => "graph"),
|
179
179
|
:ymax_type => 1
|
180
180
|
)
|
181
181
|
#Also you can use:
|
182
182
|
gitems = {
|
183
|
-
:itemid => zbx.items.get_id(:
|
183
|
+
:itemid => zbx.items.get_id(:name => "item"),
|
184
184
|
:calc_fnc => "3",
|
185
185
|
:type => "0",
|
186
186
|
:periods_cnt => "5"
|
@@ -238,7 +238,21 @@ zbx.triggers.create(
|
|
238
238
|
:templateid => 0,
|
239
239
|
:type => 0
|
240
240
|
)
|
241
|
-
|
241
|
+
```
|
242
|
+
|
243
|
+
### Get trigger with certain filter
|
244
|
+
```ruby
|
245
|
+
triggers = zbx.query(
|
246
|
+
:method => "trigger.get",
|
247
|
+
:params => {
|
248
|
+
:filter => {
|
249
|
+
:url => ""
|
250
|
+
},
|
251
|
+
:templated => true,
|
252
|
+
:output => "extend"
|
253
|
+
}
|
254
|
+
)
|
255
|
+
```
|
242
256
|
|
243
257
|
### Create user
|
244
258
|
```ruby
|
@@ -320,6 +334,22 @@ zbx.users.add_medias(
|
|
320
334
|
)
|
321
335
|
```
|
322
336
|
|
337
|
+
### Update media ###
|
338
|
+
```ruby
|
339
|
+
zbx.users.update_medias(
|
340
|
+
:userids => [zbx.users.get_id(:alias => "user")],
|
341
|
+
:media => [
|
342
|
+
{
|
343
|
+
:mediatypeid => zbx.mediatypes.get_id(:description => "mediatype"),
|
344
|
+
:sendto => "test@test",
|
345
|
+
:active => 0,
|
346
|
+
:period => "1-7,00:00-24:00", # 1-7 days and 00:00-24:00 hours
|
347
|
+
:severity => "56"
|
348
|
+
}
|
349
|
+
]
|
350
|
+
)
|
351
|
+
```
|
352
|
+
|
323
353
|
### Create proxy
|
324
354
|
#### Active proxy
|
325
355
|
```ruby
|
@@ -25,7 +25,7 @@ class ZabbixApi
|
|
25
25
|
result.each do |key, value|
|
26
26
|
case value
|
27
27
|
when Array
|
28
|
-
result
|
28
|
+
result[key] = normalize_array(value)
|
29
29
|
else
|
30
30
|
result[key] = value.to_s
|
31
31
|
end
|
@@ -33,6 +33,20 @@ class ZabbixApi
|
|
33
33
|
result
|
34
34
|
end
|
35
35
|
|
36
|
+
def normalize_array(array)
|
37
|
+
result = []
|
38
|
+
array.each do |e|
|
39
|
+
case e
|
40
|
+
when Array
|
41
|
+
result << normalize_array(e)
|
42
|
+
when Hash
|
43
|
+
result << normalize_hash(e)
|
44
|
+
else
|
45
|
+
result << e.to_s
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
36
50
|
def parse_keys(data)
|
37
51
|
case data
|
38
52
|
when Hash
|
@@ -9,6 +9,21 @@ class ZabbixApi
|
|
9
9
|
"host"
|
10
10
|
end
|
11
11
|
|
12
|
+
def dump_by_id(data)
|
13
|
+
log "[DEBUG] Call dump_by_id with parametrs: #{data.inspect}"
|
14
|
+
|
15
|
+
@client.api_request(
|
16
|
+
:method => "host.get",
|
17
|
+
:params => {
|
18
|
+
:filter => {
|
19
|
+
key.to_sym => data[key.to_sym]
|
20
|
+
},
|
21
|
+
:output => "extend",
|
22
|
+
:selectGroups => "shorten"
|
23
|
+
}
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
12
27
|
def default_options
|
13
28
|
{
|
14
29
|
:host => nil,
|
@@ -56,7 +56,7 @@ class ZabbixApi
|
|
56
56
|
# - True or False
|
57
57
|
def mass_update(data)
|
58
58
|
result = @client.api_request(
|
59
|
-
:method => "template.
|
59
|
+
:method => "template.massUpdate",
|
60
60
|
:params => {
|
61
61
|
:hosts => data[:hosts_id].map { |t| {:hostid => t} },
|
62
62
|
:templates => data[:templates_id].map { |t| {:templateid => t} }
|
@@ -28,5 +28,16 @@ class ZabbixApi
|
|
28
28
|
result ? result['mediaids'][0].to_i : nil
|
29
29
|
end
|
30
30
|
|
31
|
+
def update_medias(data)
|
32
|
+
result = @client.api_request(
|
33
|
+
:method => "user.updateMedia",
|
34
|
+
:params => {
|
35
|
+
:users => data[:userids].map { |t| {:userid => t} },
|
36
|
+
:medias => data[:media]
|
37
|
+
}
|
38
|
+
)
|
39
|
+
result ? result['userids'][0].to_i : nil
|
40
|
+
end
|
41
|
+
|
31
42
|
end
|
32
43
|
end
|
data/lib/zabbixapi/client.rb
CHANGED
@@ -47,7 +47,7 @@ class ZabbixApi
|
|
47
47
|
:jsonrpc => '2.0'
|
48
48
|
}
|
49
49
|
|
50
|
-
message[:auth] = @auth_hash unless body[:method] == 'apiinfo.version'
|
50
|
+
message[:auth] = @auth_hash unless (body[:method] == 'apiinfo.version' or body[:method] == 'user.login')
|
51
51
|
|
52
52
|
JSON.generate(message)
|
53
53
|
end
|
data/lib/zabbixapi/version.rb
CHANGED
data/spec/host.rb
CHANGED
@@ -124,6 +124,18 @@ describe 'host' do
|
|
124
124
|
:status => 0
|
125
125
|
).should eq @hostid
|
126
126
|
end
|
127
|
+
|
128
|
+
it "should update groups" do
|
129
|
+
@hostgroupid2 = zbx.hostgroups.create(:name => gen_name('hostgroup'))
|
130
|
+
|
131
|
+
zbx.hosts.update(
|
132
|
+
:hostid => @hostid,
|
133
|
+
:groups => [ :groupid => @hostgroupid2]
|
134
|
+
).should eq @hostid
|
135
|
+
|
136
|
+
expect(zbx.hosts.dump_by_id(:hostid => @hostid).first['groups'].first["groupid"]).to eq @hostgroupid2.to_s
|
137
|
+
|
138
|
+
end
|
127
139
|
end
|
128
140
|
|
129
141
|
describe 'delete' do
|
data/spec/user.rb
CHANGED
@@ -16,6 +16,16 @@ describe 'user' do
|
|
16
16
|
)
|
17
17
|
end
|
18
18
|
|
19
|
+
def media
|
20
|
+
{
|
21
|
+
:mediatypeid => @mediatypeid,
|
22
|
+
:sendto => "test@test",
|
23
|
+
:active => 0,
|
24
|
+
:period => "1-7,00:00-24:00",
|
25
|
+
:severity => "56"
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
19
29
|
context 'when not exists' do
|
20
30
|
describe 'create' do
|
21
31
|
it "should return integer id" do
|
@@ -77,19 +87,25 @@ describe 'user' do
|
|
77
87
|
it "should return integer media id" do
|
78
88
|
zbx.users.add_medias(
|
79
89
|
: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
|
-
]
|
90
|
+
:media => [media]
|
89
91
|
).should be_kind_of(Integer)
|
90
92
|
end
|
91
93
|
end
|
92
94
|
|
95
|
+
describe 'update_medias' do
|
96
|
+
it "should return the user id" do
|
97
|
+
# Call twice to ensure update_medias first successfully creates the media, then updates it
|
98
|
+
2.times do
|
99
|
+
returned_userid = zbx.users.update_medias(
|
100
|
+
:userids => [@userid],
|
101
|
+
:media => [media]
|
102
|
+
)
|
103
|
+
|
104
|
+
returned_userid.should eq @userid
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
93
109
|
describe 'delete' do
|
94
110
|
it "should return id" do
|
95
111
|
zbx.users.delete(@userid).should eq @userid
|
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.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vasiliev D.V.
|
@@ -9,26 +9,26 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2015-05-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- - ~>
|
18
|
+
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
20
|
version: '1.6'
|
21
|
-
- -
|
21
|
+
- - ">="
|
22
22
|
- !ruby/object:Gem::Version
|
23
23
|
version: 1.6.0
|
24
24
|
type: :runtime
|
25
25
|
prerelease: false
|
26
26
|
version_requirements: !ruby/object:Gem::Requirement
|
27
27
|
requirements:
|
28
|
-
- - ~>
|
28
|
+
- - "~>"
|
29
29
|
- !ruby/object:Gem::Version
|
30
30
|
version: '1.6'
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 1.6.0
|
34
34
|
description: Allows you to work with zabbix api from ruby.
|
@@ -39,11 +39,12 @@ executables: []
|
|
39
39
|
extensions: []
|
40
40
|
extra_rdoc_files: []
|
41
41
|
files:
|
42
|
-
- .gitignore
|
43
|
-
- .rspec
|
44
|
-
- .travis.yml
|
42
|
+
- ".gitignore"
|
43
|
+
- ".rspec"
|
44
|
+
- ".travis.yml"
|
45
45
|
- Gemfile
|
46
46
|
- Gemfile.lock
|
47
|
+
- LICENSE
|
47
48
|
- README.md
|
48
49
|
- Rakefile
|
49
50
|
- lib/zabbixapi.rb
|
@@ -97,17 +98,17 @@ require_paths:
|
|
97
98
|
- lib
|
98
99
|
required_ruby_version: !ruby/object:Gem::Requirement
|
99
100
|
requirements:
|
100
|
-
- -
|
101
|
+
- - ">="
|
101
102
|
- !ruby/object:Gem::Version
|
102
103
|
version: '0'
|
103
104
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
105
|
requirements:
|
105
|
-
- -
|
106
|
+
- - ">="
|
106
107
|
- !ruby/object:Gem::Version
|
107
108
|
version: '0'
|
108
109
|
requirements: []
|
109
110
|
rubyforge_project: zabbixapi
|
110
|
-
rubygems_version: 2.
|
111
|
+
rubygems_version: 2.4.3
|
111
112
|
signing_key:
|
112
113
|
specification_version: 4
|
113
114
|
summary: Realization for Zabbix API.
|