zabbix_manager 5.1.5 → 6.0.0

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 (64) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +55 -9
  3. data/LICENSE +1 -1
  4. data/README.md +241 -24
  5. data/lib/zabbix_manager/classes/actions.rb +19 -17
  6. data/lib/zabbix_manager/classes/applications.rb +11 -22
  7. data/lib/zabbix_manager/classes/configurations.rb +20 -10
  8. data/lib/zabbix_manager/classes/discovery_rules.rb +23 -0
  9. data/lib/zabbix_manager/classes/errors.rb +18 -27
  10. data/lib/zabbix_manager/classes/events.rb +8 -3
  11. data/lib/zabbix_manager/classes/graphs.rb +48 -37
  12. data/lib/zabbix_manager/classes/host_groups.rb +64 -0
  13. data/lib/zabbix_manager/classes/host_interfaces.rb +261 -0
  14. data/lib/zabbix_manager/classes/hosts.rb +232 -76
  15. data/lib/zabbix_manager/classes/http_tests.rb +32 -0
  16. data/lib/zabbix_manager/classes/items.rb +206 -72
  17. data/lib/zabbix_manager/classes/maintenance.rb +8 -3
  18. data/lib/zabbix_manager/classes/media_types.rb +18 -0
  19. data/lib/zabbix_manager/classes/problems.rb +51 -62
  20. data/lib/zabbix_manager/classes/proxies.rb +45 -14
  21. data/lib/zabbix_manager/classes/proxy_groups.rb +16 -0
  22. data/lib/zabbix_manager/classes/roles.rb +46 -41
  23. data/lib/zabbix_manager/classes/screens.rb +36 -24
  24. data/lib/zabbix_manager/classes/scripts.rb +16 -12
  25. data/lib/zabbix_manager/classes/server.rb +8 -1
  26. data/lib/zabbix_manager/classes/templates.rb +26 -51
  27. data/lib/zabbix_manager/classes/triggers.rb +251 -67
  28. data/lib/zabbix_manager/classes/user_groups.rb +63 -0
  29. data/lib/zabbix_manager/classes/user_macros.rb +110 -0
  30. data/lib/zabbix_manager/classes/users.rb +16 -23
  31. data/lib/zabbix_manager/classes/value_maps.rb +52 -0
  32. data/lib/zabbix_manager/client.rb +183 -137
  33. data/lib/zabbix_manager/configuration.rb +107 -0
  34. data/lib/zabbix_manager/http_transport.rb +240 -0
  35. data/lib/zabbix_manager/log_sanitizer.rb +58 -0
  36. data/lib/zabbix_manager/monitoring/device.rb +393 -0
  37. data/lib/zabbix_manager/monitoring/expressions.rb +36 -0
  38. data/lib/zabbix_manager/monitoring/line.rb +175 -0
  39. data/lib/zabbix_manager/monitoring/line_items.rb +110 -0
  40. data/lib/zabbix_manager/monitoring/line_lifecycle.rb +169 -0
  41. data/lib/zabbix_manager/monitoring/line_plan.rb +113 -0
  42. data/lib/zabbix_manager/monitoring/thresholds.rb +182 -0
  43. data/lib/zabbix_manager/monitoring/traffic_items.rb +132 -0
  44. data/lib/zabbix_manager/monitoring/validation.rb +92 -0
  45. data/lib/zabbix_manager/monitoring.rb +265 -0
  46. data/lib/zabbix_manager/resource.rb +235 -0
  47. data/lib/zabbix_manager/traffic.rb +238 -0
  48. data/lib/zabbix_manager/version.rb +1 -1
  49. data/lib/zabbix_manager.rb +110 -145
  50. data/zabbix_manager.gemspec +12 -15
  51. metadata +67 -30
  52. data/lib/zabbix_manager/basic/basic_alias.rb +0 -20
  53. data/lib/zabbix_manager/basic/basic_func.rb +0 -84
  54. data/lib/zabbix_manager/basic/basic_init.rb +0 -35
  55. data/lib/zabbix_manager/basic/basic_logic.rb +0 -195
  56. data/lib/zabbix_manager/classes/drules.rb +0 -41
  57. data/lib/zabbix_manager/classes/hostgroups.rb +0 -20
  58. data/lib/zabbix_manager/classes/hostinterfaces.rb +0 -29
  59. data/lib/zabbix_manager/classes/httptests.rb +0 -40
  60. data/lib/zabbix_manager/classes/mediatypes.rb +0 -79
  61. data/lib/zabbix_manager/classes/unusable.rb +0 -11
  62. data/lib/zabbix_manager/classes/usergroups.rb +0 -53
  63. data/lib/zabbix_manager/classes/usermacros.rb +0 -136
  64. data/lib/zabbix_manager/classes/valuemaps.rb +0 -32
