zabbix_manager 5.1.2.pre.alpha2 → 5.1.4

Sign up to get free protection for your applications and to get access to all the features.
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 +67 -105
  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 +12 -9
  15. data/lib/zabbix_manager/classes/hosts.rb +57 -55
  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 +16 -52
  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 +41 -84
  36. metadata +5 -5
@@ -2,64 +2,45 @@
2
2
 
3
3
  class ZabbixManager
4
4
  class Mediatypes < Basic
5
- # The method name used for interacting with MediaTypes via Zabbix API
6
- #
7
- # @return [String]
5
+ # Zabbix API 交互的媒体类型方法名称
8
6
  def method_name
9
7
  "mediatype"
10
8
  end
11
9
 
12
- # The id field name used for identifying specific MediaType objects via Zabbix API
13
- #
14
- # @return [String]
10
+ # 识别特定媒体类型对象的 id 字段名称
15
11
  def identify
16
12
  "name"
17
13
  end
18
14
 
19
- # The default options used when creating MediaType objects via Zabbix API
20
- #
21
- # @return [Hash]
15
+ # 默认选项,用于通过 Zabbix API 创建媒体类型对象
22
16
  def default_options
23
17
  {
24
- name: "", # Name
25
- description: "", # Description
26
- type: 0, # 0 - Email, 1 - External script, 2 - SMS, 3 - Jabber, 100 - EzTexting
18
+ name: "", # 媒体类型名称
19
+ description: "", # 描述
20
+ type: 0, # 0 - 电子邮件,1 - 外部脚本,2 - 短信,3 - Jabber100 - EzTexting
27
21
  smtp_server: "",
28
22
  smtp_helo: "",
29
- smtp_email: "", # Email address of Zabbix server
30
- exec_path: "", # Name of external script
31
- gsm_modem: "", # Serial device name of GSM modem
32
- username: "", # Jabber user name used by Zabbix server
33
- passwd: "" # Jabber password used by Zabbix server
23
+ smtp_email: "", # Zabbix 服务器的电子邮件地址
24
+ exec_path: "", # 外部脚本的名称
25
+ gsm_modem: "", # GSM modem 的串口设备名称
26
+ username: "", # Zabbix 服务器使用的 Jabber 用户名
27
+ passwd: "" # Zabbix 服务器使用的 Jabber 密码
34
28
  }
35
29
  end
36
30
 
37
- # def log(message)
38
- # STDERR.puts
39
- # STDERR.puts message.to_s
40
- # STDERR.puts
41
- # end
42
-
43
- # Update MediaType object using API
44
- #
45
- # @param data [Hash] Should include object's id field name (identify) and id value
46
- # @param force [Boolean] Whether to force an object update even if provided data matches Zabbix
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 created
50
- # @return [Boolean] True/False if multiple objects are created
31
+ # 使用 API 更新媒体类型对象
51
32
  def update(data, force = false)
52
- log "[DEBUG] Call update with parameters: #{data.inspect}"
33
+ log "[DEBUG] 调用 update 方法,参数: #{data.inspect}"
53
34
  if data[key.to_sym].nil?
54
35
  data[key.to_sym] = get_id(data)
55
- log "[DEBUG] Enriched data with id: #{data.inspect}"
36
+ log "[DEBUG] ID 丰富数据: #{data.inspect}"
56
37
  end
57
38
  dump = {}
58
39
  dump_by_id(key.to_sym => data[key.to_sym]).each do |item|
59
40
  dump = symbolize_keys(item) if item[key].to_i == data[key.to_sym].to_i
60
41
  end
61
42
  if hash_equals?(dump, data) && !force
62
- log "[DEBUG] Equal keys #{dump} and #{data}, skip update"
43
+ log "[DEBUG] #{dump} #{data} 相等,跳过更新"
63
44
  data[key.to_sym].to_i
64
45
  else
65
46
  data_update = [data]
