zabbixapi 2.4.4 → 2.4.5
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/CHANGELOG.md +4 -0
- data/README.md +19 -0
- data/lib/zabbixapi.rb +0 -2
- data/lib/zabbixapi/basic/basic_alias.rb +0 -1
- data/lib/zabbixapi/basic/basic_init.rb +2 -2
- data/lib/zabbixapi/classes/errors.rb +16 -4
- data/lib/zabbixapi/classes/mediatypes.rb +7 -7
- data/lib/zabbixapi/classes/proxies.rb +1 -1
- data/lib/zabbixapi/classes/templates.rb +9 -9
- data/lib/zabbixapi/classes/usergroups.rb +8 -8
- data/lib/zabbixapi/classes/users.rb +1 -1
- data/lib/zabbixapi/client.rb +6 -7
- data/lib/zabbixapi/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 25ba28c4faff22b396e0e768792448a75ca4e637
|
4
|
+
data.tar.gz: 788a52dbb357ab631f7a2029a6485c41d0d49ca1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 78dd6e98b5a32bb724259b3e34c29e509cbba0fcb5c9decbdc8a9aeca25adf1f3a3692d661de57ce76c3be2c3d4607624d3addf346c123a911a9a8c4b3b629df
|
7
|
+
data.tar.gz: 0b5ff259f158b439285c080de706336847e52c554e3dd4f4a214fc02ce877b178717c81e99b038fcd64b1bb589698b82698c447f18060af5abf58a45d47f0b1e
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -147,6 +147,25 @@ zbx.hosts.update(
|
|
147
147
|
)
|
148
148
|
#You can check host:
|
149
149
|
puts zbx.hosts.get_full_data(:host => "hostname")
|
150
|
+
|
151
|
+
# Zabbixapi checks that new object differ from one in zabbix. But if you
|
152
|
+
# want to update nested arguments (like interfaces), you should use second argument.
|
153
|
+
# For example:
|
154
|
+
|
155
|
+
zbx.hosts.update({
|
156
|
+
:hostid => zbx.hosts.get_id(:host => "hostname"),
|
157
|
+
:interfaces => [
|
158
|
+
{
|
159
|
+
:type => 1,
|
160
|
+
:main => 1,
|
161
|
+
:ip => '10.0.0.1',
|
162
|
+
:dns => 'server.example.org',
|
163
|
+
:port => 10050,
|
164
|
+
:useip => 0
|
165
|
+
}
|
166
|
+
]}, true)
|
167
|
+
|
168
|
+
|
150
169
|
```
|
151
170
|
|
152
171
|
|
data/lib/zabbixapi.rb
CHANGED
@@ -6,7 +6,7 @@ class ZabbixApi
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def method_name
|
9
|
-
raise "Can't call method_name here"
|
9
|
+
raise ApiError.new("Can't call method_name here")
|
10
10
|
end
|
11
11
|
|
12
12
|
def default_options
|
@@ -22,7 +22,7 @@ class ZabbixApi
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def indentify
|
25
|
-
raise "Can't call indentify here"
|
25
|
+
raise ApiError.new("Can't call indentify here")
|
26
26
|
end
|
27
27
|
|
28
28
|
end
|
@@ -1,6 +1,21 @@
|
|
1
1
|
class ZabbixApi
|
2
2
|
|
3
3
|
class BaseError < RuntimeError
|
4
|
+
attr_accessor :response, :error, :error_message
|
5
|
+
|
6
|
+
def initialize(message, response = nil)
|
7
|
+
super(message)
|
8
|
+
@response = response
|
9
|
+
|
10
|
+
set_error! if @response
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def set_error!
|
16
|
+
@error = @response["error"] rescue nil
|
17
|
+
@error_message = "#{@error['message']}: #{@error['data']}" rescue nil
|
18
|
+
end
|
4
19
|
end
|
5
20
|
|
6
21
|
class ApiError < BaseError
|
@@ -9,7 +24,4 @@ class ZabbixApi
|
|
9
24
|
class HttpError < BaseError
|
10
25
|
end
|
11
26
|
|
12
|
-
|
13
|
-
end
|
14
|
-
|
15
|
-
end
|
27
|
+
end
|
@@ -9,17 +9,17 @@ class ZabbixApi
|
|
9
9
|
"description"
|
10
10
|
end
|
11
11
|
|
12
|
-
def default_options
|
12
|
+
def default_options
|
13
13
|
{
|
14
14
|
:description => "", #Name
|
15
|
-
:type
|
16
|
-
:smtp_server => "",
|
15
|
+
:type => 0, #0 - Email, 1 - External script, 2 - SMS, 3 - Jabber, 100 - EzTexting
|
16
|
+
:smtp_server => "",
|
17
17
|
:smtp_helo => "",
|
18
18
|
:smtp_email => "", #Email address of Zabbix server
|
19
|
-
:exec_path
|
20
|
-
:gsm_modem
|
21
|
-
:username
|
22
|
-
:passwd
|
19
|
+
:exec_path => "", #Name of external script
|
20
|
+
:gsm_modem => "", #Serial device name of GSM modem
|
21
|
+
:username => "", #Jabber user name used by Zabbix server
|
22
|
+
:passwd => "" #Jabber password used by Zabbix server
|
23
23
|
}
|
24
24
|
end
|
25
25
|
|
@@ -21,8 +21,8 @@ class ZabbixApi
|
|
21
21
|
result.empty? ? nil : result['templateids'][0].to_i
|
22
22
|
end
|
23
23
|
|
24
|
-
# Return templateids linked with host
|
25
|
-
#
|
24
|
+
# Return templateids linked with host
|
25
|
+
#
|
26
26
|
# * *Args* :
|
27
27
|
# - +data+ -> Hash with :hostids => [hostid]
|
28
28
|
# * *Returns* :
|
@@ -36,7 +36,7 @@ class ZabbixApi
|
|
36
36
|
end
|
37
37
|
|
38
38
|
# Return templateid
|
39
|
-
#
|
39
|
+
#
|
40
40
|
# * *Args* :
|
41
41
|
# - +data+ -> Hash with :host => "Template_Name" and :groups => array with hostgroup ids
|
42
42
|
# * *Returns* :
|
@@ -46,17 +46,17 @@ class ZabbixApi
|
|
46
46
|
templateid = create(data)
|
47
47
|
end
|
48
48
|
templateid
|
49
|
-
end
|
49
|
+
end
|
50
50
|
|
51
51
|
# Analog Zabbix api call massUpdate
|
52
|
-
#
|
52
|
+
#
|
53
53
|
# * *Args* :
|
54
54
|
# - +data+ -> Hash with :hosts_id => [hostid1, hostid2 ...], and :templates_id => [templateid1, templateid2 ...]
|
55
55
|
# * *Returns* :
|
56
56
|
# - True or False
|
57
57
|
def mass_update(data)
|
58
58
|
result = @client.api_request(
|
59
|
-
:method => "template.massUpdate",
|
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} }
|
@@ -65,15 +65,15 @@ class ZabbixApi
|
|
65
65
|
result.empty? ? false : true
|
66
66
|
end
|
67
67
|
|
68
|
-
# Analog Zabbix api call massAdd
|
69
|
-
#
|
68
|
+
# Analog Zabbix api call massAdd
|
69
|
+
#
|
70
70
|
# * *Args* :
|
71
71
|
# - +data+ -> Hash with :hosts_id => [hostid1, hostid2 ...], and :templates_id => [templateid1, templateid2 ...]
|
72
72
|
# * *Returns* :
|
73
73
|
# - True or False
|
74
74
|
def mass_add(data)
|
75
75
|
result = @client.api_request(
|
76
|
-
:method => "template.massAdd",
|
76
|
+
:method => "template.massAdd",
|
77
77
|
:params => {
|
78
78
|
:hosts => data[:hosts_id].map { |t| {:hostid => t} },
|
79
79
|
:templates => data[:templates_id].map { |t| {:templateid => t} }
|
@@ -14,7 +14,7 @@ class ZabbixApi
|
|
14
14
|
end
|
15
15
|
|
16
16
|
# Return usrgrpid
|
17
|
-
#
|
17
|
+
#
|
18
18
|
# * *Args* :
|
19
19
|
# - +data+ -> Hash with :name => "UserGroup"
|
20
20
|
# * *Returns* :
|
@@ -28,15 +28,15 @@ class ZabbixApi
|
|
28
28
|
end
|
29
29
|
|
30
30
|
# Set permission for usrgrp on some hostgroup
|
31
|
-
#
|
31
|
+
#
|
32
32
|
# * *Args* :
|
33
33
|
# - +data+ -> Hash with :usrgrpids => id, :hostgroupids => [], :permission => 2,3 (read and read write)
|
34
34
|
# * *Returns* :
|
35
35
|
# - Integer
|
36
36
|
def set_perms(data)
|
37
|
-
permission = data[:permission] || 2
|
37
|
+
permission = data[:permission] || 2
|
38
38
|
result = @client.api_request(
|
39
|
-
:method => "usergroup.massAdd",
|
39
|
+
:method => "usergroup.massAdd",
|
40
40
|
:params => {
|
41
41
|
:usrgrpids => [data[:usrgrpid]],
|
42
42
|
:rights => data[:hostgroupids].map { |t| {:permission => permission, :id => t} }
|
@@ -46,14 +46,14 @@ class ZabbixApi
|
|
46
46
|
end
|
47
47
|
|
48
48
|
# Update usergroup, add user
|
49
|
-
#
|
49
|
+
#
|
50
50
|
# * *Args* :
|
51
51
|
# - +data+ -> Hash with :usrgrpids => id, :userids => []
|
52
52
|
# * *Returns* :
|
53
53
|
# - Integer
|
54
54
|
def add_user(data)
|
55
55
|
result = @client.api_request(
|
56
|
-
:method => "usergroup.massAdd",
|
56
|
+
:method => "usergroup.massAdd",
|
57
57
|
:params => {
|
58
58
|
:usrgrpids => data[:usrgrpids],
|
59
59
|
:userids => data[:userids]
|
@@ -63,14 +63,14 @@ class ZabbixApi
|
|
63
63
|
end
|
64
64
|
|
65
65
|
# Update usergroup, modify users
|
66
|
-
#
|
66
|
+
#
|
67
67
|
# * *Args* :
|
68
68
|
# - +data+ -> Hash with :usrgrpids => id, :userids => []
|
69
69
|
# * *Returns* :
|
70
70
|
# - Integer
|
71
71
|
def update_users(data)
|
72
72
|
result = @client.api_request(
|
73
|
-
:method => "usergroup.massUpdate",
|
73
|
+
:method => "usergroup.massUpdate",
|
74
74
|
:params => {
|
75
75
|
:usrgrpids => data[:usrgrpids],
|
76
76
|
:userids => data[:userids]
|
data/lib/zabbixapi/client.rb
CHANGED
@@ -19,8 +19,8 @@ class ZabbixApi
|
|
19
19
|
api_request(
|
20
20
|
:method => 'user.login',
|
21
21
|
:params => {
|
22
|
-
:user
|
23
|
-
:password
|
22
|
+
:user => @options[:user],
|
23
|
+
:password => @options[:password],
|
24
24
|
}
|
25
25
|
)
|
26
26
|
end
|
@@ -34,7 +34,7 @@ class ZabbixApi
|
|
34
34
|
@proxy_user, @proxy_pass = @proxy_uri.userinfo.split(/:/) if @proxy_uri.userinfo
|
35
35
|
end
|
36
36
|
unless api_version =~ /2\.4\.\d+/
|
37
|
-
raise "Zabbix API version: #{api_version} is not support by this version of zabbixapi"
|
37
|
+
raise ApiError.new("Zabbix API version: #{api_version} is not support by this version of zabbixapi")
|
38
38
|
end
|
39
39
|
@auth_hash = auth
|
40
40
|
end
|
@@ -55,7 +55,7 @@ class ZabbixApi
|
|
55
55
|
def http_request(body)
|
56
56
|
uri = URI.parse(@options[:url])
|
57
57
|
# set the time out the default (60) or to what the user passed
|
58
|
-
@options[:timeout] == nil ? timeout = 60 : timeout = @options[:timeout]
|
58
|
+
@options[:timeout] == nil ? timeout = 60 : timeout = @options[:timeout]
|
59
59
|
puts "[DEBUG] Timeout for request set to #{timeout} seconds" if @options[:debug]
|
60
60
|
|
61
61
|
unless @proxy_uri.nil?
|
@@ -79,7 +79,7 @@ class ZabbixApi
|
|
79
79
|
request.add_field('Content-Type', 'application/json-rpc')
|
80
80
|
request.body = body
|
81
81
|
response = http.request(request)
|
82
|
-
raise "HTTP Error: #{response.code} on #{@options[:url]}" unless response.code ==
|
82
|
+
raise HttpError.new("HTTP Error: #{response.code} on #{@options[:url]}", response) unless response.code == '200'
|
83
83
|
puts "[DEBUG] Get answer: #{response.body}" if @options[:debug]
|
84
84
|
response.body
|
85
85
|
end
|
@@ -87,7 +87,7 @@ class ZabbixApi
|
|
87
87
|
def _request(body)
|
88
88
|
puts "[DEBUG] Send request: #{body}" if @options[:debug]
|
89
89
|
result = JSON.parse(http_request(body))
|
90
|
-
raise "Server answer API error
|
90
|
+
raise ApiError.new("Server answer API error\n #{JSON.pretty_unparse(result['error'])}\n on request:\n #{JSON.pretty_unparse(JSON.parse(body))}", result) if result['error']
|
91
91
|
result['result']
|
92
92
|
end
|
93
93
|
|
@@ -97,4 +97,3 @@ class ZabbixApi
|
|
97
97
|
|
98
98
|
end
|
99
99
|
end
|
100
|
-
|
data/lib/zabbixapi/version.rb
CHANGED
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.5
|
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: 2015-
|
12
|
+
date: 2015-09-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|