zabbix_manager 5.1.3 → 5.1.4

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.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/lib/zabbix_manager/basic/basic_alias.rb +3 -20
  3. data/lib/zabbix_manager/basic/basic_func.rb +24 -46
  4. data/lib/zabbix_manager/basic/basic_init.rb +8 -24
  5. data/lib/zabbix_manager/basic/basic_logic.rb +66 -104
  6. data/lib/zabbix_manager/classes/actions.rb +11 -21
  7. data/lib/zabbix_manager/classes/applications.rb +5 -19
  8. data/lib/zabbix_manager/classes/configurations.rb +5 -19
  9. data/lib/zabbix_manager/classes/drules.rb +6 -22
  10. data/lib/zabbix_manager/classes/errors.rb +19 -9
  11. data/lib/zabbix_manager/classes/events.rb +2 -6
  12. data/lib/zabbix_manager/classes/graphs.rb +16 -47
  13. data/lib/zabbix_manager/classes/hostgroups.rb +3 -9
  14. data/lib/zabbix_manager/classes/hostinterfaces.rb +7 -15
  15. data/lib/zabbix_manager/classes/hosts.rb +42 -76
  16. data/lib/zabbix_manager/classes/httptests.rb +7 -23
  17. data/lib/zabbix_manager/classes/items.rb +12 -68
  18. data/lib/zabbix_manager/classes/maintenance.rb +2 -6
  19. data/lib/zabbix_manager/classes/mediatypes.rb +20 -52
  20. data/lib/zabbix_manager/classes/problems.rb +38 -66
  21. data/lib/zabbix_manager/classes/proxies.rb +7 -26
  22. data/lib/zabbix_manager/classes/roles.rb +18 -57
  23. data/lib/zabbix_manager/classes/screens.rb +7 -21
  24. data/lib/zabbix_manager/classes/scripts.rb +7 -10
  25. data/lib/zabbix_manager/classes/server.rb +1 -6
  26. data/lib/zabbix_manager/classes/templates.rb +15 -49
  27. data/lib/zabbix_manager/classes/triggers.rb +15 -49
  28. data/lib/zabbix_manager/classes/unusable.rb +2 -1
  29. data/lib/zabbix_manager/classes/usergroups.rb +6 -28
  30. data/lib/zabbix_manager/classes/usermacros.rb +19 -113
  31. data/lib/zabbix_manager/classes/users.rb +7 -34
  32. data/lib/zabbix_manager/classes/valuemaps.rb +5 -26
  33. data/lib/zabbix_manager/client.rb +65 -69
  34. data/lib/zabbix_manager/version.rb +1 -2
  35. data/lib/zabbix_manager.rb +33 -46
  36. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 96bd31db6f13198d30bc1de2ac7168b7e535b17e3b1d80d97a30d852dc509c55
4
- data.tar.gz: 9022b530a873d1750502c288201583707303a6128eff5c10f82f125f1538a515
3
+ metadata.gz: cebae410e9abb93e18e28e5184aca238514910332b5769d132fc282d163d218c
4
+ data.tar.gz: f02f9e2cbe167a4358dd89da12f7d04f27d84a2e9869bc9d652ef8526671c514
5
5
  SHA512:
6
- metadata.gz: 8b4e51fc29613d082df8de77f4eab1b9eb12b30acf5d4d36f751bbaf8c657577f21d1faf8e715c4694f78b832b8c02696e5aeb468d1ffbfc9a2b7ecbbd7d1722
7
- data.tar.gz: 5e56fdd12fc7afddc2df2f5899fa390f97ba0e7eacafa3141fcfc2dad37ab9aa85f7e8a4553797d6dfbe8aaa286d0ad5932ee2dadb231d4a3b2e2c4a01986c9c
6
+ metadata.gz: c73a3e5b13a7f514508ed7998bf4df6ffc6a5c778e9a8b5eac620842a3df4555fc4c4fca41d76ad8740665c4d5583ceea2440439113ebd7dd3aeeeb40eab32b4
7
+ data.tar.gz: d3f0d4c6d9e627f36ba0f1ca87098c6060e20f22218586368139e14d0446dcddef640a998dcd711b4c848ef60e9e9f99b10204a5fe0f69fe28dc6c438f256cf1
@@ -2,34 +2,17 @@
2
2
 