@@ -68,19 +49,12 @@ class ZabbixManager
68
49
  end
69
50
  end
70
51
 
71
- # Get MediaType object id from API based on provided data
72
- #
73
- # @param data [Hash]
74
- # @raise [ZbxError] Error returned when there is a problem with the Zabbix API call or missing object's id field name (identify).
75
- # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
76
- # @return [Integer, NilClass] Zabbix object id
52
+ # API 获取媒体类型对象的 id
77
53
  def get_id(data)
78
- log "[DEBUG] Call get_id with parameters: #{data.inspect}"
79
- # symbolize keys if the user used string keys instead of symbols
54
+ log "[DEBUG] 调用 get_id 方法,参数: #{data.inspect}"
80
55
  data = symbolize_keys(data) if data.key?(identify)
81
- # raise an error if identify name was not supplied
82
56
  name = data[identify.to_sym]
83
- raise ZbxError, "#{identify} not supplied in call to get_id, #{data} (#{method_name})" if name.nil?
57
+ raise ZbxError, "未提供 #{identify} 参数,#{data} (#{method_name})" if name.nil?
84
58
 
85
59
  result = @client.api_request(
86
60
  method: "#{method_name}.get",
@@ -94,15 +68,9 @@ class ZabbixManager
94
68
  id
95
69
  end
96
70
 
97
- # Create or update MediaType object using API
98
- #
99
- # @param data [Hash] Should include object's id field name (identify) and id value
100
- # @raise [ZbxError] Error returned when there is a problem with the Zabbix API call.
101
- # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
102
- # @return [Integer] The object id if a single object is created
103
- # @return [Boolean] True/False if multiple objects are created
71
+ # 创建或更新媒体类型对象
104
72
  def create_or_update(data)
105
- log "[DEBUG] Call create_or_update with parameters: #{data.inspect}"
73
+ log "[DEBUG] 调用 create_or_update 方法,参数: #{data.inspect}"
106
74
 
107
75
  id = get_id(identify.to_sym => data[identify.to_sym])
108
76
  id ? update(data.merge(key.to_sym => id.to_s)) : create(data)
@@ -5,93 +5,65 @@ class ZabbixManager
5
5
  require "active_support"
6
6
  require "active_support/core_ext/date/calculations"
7
7
 
8
- # The method name used for interacting with Hosts via Zabbix API
9
- #
10
- # @return [String]
8
+ # Zabbix API 交互的问题方法名称
11
9
  def method_name
12
10
  "problem"
13
11
  end
14
12
 
15
- # The id field name used for identifying specific Problem objects via Zabbix API
16
- #
17
- # @return [String]
13
+ # 识别特定问题对象的 id 字段名称
18
14
  def identify
19
15
  "name"
20
16
  end
21
17
 
22
- # Dump Problem object data by key from Zabbix API
23
- #
24
- # @param data [Hash] Should include desired object's key and value
25
- # @raise [ZbxError] Error returned when there is a problem with the Zabbix API call.
26
- # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
27
- # @return [Hash]
18
+ # 通过键值对从 Zabbix API 转储问题对象数据
28
19
  def dump_by_id(data)
29
- log "[DEBUG] Call #{method_name}.dump_by_id with parameters: #{data.inspect}"
20
+ log "[DEBUG] 调用 #{method_name}.dump_by_id 方法,参数: #{data.inspect}"
30
21
 
31
- @client.api_request(
32
- method: "#{method_name}.get",
33
- params: {
34
- filter: {
35
- identify.to_sym => data[identify.to_sym]
36
- },
37
- output: "extend"
38
- }
39
- )
22
+ get_raw({
23
+ filter: {
24
+ identify.to_sym => data[identify.to_sym]
25
+ },
26
+ output: "extend"
27
+ })
40
28
  end
41
29
 
42
- # Get full/extended Problem data from Zabbix API
43
- #
44
- # @param data [Hash] Should include object's id field name (identify) and id value
45
- # @raise [ZbxError] Error returned when there is a problem with the Zabbix API call.
46
- # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
47
- # @return [Hash]
30
+ # Zabbix API 获取完整/扩展的问题数据
48
31
  def get_full_data(data)
49
- log "[DEBUG] Call #{method_name}.get_full_data with parameters: #{data.inspect}"
32
+ log "[DEBUG] 调用 #{method_name}.get_full_data 方法,参数: #{data.inspect}"
50
33
 
51
34
  data = symbolize_keys(data)
52
35
 
53
- @client.api_request(
54
- method: "#{method_name}.get",
55
- params: {
56
- filter: {
57
- identify.to_sym => data[identify.to_sym]
58
- },
59
- eventids: data[:eventids] || nil,
60
- groupids: data[:groupids] || nil,
61
- hostids: data[:hostids] || nil,
62
- objectids: data[:objectids] || nil,
63
- applicationids: data[:applicationids] || nil,
64
- tags: data[:tags] || nil,
65
- time_from: data[:time_from] || nil,
66
- time_till: data[:time_till] || nil,
67
- eventid_from: data[:eventid_from] || nil,
68
- eventid_till: data[:eventid_till] || nil,
69
- recent: data[:recent] || false,
70
- sortfield: data[:sortfield] || ["eventid"],
71
- sortorder: data[:sortorder] || "DESC",
72
- countOutput: data[:countOutput] || nil,
73
- output: "extend",
74
- selectAcknowledges: "extend",
75
- selectTags: "extend",
76
- selectSuppressionData: "extend"
77
- }
78
- )
36
+ get_raw({
37
+ filter: {
38
+ identify.to_sym => data[identify.to_sym]
39
+ },
40
+ eventids: data[:eventids] || nil,
41
+ groupids: data[:groupids] || nil,
42
+ hostids: data[:hostids] || nil,
43
+ objectids: data[:objectids] || nil,
44
+ applicationids: data[:applicationids] || nil,
45
+ tags: data[:tags] || nil,
46
+ time_from: data[:time_from] || nil,
47
+ time_till: data[:time_till] || nil,
48
+ eventid_from: data[:eventid_from] || nil,
49
+ eventid_till: data[:eventid_till] || nil,
50
+ recent: data[:recent] || false,
51
+ sortfield: data[:sortfield] || ["eventid"],
52
+ sortorder: data[:sortorder] || "DESC",
53
+ countOutput: data[:countOutput] || nil,
54
+ output: "extend",
55
+ selectAcknowledges: "extend",
56
+ selectTags: "extend",
57
+ selectSuppressionData: "extend"
58
+ })
79
59
  end
80
60
 
81
- # Get full/extended Zabbix data for Problem objects from API
82
- #
83
- # @raise [ZbxError] Error returned when there is a problem with the Zabbix API call.
84
- # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
85
- # @return [Hash] Array of matching objects
61
+ # 获取所有问题对象的完整/扩展 Zabbix 数据
86
62
  def all
87
63
  get_full_data({})
88
64
  end
89
65
 
90
- # Acknowledged problems according to the given parameters.
91
- # @note 自动确认14天前的问题单
92
- # @raise [ZbxError] Error returned when there is a problem with the Zabbix API call.
93
- # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
94
- # @return [Array, NilClass] Array of matching objects
66
+ # 根据给定参数自动确认问题
95
67
  def ack_problem
96
68
  time_from = 90.days.ago.at_beginning_of_day.to_i
97
69
  time_till = 7.days.ago.at_beginning_of_day.to_i
@@ -107,7 +79,7 @@ class ZabbixManager
107
79
  params: {
108
80
  eventids: event_ids,
109
81
  action: 2,
110
- message: "本次告警通过 zabbix_api 关闭"
82
+ message: "本次告警符合自动刷新规则,已通过接口处理且刷新时间为:#{Time.now}"
111
83
  }
112
84
  )
