zabbix_manager 5.1.3 → 5.1.5
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/lib/zabbix_manager/basic/basic_alias.rb +3 -20
- data/lib/zabbix_manager/basic/basic_func.rb +24 -46
- data/lib/zabbix_manager/basic/basic_init.rb +8 -24
- data/lib/zabbix_manager/basic/basic_logic.rb +66 -104
- data/lib/zabbix_manager/classes/actions.rb +11 -21
- data/lib/zabbix_manager/classes/applications.rb +5 -19
- data/lib/zabbix_manager/classes/configurations.rb +5 -19
- data/lib/zabbix_manager/classes/drules.rb +6 -22
- data/lib/zabbix_manager/classes/errors.rb +19 -9
- data/lib/zabbix_manager/classes/events.rb +2 -6
- data/lib/zabbix_manager/classes/graphs.rb +18 -49
- data/lib/zabbix_manager/classes/hostgroups.rb +3 -9
- data/lib/zabbix_manager/classes/hostinterfaces.rb +7 -15
- data/lib/zabbix_manager/classes/hosts.rb +62 -77
- data/lib/zabbix_manager/classes/httptests.rb +8 -24
- data/lib/zabbix_manager/classes/items.rb +19 -78
- data/lib/zabbix_manager/classes/maintenance.rb +2 -6
- data/lib/zabbix_manager/classes/mediatypes.rb +20 -52
- data/lib/zabbix_manager/classes/problems.rb +38 -66
- data/lib/zabbix_manager/classes/proxies.rb +7 -26
- data/lib/zabbix_manager/classes/roles.rb +18 -57
- data/lib/zabbix_manager/classes/screens.rb +7 -21
- data/lib/zabbix_manager/classes/scripts.rb +7 -10
- data/lib/zabbix_manager/classes/server.rb +1 -6
- data/lib/zabbix_manager/classes/templates.rb +15 -49
- data/lib/zabbix_manager/classes/triggers.rb +15 -49
- data/lib/zabbix_manager/classes/unusable.rb +2 -1
- data/lib/zabbix_manager/classes/usergroups.rb +6 -28
- data/lib/zabbix_manager/classes/usermacros.rb +19 -113
- data/lib/zabbix_manager/classes/users.rb +7 -34
- data/lib/zabbix_manager/classes/valuemaps.rb +5 -26
- data/lib/zabbix_manager/client.rb +66 -69
- data/lib/zabbix_manager/version.rb +1 -2
- data/lib/zabbix_manager.rb +33 -46
- metadata +3 -3
@@ -2,23 +2,17 @@
|
|
2
2
|
|
3
3
|
class ZabbixManager
|
4
4
|
class Items < Basic
|
5
|
-
#
|
6
|
-
#
|
7
|
-
# @return [String]
|
5
|
+
# 用于通过 Zabbix API 与 Items 交互的方法名称
|
8
6
|
def method_name
|
9
7
|
"item"
|
10
8
|
end
|
11
9
|
|
12
|
-
#
|
13
|
-
#
|
14
|
-
# @return [String]
|
10
|
+
# 用于通过 Zabbix API 标识特定 Item 对象的 id 字段名称
|
15
11
|
def identify
|
16
12
|
"name"
|
17
13
|
end
|
18
14
|
|
19
|
-
#
|
20
|
-
#
|
21
|
-
# @return [Hash]
|
15
|
+
# 通过 Zabbix API 创建 Item 对象时使用的默认选项
|
22
16
|
def default_options
|
23
17
|
{
|
24
18
|
name: nil,
|
@@ -56,14 +50,9 @@ class ZabbixManager
|
|
56
50
|
}
|
57
51
|
end
|
58
52
|
|
59
|
-
#
|
60
|
-
#
|
61
|
-
# @param data [Hash] Needs to include name and hostid to properly identify Items via Zabbix API
|
62
|
-
# @raise [ZbxError] Error returned when there is a problem with the Zabbix API call.
|
63
|
-
# @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
|
64
|
-
# @return [Integer, TrueClass, FalseClass, NilClass] Zabbix object id
|
53
|
+
# 通过 Zabbix API 获取或创建 Item 对象
|
65
54
|
def get_or_create(data)
|
66
|
-
log "[DEBUG]
|
55
|
+
log "[DEBUG] 调用 #{method_name}.get_or_create 方法,参数: #{data.inspect}"
|
67
56
|
|
68
57
|
if (id = get_id(name: data[:name], hostid: data[:hostid]))
|
69
58
|
id
|
@@ -72,83 +61,35 @@ class ZabbixManager
|
|
72
61
|
end
|
73
62
|
end
|
74
63
|
|
75
|
-
#
|
76
|
-
#
|
77
|
-
# @param data [Hash] Needs to include name and hostid to properly identify Items via Zabbix API
|
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 [Integer, TrueClass, FalseClass, NilClass] Zabbix object id
|
64
|
+
# 通过 Zabbix API 创建或更新 Item 对象
|
81
65
|
def create_or_update(data)
|
82
66
|
itemid = get_id(name: data[:name], hostid: data[:hostid])
|
83
67
|
itemid ? update(data.merge(itemid: itemid)) : create(data)
|
84
68
|
end
|
85
69
|
|
86
|
-
#
|
87
|
-
# @note 根据设备名称和接口名字查询监控项:入参 GigabitEthernet1/0/12,出参 15809
|
88
|
-
# @example Interface Et0/0(TO_CLOUD): Bits sent, snmpoid 1.3.6.1.2.1.31.1.1.1.10.1
|
89
|
-
# @example Interface Et0/0(TO_CLOUD): Operational status, snmpoid 1.3.6.1.2.1.2.2.1.8.1
|
90
|
-
# @example Interface Et0/0(TO_CLOUD): Speed, snmpoid 1.3.6.1.2.1.31.1.1.1.15.1
|
91
|
-
# @example Interface Et0/0(TO_CLOUD): Bits received, snmpoid 1.3.6.1.2.1.31.1.1.1.6.1
|
92
|
-
# @param hostid [String, Integer] Needs to include name and hostid to properly identify Items via Zabbix API
|
93
|
-
# @param name [String] Needs to include name and hostid to properly identify Items via Zabbix API
|
94
|
-
# @raise [ZbxError] Error returned when there is a problem with the Zabbix API call.
|
95
|
-
# @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
|
96
|
-
# @return [Integer, TrueClass, FalseClass, NilClass] Zabbix object id
|
70
|
+
# 通过 Zabbix API 获取特定主机和接口下的监控项
|
97
71
|
def get_interface_items(hostid, name)
|
98
|
-
|
72
|
+
# 记录调试信息,标识方法调用以及传递的参数
|
73
|
+
log "[DEBUG] 调用 #{method_name}.get_interface_items,参数:hostid #{hostid.inspect},name #{name.inspect}"
|
99
74
|
|
100
|
-
#
|
101
|
-
_name = name&.gsub(%r{[^/0-9]}, "")
|
75
|
+
# 自动剔除收尾空白字符,规范化接口名
|
76
|
+
_name = name&.gsub(%r{[^/0-9]}, "")&.strip
|
102
77
|
iface = "#{_name}("
|
103
78
|
|
104
|
-
#
|
79
|
+
# 使用 Zabbix API 进行模糊查询,获取特定主机和接口下的监控项
|
105
80
|
result = get_raw(
|
106
81
|
{
|
107
82
|
output: "extend",
|
108
|
-
hostids: hostid,
|
109
|
-
search: {
|
110
|
-
name: iface
|
111
|
-
}
|
83
|
+
hostids: [hostid],
|
84
|
+
search: { name: iface }
|
112
85
|
}
|
113
|
-
)
|
114
|
-
|item| item["snmp_oid"].match?(/(1.3.6.1.2.1.31.1.1.1.(6|10|15)|1.3.6.1.2.1.2.2.1.8)./)
|
115
|
-
}.sort_by {
|
116
|
-
|item| item["key_"]
|
117
|
-
}
|
118
|
-
result.empty? ? nil : result
|
119
|
-
end
|
120
|
-
|
121
|
-
# The default options used when creating DNS Monitor objects via Zabbix API
|
122
|
-
# @note 缺省的 dns 参数
|
123
|
-
# @return [Hash]
|
124
|
-
def default_dns_params
|
125
|
-
{
|
126
|
-
type: 0, # 代表 zabbix_agent
|
127
|
-
value_type: 1, # 代表字符串
|
128
|
-
delay: "1m",
|
129
|
-
history: "90d",
|
130
|
-
lifetime: "30d",
|
131
|
-
timeout: "15s"
|
132
|
-
}
|
133
|
-
end
|
86
|
+
)
|
134
87
|
|
135
|
-
|
136
|
-
|
137
|
-
# @param hostid [Hash] Needs to include dns_name and hostid to properly identify Items via Zabbix API
|
138
|
-
# @param dns_name [Hash] Needs to include dns_name and hostid to properly identify Items via Zabbix API
|
139
|
-
# @raise [ZbxError] Error returned when there is a problem with the Zabbix API call.
|
140
|
-
# @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
|
141
|
-
# @return [Integer, TrueClass, FalseClass, NilClass] Zabbix object id
|
142
|
-
def create_dns_item(hostid, dns_name)
|
143
|
-
name = "【DNS域名解析监控】#{dns_name}"
|
144
|
-
key = "net.dns.record[,#{dns_name},A,2,2]"
|
88
|
+
# 过滤结果,只保留符合正则表达式的项
|
89
|
+
filtered_result = result.select { |item| item["snmp_oid"].match?(/(1.3.6.1.2.1.31.1.1.1.(6|10|15)|1.3.6.1.2.1.2.2.1.8)./) }
|
145
90
|
|
146
|
-
|
147
|
-
|
148
|
-
method: "item.create",
|
149
|
-
params: params
|
150
|
-
)
|
151
|
-
result.empty? ? nil : result
|
91
|
+
# 如果结果为空,则返回 nil;否则,返回排序后的结果
|
92
|
+
filtered_result.empty? ? nil : filtered_result.sort_by { |item| item["key_"] }
|
152
93
|
end
|
153
94
|
end
|
154
95
|
end
|
@@ -2,16 +2,12 @@
|
|
2
2
|
|
3
3
|
class ZabbixManager
|
4
4
|
class Maintenance < Basic
|
5
|
-
#
|
6
|
-
#
|
7
|
-
# @return [String]
|
5
|
+
# 用于通过 Zabbix API 与维护窗口对象交互的方法名称
|
8
6
|
def method_name
|
9
7
|
"maintenance"
|
10
8
|
end
|
11
9
|
|
12
|
-
#
|
13
|
-
#
|
14
|
-
# @return [String]
|
10
|
+
# 用于通过 Zabbix API 识别特定维护窗口对象的 id 字段名称
|
15
11
|
def identify
|
16
12
|
"name"
|
17
13
|
end
|
@@ -2,64 +2,45 @@
|
|
2
2
|
|
3
3
|
class ZabbixManager
|
4
4
|
class Mediatypes < Basic
|
5
|
-
#
|
6
|
-
#
|
7
|
-
# @return [String]
|
5
|
+
# 与 Zabbix API 交互的媒体类型方法名称
|
8
6
|
def method_name
|
9
7
|
"mediatype"
|
10
8
|
end
|
11
9
|
|
12
|
-
#
|
13
|
-
#
|
14
|
-
# @return [String]
|
10
|
+
# 识别特定媒体类型对象的 id 字段名称
|
15
11
|
def identify
|
16
12
|
"name"
|
17
13
|
end
|
18
14
|
|
19
|
-
#
|
20
|
-
#
|
21
|
-
# @return [Hash]
|
15
|
+
# 默认选项,用于通过 Zabbix API 创建媒体类型对象
|
22
16
|
def default_options
|
23
17
|
{
|
24
|
-
name: "", #
|
25
|
-
description: "", #
|
26
|
-
type: 0, # 0 -
|
18
|
+
name: "", # 媒体类型名称
|
19
|
+
description: "", # 描述
|
20
|
+
type: 0, # 0 - 电子邮件,1 - 外部脚本,2 - 短信,3 - Jabber,100 - EzTexting
|
27
21
|
smtp_server: "",
|
28
22
|
smtp_helo: "",
|
29
|
-
smtp_email: "", #
|
30
|
-
exec_path: "", #
|
31
|
-
gsm_modem: "", #
|
32
|
-
username: "", #
|
33
|
-
passwd: "" #
|
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
|
-
#
|
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]
|
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]
|
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]
|
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
|
-
#
|
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]
|
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}
|
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
|
-
#
|
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]
|
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
|
-
#
|
9
|
-
#
|
10
|
-
# @return [String]
|
8
|
+
# 与 Zabbix API 交互的问题方法名称
|
11
9
|
def method_name
|
12
10
|
"problem"
|
13
11
|
end
|
14
12
|
|
15
|
-
#
|
16
|
-
#
|
17
|
-
# @return [String]
|
13
|
+
# 识别特定问题对象的 id 字段名称
|
18
14
|
def identify
|
19
15
|
"name"
|
20
16
|
end
|
21
17
|
|
22
|
-
#
|
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]
|
20
|
+
log "[DEBUG] 调用 #{method_name}.dump_by_id 方法,参数: #{data.inspect}"
|
30
21
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
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
|
-
#
|
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]
|
32
|
+
log "[DEBUG] 调用 #{method_name}.get_full_data 方法,参数: #{data.inspect}"
|
50
33
|
|
51
34
|
data = symbolize_keys(data)
|
52
35
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
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
|
-
#
|
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
|
-
#
|
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: "
|
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
|
-
#
|
6
|
-
#
|
7
|
-
# @return [String]
|
5
|
+
# 与 Zabbix API 交互的代理方法名称
|
8
6
|
def method_name
|
9
7
|
"proxy"
|
10
8
|
end
|
11
9
|
|
12
|
-
#
|
13
|
-
#
|
14
|
-
# @return [String]
|
10
|
+
# 识别特定代理对象的 id 字段名称
|
15
11
|
def identify
|
16
12
|
"host"
|
17
13
|
end
|
18
14
|
|
19
|
-
#
|
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
|
-
#
|
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
|
-
#
|
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
|
-
#
|
6
|
-
#
|
7
|
-
# @return [String]
|
5
|
+
# 与 Zabbix API 交互的角色方法名称
|
8
6
|
def method_name
|
9
7
|
"role"
|
10
8
|
end
|
11
9
|
|
12
|
-
#
|
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
|
-
#
|
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
|
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:
|
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
|
-
#
|
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
|
-
#
|
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]
|
35
|
+
log "[DEBUG] 调用 dump_by_id 方法,参数: #{data.inspect}"
|
63
36
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
output: "extend",
|
37
|
+
get_raw(
|
38
|
+
{
|
39
|
+
output: "extend",
|
68
40
|
selectRules: "extend",
|
69
|
-
roleids:
|
41
|
+
roleids: data[:id]
|
70
42
|
}
|
71
43
|
)
|
72
44
|
end
|
73
45
|
|
74
|
-
#
|
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 =
|
82
|
-
|
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
|
-
#
|
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:
|
67
|
+
userids: data[:userids]
|
107
68
|
}
|
108
69
|
end
|
109
|
-
result
|
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
|
-
#
|
25
|
-
#
|
26
|
-
# @return [String]
|
24
|
+
# 与 Zabbix API 交互的屏幕方法名称
|
27
25
|
def method_name
|
28
26
|
"screen"
|
29
27
|
end
|
30
28
|
|
31
|
-
#
|
32
|
-
#
|
33
|
-
# @return [String]
|
29
|
+
# 用于通过 Zabbix API 标识特定屏幕对象的 ID 字段名称
|
34
30
|
def identify
|
35
31
|
"name"
|
36
32
|
end
|
37
33
|
|
38
|
-
#
|
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
|
-
#
|
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
|
65
|
-
width = data[:width] || 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
|
-
#
|
56
|
+
# 创建屏幕
|
71
57
|
graphids.each_with_index do |graphid, index|
|
72
58
|
screenitems << {
|
73
59
|
resourcetype: 0,
|