3
3
  class ZabbixManager
4
4
  class Basic
5
- # Get Zabbix object data from API by id
6
- # @note 通用的查询方法
7
- # @param data [Hash] Should include object's id field name (identify) and id value
8
- # @raise [ZbxError] Error returned when there is a problem with the Zabbix API call.
9
- # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
10
- # @return [Hash]
5
+ # 获取 Zabbix 对象数据
11
6
  def get(data)
12
7
  get_full_data(data)
13
8
  end
14
9
 
15
- # Add new Zabbix object using API create
16
- # @note 通用的新增方法
17
- # @param data [Hash]
18
- # @raise [ZbxError] Error returned when there is a problem with the Zabbix API call.
19
- # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
20
- # @return [Integer] The object id if a single object is created
21
- # @return [Boolean] True/False if multiple objects are created
10
+ # 新增 Zabbix 对象
22
11
  def add(data)
23
12
  create(data)
24
13
  end
25
14
 
26
- # Destroy Zabbix object using API delete
27
- # @note 通用的删除方法
28
- # @param data [Hash] Should include object's id field name (identify) and id value
29
- # @raise [ZbxError] Error returned when there is a problem with the Zabbix API call.
30
- # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
31
- # @return [Integer] The object id if a single object is deleted
32
- # @return [Boolean] True/False if multiple objects are deleted
15
+ # 删除 Zabbix 对象
33
16
  def destroy(data)
34
17
  delete(data)
35
18
  end
@@ -2,31 +2,24 @@
2
2
 
3
3
  class ZabbixManager
4
4
  class Basic
5
- # Log messages to stdout when debugging
6
- # @note 开启debug模式,打印日志
7
- # @param message [String]
5
+ # 在调试模式下将日志消息记录到 stdout
8
6
  def log(message)
9
7
  puts message if @client.options[:debug]
10
8
  end
11
9
 
12
- # Compare two hashes for equality
13
- # @note 比较两个哈希是否相等
14
- # @param first_hash [Hash]
15
- # @param second_hash [Hash]
16
- # @return [Boolean]
17
- def hash_equals?(first_hash, second_hash)
18
- normalized_first_hash = normalize_hash(first_hash)
19
- normalized_second_hash = normalize_hash(second_hash)
10
+ # 比较两个哈希是否相等
11
+ def hash_equals?(hash1, hash2)
12
+ normalized_hash1 = normalize_hash(hash1)
13
+ normalized_hash2 = normalize_hash(hash2)
20
14
 
21
- hash1 = normalized_first_hash.merge(normalized_second_hash)
22
- hash2 = normalized_second_hash.merge(normalized_first_hash)
23
- hash1 == hash2
15
+ merged_hash1 = normalized_hash1.merge(normalized_hash2)
16
+ merged_hash2 = normalized_hash2.merge(normalized_hash1)
17
+
18
+ merged_hash1 == merged_hash2
24
19
  end
25
20
 
26
- # Convert all hash/array keys to symbols
27
- # @@note 将数组或哈希序列化
28
- # @param object [Array, Hash]
29
- # @return [Array, Hash]
21
+ # 将所有哈希/数组键转换为符号
22
+ # &method(:symbolize_keys) 是 Ruby 中一种将方法转换为可传递给块或其他方法的 Proc 的方式
30
23
  def symbolize_keys(object)
31
24
  case object
32
25
  when Array
@@ -38,34 +31,27 @@ class ZabbixManager
38
31
  end
39
32
  end
40
33
 
41
- # Normalize all hash values to strings
42
- # @note 将哈希元素序列化成字符串
43
- # @param hash [Hash]
44
- # @return [Hash]
34
+ # 将所有哈希值规范化为字符串
45
35
  def normalize_hash(hash)
46
36
  result = hash.dup
47
37
 