113
85
  result.empty? ? nil : result.map { |i| { eventids: i["eventids"] } }
@@ -2,48 +2,29 @@
2
2
 
3
3
  class ZabbixManager
4
4
  class Proxies < Basic
5
- # The method name used for interacting with Proxies via Zabbix API
6
- #
7
- # @return [String]
5
+ # Zabbix API 交互的代理方法名称
8
6
  def method_name
9
7
  "proxy"
10
8
  end
11
9
 
12
- # The id field name used for identifying specific Proxy objects via Zabbix API
13
- #
14
- # @return [String]
10
+ # 识别特定代理对象的 id 字段名称
15
11
  def identify
16
12
  "host"
17
13
  end
18
14
 
19
- # Delete Proxy object using Zabbix API
20
- #
21
- # @param data [Array] Should include array of proxyid's
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, NilClass] The Proxy object id that was deleted
15
+ # 使用 Zabbix API 删除代理对象
25
16
  def delete(data)
26
17
  result = @client.api_request(method: "proxy.delete", params: data)
27
18
  result.empty? ? nil : result["proxyids"][0].to_i
28
19
  end
29
20
 
30
- # Check if a Proxy object is readable using Zabbix API
31
- #
32
- # @param data [Array] Should include array of proxyid's
33
- # @raise [ZbxError] Error returned when there is a problem with the Zabbix API call.
34
- # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
35
- # @return [Boolean] Returns true if the given proxies are readable
36
- def isreadable(data)
21
+ # 检查代理对象是否可读
22
+ def is_readable(data)
37
23
  @client.api_request(method: "proxy.isreadable", params: data)
