zabbix_manager 5.0.3 → 5.0.6
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/.idea/vcs.xml +6 -0
- data/.idea/workspace.xml +15 -4
- data/.rubocop.yml +1 -1
- data/README.md +2 -4
- data/lib/zabbix_manager/basic/basic_alias.rb +2 -0
- data/lib/zabbix_manager/basic/basic_extend.rb +11 -9
- data/lib/zabbix_manager/basic/basic_func.rb +9 -5
- data/lib/zabbix_manager/basic/basic_init.rb +6 -4
- data/lib/zabbix_manager/basic/basic_logic.rb +7 -5
- data/lib/zabbix_manager/classes/actions.rb +6 -4
- data/lib/zabbix_manager/classes/applications.rb +4 -2
- data/lib/zabbix_manager/classes/configurations.rb +6 -4
- data/lib/zabbix_manager/classes/drules.rb +5 -3
- data/lib/zabbix_manager/classes/errors.rb +5 -3
- data/lib/zabbix_manager/classes/events.rb +4 -3
- data/lib/zabbix_manager/classes/graphs.rb +11 -9
- data/lib/zabbix_manager/classes/hostgroups.rb +13 -11
- data/lib/zabbix_manager/classes/hosts.rb +36 -34
- data/lib/zabbix_manager/classes/httptests.rb +4 -2
- data/lib/zabbix_manager/classes/items.rb +52 -49
- data/lib/zabbix_manager/classes/maintenance.rb +4 -2
- data/lib/zabbix_manager/classes/mediatypes.rb +15 -13
- data/lib/zabbix_manager/classes/problems.rb +31 -30
- data/lib/zabbix_manager/classes/proxies.rb +9 -7
- data/lib/zabbix_manager/classes/roles.rb +17 -15
- data/lib/zabbix_manager/classes/screens.rb +6 -4
- data/lib/zabbix_manager/classes/scripts.rb +6 -4
- data/lib/zabbix_manager/classes/server.rb +3 -1
- data/lib/zabbix_manager/classes/templates.rb +18 -16
- data/lib/zabbix_manager/classes/triggers.rb +41 -37
- data/lib/zabbix_manager/classes/unusable.rb +2 -0
- data/lib/zabbix_manager/classes/usergroups.rb +11 -9
- data/lib/zabbix_manager/classes/usermacros.rb +21 -19
- data/lib/zabbix_manager/classes/users.rb +11 -9
- data/lib/zabbix_manager/classes/valuemaps.rb +5 -3
- data/lib/zabbix_manager/client.rb +38 -28
- data/lib/zabbix_manager/version.rb +3 -1
- data/lib/zabbix_manager.rb +36 -35
- data/zabbix_manager-5.0.3.gem +0 -0
- data/zabbix_manager-5.0.4.gem +0 -0
- data/zabbix_manager-5.0.5.gem +0 -0
- metadata +9 -4
@@ -1,31 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class ZabbixManager
|
2
4
|
class Users < Basic
|
3
5
|
# The method name used for interacting with Users via Zabbix API
|
4
6
|
#
|
5
7
|
# @return [String]
|
6
8
|
def method_name
|
7
|
-
|
9
|
+
"user"
|
8
10
|
end
|
9
11
|
|
10
12
|
# The keys field name used for User objects via Zabbix API
|
11
13
|
#
|
12
14
|
# @return [String]
|
13
15
|
def keys
|
14
|
-
|
16
|
+
"userids"
|
15
17
|
end
|
16
18
|
|
17
19
|
# The key field name used for User objects via Zabbix API
|
18
20
|
#
|
19
21
|
# @return [String]
|
20
22
|
def key
|
21
|
-
|
23
|
+
"userid"
|
22
24
|
end
|
23
25
|
|
24
26
|
# The id field name used for identifying specific User objects via Zabbix API
|
25
27
|
#
|
26
28
|
# @return [String]
|
27
29
|
def identify
|
28
|
-
|
30
|
+
"alias"
|
29
31
|
end
|
30
32
|
|
31
33
|
def medias_helper(data, action)
|
@@ -34,11 +36,11 @@ class ZabbixManager
|
|
34
36
|
params: data[:userids].map do |t|
|
35
37
|
{
|
36
38
|
userid: t,
|
37
|
-
user_medias: data[:media]
|
39
|
+
user_medias: data[:media]
|
38
40
|
}
|
39
|
-
end
|
41
|
+
end
|
40
42
|
)
|
41
|
-
result ? result[
|
43
|
+
result ? result["userids"][0].to_i : nil
|
42
44
|
end
|
43
45
|
|
44
46
|
# Add media to users using Zabbix API
|
@@ -48,7 +50,7 @@ class ZabbixManager
|
|
48
50
|
# @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
|
49
51
|
# @return [Integer] Zabbix object id (media)
|
50
52
|
def add_medias(data)
|
51
|
-
medias_helper(data,
|
53
|
+
medias_helper(data, "update")
|
52
54
|
end
|
53
55
|
|
54
56
|
# Update media for users using Zabbix API
|
@@ -58,7 +60,7 @@ class ZabbixManager
|
|
58
60
|
# @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
|
59
61
|
# @return [Integer] Zabbix object id (user)
|
60
62
|
def update_medias(data)
|
61
|
-
medias_helper(data,
|
63
|
+
medias_helper(data, "update")
|
62
64
|
end
|
63
65
|
end
|
64
66
|
end
|
@@ -1,24 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class ZabbixManager
|
2
4
|
class ValueMaps < Basic
|
3
5
|
# The method name used for interacting with ValueMaps via Zabbix API
|
4
6
|
#
|
5
7
|
# @return [String]
|
6
8
|
def method_name
|
7
|
-
|
9
|
+
"valuemap"
|
8
10
|
end
|
9
11
|
|
10
12
|
# The key field name used for ValueMap objects via Zabbix API
|
11
13
|
#
|
12
14
|
# @return [String]
|
13
15
|
def key
|
14
|
-
|
16
|
+
"valuemapid"
|
15
17
|
end
|
16
18
|
|
17
19
|
# The id field name used for identifying specific ValueMap objects via Zabbix API
|
18
20
|
#
|
19
21
|
# @return [String]
|
20
22
|
def identify
|
21
|
-
|
23
|
+
"name"
|
22
24
|
end
|
23
25
|
|
24
26
|
# Get or Create ValueMap object using Zabbix API
|
@@ -1,6 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "net/http"
|
4
|
+
require "json"
|
5
|
+
require "openssl"
|
4
6
|
|
5
7
|
class ZabbixManager
|
6
8
|
class Client
|
@@ -10,14 +12,14 @@ class ZabbixManager
|
|
10
12
|
|
11
13
|
# @return [Integer]
|
12
14
|
def id
|
13
|
-
rand
|
15
|
+
rand 10_000
|
14
16
|
end
|
15
17
|
|
16
18
|
# Returns the API version from the Zabbix Server
|
17
19
|
#
|
18
20
|
# @return [String, Hash]
|
19
21
|
def api_version
|
20
|
-
api_request(method:
|
22
|
+
api_request(method: "apiinfo.version", params: {})
|
21
23
|
end
|
22
24
|
|
23
25
|
# Log in to the Zabbix Server and generate an auth token using the API
|
@@ -25,9 +27,9 @@ class ZabbixManager
|
|
25
27
|
# @return [Hash, String]
|
26
28
|
def auth
|
27
29
|
api_request(
|
28
|
-
method:
|
30
|
+
method: "user.login",
|
29
31
|
params: {
|
30
|
-
user:
|
32
|
+
user: @options[:user],
|
31
33
|
password: @options[:password]
|
32
34
|
}
|
33
35
|
)
|
@@ -53,23 +55,24 @@ class ZabbixManager
|
|
53
55
|
# @return [ZabbixManager::Client]
|
54
56
|
def initialize(options = {})
|
55
57
|
@options = options
|
56
|
-
if !ENV[
|
57
|
-
@proxy_uri = URI.parse(ENV[
|
58
|
+
if !ENV["http_proxy"].nil? && options[:no_proxy] != true
|
59
|
+
@proxy_uri = URI.parse(ENV["http_proxy"])
|
58
60
|
@proxy_host = @proxy_uri.host
|
59
61
|
@proxy_port = @proxy_uri.port
|
60
62
|
@proxy_user, @proxy_pass = @proxy_uri.userinfo&.split(/:/) if @proxy_uri.userinfo
|
61
63
|
end
|
62
64
|
|
63
|
-
if api_version.match?
|
65
|
+
if api_version.match?(/^7\.\d+\.\d+$/)
|
64
66
|
message = "Zabbix API version: #{api_version} is not supported by this version of zabbixapi"
|
65
67
|
if @options[:ignore_version]
|
66
68
|
puts "[WARNING] #{message}" if @options[:debug]
|
67
69
|
else
|
68
|
-
raise ZabbixManager::ManagerError
|
70
|
+
raise ZabbixManager::ManagerError, message
|
69
71
|
end
|
70
72
|
end
|
71
73
|
|
72
74
|
@auth_hash = auth
|
75
|
+
puts "[DEBUG] Auth token: #{@auth_hash}" if @options[:debug]
|
73
76
|
end
|
74
77
|
|
75
78
|
# Convert message body to JSON string for the Zabbix API
|
@@ -77,16 +80,17 @@ class ZabbixManager
|
|
77
80
|
# @param body [Hash]
|
78
81
|
# @return [String]
|
79
82
|
def message_json(body)
|
80
|
-
message
|
81
|
-
method:
|
82
|
-
params:
|
83
|
-
id:
|
84
|
-
jsonrpc:
|
83
|
+
message = {
|
84
|
+
method: body[:method],
|
85
|
+
params: body[:params],
|
86
|
+
id: id,
|
87
|
+
jsonrpc: "2.0"
|
85
88
|
}
|
86
89
|
|
87
|
-
|
90
|
+
# 除登录认证和获取版本后之外,都需要携带TOKEN查询
|
91
|
+
message[:auth] = @auth_hash unless body[:method] == "apiinfo.version" || body[:method] == "user.login"
|
88
92
|
|
89
|
-
JSON
|
93
|
+
JSON(message)
|
90
94
|
end
|
91
95
|
|
92
96
|
# @param body [String]
|
@@ -105,7 +109,7 @@ class ZabbixManager
|
|
105
109
|
Net::HTTP.new(uri.host, uri.port)
|
106
110
|
end
|
107
111
|
|
108
|
-
if uri.scheme ==
|
112
|
+
if uri.scheme == "https"
|
109
113
|
http.use_ssl = true
|
110
114
|
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
111
115
|
end
|
@@ -115,33 +119,39 @@ class ZabbixManager
|
|
115
119
|
|
116
120
|
request = Net::HTTP::Post.new(uri.request_uri)
|
117
121
|
request.basic_auth @options[:http_user], @options[:http_password] if @options[:http_user]
|
118
|
-
request.add_field(
|
122
|
+
request.add_field("Content-Type", "application/json-rpc")
|
119
123
|
request.body = body
|
124
|
+
puts "[DEBUG] HTTP request params: #{request.body}" if @options[:debug]
|
120
125
|
|
121
126
|
response = http.request(request)
|
127
|
+
raise HttpError.new("HTTP Error: #{response.code} on #{@options[:url]}", response) unless response.code == "200"
|
122
128
|
|
123
|
-
|
124
|
-
|
125
|
-
puts "[DEBUG] Get answer: #{response.body}" if @options[:debug]
|
129
|
+
puts "[DEBUG] HTTP response answer: #{response.body}" if @options[:debug]
|
126
130
|
response.body
|
127
131
|
end
|
128
132
|
|
129
133
|
# @param body [String]
|
130
134
|
# @return [Hash, String]
|
131
135
|
def _request(body)
|
132
|
-
puts "[DEBUG] Send request: #{body}" if @options[:debug]
|
133
136
|
result = JSON.parse(http_request(body))
|
134
137
|
# 异常信息抛出
|
135
|
-
|
138
|
+
if result["error"]
|
139
|
+
raise ManagerError.new(
|
140
|
+
"Server answer API error\n #{JSON.pretty_unparse(result["error"])}\n on request:\n #{pretty_body(body)}", result
|
141
|
+
)
|
142
|
+
end
|
136
143
|
|
137
|
-
result[
|
144
|
+
result["result"]
|
138
145
|
end
|
139
146
|
|
140
147
|
def pretty_body(body)
|
141
|
-
parsed_body
|
148
|
+
parsed_body = JSON.parse(body)
|
142
149
|
|
143
150
|
# If password is in body hide it
|
144
|
-
|
151
|
+
if parsed_body["params"].is_a?(Hash) && parsed_body["params"].key?("password")
|
152
|
+
parsed_body["params"]["password"] =
|
153
|
+
"***"
|
154
|
+
end
|
145
155
|
|
146
156
|
JSON.pretty_unparse(parsed_body)
|
147
157
|
end
|
data/lib/zabbix_manager.rb
CHANGED
@@ -1,37 +1,39 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
require
|
5
|
-
|
6
|
-
require
|
7
|
-
require
|
8
|
-
|
9
|
-
require
|
10
|
-
|
11
|
-
require
|
12
|
-
require
|
13
|
-
require
|
14
|
-
require
|
15
|
-
require
|
16
|
-
require
|
17
|
-
require
|
18
|
-
require
|
19
|
-
require
|
20
|
-
require
|
21
|
-
require
|
22
|
-
require
|
23
|
-
require
|
24
|
-
require
|
25
|
-
require
|
26
|
-
require
|
27
|
-
require
|
28
|
-
require
|
29
|
-
require
|
30
|
-
require
|
31
|
-
require
|
32
|
-
require
|
33
|
-
require
|
34
|
-
require
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "zabbix_manager/version"
|
4
|
+
require "zabbix_manager/client"
|
5
|
+
|
6
|
+
require "zabbix_manager/basic/basic_alias"
|
7
|
+
require "zabbix_manager/basic/basic_func"
|
8
|
+
require "zabbix_manager/basic/basic_init"
|
9
|
+
require "zabbix_manager/basic/basic_logic"
|
10
|
+
|
11
|
+
require "zabbix_manager/classes/actions"
|
12
|
+
require "zabbix_manager/classes/applications"
|
13
|
+
require "zabbix_manager/classes/configurations"
|
14
|
+
require "zabbix_manager/classes/errors"
|
15
|
+
require "zabbix_manager/classes/events"
|
16
|
+
require "zabbix_manager/classes/graphs"
|
17
|
+
require "zabbix_manager/classes/hostgroups"
|
18
|
+
require "zabbix_manager/classes/hosts"
|
19
|
+
require "zabbix_manager/classes/httptests"
|
20
|
+
require "zabbix_manager/classes/items"
|
21
|
+
require "zabbix_manager/classes/maintenance"
|
22
|
+
require "zabbix_manager/classes/mediatypes"
|
23
|
+
require "zabbix_manager/classes/proxies"
|
24
|
+
require "zabbix_manager/classes/problems"
|
25
|
+
require "zabbix_manager/classes/roles"
|
26
|
+
require "zabbix_manager/classes/screens"
|
27
|
+
require "zabbix_manager/classes/scripts"
|
28
|
+
require "zabbix_manager/classes/server"
|
29
|
+
require "zabbix_manager/classes/templates"
|
30
|
+
require "zabbix_manager/classes/triggers"
|
31
|
+
require "zabbix_manager/classes/unusable"
|
32
|
+
require "zabbix_manager/classes/usergroups"
|
33
|
+
require "zabbix_manager/classes/usermacros"
|
34
|
+
require "zabbix_manager/classes/users"
|
35
|
+
require "zabbix_manager/classes/valuemaps"
|
36
|
+
require "zabbix_manager/classes/drules"
|
35
37
|
|
36
38
|
class ZabbixManager
|
37
39
|
# @return [ZabbixManager::Client]
|
@@ -192,4 +194,3 @@ class ZabbixManager
|
|
192
194
|
@drules ||= Drules.new(@client)
|
193
195
|
end
|
194
196
|
end
|
195
|
-
|
Binary file
|
Binary file
|
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zabbix_manager
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.0.
|
4
|
+
version: 5.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- WENWU YAN
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-03-
|
11
|
+
date: 2022-03-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: http
|
@@ -52,13 +52,15 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
-
description:
|
55
|
+
description: most codes are borrowed from zabbixapi, but changed some logic to fit
|
56
|
+
everyday job wells. now support ZABBIX 4.0, 5.0, 6.0
|
56
57
|
email:
|
57
58
|
- careline@foxmail.com
|
58
59
|
executables: []
|
59
60
|
extensions: []
|
60
61
|
extra_rdoc_files: []
|
61
62
|
files:
|
63
|
+
- ".idea/vcs.xml"
|
62
64
|
- ".idea/workspace.xml"
|
63
65
|
- ".rubocop.yml"
|
64
66
|
- CHANGELOG.md
|
@@ -105,6 +107,9 @@ files:
|
|
105
107
|
- lib/zabbix_manager/version.rb
|
106
108
|
- zabbix_manager-5.0.1.gem
|
107
109
|
- zabbix_manager-5.0.2.gem
|
110
|
+
- zabbix_manager-5.0.3.gem
|
111
|
+
- zabbix_manager-5.0.4.gem
|
112
|
+
- zabbix_manager-5.0.5.gem
|
108
113
|
homepage: https://github.com/snmpd/zabbix_manager
|
109
114
|
licenses:
|
110
115
|
- MIT
|
@@ -131,5 +136,5 @@ requirements: []
|
|
131
136
|
rubygems_version: 3.3.3
|
132
137
|
signing_key:
|
133
138
|
specification_version: 4
|
134
|
-
summary:
|
139
|
+
summary: ZABBIX API connector for VERSION 4.0 5.0 6.0
|
135
140
|
test_files: []
|