48
- result.delete(:hostid) # TODO: remove to logig. TemplateID and HostID has different id
38
+ # 移除用于日志记录的 TODO 注释。TemplateID HostID 具有不同的 ID
39
+ result.delete(:hostid)
49
40
 
50
- result.each do |key, value|
51
- result[key.to_sym] = value.is_a?(Array) ? normalize_array(value) : value.to_s
52
- end
41
+ result.transform_keys!(&:to_sym)
42
+ result.transform_values! { |value| value.is_a?(Array) ? normalize_array(value) : value.to_s }
53
43
 
54
44
  result
55
45
  end
56
46
 
57
- # Normalize all array values to strings
58
- # @note 将数组元素序列化成字符串
59
- # @param array [Array]
60
- # @return [Array]
47
+ # 将所有数组值规范化为字符串
61
48
  def normalize_array(array)
62
49
  result = []
63
50
 
64
51
  array.each do |e|
65
- case e
66
- when Array
52
+ if e.is_a?(Array)
67
53
  result.push(normalize_array(e))
68
- when Hash
54
+ elsif e.is_a?(Hash)
69
55
  result.push(normalize_hash(e))
70
56
  else
71
57
  result.push(e.to_s)
@@ -75,11 +61,7 @@ class ZabbixManager
75
61
  result
76
62
  end
77
63
 
78
- # Parse a data hash for id key or boolean to return
79
- # @note 提取 zabbix 监控对象 CRUD key 或者 keys
80
- # @param data
81
- # @return [Integer] The object id if a single object hash is provided with key
82
- # @return [Boolean] True/False if multiple class object hash is provided
64
+ # 解析包含 ID 键或布尔值的数据哈希
83
65
  def parse_keys(data)
84
66
  case data
85
67
  when Hash
@@ -93,14 +75,10 @@ class ZabbixManager
93
75
  end
94
76
  end
95
77
 
96
- # Merge two hashes into a single new hash
97
- #
98
- # @param first_hash [Hash]
99
- # @param second_hash [Hash]
100
- # @return [Hash]
101
- def merge_params(first_hash, second_hash)
102
- new = first_hash.dup
103
- new.merge(second_hash)
78
+ # 合并两个哈希为一个新的哈希
79
+ def merge_hashes(hash1, hash2)
80
+ new_hash = hash1.dup
81
+ new_hash.merge(hash2)
104
82
  end
105
83
  end
106
84
  end
@@ -1,49 +1,33 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class ZabbixManager
4
- # @author: WENWU YAN
5
- # @email: 968828@gmail.com
6
- # @date: 2023/3/25下午4:47
7
4
  class Basic
8
- # Initializes a new Basic object with ZabbixManager Client
9
- # @note zabbix api 基类
10
- # @param client [ZabbixManager::Client]
11
- # @return [ZabbixManager::Client]
5
+ # 使用 ZabbixManager 客户端初始化一个新的 Basic 对象
12
6
  def initialize(client)
13
7
  @client = client
14
8
  end
15
9
 
16
- # Placeholder for inherited objects to provide object-specific method name
17
- # @note 子类必须实现的方法 method_name
18
- # @raise [ZbxError] Basic object does not directly support method_name
10
+ # 在派生类中应该重写此方法以提供特定的方法名
19
11
  def method_name
20
- raise ZbxError, "Can't call method_name here"
12
+ raise ZbxError, "子类需要自行实现 method_name"
21
13
  end
22
14
 
23
- # Placeholder for inherited objects to provide object-specific id field name
24
- # @note 子类必须实现的方法
25
- # @raise [ZbxError] Basic object does not directly support identify
15
+ # 在派生类中应该重写此方法以提供特定的 ID 字段名
26
16
  def identify
27
- raise ZbxError, "Can't call identify here"
17
+ raise ZbxError, "子类需要自行实现 identify"
28
18
  end
29
19
 
30
- # Placeholder for inherited objects to provide default options
31
- # @note 子类缺省的 options
32
- # @return [Hash]
20
+ # 派生类可以重写此方法以提供特定的默认选项
33
21
  def default_options
34
22
  {}
35
23
  end
36
24
 
