zabbix_manager 5.0.4 → 5.0.7
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/CHANGELOG.md +2 -4
- data/LICENSE.txt +1 -1
- data/README.md +76 -21
- data/lib/zabbix_manager/basic/basic_alias.rb +2 -0
- data/lib/zabbix_manager/basic/basic_extend.rb +11 -9
- data/lib/zabbix_manager/basic/basic_func.rb +9 -5
- data/lib/zabbix_manager/basic/basic_init.rb +6 -4
- data/lib/zabbix_manager/basic/basic_logic.rb +7 -5
- data/lib/zabbix_manager/classes/actions.rb +6 -4
- data/lib/zabbix_manager/classes/applications.rb +4 -2
- data/lib/zabbix_manager/classes/configurations.rb +6 -4
- data/lib/zabbix_manager/classes/drules.rb +5 -3
- data/lib/zabbix_manager/classes/errors.rb +10 -9
- data/lib/zabbix_manager/classes/events.rb +4 -3
- data/lib/zabbix_manager/classes/graphs.rb +13 -11
- data/lib/zabbix_manager/classes/hostgroups.rb +13 -11
- data/lib/zabbix_manager/classes/hosts.rb +36 -34
- data/lib/zabbix_manager/classes/httptests.rb +4 -2
- data/lib/zabbix_manager/classes/items.rb +52 -50
- data/lib/zabbix_manager/classes/maintenance.rb +4 -2
- data/lib/zabbix_manager/classes/mediatypes.rb +15 -13
- data/lib/zabbix_manager/classes/problems.rb +31 -30
- data/lib/zabbix_manager/classes/proxies.rb +9 -7
- data/lib/zabbix_manager/classes/roles.rb +19 -17
- data/lib/zabbix_manager/classes/screens.rb +6 -4
- data/lib/zabbix_manager/classes/scripts.rb +6 -4
- data/lib/zabbix_manager/classes/server.rb +3 -1
- data/lib/zabbix_manager/classes/templates.rb +18 -16
- data/lib/zabbix_manager/classes/triggers.rb +41 -37
- data/lib/zabbix_manager/classes/unusable.rb +2 -0
- data/lib/zabbix_manager/classes/usergroups.rb +11 -9
- data/lib/zabbix_manager/classes/usermacros.rb +38 -37
- data/lib/zabbix_manager/classes/users.rb +11 -9
- data/lib/zabbix_manager/classes/valuemaps.rb +5 -3
- data/lib/zabbix_manager/client.rb +40 -30
- data/lib/zabbix_manager/version.rb +3 -1
- data/lib/zabbix_manager.rb +36 -35
- data/zabbix_manager.gemspec +43 -0
- metadata +143 -19
- data/.idea/workspace.xml +0 -69
- data/.rubocop.yml +0 -13
- data/CODE_OF_CONDUCT.md +0 -84
- data/Gemfile +0 -10
- data/Rakefile +0 -8
- data/bin/console +0 -15
- data/bin/setup +0 -8
- data/zabbix_manager-5.0.1.gem +0 -0
- data/zabbix_manager-5.0.2.gem +0 -0
@@ -1,24 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class ZabbixManager
|
2
4
|
class Roles < Basic
|
3
5
|
# The method name used for interacting with Role via Zabbix API
|
4
6
|
#
|
5
7
|
# @return [String]
|
6
8
|
def method_name
|
7
|
-
|
9
|
+
"role"
|
8
10
|
end
|
9
11
|
|
10
12
|
# The key field name used for Role objects via Zabbix API
|
11
13
|
#
|
12
14
|
# @return [String]
|
13
15
|
def key
|
14
|
-
|
16
|
+
"roleid"
|
15
17
|
end
|
16
18
|
|
17
19
|
# The id field name used for identifying specific Role objects via Zabbix API
|
18
20
|
#
|
19
21
|
# @return [String]
|
20
22
|
def identify
|
21
|
-
|
23
|
+
"name"
|
22
24
|
end
|
23
25
|
|
24
26
|
# Set permissions for usergroup using Zabbix API
|
@@ -30,13 +32,13 @@ class ZabbixManager
|
|
30
32
|
def rules(data)
|
31
33
|
rules = data[:rules] || 2
|
32
34
|
result = @client.api_request(
|
33
|
-
method:
|
35
|
+
method: "role.update",
|
34
36
|
params: {
|
35
37
|
roleid: data[:roleid],
|
36
38
|
rules: data[:hostgroupids].map { |t| { permission: permission, id: t } }
|
37
39
|
}
|
38
40
|
)
|
39
|
-
result ? result[
|
41
|
+
result ? result["usrgrpids"][0].to_i : nil
|
40
42
|
end
|
41
43
|
|
42
44
|
# Add users to usergroup using Zabbix API
|
@@ -60,10 +62,10 @@ class ZabbixManager
|
|
60
62
|
log "[DEBUG] Call dump_by_id with parameters: #{data.inspect}"
|
61
63
|
|
62
64
|
@client.api_request(
|
63
|
-
method:
|
65
|
+
method: "role.get",
|
64
66
|
params: {
|
65
|
-
output:
|
66
|
-
selectRules:
|
67
|
+
output: "extend",
|
68
|
+
selectRules: "extend",
|
67
69
|
roleids: data[:id]
|
68
70
|
}
|
69
71
|
)
|
@@ -77,18 +79,18 @@ class ZabbixManager
|
|
77
79
|
# @return [Array] Returns array of Graph ids
|
78
80
|
def get_ids_by_name(data)
|
79
81
|
result = @client.api_request(
|
80
|
-
method:
|
82
|
+
method: "role.get",
|
81
83
|
params: {
|
82
84
|
filter: {
|
83
85
|
name: data[:name]
|
84
86
|
},
|
85
|
-
output:
|
87
|
+
output: "extend"
|
86
88
|
}
|
87
89
|
)
|
88
90
|
|
89
|
-
result.
|
90
|
-
rule[
|
91
|
-
end
|
91
|
+
result.filter_map do |rule|
|
92
|
+
rule["roleid"]
|
93
|
+
end
|
92
94
|
end
|
93
95
|
|
94
96
|
# Update users in Userroles using Zabbix API
|
@@ -101,14 +103,14 @@ class ZabbixManager
|
|
101
103
|
user_groups = data[:usrgrpids].map do |t|
|
102
104
|
{
|
103
105
|
usrgrpid: t,
|
104
|
-
userids: data[:userids]
|
106
|
+
userids: data[:userids]
|
105
107
|
}
|
106
108
|
end
|
107
109
|
result = @client.api_request(
|
108
|
-
method:
|
109
|
-
params: user_groups
|
110
|
+
method: "usergroup.update",
|
111
|
+
params: user_groups
|
110
112
|
)
|
111
|
-
result ? result[
|
113
|
+
result ? result["usrgrpids"][0].to_i : nil
|
112
114
|
end
|
113
115
|
end
|
114
116
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class ZabbixManager
|
2
4
|
class Screens < Basic
|
3
5
|
# extracted from frontends/php/include/defines.inc.php
|
@@ -23,14 +25,14 @@ class ZabbixManager
|
|
23
25
|
#
|
24
26
|
# @return [String]
|
25
27
|
def method_name
|
26
|
-
|
28
|
+
"screen"
|
27
29
|
end
|
28
30
|
|
29
31
|
# The id field name used for identifying specific Screen objects via Zabbix API
|
30
32
|
#
|
31
33
|
# @return [String]
|
32
34
|
def identify
|
33
|
-
|
35
|
+
"name"
|
34
36
|
end
|
35
37
|
|
36
38
|
# Delete Screen object using Zabbix API
|
@@ -40,8 +42,8 @@ class ZabbixManager
|
|
40
42
|
# @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
|
41
43
|
# @return [Integer] Zabbix object id
|
42
44
|
def delete(data)
|
43
|
-
result = @client.api_request(method:
|
44
|
-
result.empty? ? nil : result[
|
45
|
+
result = @client.api_request(method: "screen.delete", params: [data])
|
46
|
+
result.empty? ? nil : result["screenids"][0].to_i
|
45
47
|
end
|
46
48
|
|
47
49
|
# Get or Create Screen object for Host using Zabbix API
|
@@ -1,14 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class ZabbixManager
|
2
4
|
class Scripts < Basic
|
3
5
|
def method_name
|
4
|
-
|
6
|
+
"script"
|
5
7
|
end
|
6
8
|
|
7
9
|
# The id field name used for identifying specific Screen objects via Zabbix API
|
8
10
|
#
|
9
11
|
# @return [String]
|
10
12
|
def identify
|
11
|
-
|
13
|
+
"name"
|
12
14
|
end
|
13
15
|
|
14
16
|
# Submits a request to the zabbix api
|
@@ -20,7 +22,7 @@ class ZabbixManager
|
|
20
22
|
# Returns nothing
|
21
23
|
def execute(data)
|
22
24
|
@client.api_request(
|
23
|
-
method:
|
25
|
+
method: "script.execute",
|
24
26
|
params: {
|
25
27
|
scriptid: data[:scriptid],
|
26
28
|
hostid: data[:hostid]
|
@@ -29,7 +31,7 @@ class ZabbixManager
|
|
29
31
|
end
|
30
32
|
|
31
33
|
def getscriptsbyhost(data)
|
32
|
-
@client.api_request(method:
|
34
|
+
@client.api_request(method: "script.getscriptsbyhosts", params: data)
|
33
35
|
end
|
34
36
|
end
|
35
37
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class ZabbixManager
|
2
4
|
class Server
|
3
5
|
# @return [String]
|
@@ -10,7 +12,7 @@ class ZabbixManager
|
|
10
12
|
# @return [String] Zabbix API version number
|
11
13
|
def initialize(client)
|
12
14
|
@client = client
|
13
|
-
@version = @client.api_version
|
15
|
+
@version = @client.api_version
|
14
16
|
end
|
15
17
|
end
|
16
18
|
end
|
@@ -1,17 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class ZabbixManager
|
2
4
|
class Templates < Basic
|
3
5
|
# The method name used for interacting with Templates via Zabbix API
|
4
6
|
#
|
5
7
|
# @return [String]
|
6
8
|
def method_name
|
7
|
-
|
9
|
+
"template"
|
8
10
|
end
|
9
11
|
|
10
12
|
# The id field name used for identifying specific Template objects via Zabbix API
|
11
13
|
#
|
12
14
|
# @return [String]
|
13
15
|
def identify
|
14
|
-
|
16
|
+
"host"
|
15
17
|
end
|
16
18
|
|
17
19
|
# Delete Template object using Zabbix API
|
@@ -21,8 +23,8 @@ class ZabbixManager
|
|
21
23
|
# @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
|
22
24
|
# @return [Integer] The Template object id that was deleted
|
23
25
|
def delete(data)
|
24
|
-
result = @client.api_request(method:
|
25
|
-
result.empty? ? nil : result[
|
26
|
+
result = @client.api_request(method: "template.delete", params: [data])
|
27
|
+
result.empty? ? nil : result["templateids"][0].to_i
|
26
28
|
end
|
27
29
|
|
28
30
|
# Get Template ids for Host from Zabbix API
|
@@ -32,8 +34,8 @@ class ZabbixManager
|
|
32
34
|
# @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
|
33
35
|
# @return [Array] Returns array of Template ids
|
34
36
|
def get_ids_by_host(data)
|
35
|
-
@client.api_request(method:
|
36
|
-
tmpl[
|
37
|
+
@client.api_request(method: "template.get", params: data).map do |tmpl|
|
38
|
+
tmpl["templateid"]
|
37
39
|
end
|
38
40
|
end
|
39
41
|
|
@@ -58,9 +60,9 @@ class ZabbixManager
|
|
58
60
|
# @return [Boolean]
|
59
61
|
def mass_update(data)
|
60
62
|
result = @client.api_request(
|
61
|
-
method:
|
63
|
+
method: "template.massUpdate",
|
62
64
|
params: {
|
63
|
-
hosts:
|
65
|
+
hosts: data[:hosts_id].map { |t| { hostid: t } },
|
64
66
|
templates: data[:templates_id].map { |t| { templateid: t } }
|
65
67
|
}
|
66
68
|
)
|
@@ -75,9 +77,9 @@ class ZabbixManager
|
|
75
77
|
# @return [Boolean]
|
76
78
|
def mass_add(data)
|
77
79
|
result = @client.api_request(
|
78
|
-
method:
|
80
|
+
method: "template.massAdd",
|
79
81
|
params: {
|
80
|
-
hosts:
|
82
|
+
hosts: data[:hosts_id].map { |t| { hostid: t } },
|
81
83
|
templates: data[:templates_id].map { |t| { templateid: t } }
|
82
84
|
}
|
83
85
|
)
|
@@ -92,12 +94,12 @@ class ZabbixManager
|
|
92
94
|
# @return [Boolean]
|
93
95
|
def mass_remove(data)
|
94
96
|
result = @client.api_request(
|
95
|
-
method:
|
97
|
+
method: "template.massRemove",
|
96
98
|
params: {
|
97
|
-
hostids:
|
99
|
+
hostids: data[:hosts_id],
|
98
100
|
templateids: data[:templates_id],
|
99
|
-
groupids:
|
100
|
-
force:
|
101
|
+
groupids: data[:group_id],
|
102
|
+
force: 1
|
101
103
|
}
|
102
104
|
)
|
103
105
|
result.empty? ? false : true
|
@@ -107,14 +109,14 @@ class ZabbixManager
|
|
107
109
|
def get_template_ids(data)
|
108
110
|
# 直接调后端接口
|
109
111
|
result = @client.api_request(
|
110
|
-
method:
|
112
|
+
method: "template.get",
|
111
113
|
params: {
|
112
114
|
output: "extend",
|
113
115
|
filter: {
|
114
116
|
host: [data].flatten
|
115
117
|
}
|
116
118
|
}
|
117
|
-
).map { |temp| [templateid: temp[
|
119
|
+
).map { |temp| [templateid: temp["templateid"]] }
|
118
120
|
|
119
121
|
# 返回 template 模板数组对象
|
120
122
|
result.empty? ? nil : result.flatten
|
@@ -1,17 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class ZabbixManager
|
2
4
|
class Triggers < Basic
|
3
5
|
# The method name used for interacting with Triggers via Zabbix API
|
4
6
|
#
|
5
7
|
# @return [String]
|
6
8
|
def method_name
|
7
|
-
|
9
|
+
"trigger"
|
8
10
|
end
|
9
11
|
|
10
12
|
# The id field name used for identifying specific Trigger objects via Zabbix API
|
11
13
|
#
|
12
14
|
# @return [String]
|
13
15
|
def identify
|
14
|
-
|
16
|
+
"description"
|
15
17
|
end
|
16
18
|
|
17
19
|
# Dump Trigger object data by key from Zabbix API
|
@@ -24,14 +26,14 @@ class ZabbixManager
|
|
24
26
|
log "[DEBUG] Call dump_by_id with parameters: #{data.inspect}"
|
25
27
|
|
26
28
|
@client.api_request(
|
27
|
-
method:
|
29
|
+
method: "trigger.get",
|
28
30
|
params: {
|
29
|
-
filter:
|
31
|
+
filter: {
|
30
32
|
keys.to_sym => data[keys.to_sym]
|
31
33
|
},
|
32
|
-
output:
|
33
|
-
select_items:
|
34
|
-
select_functions:
|
34
|
+
output: "extend",
|
35
|
+
select_items: "extend",
|
36
|
+
select_functions: "extend"
|
35
37
|
}
|
36
38
|
)
|
37
39
|
end
|
@@ -51,13 +53,13 @@ class ZabbixManager
|
|
51
53
|
dump = symbolize_keys(item) if item[key].to_i == data[key.to_sym].to_i
|
52
54
|
end
|
53
55
|
|
54
|
-
expression = dump[:items][0][:key_]
|
56
|
+
expression = "#{dump[:items][0][:key_]}.#{dump[:functions][0][:function]}(#{dump[:functions][0][:parameter]})"
|
55
57
|
dump[:expression] = dump[:expression].gsub(/\{(\d*)\}/, "{#{expression}}") # TODO: ugly regexp
|
56
58
|
dump.delete(:functions)
|
57
59
|
dump.delete(:items)
|
58
60
|
|
59
61
|
old_expression = data[:expression]
|
60
|
-
data[:expression] = data[:expression].gsub(/\{
|
62
|
+
data[:expression] = data[:expression].gsub(/\{.*:/, "{") # TODO: ugly regexp
|
61
63
|
data.delete(:templateid)
|
62
64
|
|
63
65
|
log "[DEBUG] expression: #{dump[:expression]}\n data: #{data[:expression]}"
|
@@ -68,7 +70,10 @@ class ZabbixManager
|
|
68
70
|
else
|
69
71
|
data[:expression] = old_expression
|
70
72
|
# disable old trigger
|
71
|
-
log
|
73
|
+
log "[DEBUG] disable :" + @client.api_request(method: "#{method_name}.update",
|
74
|
+
params: [{
|
75
|
+
triggerid: data[:triggerid], status: "1"
|
76
|
+
}]).inspect
|
72
77
|
# create new trigger
|
73
78
|
data.delete(:triggerid)
|
74
79
|
create(data)
|
@@ -105,16 +110,15 @@ class ZabbixManager
|
|
105
110
|
# 测试数据
|
106
111
|
def mojo_data
|
107
112
|
data = {
|
108
|
-
comments:
|
109
|
-
opdata:
|
110
|
-
priority:
|
111
|
-
description:
|
112
|
-
expression:
|
113
|
-
recovery_expression: "{SZX1-ISP-SW7:net.if.in[ifHCInOctets.1].avg(15m)}<=350000000 or {SZX1-ISP-SW7:net.if.out[ifHCOutOctets.1].avg(15m)}<=350000000"
|
113
|
+
comments: "MOJO1",
|
114
|
+
opdata: "MOJO_OPDATA",
|
115
|
+
priority: 1,
|
116
|
+
description: "MOJO1",
|
117
|
+
expression: "{SZX1-ISP-SW7:net.if.in[ifHCInOctets.1].avg(15m)}>=450000000 or {SZX1-ISP-SW7:net.if.out[ifHCOutOctets.1].avg(15m)}>=450000000",
|
118
|
+
recovery_expression: "{SZX1-ISP-SW7:net.if.in[ifHCInOctets.1].avg(15m)}<=350000000 or {SZX1-ISP-SW7:net.if.out[ifHCOutOctets.1].avg(15m)}<=350000000"
|
114
119
|
}
|
115
120
|
|
116
121
|
create_trigger data.stringify_keys!
|
117
|
-
|
118
122
|
end
|
119
123
|
|
120
124
|
# 设置触发器
|
@@ -122,17 +126,17 @@ class ZabbixManager
|
|
122
126
|
data = data.with_indifferent_access
|
123
127
|
# 请求生成触发器
|
124
128
|
result = @client.api_request(
|
125
|
-
method:
|
129
|
+
method: "trigger.create",
|
126
130
|
params: {
|
127
|
-
comments:
|
128
|
-
priority:
|
129
|
-
description:
|
130
|
-
expression:
|
131
|
+
comments: data["comments"],
|
132
|
+
priority: data["priority"],
|
133
|
+
description: data["description"],
|
134
|
+
expression: data["expression"],
|
131
135
|
recovery_expression: data["recovery_expression"],
|
132
|
-
opdata:
|
133
|
-
recovery_mode:
|
134
|
-
type:
|
135
|
-
manual_close:
|
136
|
+
opdata: data["opdata"],
|
137
|
+
recovery_mode: 1,
|
138
|
+
type: 0,
|
139
|
+
manual_close: 1
|
136
140
|
}
|
137
141
|
)
|
138
142
|
# 检查是是否存在
|
@@ -144,21 +148,21 @@ class ZabbixManager
|
|
144
148
|
data = data.with_indifferent_access
|
145
149
|
# 请求生成触发器
|
146
150
|
result = @client.api_request(
|
147
|
-
method:
|
151
|
+
method: "trigger.update",
|
148
152
|
params: {
|
149
|
-
triggerid:
|
150
|
-
comments:
|
151
|
-
priority:
|
152
|
-
description:
|
153
|
-
expression:
|
153
|
+
triggerid: triggerid,
|
154
|
+
comments: data["comments"],
|
155
|
+
priority: data["priority"],
|
156
|
+
description: data["description"],
|
157
|
+
expression: data["expression"],
|
154
158
|
recovery_expression: data["recovery_expression"],
|
155
|
-
opdata:
|
156
|
-
recovery_mode:
|
157
|
-
type:
|
158
|
-
manual_close:
|
159
|
+
opdata: data["opdata"],
|
160
|
+
recovery_mode: 1,
|
161
|
+
type: 1,
|
162
|
+
manual_close: 1
|
159
163
|
}
|
160
164
|
)
|
161
|
-
ap result
|
165
|
+
# ap result
|
162
166
|
# 检查是是否存在
|
163
167
|
result.empty? ? nil : result["triggerids"]
|
164
168
|
end
|
@@ -1,24 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class ZabbixManager
|
2
4
|
class Usergroups < Basic
|
3
5
|
# The method name used for interacting with Usergroups via Zabbix API
|
4
6
|
#
|
5
7
|
# @return [String]
|
6
8
|
def method_name
|
7
|
-
|
9
|
+
"usergroup"
|
8
10
|
end
|
9
11
|
|
10
12
|
# The key field name used for Usergroup objects via Zabbix API
|
11
13
|
#
|
12
14
|
# @return [String]
|
13
15
|
def key
|
14
|
-
|
16
|
+
"usrgrpid"
|
15
17
|
end
|
16
18
|
|
17
19
|
# The id field name used for identifying specific Usergroup objects via Zabbix API
|
18
20
|
#
|
19
21
|
# @return [String]
|
20
22
|
def identify
|
21
|
-
|
23
|
+
"name"
|
22
24
|
end
|
23
25
|
|
24
26
|
# Set permissions for usergroup using Zabbix API
|
@@ -30,13 +32,13 @@ class ZabbixManager
|
|
30
32
|
def permissions(data)
|
31
33
|
permission = data[:permission] || 2
|
32
34
|
result = @client.api_request(
|
33
|
-
method:
|
35
|
+
method: "usergroup.update",
|
34
36
|
params: {
|
35
37
|
usrgrpid: data[:usrgrpid],
|
36
38
|
rights: data[:hostgroupids].map { |t| { permission: permission, id: t } }
|
37
39
|
}
|
38
40
|
)
|
39
|
-
result ? result[
|
41
|
+
result ? result["usrgrpids"][0].to_i : nil
|
40
42
|
end
|
41
43
|
|
42
44
|
# Add users to usergroup using Zabbix API
|
@@ -60,14 +62,14 @@ class ZabbixManager
|
|
60
62
|
user_groups = data[:usrgrpids].map do |t|
|
61
63
|
{
|
62
64
|
usrgrpid: t,
|
63
|
-
userids: data[:userids]
|
65
|
+
userids: data[:userids]
|
64
66
|
}
|
65
67
|
end
|
66
68
|
result = @client.api_request(
|
67
|
-
method:
|
68
|
-
params: user_groups
|
69
|
+
method: "usergroup.update",
|
70
|
+
params: user_groups
|
69
71
|
)
|
70
|
-
result ? result[
|
72
|
+
result ? result["usrgrpids"][0].to_i : nil
|
71
73
|
end
|
72
74
|
end
|
73
75
|
end
|