zabbixapi 0.4.2 → 0.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.
- data/Gemfile +1 -1
- data/lib/zabbixapi/applications.rb +1 -3
- data/lib/zabbixapi/client.rb +11 -1
- data/lib/zabbixapi/errors.rb +3 -0
- data/lib/zabbixapi/graphs.rb +2 -4
- data/lib/zabbixapi/hostgroups.rb +6 -3
- data/lib/zabbixapi/hosts.rb +1 -3
- data/lib/zabbixapi/items.rb +1 -3
- data/lib/zabbixapi/templates.rb +51 -4
- data/lib/zabbixapi/triggers.rb +2 -4
- data/lib/zabbixapi/users.rb +1 -3
- data/lib/zabbixapi/version.rb +1 -1
- data/spec/localhost.rb +5 -1
- data/spec/run.rb +19 -19
- data/zabbixapi.gemspec +1 -1
- metadata +6 -4
data/Gemfile
CHANGED
@@ -31,9 +31,7 @@ class ZabbixApi
|
|
31
31
|
def get_id(data)
|
32
32
|
result = get_full_data(data)
|
33
33
|
applicationid = nil
|
34
|
-
result.each
|
35
|
-
applicationid = app['applicationid'].to_i if app['name'] == data[:name]
|
36
|
-
end
|
34
|
+
result.each { |app| applicationid = app['applicationid'].to_i if app['name'] == data[:name] }
|
37
35
|
applicationid
|
38
36
|
end
|
39
37
|
|
data/lib/zabbixapi/client.rb
CHANGED
@@ -25,6 +25,12 @@ class ZabbixApi
|
|
25
25
|
def initialize(options = {})
|
26
26
|
@options = options
|
27
27
|
@auth_hash = auth
|
28
|
+
unless ENV['http_proxy'].nil?
|
29
|
+
@proxy_uri = URI.parse(ENV['http_proxy'])
|
30
|
+
@proxy_host = @proxy_uri.host
|
31
|
+
@proxy_port = @proxy_uri.port
|
32
|
+
@proxy_user, @proxy_pass = @proxy_uri.userinfo.split(/:/) if @proxy_uri.userinfo
|
33
|
+
end
|
28
34
|
end
|
29
35
|
|
30
36
|
def message_json(body)
|
@@ -40,7 +46,11 @@ class ZabbixApi
|
|
40
46
|
|
41
47
|
def http_request(body)
|
42
48
|
uri = URI.parse(@options[:url])
|
43
|
-
|
49
|
+
unless @proxy_uri.nil?
|
50
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
51
|
+
else
|
52
|
+
http = Net::HTTP.Proxy(@proxy_host, @proxy_port, @proxy_user, @proxy_pass).new(uri.host, uri.port)
|
53
|
+
end
|
44
54
|
request = Net::HTTP::Post.new(uri.request_uri)
|
45
55
|
request.add_field('Content-Type', 'application/json-rpc')
|
46
56
|
request.body = body
|
data/lib/zabbixapi/errors.rb
CHANGED
data/lib/zabbixapi/graphs.rb
CHANGED
@@ -40,9 +40,7 @@ class ZabbixApi
|
|
40
40
|
def get_id(data)
|
41
41
|
result = @client.api_request(:method => "graph.get", :params => {:filter => {:name=> data[:name]}, :output => "extend"})
|
42
42
|
graphid = nil
|
43
|
-
result.each
|
44
|
-
graphid = graph['graphid'].to_i if graph['name'] == data[:name]
|
45
|
-
end
|
43
|
+
result.each { |graph| graphid = graph['graphid'].to_i if graph['name'] == data[:name] }
|
46
44
|
graphid
|
47
45
|
end
|
48
46
|
|
@@ -54,7 +52,7 @@ class ZabbixApi
|
|
54
52
|
def update(data)
|
55
53
|
case @client.api_version
|
56
54
|
when "1.2"
|
57
|
-
|
55
|
+
@client.api_request(:method => "graph.update", :params => data)
|
58
56
|
else
|
59
57
|
result = @client.api_request(:method => "graph.update", :params => data)
|
60
58
|
result.empty? ? nil : result['graphids'][0].to_i
|
data/lib/zabbixapi/hostgroups.rb
CHANGED
@@ -24,6 +24,11 @@ class ZabbixApi
|
|
24
24
|
delete(data)
|
25
25
|
end
|
26
26
|
|
27
|
+
def create_or_update(data)
|
28
|
+
hostgroupid = get_id(:name => data[:name])
|
29
|
+
hostgroupid ? update(data.merge(:groupid => hostgroupid)) : create(data)
|
30
|
+
end
|
31
|
+
|
27
32
|
def get_full_data(data)
|
28
33
|
case @client.api_version
|
29
34
|
when "1.2"
|
@@ -36,9 +41,7 @@ class ZabbixApi
|
|
36
41
|
def get_id(data)
|
37
42
|
result = get_full_data(data)
|
38
43
|
hostgroupid = nil
|
39
|
-
result.each
|
40
|
-
hostgroupid = hgroup['groupid'].to_i if hgroup['name'] == data[:name]
|
41
|
-
end
|
44
|
+
result.each { |hgroup| hostgroupid = hgroup['groupid'].to_i if hgroup['name'] == data[:name] }
|
42
45
|
hostgroupid
|
43
46
|
end
|
44
47
|
|
data/lib/zabbixapi/hosts.rb
CHANGED
@@ -79,9 +79,7 @@ class ZabbixApi
|
|
79
79
|
def get_id(data)
|
80
80
|
result = get_full_data(data)
|
81
81
|
hostid = nil
|
82
|
-
result.each
|
83
|
-
hostid = host['hostid'].to_i if host['host'] == data[:host]
|
84
|
-
end
|
82
|
+
result.each { |host| hostid = host['hostid'].to_i if host['host'] == data[:host] }
|
85
83
|
hostid
|
86
84
|
end
|
87
85
|
|
data/lib/zabbixapi/items.rb
CHANGED
@@ -61,9 +61,7 @@ class ZabbixApi
|
|
61
61
|
def get_id(data)
|
62
62
|
result = get_full_data(data)
|
63
63
|
itemid = nil
|
64
|
-
result.each
|
65
|
-
itemid = item['itemid'].to_i if item['name'] == data[:name]
|
66
|
-
end
|
64
|
+
result.each { |item| itemid = item['itemid'].to_i if item['name'] == data[:name] }
|
67
65
|
itemid
|
68
66
|
end
|
69
67
|
|
data/lib/zabbixapi/templates.rb
CHANGED
@@ -6,24 +6,46 @@ class ZabbixApi
|
|
6
6
|
@options = options
|
7
7
|
end
|
8
8
|
|
9
|
+
# Create template
|
10
|
+
#
|
11
|
+
# * *Args* :
|
12
|
+
# - +data+ -> Hash with :host => "Template_Name" and :groups => array with hostgroup ids
|
13
|
+
# * *Returns* :
|
14
|
+
# - Nil or Integer
|
9
15
|
def create(data)
|
10
16
|
result = @client.api_request(:method => "template.create", :params => [data])
|
11
17
|
result.empty? ? nil : result['templateids'][0].to_i
|
12
18
|
end
|
13
19
|
|
20
|
+
# Add template
|
21
|
+
# Synonym create
|
14
22
|
def add(data)
|
15
23
|
create(data)
|
16
24
|
end
|
17
25
|
|
26
|
+
# Delete template
|
27
|
+
#
|
28
|
+
# * *Args* :
|
29
|
+
# - +data+ -> Hash with :host => "Template_Name"
|
30
|
+
# * *Returns* :
|
31
|
+
# - Nil or Integer
|
18
32
|
def delete(data)
|
19
33
|
result = @client.api_request(:method => "template.delete", :params => [:templateid => data])
|
20
34
|
result.empty? ? nil : result['templateids'][0].to_i
|
21
35
|
end
|
22
36
|
|
37
|
+
# Destroy template
|
38
|
+
# Synonym delete
|
23
39
|
def destroy(data)
|
24
40
|
delete(data)
|
25
41
|
end
|
26
42
|
|
43
|
+
# Return templateids linked with host
|
44
|
+
#
|
45
|
+
# * *Args* :
|
46
|
+
# - +data+ -> Hash with :hostids => [hostid]
|
47
|
+
# * *Returns* :
|
48
|
+
# - Array with templateids
|
27
49
|
def get_ids_by_host(data)
|
28
50
|
result = []
|
29
51
|
@client.api_request(:method => "template.get", :params => data).each do |tmpl|
|
@@ -32,6 +54,12 @@ class ZabbixApi
|
|
32
54
|
result
|
33
55
|
end
|
34
56
|
|
57
|
+
# Analog Zabbix api call massAdd
|
58
|
+
#
|
59
|
+
# * *Args* :
|
60
|
+
# - +data+ -> Hash with :hosts_id => [hostid1, hostid2 ...], and :templates_id => [templateid1, templateid2 ...]
|
61
|
+
# * *Returns* :
|
62
|
+
# - True or False
|
35
63
|
def mass_add(data)
|
36
64
|
result = @client.api_request(
|
37
65
|
:method => "template.massAdd",
|
@@ -43,6 +71,12 @@ class ZabbixApi
|
|
43
71
|
result.empty? ? false : true
|
44
72
|
end
|
45
73
|
|
74
|
+
# Analog Zabbix api call massRemove
|
75
|
+
#
|
76
|
+
# * *Args* :
|
77
|
+
# - +data+ -> Hash with :hosts_id => [hostid1, hostid2 ...], and :templates_id => [templateid1, templateid2 ...]
|
78
|
+
# * *Returns* :
|
79
|
+
# - True or False
|
46
80
|
def mass_remove(data)
|
47
81
|
result = @client.api_request(
|
48
82
|
:method => "template.massRemove",
|
@@ -54,6 +88,10 @@ class ZabbixApi
|
|
54
88
|
result.empty? ? false : true
|
55
89
|
end
|
56
90
|
|
91
|
+
# Return all templates
|
92
|
+
#
|
93
|
+
# * *Returns* :
|
94
|
+
# - Hash with {"Template_Name1" => "templateid1", "Template_Name2" => "templateid2"}
|
57
95
|
def all
|
58
96
|
result = {}
|
59
97
|
case @client.api_version
|
@@ -69,6 +107,12 @@ class ZabbixApi
|
|
69
107
|
result
|
70
108
|
end
|
71
109
|
|
110
|
+
# Return info about template
|
111
|
+
#
|
112
|
+
# * *Args* :
|
113
|
+
# - +data+ -> Hash with :host => "Template name"
|
114
|
+
# * *Returns* :
|
115
|
+
# - Hash with template info
|
72
116
|
def get_full_data(data)
|
73
117
|
case @client.api_version
|
74
118
|
when "1.2"
|
@@ -80,12 +124,15 @@ class ZabbixApi
|
|
80
124
|
end
|
81
125
|
end
|
82
126
|
|
127
|
+
# Return info about template
|
128
|
+
#
|
129
|
+
# * *Args* :
|
130
|
+
# - +data+ -> Hash with :host => "Template name"
|
131
|
+
# * *Returns* :
|
132
|
+
# - Nil or Integer
|
83
133
|
def get_id(data)
|
84
|
-
result = get_full_data(data)
|
85
134
|
templateid = nil
|
86
|
-
|
87
|
-
templateid = template['templateid'].to_i if template['host'] == data[:host]
|
88
|
-
end
|
135
|
+
get_full_data(data).each { |template| templateid = template['templateid'].to_i if template['host'] == data[:host] }
|
89
136
|
templateid
|
90
137
|
end
|
91
138
|
|
data/lib/zabbixapi/triggers.rb
CHANGED
@@ -26,7 +26,7 @@ class ZabbixApi
|
|
26
26
|
|
27
27
|
def update(data)
|
28
28
|
result = @client.api_request(:method => "trigger.update", :params => data)
|
29
|
-
result.empty? ? nil : result['
|
29
|
+
result.empty? ? nil : result['triggerids'][0].to_i
|
30
30
|
end
|
31
31
|
|
32
32
|
def create_or_update(data)
|
@@ -41,9 +41,7 @@ class ZabbixApi
|
|
41
41
|
def get_id(data)
|
42
42
|
result = get_full_data(data)
|
43
43
|
triggerid = nil
|
44
|
-
result.each
|
45
|
-
triggerid = template['triggerid'].to_i if template['name'] == data[:name]
|
46
|
-
end
|
44
|
+
result.each { |template| triggerid = template['triggerid'].to_i if template['name'] == data[:name] }
|
47
45
|
triggerid
|
48
46
|
end
|
49
47
|
|
data/lib/zabbixapi/users.rb
CHANGED
@@ -39,9 +39,7 @@ class ZabbixApi
|
|
39
39
|
def get_id(data)
|
40
40
|
result = get_full_data(data)
|
41
41
|
userid = nil
|
42
|
-
result.each
|
43
|
-
userid = usr['userid'].to_i if usr['name'] == data[:name]
|
44
|
-
end
|
42
|
+
result.each { |usr| userid = usr['userid'].to_i if usr['name'] == data[:name] }
|
45
43
|
userid
|
46
44
|
end
|
47
45
|
|
data/lib/zabbixapi/version.rb
CHANGED
data/spec/localhost.rb
CHANGED
@@ -45,6 +45,10 @@ describe ZabbixApi, "test_api" do
|
|
45
45
|
zbx.hostgroups.get_id(:name => "#{hostgroup}______").should be_kind_of(NilClass)
|
46
46
|
end
|
47
47
|
|
48
|
+
it "HOSTGROUP: Create or update" do
|
49
|
+
zbx.hostgroups.create_or_update(:name => hostgroup).should be_kind_of(Integer)
|
50
|
+
end
|
51
|
+
|
48
52
|
it "TEMPLATE: Create" do
|
49
53
|
zbx.templates.create(
|
50
54
|
:host => template,
|
@@ -208,7 +212,7 @@ describe ZabbixApi, "test_api" do
|
|
208
212
|
).should be_kind_of(Integer)
|
209
213
|
end
|
210
214
|
|
211
|
-
it "GRAPH: Find
|
215
|
+
it "GRAPH: Find gititems" do
|
212
216
|
zbx.graphs.get_items( zbx.graphs.get_id(:name => graph) )
|
213
217
|
end
|
214
218
|
|
data/spec/run.rb
CHANGED
@@ -169,7 +169,7 @@ describe ZabbixApi, "test_api" do
|
|
169
169
|
).should be_kind_of(TrueClass)
|
170
170
|
end
|
171
171
|
|
172
|
-
it "TEMPLATE: Get all" do
|
172
|
+
it "TEMPLATE: Get all" do
|
173
173
|
zbx.templates.all.should be_kind_of(Hash)
|
174
174
|
end
|
175
175
|
|
@@ -189,12 +189,12 @@ describe ZabbixApi, "test_api" do
|
|
189
189
|
zbx.triggers.get_id(:description => trigger).should be_kind_of(Integer)
|
190
190
|
end
|
191
191
|
|
192
|
-
it "GRAPH: Create" do
|
192
|
+
it "GRAPH: Create" do
|
193
193
|
gitems = {
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
194
|
+
:itemid => zbx.items.get_id(:description => item),
|
195
|
+
:calc_fnc => "2",
|
196
|
+
:type => "0",
|
197
|
+
:periods_cnt => "5"
|
198
198
|
}
|
199
199
|
zbx.graphs.create(
|
200
200
|
:gitems => [gitems],
|
@@ -205,7 +205,7 @@ describe ZabbixApi, "test_api" do
|
|
205
205
|
).should be_kind_of(Integer)
|
206
206
|
end
|
207
207
|
|
208
|
-
it "GRAPH: Find
|
208
|
+
it "GRAPH: Find gititems" do
|
209
209
|
zbx.graphs.get_items( zbx.graphs.get_id(:name => graph) )
|
210
210
|
end
|
211
211
|
|
@@ -218,25 +218,25 @@ describe ZabbixApi, "test_api" do
|
|
218
218
|
:graphid => zbx.graphs.get_id(
|
219
219
|
:name => graph,
|
220
220
|
:hostid => zbx.hosts.get_id(:host => host)
|
221
|
-
),
|
221
|
+
),
|
222
222
|
:ymax_type => 1
|
223
223
|
).should be_kind_of(Integer)
|
224
224
|
end
|
225
225
|
|
226
226
|
it "GRAPH: Create or Update" do
|
227
227
|
gitems = {
|
228
|
-
:itemid => zbx.items.get_id(:description => item),
|
228
|
+
:itemid => zbx.items.get_id(:description => item),
|
229
229
|
:calc_fnc => "3",
|
230
230
|
:type => "0",
|
231
231
|
:periods_cnt => "5"
|
232
232
|
}
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
233
|
+
zbx.graphs.create_or_update(
|
234
|
+
:gitems => [gitems],
|
235
|
+
:show_triggers => "1",
|
236
|
+
:name => graph,
|
237
|
+
:width => "900",
|
238
|
+
:height => "200"
|
239
|
+
).should be_kind_of(Integer)
|
240
240
|
end
|
241
241
|
|
242
242
|
it "GRAPH: Delete" do
|
@@ -298,9 +298,9 @@ describe ZabbixApi, "test_api" do
|
|
298
298
|
|
299
299
|
it "QUERY" do
|
300
300
|
zbx.query(
|
301
|
-
:method => "apiinfo.version",
|
301
|
+
:method => "apiinfo.version",
|
302
302
|
:params => {}
|
303
303
|
).should be_kind_of(String)
|
304
304
|
end
|
305
|
-
|
306
|
-
end
|
305
|
+
|
306
|
+
end
|
data/zabbixapi.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.homepage = "https://github.com/vadv/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
|
-
s.licenses =
|
13
|
+
s.licenses = %w(MIT)
|
14
14
|
|
15
15
|
s.rubyforge_project = "zabbixapi"
|
16
16
|
|
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: 0.4.
|
4
|
+
version: 0.4.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-11-
|
13
|
+
date: 2012-11-22 00:00:00.000000000 Z
|
14
14
|
dependencies: []
|
15
15
|
description: Allows you to work with zabbix api from ruby.
|
16
16
|
email:
|
@@ -57,7 +57,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
57
57
|
version: '0'
|
58
58
|
segments:
|
59
59
|
- 0
|
60
|
-
hash:
|
60
|
+
hash: -2337601613432576299
|
61
61
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
62
|
none: false
|
63
63
|
requirements:
|
@@ -70,4 +70,6 @@ rubygems_version: 1.8.24
|
|
70
70
|
signing_key:
|
71
71
|
specification_version: 3
|
72
72
|
summary: Realization for Zabbix API.
|
73
|
-
test_files:
|
73
|
+
test_files:
|
74
|
+
- spec/localhost.rb
|
75
|
+
- spec/run.rb
|