37
- # Returns the object's id field name (identify) based on method_name + id
38
- # @note 默认 key 为 "#{method_name}id"
39
- # @return [String]
25
+ # 根据 method_name + id 返回对象的 ID 字段名(identify
40
26
  def key
41
27
  "#{method_name}id"
42
28
  end
43
29
 
44
- # Returns the object's plural id field name (identify) based on key
45
- # @note 默认 key 为 "#{method_name}ids"
46
- # @return [String]
30
+ # 根据 key 返回对象的复数 ID 字段名(identify
47
31
  def keys
48
32
  "#{key}s"
49
33
  end
@@ -2,38 +2,25 @@
2
2
 
3
3
  class ZabbixManager
4
4
  class Basic
5
- # Create new Zabbix object using API (with defaults)
6
- # @note 新增 zabbix 监控对象,返回监控对象 id
7
- # @param data [Hash]
8
- # @raise [ZbxError] Error returned when there is a problem with the Zabbix API call.
9
- # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
10
- # @return [Integer] The object id if a single object is created
11
- # @return [Boolean] True/False if multiple objects are created
5
+ # 使用 API 新增 Zabbix 监控对象(使用默认值)
12
6
  def create(data)
13
- log "[DEBUG] Call #{method_name}.create with parameters: #{data.inspect}"
7
+ log "[DEBUG] 调用 #{method_name}.create,参数: #{data.inspect}"
14
8
 
15
9
  params = default_options.merge(data)
16
10
  result = @client.api_request(method: "#{method_name}.create", params: params)
17
11
  parse_keys result
18
12
  end
19
13
 
20
- # Update Zabbix object using API
21
- # @note 更新 zabbix 监控对象,返回监控对象 id
22
- # @param data [Hash] Should include object's id field name (identify) and id value
23
- # @param force [Boolean] Whether to force an object update even if provided data matches Zabbix
24
- # @raise [ZbxError] Error returned when there is a problem with the Zabbix API call.
25
- # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
26
- # @return [Integer] The object id if a single object is created
27
- # @return [Boolean] True/False if multiple objects are created
14
+ # 使用 API 更新 Zabbix 监控对象
28
15
  def update(data, force = false)
29
- log "[DEBUG] Call #{method_name}.update with parameters: #{data.inspect}"
16
+ log "[DEBUG] 调用 #{method_name}.update,参数: #{data.inspect}"
30
17
 
31
18
  dump = {}
32
19
  dump_by_id(key.to_sym => data[key.to_sym]).each do |item|
33
20
  dump = symbolize_keys(item) if item[key].to_i == data[key.to_sym].to_i
34
21
  end
35
22
  if hash_equals?(dump, data) && !force
36
- log "[DEBUG] Equal keys #{dump} and #{data}, skip update"
23
+ log "[DEBUG] 系统以有数据 #{dump} 待更新的数据 #{data} 相同,跳过本次更新"
37
24
  data[key.to_sym].to_i
38
25
  else
39
26
  result = @client.api_request(method: "#{method_name}.update", params: data)
@@ -41,30 +28,18 @@ class ZabbixManager
41
28
  end
42
29
  end
43
30
 
44
- # Delete Zabbix object using API
45
- # @note 删除 zabbix 监控对象,返回监控对象 id
46
- # @param data [Hash] Should include object's id field name (identify) and id value
47
- # @raise [ZbxError] Error returned when there is a problem with the Zabbix API call.
48
- # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
49
- # @return [Integer] The object id if a single object is deleted
50
- # @return [Boolean] True/False if multiple objects are deleted
31
+ # 使用 API 删除 Zabbix 监控对象
51
32
  def delete(data)
52
- log "[DEBUG] Call #{method_name}.delete with parameters: #{data.inspect}"
33
+ log "[DEBUG] 调用 #{method_name}.delete,参数: #{data.inspect}"
53
34
 
54
35
  result = @client.api_request(method: "#{method_name}.delete", params: [data].flatten)
55
36
  parse_keys result
56
37
  end
57
38
 
