zabbix_manager 5.1.2.pre.alpha1 → 5.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cdf16c4b624bb9e8c258d89ce7ab1b2d28ff5e9b98ca07e21fb35bdecf694461
4
- data.tar.gz: ac0325dbbf69515af8ec178d378e9c4acdb64998030fac73d4097a60370b645b
3
+ metadata.gz: 96bd31db6f13198d30bc1de2ac7168b7e535b17e3b1d80d97a30d852dc509c55
4
+ data.tar.gz: 9022b530a873d1750502c288201583707303a6128eff5c10f82f125f1538a515
5
5
  SHA512:
6
- metadata.gz: 65d75bd728d6fe2cf9d9c76f058f68fb9d12140e668dc2363b23e8064164f098811d345c2ec59f0af43c49db1511058dae1d361c304fe96799875536ca91d9e8
7
- data.tar.gz: 3efc570deed7731861f4f663eb704d80d2757c67e02f5c0899fb688f9c43cb9784d9f7a5b77e19ed6354b469e199baac56c882aace9d981faa815e54cc2fe132
6
+ metadata.gz: 8b4e51fc29613d082df8de77f4eab1b9eb12b30acf5d4d36f751bbaf8c657577f21d1faf8e715c4694f78b832b8c02696e5aeb468d1ffbfc9a2b7ecbbd7d1722
7
+ data.tar.gz: 5e56fdd12fc7afddc2df2f5899fa390f97ba0e7eacafa3141fcfc2dad37ab9aa85f7e8a4553797d6dfbe8aaa286d0ad5932ee2dadb231d4a3b2e2c4a01986c9c
@@ -51,7 +51,7 @@ class ZabbixManager
51
51
  def delete(data)
52
52
  log "[DEBUG] Call #{method_name}.delete with parameters: #{data.inspect}"
53
53
 
54
- result = @client.api_request(method: "#{method_name}.delete", params: data)
54
+ result = @client.api_request(method: "#{method_name}.delete", params: [data].flatten)
55
55
  parse_keys result
56
56
  end
57
57
 
@@ -22,5 +22,16 @@ class ZabbixManager
22
22
  def key
23
23
  "interfaceid"
24
24
  end
25
+
26
+ # Get Zabbix interface id from API based on provided hostid
27
+ # @note 基于 hostid 查询关联的 Interfaceid
28
+ # @param hostid [Integer, String]
29
+ # @raise [ZbxError] Error returned when there is a problem with the Zabbix API call or missing object's id field name (identify).
30
+ # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
31
+ # @return [Integer, NilClass] Zabbix object id
32
+ def get_interfaceid(hostid)
33
+ result = get_raw({ output: key, "#{identify}": hostid })
34
+ result&.[](0)&.[](key)&.to_i
35
+ end
25
36
  end
26
37
  end
@@ -98,5 +98,41 @@ class ZabbixManager
98
98
  result.empty? ? nil : result.map { |i| { "#{key}": i[key] } }
99
99
  end
100
100
 
101
+ # Create or update Zabbix object using API
102
+ # @note 创建或更新 Host 监控对象,入参为基于符号的哈希对象,返回监控对象 id
103
+ # @note 重写基类方法 create_or_update,特殊处理 interfaces 对象
104
+ # @param data [Hash] Should include object's id field name (identify) and id value
105
+ # @raise [ZbxError] Error returned when there is a problem with the Zabbix API call.
106
+ # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
107
+ # @return [Integer] The object id if a single object is created
108
+ # @return [Boolean] True/False if multiple objects are created
109
+ def create_or_update(data)
110
+ log "[DEBUG] Call #{method_name}.create_or_update with parameters: #{data.inspect}"
111
+
112
+ hostid = get_id(identify.to_sym => data[identify.to_sym])
113
+ return create(data) unless hostid
114
+
115
+ interface_id = get_interfaceid(hostid)
116
+ raise ZbxError, "interfaceid not found in call to get_interfaceid" unless interface_id
117
+
118
+ interfaces = data.delete(:interfaces)&.merge(interfaceid: interface_id)
119
+ params = data.merge(interfaces: interfaces).merge(key.to_sym => hostid.to_s)
120
+ update(params)
121
+ end
122
+
123
+ # Get Zabbix interface id from API based on provided hostid
124
+ # @note 基于 hostid 查询关联的 Interfaceid
125
+ # @param hostid [Integer, String]
126
+ # @raise [ZbxError] Error returned when there is a problem with the Zabbix API call or missing object's id field name (identify).
127
+ # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
128
+ # @return [Integer, NilClass] Zabbix object id
129
+ def get_interfaceid(hostid)
130
+ result = @client.api_request(
131
+ method: "hostinterface.get",
132
+ params: { output: "interfaceid", hostids: hostid }
133
+ )
134
+ result&.[](0)&.[]("interfaceid")&.to_i
135
+ end
101
136
  end