38
24
  end
39
25
 
40
- # Check if a Proxy object is writable using Zabbix API
41
- #
42
- # @param data [Array] Should include array of proxyid's
43
- # @raise [ZbxError] Error returned when there is a problem with the Zabbix API call.
44
- # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
45
- # @return [Boolean] Returns true if the given proxies are writable
46
- def iswritable(data)
26
+ # 检查代理对象是否可写
27
+ def is_writable(data)
47
28
  @client.api_request(method: "proxy.iswritable", params: data)
48
29
  end
49
30
  end
@@ -2,85 +2,51 @@
2
2
 
3
3
  class ZabbixManager
4
4
  class Roles < Basic
5
- # The method name used for interacting with Role via Zabbix API
6
- #
7
- # @return [String]
5
+ # Zabbix API 交互的角色方法名称
8
6
  def method_name
9
7
  "role"
10
8
  end
11
9
 
12
- # The key field name used for Role objects via Zabbix API
13
- #
14
- # @return [String]
15
- def key
16
- "roleid"
17
- end
18
-
19
- # The id field name used for identifying specific Role objects via Zabbix API
20
- #
21
- # @return [String]
10
+ # 识别特定角色对象的 id 字段名称
22
11
  def identify
23
12
  "name"
24
13
  end
25
14
 
26
- # Set permissions for usergroup using Zabbix API
27
- #
28
- # @param data [Hash] Needs to include usrgrpids and hostgroupids along with permissions to set
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, NilClass] Zabbix object id (usergroup)
15
+ # 使用 Zabbix API 为用户组设置权限
32
16
  def rules(data)
33
- rules = data[:rules] || 2
17
+ rules = data[:rules] || 2
34
18
  result = @client.api_request(
35
19
  method: "role.update",
36
20
  params: {
37
21
  roleid: data[:roleid],
38
- rules: data[:hostgroupids].map { |t| { permission: permission, id: t } }
22
+ rules: data[:hostgroupids].map { |t| { permission: permission, id: t } }
39
23
  }
40
24
  )
41
25
  result ? result["usrgrpids"][0].to_i : nil
42
26
  end
43
27
 