58
- # Get or Create Zabbix object using API
59
- # @note 创建或更新 zabbix 监控对象,返回监控对象 id
60
- # @param data [Hash] Should include object's id field name (identify) and id value
61
- # @raise [ZbxError] Error returned when there is a problem with the Zabbix API call.
62
- # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
63
- # @return [Integer, Array, TrueClass, FalseClass] Zabbix object id
39
+ # 使用 API 获取或创建 Zabbix 监控对象
64
40
  def get_or_create(data)
65
- log "[DEBUG] Call #{method_name}.get_or_create with parameters: #{data.inspect}"
41
+ log "[DEBUG] 调用 #{method_name}.get_or_create,参数: #{data.inspect}"
66
42
 
67
- # Call get_id return object id if exists
68
43
  if (id = get_id(identify.to_sym => data[identify.to_sym]))
69
44
  id
70
45
  else
@@ -72,46 +47,30 @@ class ZabbixManager
72
47
  end
73
48
  end
74
49
 
75
- # Get or Create Zabbix object [{ key: id }] using API
76
- # @note 批量创建或更新监控对象并返回 [ { "#{key}": id } ]
77
- # @param data [Hash, Array] Should include object's id field name (identify) and id value
78
- # @raise [ZbxError] Error returned when there is a problem with the Zabbix API call.
79
- # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
80
- # @return [Array] Zabbix object [{keys: id}]
50
+ # 使用 API 批量获取或创建 Zabbix 监控对象
81
51
  def get_or_create_keys(data)
82
- log "[DEBUG] Call #{method_name}.get_or_create_keys with parameters: #{data.inspect}"
52
+ log "[DEBUG] 调用 #{method_name}.get_or_create_keys,参数: #{data.inspect}"
83
53
 
84
54
  ids = []
85
55
  [data].flatten.each do |item|
86
56
  if (id = get_or_create(item))
87
- ids << { "#{key}": id }
57
+ ids << { key.to_sym => id }
88
58
  end
89
59
  end
90
60
  ids
91
61
  end
92
62
 
93
- # Create or update Zabbix object using API
94
- # @note 创建或更新 zabbix 监控对象,入参为基于符号的哈希对象,返回监控对象 id
95
- # @param data [Hash] Should include object's id field name (identify) and id value
96
- # @raise [ZbxError] Error returned when there is a problem with the Zabbix API call.
97
- # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
98
- # @return [Integer] The object id if a single object is created
99
- # @return [Boolean] True/False if multiple objects are created
63
+ # 使用 API 创建或更新 Zabbix 监控对象
100
64
  def create_or_update(data)
101
- log "[DEBUG] Call #{method_name}.create_or_update with parameters: #{data.inspect}"
65
+ log "[DEBUG] 调用 #{method_name}.create_or_update,参数: #{data.inspect}"
102
66
 
103
67
  id = get_id(identify.to_sym => data[identify.to_sym])
104
68
  id ? update(data.merge(key.to_sym => id.to_s)) : create(data)
105
69
  end
106
70
 
107
- # Dump Zabbix object data by key from API
108
- # @note 基于 "#{key}" 打印 zabbix 监控对象详情
109
- # @param data [Hash] Should include desired object's key and value
110
- # @raise [ZbxError] Error returned when there is a problem with the Zabbix API call.
111
- # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
112
- # @return [Hash]
71
+ # 使用 API 基于 key 打印 Zabbix 监控对象详情
113
72
  def dump_by_id(data)
114
- log "[DEBUG] Call #{method_name}.dump_by_id with parameters: #{data.inspect}"
73
+ log "[DEBUG] 调用 #{method_name}.dump_by_id,参数: #{data.inspect}"
115
74
 