@@ -1,168 +1,133 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "active_support/core_ext/hash/indifferent_access"
4
+ require "active_support/core_ext/hash/keys"
5
+ require "active_support/core_ext/hash/deep_transform_values"
6
+ require "active_support/core_ext/enumerable"
7
+ require "active_support/core_ext/array/wrap"
8
+ require "active_support/core_ext/object/blank"
9
+ require "active_support/core_ext/object/deep_dup"
3
10
  require "zabbix_manager/version"
11
+ require "zabbix_manager/classes/errors"
12
+ require "zabbix_manager/log_sanitizer"
13
+ require "zabbix_manager/http_transport"
14
+ require "zabbix_manager/configuration"
4
15
  require "zabbix_manager/client"
5
16
 
6
- # 动态加载基础类
7
- Dir.glob(File.join(__dir__, "zabbix_manager/basic", "**", "*.rb")).sort.each do |basic_class|
8
- require basic_class
9
- end
10
-
11
- # 动态加载扩展类
12
- Dir.glob(File.join(__dir__, "zabbix_manager/classes", "**", "*.rb")).sort.each do |extend_class|
13
- require extend_class
14
- end
15
-
17
+ require "zabbix_manager/resource"
18
+
19
+ require "zabbix_manager/classes/actions"
20
+ require "zabbix_manager/classes/applications"
21
+ require "zabbix_manager/classes/configurations"
22
+ require "zabbix_manager/classes/events"
23
+ require "zabbix_manager/classes/graphs"
24
+ require "zabbix_manager/classes/host_groups"
25
+ require "zabbix_manager/classes/host_interfaces"
26
+ require "zabbix_manager/classes/hosts"
27
+ require "zabbix_manager/classes/http_tests"
28
+ require "zabbix_manager/classes/items"
29
+ require "zabbix_manager/classes/maintenance"
30
+ require "zabbix_manager/classes/media_types"
31
+ require "zabbix_manager/classes/proxies"
32
+ require "zabbix_manager/classes/proxy_groups"
33
+ require "zabbix_manager/classes/problems"
34
+ require "zabbix_manager/classes/roles"
35
+ require "zabbix_manager/classes/screens"
36
+ require "zabbix_manager/classes/scripts"
37
+ require "zabbix_manager/classes/server"
38
+ require "zabbix_manager/classes/templates"
39
+ require "zabbix_manager/classes/triggers"
40
+ require "zabbix_manager/classes/user_groups"
41
+ require "zabbix_manager/classes/user_macros"
42
+ require "zabbix_manager/classes/users"
43
+ require "zabbix_manager/classes/value_maps"
44
+ require "zabbix_manager/classes/discovery_rules"
45
+ require "zabbix_manager/monitoring"
46
+ require "zabbix_manager/traffic"
47
+
48
+ # 管理一个已认证客户端及其资源、监控和流量入口;连接生命周期由调用方负责。
49
+ # 原生 API 透传不代替应用层授权,资源对象共享同一客户端凭据。
16
50
  class ZabbixManager
51
+ # @return [ZabbixManager::Client]
17
52
  attr_reader :client
18
53
 