44
- # Add users to usergroup using Zabbix API
45
- #
46
- # @deprecated Zabbix has removed massAdd in favor of update.
47
- # @param data [Hash] Needs to include userids and usrgrpids to mass add users to groups
48
- # @raise [ZbxError] Error returned when there is a problem with the Zabbix API call.
49
- # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
50
- # @return [Integer] Zabbix object id (usergroup)
28
+ # 使用 Zabbix API 将用户添加到用户组
51
29
  def add_user(data)
52
30
  update_users(data)
53
31
  end
54
32
 
55
- # Dump Role object data by key from Zabbix API
56
- #
57
- # @param data [Hash] Should include desired object's key and value
58
- # @raise [ZbxError] Error returned when there is a problem with the Zabbix API call.
59
- # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
60
- # @return [Hash]
33
+ # Zabbix API 中根据指定键和值获取角色对象的数据
61
34
  def dump_by_id(data)
62
- log "[DEBUG] Call dump_by_id with parameters: #{data.inspect}"
35
+ log "[DEBUG] 调用 dump_by_id 方法,参数: #{data.inspect}"
63
36
 
64
- @client.api_request(
65
- method: "role.get",
66
- params: {
67
- output: "extend",
37
+ get_raw(
38
+ {
39
+ output: "extend",
68
40
  selectRules: "extend",
69
- roleids: data[:id]
41
+ roleids: data[:id]
70
42
  }
71
43
  )
72
44
  end
73
45
 
74
- # Get Role ids by Role Name from Zabbix API
75
- #
76
- # @param data [Hash] Should include host value to query for matching graphs
77
- # @raise [ZbxError] Error returned when there is a problem with the Zabbix API call.
78
- # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
79
- # @return [Array] Returns array of Graph ids
46
+ # 通过角色名称从 Zabbix API 获取角色 id
80
47
  def get_ids_by_name(data)
81
- result = @client.api_request(
82
- method: "role.get",
83
- params: {
48
+ result = get_raw(
49
+ {
84
50
  filter: {
85
51
  name: data[:name]
86
52
  },
@@ -93,20 +59,15 @@ class ZabbixManager
93
59
  end
94
60
  end
95
61
 
96
- # Update users in Userroles using Zabbix API
97
- #
98
- # @param data [Hash] Needs to include userids and usrgrpids to mass update users in groups
99
- # @raise [ZbxError] Error returned when there is a problem with the Zabbix API call.
100
- # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
101
- # @return [Integer, NilClass] Zabbix object id (usergroup)
62
+ # 使用 Zabbix API 更新用户角色中的用户
102
63
  def update_users(data)
103
64
  user_groups = data[:usrgrpids].map do |t|
104
65
  {
105
66
  usrgrpid: t,
106
- userids: data[:userids]
67
+ userids: data[:userids]
107
68
  }
108
69
  end
109
- result = @client.api_request(
70
+ result = @client.api_request(
110
71
  method: "usergroup.update",
111
72
  params: user_groups
112
73
  )
@@ -21,37 +21,23 @@ class ZabbixManager
21
21
  # SCREEN_RESOURCE_SYSTEM_STATUS => 15,
22
22
  # SCREEN_RESOURCE_HOST_TRIGGERS => 16
23
23
 
24
- # The method name used for interacting with Screens via Zabbix API
25
- #
26
- # @return [String]
24
+ # Zabbix API 交互的屏幕方法名称
27
25
  def method_name
28
26
  "screen"
29
27
  end
30
28
 
31
- # The id field name used for identifying specific Screen objects via Zabbix API
32
- #
33
- # @return [String]
29
+ # 用于通过 Zabbix API 标识特定屏幕对象的 ID 字段名称
34
30
  def identify
35
31
  "name"
36
32
  end
37
33
 
38
- # Delete Screen object using Zabbix API
39
- #
40
- # @param data [String, Array] Should include id's of the screens to delete
41
- # @raise [ZbxError] Error returned when there is a problem with the Zabbix API call.
42
- # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
43
- # @return [Integer, NilClass] Zabbix object id
34
+ # 删除 Zabbix API 中的屏幕对象
44
35
  def delete(data)
45
36
  result = @client.api_request(method: "screen.delete", params: [data])
46
37
  result.empty? ? nil : result["screenids"][0].to_i
47
38
  end
48
39
 
49
- # Get or Create Screen object for Host using Zabbix API
50
- #
51
- # @param data [Hash] Needs to include screen_name and graphids to properly identify Screens via Zabbix API
52
- # @raise [ZbxError] Error returned when there is a problem with the Zabbix API call.
53
- # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
54
- # @return [Integer] Zabbix object id
40
+ # 使用 Zabbix API 为主机获取或创建屏幕对象
55
41
  def get_or_create_for_host(data)
56
42
  screen_name = data[:screen_name]
57
43
  graphids = data[:graphids]
@@ -61,13 +47,13 @@ class ZabbixManager
61
47
  halign = data[:halign] || 2
62
48
  rowspan = data[:rowspan] || 1
63
49
  colspan = data[:colspan] || 1
64
- height = data[:height] || 320 # default 320
65
- width = data[:width] || 200 # default 200
50
+ height = data[:height] || 320
51
+ width = data[:width] || 200
66
52
  vsize = data[:vsize] || [1, (graphids.size / hsize).to_i].max
67
53
  screenid = get_id(name: screen_name)
68
54
 
69
55
  unless screenid
70
- # Create screen
56
+ # 创建屏幕
71
57
  graphids.each_with_index do |graphid, index|
72
58
  screenitems << {
73
59
  resourcetype: 0,
@@ -2,24 +2,20 @@
2
2
 
3
3
  class ZabbixManager
4
4
  class Scripts < Basic
5
+ # 与 Zabbix API 交互的方法名称
5
6
  def method_name
6
7
  "script"
7
8
  end
8
9
 
9
- # The id field name used for identifying specific Screen objects via Zabbix API
10
- #
11
- # @return [String]
10
+ # 用于通过 Zabbix API 标识特定脚本对象的 ID 字段名称
12
11
  def identify
13
12
  "name"
14
13
  end
15
14
 
16
- # Submits a request to the zabbix api
17
- # data - A Hash containing the scriptid and hostid
18
- #
19
- # Example:
20
- # execute({ scriptid: '12', hostid: '32 })
15
+ # 执行 Zabbix API 中特定主机上的脚本
21
16
  #
22
- # Returns nothing
17
+ # 示例:
18
+ # execute({ scriptid: '12', hostid: '32' })
23
19
  def execute(data)
24
20
  @client.api_request(
25
21
  method: "script.execute",
@@ -30,7 +26,8 @@ class ZabbixManager
30
26
  )
31
27
  end
32
28
 
33
- def getscriptsbyhost(data)
29
+ # 使用 Zabbix API 通过主机获取脚本
30
+ def get_scripts_by_host(data)
34
31
  @client.api_request(method: "script.getscriptsbyhosts", params: data)
35
32
  end
36
33
  end
@@ -2,14 +2,9 @@
2
2
 
3
3
  class ZabbixManager
4
4
  class Server
5
- # @return [String]
6
5
  attr_reader :version
7
6
 
8
- # Initializes a new Server object with ZabbixManager Client and fetches Zabbix Server API version
9
- #
10
- # @param client [ZabbixManager::Client]
11
- # @return [ZabbixManager::Client]
12
- # @return [String] Zabbix API version number
7
+ # 初始化一个新的 Server 对象,使用 ZabbixManager 客户端,并获取 Zabbix 服务器 API 版本
13
8
  def initialize(client)
14
9
  @client = client
15
10
  @version = @client.api_version
@@ -2,63 +2,39 @@
2
2
 
3
3
  class ZabbixManager
4
4
  class Templates < Basic
5
- # The method name used for interacting with Templates via Zabbix API
6
- #
7
- # @return [String]
5
+ # Zabbix API 中与模板交互的方法名称
8
6
  def method_name
9
7
  "template"
10
8
  end
11
9
 
12
- # The id field name used for identifying specific Template objects via Zabbix API
13
- #
14
- # @return [String]
10
+ # 用于通过 Zabbix API 标识特定模板对象的 id 字段名称
15
11
  def identify
16
12
  "host"
17
13
  end
18
14
 
19
- # Delete Template object using Zabbix API
20
- #
21
- # @param data [Array] Should include array of templateid's
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, NilClass] The Template object id that was deleted
15
+ # 通过 Zabbix API 删除模板对象
25
16
  def delete(data)
26
17
  result = @client.api_request(method: "template.delete", params: [data])
27
18
  result.empty? ? nil : result["templateids"][0].to_i
28
19
  end
29
20
 
30
- # Get Template ids for Host from Zabbix API
31
- #
32
- # @param data [Hash] Should include host value to query for matching templates
33
- # @raise [ZbxError] Error returned when there is a problem with the Zabbix API call.
34
- # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
35
- # @return [Array] Returns array of Template ids
21
+ # Zabbix API 获取主机的模板 id
36
22
  def get_ids_by_host(data)
37
23
  @client.api_request(method: "template.get", params: data).map do |tmpl|
38
24
  tmpl["templateid"]
39
25
  end
40
26
  end
41
27
 
42
- # Get or Create Template object using Zabbix API
43
- #
44
- # @param data [Hash] Needs to include host to properly identify Templates via Zabbix API
45
- # @raise [ZbxError] Error returned when there is a problem with the Zabbix API call.
46
- # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
47
- # @return [Integer, TrueClass, FalseClass] Zabbix object id
48
- def get_or_create(data)
49
- if (templateid = get_id(host: data[:host]))
50
- templateid
51
- else
52
- create(data)
53
- end
54
- end
28
+ # 通过 Zabbix API 获取或创建模板对象
29
+ # def get_or_create(data)
30
+ # if (templateid = get_id(host: data[:host]))
31
+ # templateid
32
+ # else
33
+ # create(data)
34
+ # end
35
+ # end
55
36
 
56
- # Mass update Templates for Hosts using Zabbix API
57
- #
58
- # @param data [Hash] Should include hosts_id array and templates_id array
59
- # @raise [ZbxError] Error returned when there is a problem with the Zabbix API call.
60
- # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
61
- # @return [Boolean]
37
+ # 通过 Zabbix API 批量更新主机的模板
62
38
  def mass_update(data)
63
39
  result = @client.api_request(
64
40
  method: "template.massUpdate",
@@ -70,12 +46,7 @@ class ZabbixManager
70
46
  result.empty? ? false : true
71
47
  end
72
48
 
73
- # Mass add Templates to Hosts using Zabbix API
74
- #
75
- # @param data [Hash] Should include hosts_id array and templates_id array
76
- # @raise [ZbxError] Error returned when there is a problem with the Zabbix API call.
77
- # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
78
- # @return [Boolean]
49
+ # 通过 Zabbix API 批量添加模板到主机
79
50
  def mass_add(data)
80
51
  result = @client.api_request(
81
52
  method: "template.massAdd",
@@ -87,12 +58,7 @@ class ZabbixManager
87
58
  result.empty? ? false : true
88
59
  end
89
60
 
90
- # Mass remove Templates to Hosts using Zabbix API
91
- #
92
- # @param data [Hash] Should include hosts_id array and templates_id array
93
- # @raise [ZbxError] Error returned when there is a problem with the Zabbix API call.
94
- # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
95
- # @return [Boolean]
61
+ # 通过 Zabbix API 批量从主机移除模板
96
62
  def mass_remove(data)
97
63
  result = @client.api_request(
98
64
  method: "template.massRemove",