116
75
  get_raw(
117
76
  {
@@ -123,21 +82,15 @@ class ZabbixManager
123
82
  )
124
83
  end
125
84
 
126
- # Get Zabbix object id from API based on provided data
127
- # @note 基于 zabbix "#{identify}" 查询监控对象的 "#{key}"
128
- # @param data [Hash]
129
- # @raise [ZbxError] Error returned when there is a problem with the Zabbix API call or missing object's id field name (identify).
130
- # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
131
- # @return [Integer, NilClass] Zabbix object id
85
+ # 使用 API 基于提供的数据查询 Zabbix 监控对象 id
132
86
  def get_id(data)
133
- log "[DEBUG] Call #{method_name}.get_id with parameters: #{data.inspect}"
87
+ log "[DEBUG] 调用 #{method_name}.get_id,参数: #{data.inspect}"
134
88
 
135
- # symbolize keys if the user used string keys instead of symbols
136
89
  data = symbolize_keys(data) if data.key?(identify)
137
- # raise an error if identify name was not supplied
138
90
  name = data[identify.to_sym]
139
- raise ZbxError, "#{identify} not supplied in call to get_id" if name.nil?
91
+ raise ZbxError, "在调用 get_id 时未提供 identify #{identify}" if name.nil?
140
92
 
93
+ # 输出信息截取 key identify
141
94
  result = get_raw(
142
95
  {
143
96
  filter: data,
@@ -148,47 +101,59 @@ class ZabbixManager
148
101
  result.find { |item| item[identify] == data[identify.to_sym] }&.[](key)&.to_i
149
102
  end
150
103
 
151
- # Get Zabbix object [{ key: id }] from API based on provided data
152
- # @note 基于监控对象索引建"#{identify}"查询 { "#{key}": id }
153
- # @param data [Hash, Array]
154
- # @raise [ZbxError] Error returned when there is a problem with the Zabbix API call or missing object's id field name (identify).
155
- # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
156
- # @return [Array] Zabbix object id
104
+ # 使用 API 基于提供的数据查询 Zabbix 监控对象 ids
105
+ def get_ids(data)
106
+ log "[DEBUG] 调用 #{method_name}.get_ids,参数: #{data.inspect}"
107
+
108
+ ids = []
109
+ [data].flatten.each do |item|
110
+ if (id = get_id(item))
111
+ ids << id
112
+ end
113
+ end
114
+ ids
115
+ end
116
+
117
+ # 使用 API 基于提供的数据查询 Zabbix 监控对象 id
157
118
  def get_key_ids(data)
158
- log "[DEBUG] Call #{method_name}.get_key_ids with parameters: #{data.inspect}"
119
+ log "[DEBUG] 调用 #{method_name}.get_key_ids,参数: #{data.inspect}"
159
120
 
160
121
  ids = []
161
122
  [data].flatten.each do |item|
162
123
  if (id = get_id(item))
163
- ids << { "#{key}": id }
124
+ ids << { key.to_sym => id }
164
125
  end
165
126
  end
166
127
  ids
167
128
  end
168
129
 
169
- # Get Zabbix object ID by name using Zabbix API
170
- # @note 基于监控对象索引键(#{identify})查询 #{key}
171
- # @param data [String, Array] Needs to include host to properly identify Zabbix Objects via Zabbix API
172
- # @raise [ZbxError] Error returned when there is a problem with the Zabbix API call.
173
- # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
174
- # @return [Array, NilClass] Zabbix object id
130
+ # 使用 API 基于 name 查询 Zabbix 监控对象 id
131
+ def get_ids_by_identify(data)
132
+ log "[DEBUG] 调用 #{method_name}.get_ids_by_identify,参数: #{data.inspect}"
133
+
134
+ result = get_raw(
135
+ {
136
+ filter: { identify.to_sym => [data].flatten },
137
+ output: [key]
138
+ }
139
+ )
140
+ result.empty? ? nil : result.map { |i| i[key] }
141
+ end
142
+
143
+ # 使用 API 基于 name 查询 Zabbix 监控对象 id
175
144
  def get_key_ids_by_identify(data)
176
- log "[DEBUG] Call #{method_name}.get_ids_by_name with parameters: #{data.inspect}"
145
+ log "[DEBUG] 调用 #{method_name}.get_key_ids_by_identify,参数: #{data.inspect}"
177
146
 
178
147
  result = get_raw(
179
148
  {
180
- filter: { "#{identify}": [data].flatten },
181
- output: ["#{key}"]
149
+ filter: { identify.to_sym => [data].flatten },
150
+ output: [key]
182
151
  }
183
152
  )
184
- result.empty? ? nil : result.map { |i| { "#{key}": i[key] } }
153
+ result.empty? ? nil : result.map { |i| { key.to_sym => i[key] } }
185
154
  end
186
155
 
187
- # Get full/extended Zabbix data for all objects of type/class from API
188
- # @note 查询 zabbix 监控对象所有的 "#{identify}: #{key}"
189
- # @raise [ZbxError] Error returned when there is a problem with the Zabbix API call.
190
- # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
191
- # @return [Hash] Array of matching objects
156
+ # 使用 API 查询所有 Zabbix 监控对象的详细信息
192
157
  def all
193
158
  result = {}
194
159
  get_raw({ output: "extend" }).each do |item|
@@ -197,14 +162,9 @@ class ZabbixManager
197
162
  result
198
163
  end
199
164
 
200
- # Get full/extended Zabbix object data from API
201
- # @note 基于 "#{identify}" 过滤 zabbix 监控对象,输出详情
202
- # @param data [Hash] Should include object's id field name (identify) and id value
203
- # @raise [ZbxError] Error returned when there is a problem with the Zabbix API call.
204
- # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
205
- # @return [Hash]
165
+ # 使用 API 查询 Zabbix 监控对象的详细信息
206
166
  def get_full_data(data)
207
- log "[DEBUG] Call #{method_name}.get_full_data with parameters: #{data.inspect}"
167
+ log "[DEBUG] 调用 #{method_name}.get_full_data,参数: #{data.inspect}"
208
168
 
209
169
  get_raw(
210
170
  {
@@ -216,18 +176,20 @@ class ZabbixManager
216
176
  )
217
177
  end
218
178
 
219
- # Get raw Zabbix object data from API
220
- # @note zabbix 监控对象低阶查询方法,静默方法 debug 打印信息
221
- # @param data [Hash]
222
- # @raise [ZbxError] Error returned when there is a problem with the Zabbix API call.
223
- # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
224
- # @return [Hash]
179
+ # 使用 API 查询 Zabbix 监控对象的原始数据
225
180
  def get_raw(data)
226
- # log "[DEBUG] Call #{method_name}.get_raw with parameters: #{data.inspect}"
227
181
  @client.api_request(
228
182
  method: "#{method_name}.get",
229
183
  params: data
230
184
  )
231
185
  end
186
+
187
+ # 使用 API 查询 Zabbix 监控对象的原始数据
188
+ def request_raw(method, data)
189
+ @client.api_request(
190
+ method: method,
191
+ params: data
192
+ )
193
+ end
232
194
  end
233
195
  end
@@ -2,40 +2,30 @@
2
2
 
3
3
  class ZabbixManager
4
4
  class Actions < Basic
5
- # The method name used for interacting with Actions via Zabbix API
6
- #
7
- # @return [String]
5
+ # 用于与 Zabbix API 交互的方法名称
8
6
  def method_name
9
7
  "action"
10
8
  end
11
9
 
12
- # The id field name used for identifying specific Action objects via Zabbix API
13
- #
14
- # @return [String]
10
+ # 用于通过 Zabbix API 标识特定 Action 对象的 id 字段名称
15
11
  def identify
16
12
  "name"
17
13
  end
18
14
 
19
- # Get full/extended Action object data from API
20
- #
21
- # @param data [Hash] Should include object's id field name (identify) and id value
22
- # @raise [ZbxError] Error returned when there is a problem with the Zabbix API call.
23
- # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
24
- # @return [Hash]
15
+ # API 获取完整/扩展的 Action 对象数据
25
16
  def get_full_data(data)
26
- log "[DEBUG] Call get_full_data with parameters: #{data.inspect}"
17
+ log "[DEBUG] 调用 get_full_data,参数为:#{data.inspect}"
27
18
 
28
- @client.api_request(
29
- method: "#{method_name}.get",
30
- params: {
31
- filter: {
19
+ get_raw(
20
+ {
21
+ filter: {
32
22
  identify.to_sym => data[identify.to_sym]
33
23
  },
34
- output: "extend",
35
- selectOperations: "extend",
36
- selectRecoveryOperations: "extend",
24
+ output: "extend",
25
+ selectOperations: "extend",
26
+ selectRecoveryOperations: "extend",
37
27
  selectAcknowledgeOperations: "extend",
38
- selectFilter: "extend"
28
+ selectFilter: "extend"
39
29
  }
40
30
  )
41
31
  end
@@ -2,28 +2,19 @@
2
2
 
3
3
  class ZabbixManager
4
4
  class Applications < Basic
5
- # The method name used for interacting with Applications via Zabbix API
6
- #
7
- # @return [String]
5
+ # 用于通过 Zabbix API Applications 交互的方法名称
8
6
  def method_name
9
7
  "application"
10
8
  end
11
9
 
12
- # The id field name used for identifying specific Application objects via Zabbix API
13
- #
14
- # @return [String]
10
+ # 用于通过 Zabbix API 标识特定 Application 对象的 id 字段名称
15
11
  def identify
16
12
  "name"
17
13
  end
18
14
 
19
- # Get or Create Application object using Zabbix API
20
- #
21
- # @param data [Hash] Needs to include name and hostid to properly identify Applications via Zabbix API
22
- # @raise [ZbxError] Error returned when there is a problem with the Zabbix API call.
23
- # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
24
- # @return [Integer, TrueClass, FalseClass] Zabbix object id
15
+ # 通过 Zabbix API 获取或创建 Application 对象
25
16
  def get_or_create(data)
26
- log "[DEBUG] Call get_or_create with parameters: #{data.inspect}"
17
+ log "[DEBUG] 调用 get_or_create,参数为:#{data.inspect}"
27
18
 
28
19
  if (id = get_id(name: data[:name], hostid: data[:hostid]))
29
20
  id
@@ -32,12 +23,7 @@ class ZabbixManager
32
23
  end
33
24
  end
34
25
 
35
- # Create or update Application object using Zabbix API
36
- #
37
- # @param data [Hash] Needs to include name and hostid to properly identify Applications via Zabbix API
38
- # @raise [ZbxError] Error returned when there is a problem with the Zabbix API call.
39
- # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
40
- # @return [Integer,TrueClass, FalseClass] Zabbix object id
26
+ # 通过 Zabbix API 创建或更新 Application 对象
41
27
  def create_or_update(data)
42
28
  applicationid = get_id(name: data[:name], hostid: data[:hostid])
43
29
  applicationid ? update(data.merge(applicationid: applicationid)) : create(data)
@@ -2,41 +2,27 @@
2
2
 
3
3
  class ZabbixManager
4
4
  class Configurations < Basic
5
- # @return [Boolean]
5
+ # 用于标识返回结果是否为数组
6
6
  def array_flag
7
7
  true
8
8
  end
9
9
 
10
- # The method name used for interacting with Configurations via Zabbix API
11
- #
12
- # @return [String]
10
+ # 用于通过 Zabbix API Configurations 交互的方法名称
13
11
  def method_name
14
12
  "configuration"
15
13
  end
16
14
 
17
- # The id field name used for identifying specific Configuration objects via Zabbix API
18
- #
19
- # @return [String]
15
+ # 用于通过 Zabbix API 标识特定 Configuration 对象的 id 字段名称
20
16
  def identify
21
17
  "host"
22
18
  end
23
19
 
24
- # Export configuration data using Zabbix API
25
- #
26
- # @param data [Hash]
27
- # @raise [ZbxError] Error returned when there is a problem with the Zabbix API call.
28
- # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
29
- # @return [Hash]
20
+ # 使用 Zabbix API 导出配置数据
30
21
  def export(data)
31
22
  @client.api_request(method: "configuration.export", params: data)
32
23
  end
33
24
 
34
- # Import configuration data using Zabbix API
35
- #
36
- # @param data [Hash]
37
- # @raise [ZbxError] Error returned when there is a problem with the Zabbix API call.
38
- # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
39
- # @return [Hash]
25
+ # 使用 Zabbix API 导入配置数据
40
26
  def import(data)
41
27
  @client.api_request(method: "configuration.import", params: data)
42
28
  end