19
- # 初始化一个新的 ZabbixManager 对象
20
- def self.connect(options = {})
21
- new(options)
22
- end
23
-
24
- # 获取当前 ZabbixManager 对象
25
- def self.current
26
- @current ||= new
27
- end
28
-
29
- # 直接使用自定义查询执行 API 请求
30
- def query(data)
31
- @client.api_request(method: data[:method], params: data[:params])
32
- end
33
-
34
- # 注销当前身份验证令牌
54
+ # 使用显式配置创建管理器,并立即查询 API 版本、完成认证。
55
+ #
56
+ # @param options [Hash]
57
+ # @return [ZabbixManager]
58
+ # @raise [Invalid, ApiError, TransportError] 配置、认证或连接失败
59
+ def self.connect(**options)
60
+ new(**options)
61
+ end
62
+
63
+ # 仅使用文档列出的连接环境变量创建管理器。
64
+ # 显式选项覆盖环境配置,包含显式传入的 nil。
65
+ # @param env [#[]] 包含四个约定 ZABBIX_* 环境变量的映射
66
+ # @param options [Hash] 显式连接配置
67
+ # @return [ZabbixManager] 已认证管理器,其生命周期由调用方负责
68
+ def self.from_env(env: ENV, **options)
69
+ new(**Configuration.from_env(env, options))
70
+ end
71
+
72
+ # 直接执行调用方指定的 Zabbix API 方法。
73
+ #
74
+ # @param method [String]
75
+ # @param params [Hash, Array]
76
+ # @return [Object]
77
+ # @raise [ApiError] 服务端明确拒绝请求
78
+ # @raise [TransportError, ProtocolError] 未获得可确认结果;写请求不可盲目重试
79
+ def query(method:, params: {})
80
+ @client.api_request(method: method, params: params)
81
+ end
82
+
83
+ # 注销用户名会话并关闭连接。
84
+ # @return [Boolean]
35
85
  def logout
36
86
  @client.logout
37
87
  end
38
88
 
39
- # 初始化一个新的 ZabbixManager 对象
40
- def initialize(options = {})
41
- @client = Client.new(options)
42
- end
43
-
44
- # 返回 ZabbixManager::Actions 对象
45
- def actions
46
- @actions ||= Actions.new(@client)
47
- end
48
-
49
- # 返回 ZabbixManager::Applications 对象
50
- def applications
51
- @applications ||= Applications.new(@client)
52
- end
53
-
54
- # 返回 ZabbixManager::Configurations 对象
55
- def configurations
56
- @configurations ||= Configurations.new(@client)
57
- end
58
-
59
- # 返回 ZabbixManager::Events 对象
60
- def events
61
- @events ||= Events.new(@client)
62
- end
63
-
64
- # 返回 ZabbixManager::Graphs 对象
65
- def graphs
66
- @graphs ||= Graphs.new(@client)
67
- end
68
-
69
- # 返回 ZabbixManager::HostGroups 对象
70
- def hostgroups
71
- @hostgroups ||= HostGroups.new(@client)
72
- end
73
-
74
- # 返回 ZabbixManager::HostInterfaces 对象
75
- def hostinterfaces
76
- @hostinterfaces ||= HostInterfaces.new(@client)
77
- end
78
-
79
- # 返回 ZabbixManager::Hosts 对象
80
- def hosts
81
- @hosts ||= Hosts.new(@client)
89
+ # 关闭持久 HTTP 连接但不改变远端凭据。
90
+ # @return [true] 下次请求可按需重新连接
91
+ def close
92
+ @client.close
82
93
  end
83
94
 
84
- # 返回 ZabbixManager::HttpTests 对象
85
- def httptests
86
- @httptests ||= HttpTests.new(@client)
95
+ # 初始化管理器并创建唯一共享客户端。
96
+ #
97
+ # @param options [Hash]
98
+ # @raise [Invalid, ApiError, TransportError] 配置、认证或连接失败
99
+ def initialize(**options)
100
+ @client = Client.new(**options)
101
+ @resources = {}
87
102
  end
88
103
 
89
- # 返回 ZabbixManager::Items 对象
90
- def items
91
- @items ||= Items.new(@client)
92
- end
93
-
94
- # 返回 ZabbixManager::Maintenance 对象
95
- def maintenance
96
- @maintenance ||= Maintenance.new(@client)
97
- end
98
-
99
- # 返回 ZabbixManager::Mediatypes 对象
100
- def mediatypes
101
- @mediatypes ||= Mediatypes.new(@client)
102
- end
103
-
104
- # 返回 ZabbixManager::Problems 对象
105
- def problems
106
- @problems ||= Problems.new(@client)
107
- end
108
-
109
- # 返回 ZabbixManager::Proxies 对象
110
- def proxies
111
- @proxies ||= Proxies.new(@client)
112
- end
113
-
114
- # 返回 ZabbixManager::Roles 对象
115
- def roles
116
- @roles ||= Roles.new(@client)
117
- end
118
-
119
- # 返回 ZabbixManager::Screens 对象
120
- def screens
121
- @screens ||= Screens.new(@client)
122
- end
123
-
124
- # 返回 ZabbixManager::Scripts 对象
125
- def scripts
126
- @scripts ||= Scripts.new(@client)
127
- end
128
-
129
- # 返回 ZabbixManager::Server 对象
130
- def server
131
- @server ||= Server.new(@client)
132
- end
133
-
134
- # 返回 ZabbixManager::Templates 对象
135
- def templates
136
- @templates ||= Templates.new(@client)
137
- end
138
-
139
- # 返回 ZabbixManager::Triggers 对象
140
- def triggers
141
- @triggers ||= Triggers.new(@client)
142
- end
143
-
144
- # 返回 ZabbixManager::Usergroups 对象
145
- def usergroups
146
- @usergroups ||= Usergroups.new(@client)
147
- end
148
-
149
- # 返回 ZabbixManager::Usermacros 对象
150
- def usermacros
151
- @usermacros ||= Usermacros.new(@client)
152
- end
104
+ # 各资源对象共享当前管理器的已认证客户端。
105
+ RESOURCES = {
106
+ actions: Actions, applications: Applications, configurations: Configurations,
107
+ events: Events, graphs: Graphs, host_groups: HostGroups, host_interfaces: HostInterfaces,
108
+ hosts: Hosts, http_tests: HttpTests, items: Items, maintenance: Maintenance,
109
+ media_types: MediaTypes, problems: Problems, proxies: Proxies, proxy_groups: ProxyGroups, roles: Roles,
110
+ screens: Screens, scripts: Scripts, server: Server, templates: Templates,
111
+ triggers: Triggers, user_groups: UserGroups, user_macros: UserMacros, users: Users,
112
+ value_maps: ValueMaps, discovery_rules: DiscoveryRules
113
+ }.freeze
114
+ private_constant :RESOURCES
153
115
 
154
- # 返回 ZabbixManager::Users 对象
155
- def users
156
- @users ||= Users.new(@client)
116
+ # 在加载期按固定映射生成 actions、host_groups 等访问器,避免重复的资源工厂方法。
117
+ # 名称不来自外部输入;实例按管理器缓存,认证和连接由共享 Client 持有。
118
+ RESOURCES.each do |name, resource_class|
119
+ define_method(name) { @resources[name] ||= resource_class.new(@client) }
157
120
  end
158
121
 
159
- # 返回 ZabbixManager::ValueMaps 对象
160
- def valuemaps
161
- @valuemaps ||= ValueMaps.new(@client)
122
+ # 返回仅使用 Zabbix 原生 API 的设备、接口和线路监控编排入口。
123
+ # @return [ZabbixManager::Monitoring] 同一 manager 复用同一业务实例
124
+ def monitoring
125
+ @monitoring ||= Monitoring.new(self)
162
126
  end
163
127
 
164
- # 返回 ZabbixManager::Drules 对象
165
- def drules
166
- @drules ||= Drules.new(@client)
128
+ # 查询数值监控项的历史或趋势序列,不访问数据库、不补造缺失观测。
129
+ # @return [ZabbixManager::Traffic] 同一 manager 复用同一查询实例
130
+ def traffic
131
+ @traffic ||= Traffic.new(self)
167
132
  end
168
133
  end
@@ -1,34 +1,31 @@
1
- # coding: utf-8
2
1
  # frozen_string_literal: true
3
2
 
4
- lib = File.expand_path("../lib", __FILE__)
5
-
6
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
7
-
8
- require "zabbix_manager/version"
3
+ require_relative "lib/zabbix_manager/version"
9
4
 
10
5
  Gem::Specification.new do |spec|
11
- spec.add_dependency "http"
12
- spec.add_dependency "json"
13
- spec.add_dependency "activesupport"
6
+ spec.add_dependency "activesupport", ">= 7.2"
7
+ spec.add_dependency "bigdecimal"
8
+ spec.add_dependency "json", ">= 2.0"
9
+ spec.add_dependency "logger", ">= 1.4"
10
+ spec.add_dependency "net-http"
14
11
 
15
12
  spec.name = "zabbix_manager"
16
13
  spec.version = ZabbixManager::VERSION
17
14
  spec.authors = ["WENWU YAN"]
18
15
  spec.email = ["careline@foxmail.com"]
19
16
 
20
- spec.summary = "Common code for Zabbix API clients"
21
- spec.description = "A Ruby interface to the Zabbix API"
22
- spec.homepage = "https://github.com/snmpd/zabbix_manager"
17
+ spec.summary = "Ruby client and monitoring workflows for the Zabbix 4.0 through 7.x API"
18
+ spec.description = "A reusable Zabbix API client with device and network-interface monitoring workflows."
19
+ spec.homepage = "https://github.com/gatework/zabbix_manager/tree/master"
23
20
  spec.licenses = "MIT"
24
21
 
25
22
  spec.metadata["allowed_push_host"] = "https://rubygems.org"
26
23
 
27
24
  spec.metadata["homepage_uri"] = spec.homepage
28
- spec.metadata["source_code_uri"] = "https://github.com/snmpd/zabbix_manager"
29
- spec.metadata["changelog_uri"] = "https://github.com/snmpd/zabbix_manager"
25
+ spec.metadata["source_code_uri"] = "https://github.com/gatework/zabbix_manager"
26
+ spec.metadata["changelog_uri"] = "https://github.com/gatework/zabbix_manager/blob/master/CHANGELOG.md"
30
27
 
31
28
  spec.files = %w[CHANGELOG.md LICENSE README.md zabbix_manager.gemspec] + Dir["lib/**/*.rb"]
32
29
  spec.require_paths = "lib"
33
- spec.required_ruby_version = ">= 2.7.0"
30
+ spec.required_ruby_version = ">= 3.4"
34
31
  end
metadata CHANGED
@@ -1,17 +1,30 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zabbix_manager
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.1.5
4
+ version: 6.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - WENWU YAN
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2023-11-26 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
- name: http
13
+ name: activesupport
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '7.2'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '7.2'
26
+ - !ruby/object:Gem::Dependency
27
+ name: bigdecimal
15
28
  requirement: !ruby/object:Gem::Requirement
16
29
  requirements:
17
30
  - - ">="
@@ -30,16 +43,30 @@ dependencies:
30
43
  requirements:
31
44
  - - ">="
32
45
  - !ruby/object:Gem::Version
33
- version: '0'
46
+ version: '2.0'
34
47
  type: :runtime
35
48
  prerelease: false
36
49
  version_requirements: !ruby/object:Gem::Requirement
37
50
  requirements:
38
51
  - - ">="
39
52
  - !ruby/object:Gem::Version
40
- version: '0'
53
+ version: '2.0'
41
54
  - !ruby/object:Gem::Dependency
42
- name: activesupport
55
+ name: logger
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '1.4'
61
+ type: :runtime
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '1.4'
68
+ - !ruby/object:Gem::Dependency
69
+ name: net-http
43
70
  requirement: !ruby/object:Gem::Requirement
44
71
  requirements:
45
72
  - - ">="
@@ -52,7 +79,8 @@ dependencies:
52
79
  - - ">="
53
80
  - !ruby/object:Gem::Version
54
81
  version: '0'
55
- description: A Ruby interface to the Zabbix API
82
+ description: A reusable Zabbix API client with device and network-interface monitoring
83
+ workflows.
56
84
  email:
57
85
  - careline@foxmail.com
58
86
  executables: []
@@ -63,49 +91,59 @@ files:
63
91
  - LICENSE
64
92
  - README.md
65
93
  - lib/zabbix_manager.rb
66
- - lib/zabbix_manager/basic/basic_alias.rb
67
- - lib/zabbix_manager/basic/basic_func.rb
68
- - lib/zabbix_manager/basic/basic_init.rb
69
- - lib/zabbix_manager/basic/basic_logic.rb
70
94
  - lib/zabbix_manager/classes/actions.rb
71
95
  - lib/zabbix_manager/classes/applications.rb
72
96
  - lib/zabbix_manager/classes/configurations.rb
73
- - lib/zabbix_manager/classes/drules.rb
97
+ - lib/zabbix_manager/classes/discovery_rules.rb
74
98
  - lib/zabbix_manager/classes/errors.rb
75
99
  - lib/zabbix_manager/classes/events.rb
76
100
  - lib/zabbix_manager/classes/graphs.rb