102
137
  end
138
+
@@ -95,7 +95,7 @@ class ZabbixManager
95
95
  # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
96
96
  # @return [Integer, TrueClass, FalseClass, NilClass] Zabbix object id
97
97
  def get_interface_items(hostid, name)
98
- log "[DEBUG] Call #{method_name}.get_interface_items with parameters: #{data.inspect}"
98
+ log "[DEBUG] Call #{method_name}.get_interface_items with: hostid #{hostid.inspect} name #{name.inspect}"
99
99
 
100
100
  # 自动剔除收尾空白字串
101
101
  _name = name&.gsub(%r{[^/0-9]}, "").strip
@@ -18,6 +18,7 @@ class ZabbixManager
18
18
 
19
19
  # The default options used when creating zabbix triggers
20
20
  # @note 缺省的 trigger 参数
21
+ # @see https://www.zabbix.com/documentation/current/en/manual/api/reference/trigger/get
21
22
  # @return [Hash]
22
23
  def default_options
23
24
  {
@@ -39,9 +40,7 @@ class ZabbixManager
39
40
  @client.api_request(
40
41
  method: "trigger.get",
41
42
  params: {
42
- filter: {
43
- keys.to_sym => data[keys.to_sym]
44
- },
43
+ triggerids: data[keys.to_sym],
45
44
  output: "extend",
46
45
  select_items: "extend",
47
46
  select_functions: "extend"
@@ -118,7 +117,6 @@ class ZabbixManager
118
117
  triggerid ? update(data.merge(triggerid: triggerid)) : create(data)
119
118
  end
120
119
 
121
-
122
120
  # Add dependsOnTrigger using Zabbix API
123
121
  #
124
122
  # @param triggerid [Integer] identify for trigger via Zabbix API
@@ -2,5 +2,5 @@
2
2
 
3
3
  class ZabbixManager
4
4
  # @note find ./* -type f -exec sed -i 's/\[X\]/\[Y\]/g' {} +
5
- VERSION = "5.1.2.pre.alpha1"
5
+ VERSION = "5.1.3"
6
6
  end
@@ -1,13 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Dynamically load Ruby modules
4
- Dir.glob(File.join(__dir__, "zabbix_manager", "**", "*.rb")).sort.each do |module_rb|
5
- require module_rb
3
+ require "zabbix_manager/version"
4
+ require "zabbix_manager/client"
5
+
6
+ # Dynamically load Basic Classes
7
+ Dir.glob(File.join(__dir__, "zabbix_manager/basic", "**", "*.rb")).sort.each do |basic_class|
8
+ require basic_class
9
+ end
10
+
11
+ # Dynamically load Extend Classes
12
+ Dir.glob(File.join(__dir__, "zabbix_manager/classes", "**", "*.rb")).sort.each do |extend_class|
13
+ require extend_class
6
14
  end
7
15
 
8
- # @author: WENWU YAN
9
- # @email: 968828@gmail.com
10
- # @date: 2023/3/25下午4:47
11
16
  class ZabbixManager
12
17
  # @return [ZabbixManager::Client]
13
18
  attr_reader :client
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.1.2.pre.alpha1
4
+ version: 5.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - WENWU YAN
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-25 00:00:00.000000000 Z
11
+ date: 2023-03-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http
@@ -116,9 +116,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
116
116
  version: 2.7.0
117
117
  required_rubygems_version: !ruby/object:Gem::Requirement
118
118
  requirements:
119
- - - ">"
119
+ - - ">="
120
120
  - !ruby/object:Gem::Version
121
- version: 1.3.1
121
+ version: '0'
122
122
  requirements: []
123
123
  rubygems_version: 3.4.6
124
124
  signing_key: