zabbix_manager 5.0.3 → 5.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/.idea/vcs.xml +6 -0
  3. data/.idea/workspace.xml +15 -4
  4. data/.rubocop.yml +1 -1
  5. data/README.md +2 -4
  6. data/lib/zabbix_manager/basic/basic_alias.rb +2 -0
  7. data/lib/zabbix_manager/basic/basic_extend.rb +11 -9
  8. data/lib/zabbix_manager/basic/basic_func.rb +9 -5
  9. data/lib/zabbix_manager/basic/basic_init.rb +6 -4
  10. data/lib/zabbix_manager/basic/basic_logic.rb +7 -5
  11. data/lib/zabbix_manager/classes/actions.rb +6 -4
  12. data/lib/zabbix_manager/classes/applications.rb +4 -2
  13. data/lib/zabbix_manager/classes/configurations.rb +6 -4
  14. data/lib/zabbix_manager/classes/drules.rb +5 -3
  15. data/lib/zabbix_manager/classes/errors.rb +5 -3
  16. data/lib/zabbix_manager/classes/events.rb +4 -3
  17. data/lib/zabbix_manager/classes/graphs.rb +11 -9
  18. data/lib/zabbix_manager/classes/hostgroups.rb +13 -11
  19. data/lib/zabbix_manager/classes/hosts.rb +36 -34
  20. data/lib/zabbix_manager/classes/httptests.rb +4 -2
  21. data/lib/zabbix_manager/classes/items.rb +52 -49
  22. data/lib/zabbix_manager/classes/maintenance.rb +4 -2
  23. data/lib/zabbix_manager/classes/mediatypes.rb +15 -13
  24. data/lib/zabbix_manager/classes/problems.rb +31 -30
  25. data/lib/zabbix_manager/classes/proxies.rb +9 -7
  26. data/lib/zabbix_manager/classes/roles.rb +17 -15
  27. data/lib/zabbix_manager/classes/screens.rb +6 -4
  28. data/lib/zabbix_manager/classes/scripts.rb +6 -4
  29. data/lib/zabbix_manager/classes/server.rb +3 -1
  30. data/lib/zabbix_manager/classes/templates.rb +18 -16
  31. data/lib/zabbix_manager/classes/triggers.rb +41 -37
  32. data/lib/zabbix_manager/classes/unusable.rb +2 -0
  33. data/lib/zabbix_manager/classes/usergroups.rb +11 -9
  34. data/lib/zabbix_manager/classes/usermacros.rb +21 -19
  35. data/lib/zabbix_manager/classes/users.rb +11 -9
  36. data/lib/zabbix_manager/classes/valuemaps.rb +5 -3
  37. data/lib/zabbix_manager/client.rb +38 -28
  38. data/lib/zabbix_manager/version.rb +3 -1
  39. data/lib/zabbix_manager.rb +36 -35
  40. data/zabbix_manager-5.0.3.gem +0 -0
  41. data/zabbix_manager-5.0.4.gem +0 -0
  42. data/zabbix_manager-5.0.5.gem +0 -0
  43. metadata +9 -4
@@ -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
- 'role'
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
- 'roleid'
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
- 'name'
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: 'role.update',
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['usrgrpids'][0].to_i : nil
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: 'role.get',
65
+ method: "role.get",
64
66
  params: {
65
- output: 'extend',
66
- selectRules: 'extend',
67
+ output: "extend",
68
+ selectRules: "extend",
67
69
  roleids: data[:id]
68
70
  }
69
71
  )
@@ -77,17 +79,17 @@ 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: 'role.get',
82
+ method: "role.get",
81
83
  params: {
82
84
  filter: {
83
85
  name: data[:name]
84
86
  },
85
- output: 'extend'
87
+ output: "extend"
86
88
  }
87
89
  )
88
90
 
89
91
  result.map do |rule|
90
- rule['roleid']
92
+ rule["roleid"]
91
93
  end.compact
92
94
  end
93
95
 
@@ -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: 'usergroup.update',
109
- params: user_groups,
110
+ method: "usergroup.update",
111
+ params: user_groups
110
112
  )
111
- result ? result['usrgrpids'][0].to_i : nil
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
- 'screen'
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
- 'name'
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: 'screen.delete', params: [data])
44
- result.empty? ? nil : result['screenids'][0].to_i
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
- 'script'
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
- 'name'
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: 'script.execute',
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: 'script.getscriptsbyhosts', params: data)
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
- 'template'
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
- 'host'
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: 'template.delete', params: [data])
25
- result.empty? ? nil : result['templateids'][0].to_i
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: 'template.get', params: data).map do |tmpl|
36
- tmpl['templateid']
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: 'template.massUpdate',
63
+ method: "template.massUpdate",
62
64
  params: {
63
- hosts: data[:hosts_id].map { |t| { hostid: t } },
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: 'template.massAdd',
80
+ method: "template.massAdd",
79
81
  params: {
80
- hosts: data[:hosts_id].map { |t| { hostid: t } },
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: 'template.massRemove',
97
+ method: "template.massRemove",
96
98
  params: {
97
- hostids: data[:hosts_id],
99
+ hostids: data[:hosts_id],
98
100
  templateids: data[:templates_id],
99
- groupids: data[:group_id],
100
- force: 1
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: 'template.get',
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['templateid']]}
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
- 'trigger'
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
- 'description'
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: 'trigger.get',
29
+ method: "trigger.get",
28
30
  params: {
29
- filter: {
31
+ filter: {
30
32
  keys.to_sym => data[keys.to_sym]
31
33
  },
32
- output: 'extend',
33
- select_items: 'extend',
34
- select_functions: 'extend'
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_] + '.' + dump[:functions][0][:function] + '(' + dump[:functions][0][:parameter] + ')'
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(/\{.*\:/, '{') # TODO: ugly regexp
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 '[DEBUG] disable :' + @client.api_request(method: "#{method_name}.update", params: [{ triggerid: data[:triggerid], status: '1' }]).inspect
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: "MOJO1",
109
- opdata: "MOJO_OPDATA",
110
- priority: 1,
111
- description: "MOJO1",
112
- expression: "{SZX1-ISP-SW7:net.if.in[ifHCInOctets.1].avg(15m)}>=450000000 or {SZX1-ISP-SW7:net.if.out[ifHCOutOctets.1].avg(15m)}>=450000000",
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: 'trigger.create',
129
+ method: "trigger.create",
126
130
  params: {
127
- comments: data["comments"],
128
- priority: data["priority"],
129
- description: data["description"],
130
- expression: data["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: data["opdata"],
133
- recovery_mode: 1,
134
- type: 0,
135
- manual_close: 1,
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: 'trigger.update',
151
+ method: "trigger.update",
148
152
  params: {
149
- triggerid: triggerid.to_i,
150
- comments: data["comments"],
151
- priority: data["priority"],
152
- description: data["description"],
153
- expression: data["expression"],
153
+ triggerid: triggerid.to_i,
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: data["opdata"],
156
- recovery_mode: 1,
157
- type: 1,
158
- manual_close: 1,
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,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class ZabbixManager
2
4
  class Triggers < Basic
3
5
  def create_or_update(data)
@@ -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
- 'usergroup'
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
- 'usrgrpid'
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
- 'name'
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: 'usergroup.update',
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['usrgrpids'][0].to_i : nil
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: 'usergroup.update',
68
- params: user_groups,
69
+ method: "usergroup.update",
70
+ params: user_groups
69
71
  )
70
- result ? result['usrgrpids'][0].to_i : nil
72
+ result ? result["usrgrpids"][0].to_i : nil
71
73
  end
72
74
  end
73
75
  end
@@ -1,17 +1,19 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class ZabbixManager
2
4
  class Usermacros < Basic
3
5
  # The id field name used for identifying specific User macro objects via Zabbix API
4
6
  #
5
7
  # @return [String]
6
8
  def identify
7
- 'macro'
9
+ "macro"
8
10
  end
9
11
 
10
12
  # The method name used for interacting with User macros via Zabbix API
11
13
  #
12
14
  # @return [String]
13
15
  def method_name
14
- 'usermacro'
16
+ "usermacro"
15
17
  end
16
18
 
17
19
  # Get User macro object id from Zabbix API based on provided data
@@ -27,11 +29,11 @@ class ZabbixManager
27
29
  data = symbolize_keys(data) if data.key?(identify)
28
30
  # raise an error if identify name was not supplied
29
31
  name = data[identify.to_sym]
30
- raise ManagerError.new("#{identify} not supplied in call to get_id") if name.nil?
32
+ raise ManagerError, "#{identify} not supplied in call to get_id" if name.nil?
31
33
 
32
- result = request(data, 'usermacro.get', 'hostmacroid')
34
+ result = request(data, "usermacro.get", "hostmacroid")
33
35
 
34
- !result.empty? && result[0].key?('hostmacroid') ? result[0]['hostmacroid'].to_i : nil
36
+ !result.empty? && result[0].key?("hostmacroid") ? result[0]["hostmacroid"].to_i : nil
35
37
  end
36
38
 
37
39
  # Get Global macro object id from Zabbix API based on provided data
@@ -47,11 +49,11 @@ class ZabbixManager
47
49
  data = symbolize_keys(data) if data.key?(identify)
48
50
  # raise an error if identify name was not supplied
49
51
  name = data[identify.to_sym]
50
- raise ManagerError.new("#{identify} not supplied in call to get_id_global") if name.nil?
52
+ raise ManagerError, "#{identify} not supplied in call to get_id_global" if name.nil?
51
53
 
52
- result = request(data, 'usermacro.get', 'globalmacroid')
54
+ result = request(data, "usermacro.get", "globalmacroid")
53
55
 
54
- !result.empty? && result[0].key?('globalmacroid') ? result[0]['globalmacroid'].to_i : nil
56
+ !result.empty? && result[0].key?("globalmacroid") ? result[0]["globalmacroid"].to_i : nil
55
57
  end
56
58
 
57
59
  # Get full/extended User macro data from Zabbix API
@@ -63,7 +65,7 @@ class ZabbixManager
63
65
  def get_full_data(data)
64
66
  log "[DEBUG] Call get_full_data with parameters: #{data.inspect}"
65
67
 
66
- request(data, 'usermacro.get', 'hostmacroid')
68
+ request(data, "usermacro.get", "hostmacroid")
67
69
  end
68
70
 
69
71
  # Get full/extended Global macro data from Zabbix API
@@ -75,7 +77,7 @@ class ZabbixManager
75
77
  def get_full_data_global(data)
76
78
  log "[DEBUG] Call get_full_data_global with parameters: #{data.inspect}"
77
79
 
78
- request(data, 'usermacro.get', 'globalmacroid')
80
+ request(data, "usermacro.get", "globalmacroid")
79
81
  end
80
82
 
81
83
  # Create new User macro object using Zabbix API (with defaults)
@@ -86,7 +88,7 @@ class ZabbixManager
86
88
  # @return [Integer] The object id if a single object is created
87
89
  # @return [Boolean] True/False if multiple objects are created
88
90
  def create(data)
89
- request(data, 'usermacro.create', 'hostmacroids')
91
+ request(data, "usermacro.create", "hostmacroids")
90
92
  end
91
93
 
92
94
  # Create new Global macro object using Zabbix API (with defaults)
@@ -97,7 +99,7 @@ class ZabbixManager
97
99
  # @return [Integer] The object id if a single object is created
98
100
  # @return [Boolean] True/False if multiple objects are created
99
101
  def create_global(data)
100
- request(data, 'usermacro.createglobal', 'globalmacroids')
102
+ request(data, "usermacro.createglobal", "globalmacroids")
101
103
  end
102
104
 
103
105
  # Delete User macro object using Zabbix API
@@ -109,7 +111,7 @@ class ZabbixManager
109
111
  # @return [Boolean] True/False if multiple objects are deleted
110
112
  def delete(data)
111
113
  data_delete = [data]
112
- request(data_delete, 'usermacro.delete', 'hostmacroids')
114
+ request(data_delete, "usermacro.delete", "hostmacroids")
113
115
  end
114
116
 
115
117
  # Delete Global macro object using Zabbix API
@@ -121,7 +123,7 @@ class ZabbixManager
121
123
  # @return [Boolean] True/False if multiple objects are deleted
122
124
  def delete_global(data)
123
125
  data_delete = [data]
124
- request(data_delete, 'usermacro.deleteglobal', 'globalmacroids')
126
+ request(data_delete, "usermacro.deleteglobal", "globalmacroids")
125
127
  end
126
128
 
127
129
  # Update User macro object using Zabbix API
@@ -133,7 +135,7 @@ class ZabbixManager
133
135
  # @return [Integer] The object id if a single object is created
134
136
  # @return [Boolean] True/False if multiple objects are created
135
137
  def update(data)
136
- request(data, 'usermacro.update', 'hostmacroids')
138
+ request(data, "usermacro.update", "hostmacroids")
137
139
  end
138
140
 
139
141
  # Update Global macro object using Zabbix API
@@ -145,7 +147,7 @@ class ZabbixManager
145
147
  # @return [Integer] The object id if a single object is created
146
148
  # @return [Boolean] True/False if multiple objects are created
147
149
  def update_global(data)
148
- request(data, 'usermacro.updateglobal', 'globalmacroids')
150
+ request(data, "usermacro.updateglobal", "globalmacroids")
149
151
  end
150
152
 
151
153
  # Get or Create User macro object using Zabbix API
@@ -200,7 +202,7 @@ class ZabbixManager
200
202
  globalmacroid ? update_global(data.merge(globalmacroid: globalmacroid)) : create_global(data)
201
203
  end
202
204
 
203
- private
205
+ private
204
206
 
205
207
  # Custom request method to handle both User and Global macros in one
206
208
  #
@@ -212,8 +214,8 @@ class ZabbixManager
212
214
  # @return [Integer] Zabbix object id
213
215
  def request(data, method, result_key)
214
216
  # Zabbix has different result formats for gets vs updates
215
- if method.include?('.get')
216
- if result_key.include?('global')
217
+ if method.include?(".get")
218
+ if result_key.include?("global")
217
219
  @client.api_request(method: method, params: { globalmacro: true, filter: data })
218
220
  else
219
221
  @client.api_request(method: method, params: { filter: data })