77
- - lib/zabbix_manager/classes/hostgroups.rb
78
- - lib/zabbix_manager/classes/hostinterfaces.rb
101
+ - lib/zabbix_manager/classes/host_groups.rb
102
+ - lib/zabbix_manager/classes/host_interfaces.rb
79
103
  - lib/zabbix_manager/classes/hosts.rb
80
- - lib/zabbix_manager/classes/httptests.rb
104
+ - lib/zabbix_manager/classes/http_tests.rb
81
105
  - lib/zabbix_manager/classes/items.rb
82
106
  - lib/zabbix_manager/classes/maintenance.rb
83
- - lib/zabbix_manager/classes/mediatypes.rb
107
+ - lib/zabbix_manager/classes/media_types.rb
84
108
  - lib/zabbix_manager/classes/problems.rb
85
109
  - lib/zabbix_manager/classes/proxies.rb
110
+ - lib/zabbix_manager/classes/proxy_groups.rb
86
111
  - lib/zabbix_manager/classes/roles.rb
87
112
  - lib/zabbix_manager/classes/screens.rb
88
113
  - lib/zabbix_manager/classes/scripts.rb
89
114
  - lib/zabbix_manager/classes/server.rb
90
115
  - lib/zabbix_manager/classes/templates.rb
91
116
  - lib/zabbix_manager/classes/triggers.rb
92
- - lib/zabbix_manager/classes/unusable.rb
93
- - lib/zabbix_manager/classes/usergroups.rb
94
- - lib/zabbix_manager/classes/usermacros.rb
117
+ - lib/zabbix_manager/classes/user_groups.rb
118
+ - lib/zabbix_manager/classes/user_macros.rb
95
119
  - lib/zabbix_manager/classes/users.rb
96
- - lib/zabbix_manager/classes/valuemaps.rb
120
+ - lib/zabbix_manager/classes/value_maps.rb
97
121
  - lib/zabbix_manager/client.rb
122
+ - lib/zabbix_manager/configuration.rb
123
+ - lib/zabbix_manager/http_transport.rb
124
+ - lib/zabbix_manager/log_sanitizer.rb
125
+ - lib/zabbix_manager/monitoring.rb
126
+ - lib/zabbix_manager/monitoring/device.rb
127
+ - lib/zabbix_manager/monitoring/expressions.rb
128
+ - lib/zabbix_manager/monitoring/line.rb
129
+ - lib/zabbix_manager/monitoring/line_items.rb
130
+ - lib/zabbix_manager/monitoring/line_lifecycle.rb
131
+ - lib/zabbix_manager/monitoring/line_plan.rb
132
+ - lib/zabbix_manager/monitoring/thresholds.rb
133
+ - lib/zabbix_manager/monitoring/traffic_items.rb
134
+ - lib/zabbix_manager/monitoring/validation.rb
135
+ - lib/zabbix_manager/resource.rb
136
+ - lib/zabbix_manager/traffic.rb
98
137
  - lib/zabbix_manager/version.rb
99
138
  - zabbix_manager.gemspec
100
- homepage: https://github.com/snmpd/zabbix_manager
139
+ homepage: https://github.com/gatework/zabbix_manager/tree/master
101
140
  licenses:
102
141
  - MIT
103
142
  metadata:
104
143
  allowed_push_host: https://rubygems.org
105
- homepage_uri: https://github.com/snmpd/zabbix_manager
106
- source_code_uri: https://github.com/snmpd/zabbix_manager
107
- changelog_uri: https://github.com/snmpd/zabbix_manager
108
- post_install_message:
144
+ homepage_uri: https://github.com/gatework/zabbix_manager/tree/master
145
+ source_code_uri: https://github.com/gatework/zabbix_manager
146
+ changelog_uri: https://github.com/gatework/zabbix_manager/blob/master/CHANGELOG.md
109
147
  rdoc_options: []
110
148
  require_paths:
111
149
  - lib
@@ -113,15 +151,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
113
151
  requirements:
114
152
  - - ">="
115
153
  - !ruby/object:Gem::Version
116
- version: 2.7.0
154
+ version: '3.4'
117
155
  required_rubygems_version: !ruby/object:Gem::Requirement
118
156
  requirements:
119
157
  - - ">="
120
158
  - !ruby/object:Gem::Version
121
159
  version: '0'
122
160
  requirements: []
123
- rubygems_version: 3.4.10
124
- signing_key:
161
+ rubygems_version: 3.6.9
125
162
  specification_version: 4
126
- summary: Common code for Zabbix API clients
163
+ summary: Ruby client and monitoring workflows for the Zabbix 4.0 through 7.x API
127
164
  test_files: []
@@ -1,20 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class ZabbixManager
4
- class Basic
5
- # 获取 Zabbix 对象数据
6
- def get(data)
7
- get_full_data(data)
8
- end
9
-
10
- # 新增 Zabbix 对象
11
- def add(data)
12
- create(data)
13
- end
14
-
15
- # 删除 Zabbix 对象
16
- def destroy(data)
17
- delete(data)
18
- end
19
- end
20
- end
@@ -1,84 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class ZabbixManager
4
- class Basic
5
- # 在调试模式下将日志消息记录到 stdout
6
- def log(message)
7
- puts message if @client.options[:debug]
8
- end
9
-
10
- # 比较两个哈希是否相等
11
- def hash_equals?(hash1, hash2)
12
- normalized_hash1 = normalize_hash(hash1)
13
- normalized_hash2 = normalize_hash(hash2)
14
-
15
- merged_hash1 = normalized_hash1.merge(normalized_hash2)
16
- merged_hash2 = normalized_hash2.merge(normalized_hash1)
17
-
18
- merged_hash1 == merged_hash2
19
- end
20
-
21
- # 将所有哈希/数组键转换为符号
22
- # &method(:symbolize_keys) 是 Ruby 中一种将方法转换为可传递给块或其他方法的 Proc 的方式
23
- def symbolize_keys(object)
24
- case object
25
- when Array
26
- object.map(&method(:symbolize_keys))
27
- when Hash
28
- object.transform_keys(&:to_sym).transform_values(&method(:symbolize_keys))
29
- else
30
- object
31
- end
32
- end
33
-
34
- # 将所有哈希值规范化为字符串
35
- def normalize_hash(hash)
36
- result = hash.dup
37
-
38
- # 移除用于日志记录的 TODO 注释。TemplateID 和 HostID 具有不同的 ID
39
- result.delete(:hostid)
40
-
41
- result.transform_keys!(&:to_sym)
42
- result.transform_values! { |value| value.is_a?(Array) ? normalize_array(value) : value.to_s }
43
-
44
- result
45
- end
46
-
47
- # 将所有数组值规范化为字符串
48
- def normalize_array(array)
49
- result = []
50
-
51
- array.each do |e|
52
- if e.is_a?(Array)
53
- result.push(normalize_array(e))
54
- elsif e.is_a?(Hash)
55
- result.push(normalize_hash(e))
56
- else
57
- result.push(e.to_s)
58
- end
59
- end
60
-
61
- result
62
- end
63
-
64
- # 解析包含 ID 键或布尔值的数据哈希
65
- def parse_keys(data)
66
- case data
67
- when Hash
68
- data.empty? ? false : data[keys][0].to_i
69
- when TrueClass
70
- true
71
- when FalseClass
72
- false
73
- else
74
- false
75
- end
76
- end
77
-
78
- # 合并两个哈希为一个新的哈希
79
- def merge_hashes(hash1, hash2)
80
- new_hash = hash1.dup
81
- new_hash.merge(hash2)
82
- end
83
- end
84
- end
@@ -1,35 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class ZabbixManager
4
- class Basic
5
- # 使用 ZabbixManager 客户端初始化一个新的 Basic 对象
6
- def initialize(client)
7
- @client = client
8
- end
9
-
10
- # 在派生类中应该重写此方法以提供特定的方法名
11
- def method_name
12
- raise ZbxError, "子类需要自行实现 method_name"
13
- end
14
-
15
- # 在派生类中应该重写此方法以提供特定的 ID 字段名
16
- def identify
17
- raise ZbxError, "子类需要自行实现 identify"
18
- end
19
-
20
- # 派生类可以重写此方法以提供特定的默认选项
21
- def default_options
22
- {}
23
- end
24
-
25
- # 根据 method_name + id 返回对象的 ID 字段名(identify)
26
- def key
27
- "#{method_name}id"
28
- end
29
-
30
- # 根据 key 返回对象的复数 ID 字段名(identify)
31
- def keys
32
- "#{key}s"
33
- end
34
- end
35
- end