zabbix_manager 5.0.5 → 5.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +2 -4
  3. data/LICENSE.txt +1 -1
  4. data/README.md +48 -21
  5. data/lib/zabbix_manager/basic/basic_alias.rb +2 -0
  6. data/lib/zabbix_manager/basic/basic_extend.rb +11 -9
  7. data/lib/zabbix_manager/basic/basic_func.rb +9 -5
  8. data/lib/zabbix_manager/basic/basic_init.rb +6 -4
  9. data/lib/zabbix_manager/basic/basic_logic.rb +7 -5
  10. data/lib/zabbix_manager/classes/actions.rb +6 -4
  11. data/lib/zabbix_manager/classes/applications.rb +4 -2
  12. data/lib/zabbix_manager/classes/configurations.rb +6 -4
  13. data/lib/zabbix_manager/classes/drules.rb +5 -3
  14. data/lib/zabbix_manager/classes/errors.rb +10 -9
  15. data/lib/zabbix_manager/classes/events.rb +4 -3
  16. data/lib/zabbix_manager/classes/graphs.rb +13 -11
  17. data/lib/zabbix_manager/classes/hostgroups.rb +13 -11
  18. data/lib/zabbix_manager/classes/hosts.rb +36 -34
  19. data/lib/zabbix_manager/classes/httptests.rb +4 -2
  20. data/lib/zabbix_manager/classes/items.rb +34 -28
  21. data/lib/zabbix_manager/classes/maintenance.rb +4 -2
  22. data/lib/zabbix_manager/classes/mediatypes.rb +15 -13
  23. data/lib/zabbix_manager/classes/problems.rb +31 -30
  24. data/lib/zabbix_manager/classes/proxies.rb +9 -7
  25. data/lib/zabbix_manager/classes/roles.rb +19 -17
  26. data/lib/zabbix_manager/classes/screens.rb +6 -4
  27. data/lib/zabbix_manager/classes/scripts.rb +6 -4
  28. data/lib/zabbix_manager/classes/server.rb +3 -1
  29. data/lib/zabbix_manager/classes/templates.rb +18 -16
  30. data/lib/zabbix_manager/classes/triggers.rb +35 -17
  31. data/lib/zabbix_manager/classes/unusable.rb +2 -0
  32. data/lib/zabbix_manager/classes/usergroups.rb +11 -9
  33. data/lib/zabbix_manager/classes/usermacros.rb +38 -37
  34. data/lib/zabbix_manager/classes/users.rb +11 -9
  35. data/lib/zabbix_manager/classes/valuemaps.rb +5 -3
  36. data/lib/zabbix_manager/client.rb +40 -30
  37. data/lib/zabbix_manager/version.rb +3 -1
  38. data/lib/zabbix_manager.rb +36 -35
  39. data/zabbix_manager.gemspec +43 -0
  40. metadata +143 -19
  41. data/.idea/workspace.xml +0 -69
  42. data/.rubocop.yml +0 -13
  43. data/CODE_OF_CONDUCT.md +0 -84
  44. data/Gemfile +0 -10
  45. data/Rakefile +0 -8
  46. data/bin/console +0 -15
  47. data/bin/setup +0 -8
  48. data/zabbix_manager-5.0.1.gem +0 -0
  49. data/zabbix_manager-5.0.2.gem +0 -0
@@ -1,17 +1,19 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class ZabbixManager
2
4
  class Hosts < Basic
3
5
  # The method name used for interacting with Hosts via Zabbix API
4
6
  #
5
7
  # @return [String]
6
8
  def method_name
7
- 'host'
9
+ "host"
8
10
  end
9
11
 
10
12
  # The id field name used for identifying specific Host 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
  # Dump Host object data by key from Zabbix API
@@ -23,12 +25,12 @@ class ZabbixManager
23
25
  def dump_by_id(data)
24
26
  log "[DEBUG] Call dump_by_id with parameters: #{data.inspect}"
25
27
  @client.api_request(
26
- method: 'host.get',
28
+ method: "host.get",
27
29
  params: {
28
30
  filter: {
29
31
  key.to_sym => data[key.to_sym]
30
32
  },
31
- output: 'extend',
33
+ output: "extend"
32
34
  # selectHosts: 'shorten'
33
35
  }
34
36
  )
@@ -39,23 +41,23 @@ class ZabbixManager
39
41
  # @return [Hash]
40
42
  def default_options
41
43
  {
42
- host: nil,
43
- interfaces: {
44
- main: 1,
45
- useip: 1,
46
- type: 2,
47
- ip: nil,
48
- dns: "",
49
- port: 161,
44
+ host: nil,
45
+ interfaces: {
46
+ main: 1,
47
+ useip: 1,
48
+ type: 2,
49
+ ip: nil,
50
+ dns: "",
51
+ port: 161,
50
52
  details: {
51
- version: 2,
53
+ version: 2,
52
54
  community: "transsion"
53
55
  }
54
56
  },
55
- status: 0,
56
- available: 1,
57
- groups: [],
58
- proxy_hostid: nil,
57
+ status: 0,
58
+ available: 1,
59
+ groups: [],
60
+ proxy_hostid: nil,
59
61
  inventory_mode: 1
60
62
  }
61
63
  end
@@ -68,9 +70,9 @@ class ZabbixManager
68
70
  # @return [Boolean]
69
71
  def unlink_templates(data)
70
72
  result = @client.api_request(
71
- method: 'host.massRemove',
73
+ method: "host.massRemove",
72
74
  params: {
73
- hostids: data[:hosts_id],
75
+ hostids: data[:hosts_id],
74
76
  templates: data[:templates_id]
75
77
  }
76
78
  )
@@ -120,19 +122,19 @@ class ZabbixManager
120
122
  # 测试数据
121
123
  def update_mojo
122
124
  data = {
123
- name: "SZX1-16-SW3111111111",
124
- groups: [
125
- {
126
- groupid: 22
127
- }
128
- ],
129
- templates: [
130
- {
131
- templateid: 10227
132
- }
133
- ],
125
+ name: "SZX1-16-SW3111111111",
126
+ groups: [
127
+ {
128
+ groupid: 22
129
+ }
130
+ ],
131
+ templates: [
132
+ {
133
+ templateid: 10_227
134
+ }
135
+ ],
134
136
  inventory_mode: 1,
135
- hostid: 15951
137
+ hostid: 15_951
136
138
  }
137
139
 
138
140
  # 请求后端接口
@@ -142,7 +144,7 @@ class ZabbixManager
142
144
  # 根据主机名查询 hostid
143
145
  def get_host_id(name)
144
146
  result = @client.api_request(
145
- method: 'host.get',
147
+ method: "host.get",
146
148
  params: {
147
149
  output: "extend",
148
150
  filter: {
@@ -158,7 +160,7 @@ class ZabbixManager
158
160
  # 根据可见名称查询 hostid
159
161
  def get_hostid_by_name(name)
160
162
  result = @client.api_request(
161
- method: 'host.get',
163
+ method: "host.get",
162
164
  params: {
163
165
  output: "extend",
164
166
  filter: {
@@ -210,7 +212,7 @@ class ZabbixManager
210
212
  # 新增监控对象
211
213
  create data
212
214
  end
213
- rescue => e
215
+ rescue StandardError => e
214
216
  puts "创建或新增主机 #{data[:host]} 异常,异常信息:#{e}"
215
217
  # raise NotImplementedError
216
218
  end
@@ -1,17 +1,19 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class ZabbixManager
2
4
  class HttpTests < Basic
3
5
  # The method name used for interacting with HttpTests via Zabbix API
4
6
  #
5
7
  # @return [String]
6
8
  def method_name
7
- 'httptest'
9
+ "httptest"
8
10
  end
9
11
 
10
12
  # The id field name used for identifying specific HttpTest objects via Zabbix API
11
13
  #
12
14
  # @return [String]
13
15
  def identify
14
- 'name'
16
+ "name"
15
17
  end
16
18
 
17
19
  # The default options used when creating HttpTest objects via Zabbix API
@@ -1,17 +1,19 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class ZabbixManager
2
4
  class Items < Basic
3
5
  # The method name used for interacting with Items via Zabbix API
4
6
  #
5
7
  # @return [String]
6
8
  def method_name
7
- 'item'
9
+ "item"
8
10
  end
9
11
 
10
12
  # The id field name used for identifying specific Item objects via Zabbix API
11
13
  #
12
14
  # @return [String]
13
15
  def identify
14
- 'name'
16
+ "name"
15
17
  end
16
18
 
17
19
  # The default options used when creating Item objects via Zabbix API
@@ -26,31 +28,31 @@ class ZabbixManager
26
28
  history: 3600,
27
29
  status: 0,
28
30
  type: 7,
29
- snmp_community: '',
30
- snmp_oid: '',
31
+ snmp_community: "",
32
+ snmp_oid: "",
31
33
  value_type: 3,
32
34
  data_type: 0,
33
- trapper_hosts: 'localhost',
35
+ trapper_hosts: "localhost",
34
36
  snmp_port: 161,
35
- units: '',
37
+ units: "",
36
38
  multiplier: 0,
37
39
  delta: 0,
38
- snmpv3_securityname: '',
40
+ snmpv3_securityname: "",
39
41
  snmpv3_securitylevel: 0,
40
- snmpv3_authpassphrase: '',
41
- snmpv3_privpassphrase: '',
42
+ snmpv3_authpassphrase: "",
43
+ snmpv3_privpassphrase: "",
42
44
  formula: 0,
43
- trends: 86400,
44
- logtimefmt: '',
45
+ trends: 86_400,
46
+ logtimefmt: "",
45
47
  valuemapid: 0,
46
- delay_flex: '',
48
+ delay_flex: "",
47
49
  authtype: 0,
48
- username: '',
49
- password: '',
50
- publickey: '',
51
- privatekey: '',
52
- params: '',
53
- ipmi_sensor: ''
50
+ username: "",
51
+ password: "",
52
+ publickey: "",
53
+ privatekey: "",
54
+ params: "",
55
+ ipmi_sensor: ""
54
56
  }
55
57
  end
56
58
 
@@ -83,21 +85,25 @@ class ZabbixManager
83
85
  # 根据设备名称和接口名字查询监控项 | 15809 | GigabitEthernet1/0/12
84
86
  def get_interface_items(hostid, name)
85
87
  # 自动剔除收尾空白字串
86
- _name = name&.gsub(%r"[^\/0-9]", "")&.strip
88
+ _name = name&.gsub(%r{[^/0-9]}, "")&.strip
87
89
  iface = "#{_name}("
88
90
 
89
91
  # 模糊查询接口下所有监控项,同时过滤出特定的 snmp_oid
90
92
  result = @client.api_request(
91
- method: 'item.get',
93
+ method: "item.get",
92
94
  params: {
93
95
  # output: ["itemid", "name", "snmp_oid", "key_", "triggerids"],
94
- output: 'extend',
96
+ output: "extend",
95
97
  hostids: hostid,
96
98
  search: {
97
99
  name: iface
98
- },
100
+ }
99
101
  }
100
- ).select { |item| item["snmp_oid"].match?(/1.3.6.1.2.1.31.1.1.1.(6|10)./) }
102
+ ).select {
103
+ |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)./)
104
+ }.sort_by {
105
+ |item| item["key_"]
106
+ }
101
107
 
102
108
  # 检查是是否存在
103
109
  result.empty? ? nil : result
@@ -111,7 +117,7 @@ class ZabbixManager
111
117
 
112
118
  # 请求绑定 dns 监控项到特定的 hostid
113
119
  result = @client.api_request(
114
- method: 'item.create',
120
+ method: "item.create",
115
121
  params: {
116
122
  hostid: hostid,
117
123
  name: item_name,
@@ -124,21 +130,21 @@ class ZabbixManager
124
130
  delay: "1m",
125
131
  history: "90d",
126
132
  lifetime: "30d",
127
- timeout: "3s",
133
+ timeout: "3s"
128
134
  }
129
135
  )
130
136
  p "成功创建 dns监控 #{dns_name}"
131
- rescue
137
+ rescue StandardError
132
138
  p "创建 dns监控 #{dns_name} 异常"
133
139
  end
134
140
 
135
141
  # 查询某个监控项具体信息
136
142
  def get_item_info
137
143
  result = @client.api_request(
138
- method: 'item.get',
144
+ method: "item.get",
139
145
  params: {
140
146
  output: "extend",
141
- hostids: "16914",
147
+ hostids: "16914"
142
148
  }
143
149
  )
144
150
  end
@@ -1,17 +1,19 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class ZabbixManager
2
4
  class Maintenance < Basic
3
5
  # The method name used for interacting with Maintenances via Zabbix API
4
6
  #
5
7
  # @return [String]
6
8
  def method_name
7
- 'maintenance'
9
+ "maintenance"
8
10
  end
9
11
 
10
12
  # The id field name used for identifying specific Maintenance objects via Zabbix API
11
13
  #
12
14
  # @return [String]
13
15
  def identify
14
- 'name'
16
+ "name"
15
17
  end
16
18
  end
17
19
  end
@@ -1,17 +1,19 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class ZabbixManager
2
4
  class Mediatypes < Basic
3
5
  # The method name used for interacting with MediaTypes via Zabbix API
4
6
  #
5
7
  # @return [String]
6
8
  def method_name
7
- 'mediatype'
9
+ "mediatype"
8
10
  end
9
11
 
10
12
  # The id field name used for identifying specific MediaType objects via Zabbix API
11
13
  #
12
14
  # @return [String]
13
15
  def identify
14
- 'name'
16
+ "name"
15
17
  end
16
18
 
17
19
  # The default options used when creating MediaType objects via Zabbix API
@@ -19,16 +21,16 @@ class ZabbixManager
19
21
  # @return [Hash]
20
22
  def default_options
21
23
  {
22
- name: '', # Name
23
- description: '', # Description
24
+ name: "", # Name
25
+ description: "", # Description
24
26
  type: 0, # 0 - Email, 1 - External script, 2 - SMS, 3 - Jabber, 100 - EzTexting
25
- smtp_server: '',
26
- smtp_helo: '',
27
- smtp_email: '', # Email address of Zabbix server
28
- exec_path: '', # Name of external script
29
- gsm_modem: '', # Serial device name of GSM modem
30
- username: '', # Jabber user name used by Zabbix server
31
- passwd: '' # Jabber password used by Zabbix server
27
+ smtp_server: "",
28
+ 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
32
34
  }
33
35
  end
34
36
 
@@ -78,12 +80,12 @@ class ZabbixManager
78
80
  data = symbolize_keys(data) if data.key?(identify)
79
81
  # raise an error if identify name was not supplied
80
82
  name = data[identify.to_sym]
81
- raise ManagerError.new("#{identify} not supplied in call to get_id, #{data} (#{method_name})") if name.nil?
83
+ raise ManagerError, "#{identify} not supplied in call to get_id, #{data} (#{method_name})" if name.nil?
82
84
 
83
85
  result = @client.api_request(
84
86
  method: "#{method_name}.get",
85
87
  params: {
86
- filter: {name: name},
88
+ filter: { name: name },
87
89
  output: [key, identify]
88
90
  }
89
91
  )
@@ -1,17 +1,19 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class ZabbixManager
2
4
  class Problems < Basic
3
5
  # The method name used for interacting with Hosts via Zabbix API
4
6
  #
5
7
  # @return [String]
6
8
  def method_name
7
- 'problem'
9
+ "problem"
8
10
  end
9
11
 
10
12
  # The id field name used for identifying specific Problem objects via Zabbix API
11
13
  #
12
14
  # @return [String]
13
15
  def identify
14
- 'name'
16
+ "name"
15
17
  end
16
18
 
17
19
  # The key field name used for Problem objects via Zabbix API
@@ -19,7 +21,7 @@ class ZabbixManager
19
21
  #
20
22
  # @return [String]
21
23
  def key
22
- 'problemid'
24
+ "problemid"
23
25
  end
24
26
 
25
27
  # Returns the object's plural id field name (identify) based on key
@@ -27,7 +29,7 @@ class ZabbixManager
27
29
  #
28
30
  # @return [String]
29
31
  def keys
30
- 'problemids'
32
+ "problemids"
31
33
  end
32
34
 
33
35
  # Dump Problem object data by key from Zabbix API
@@ -40,12 +42,12 @@ class ZabbixManager
40
42
  log "[DEBUG] Call dump_by_id with parameters: #{data.inspect}"
41
43
 
42
44
  @client.api_request(
43
- method: 'problem.get',
45
+ method: "problem.get",
44
46
  params: {
45
47
  filter: {
46
48
  identify.to_sym => data[identify.to_sym]
47
49
  },
48
- output: 'extend'
50
+ output: "extend"
49
51
  }
50
52
  )
51
53
  end
@@ -64,27 +66,27 @@ class ZabbixManager
64
66
  @client.api_request(
65
67
  method: "#{method_name}.get",
66
68
  params: {
67
- filter: {
69
+ filter: {
68
70
  identify.to_sym => data[identify.to_sym]
69
71
  },
70
- eventids: data[:eventids] || nil,
71
- groupids: data[:groupids] || nil,
72
- hostids: data[:hostids] || nil,
73
- objectids: data[:objectids] || nil,
74
- applicationids: data[:applicationids] || nil,
75
- tags: data[:tags] || nil,
76
- time_from: data[:time_from] || nil,
77
- time_till: data[:time_till] || nil,
78
- eventid_from: data[:eventid_from] || nil,
79
- eventid_till: data[:eventid_till] || nil,
80
- recent: data[:recent] || false,
81
- sortfield: data[:sortfield] || ['eventid'],
82
- sortorder: data[:sortorder] || 'DESC',
83
- countOutput: data[:countOutput] || nil,
84
- output: 'extend',
85
- selectAcknowledges: 'extend',
86
- selectTags: 'extend',
87
- selectSuppressionData: 'extend'
72
+ eventids: data[:eventids] || nil,
73
+ groupids: data[:groupids] || nil,
74
+ hostids: data[:hostids] || nil,
75
+ objectids: data[:objectids] || nil,
76
+ applicationids: data[:applicationids] || nil,
77
+ tags: data[:tags] || nil,
78
+ time_from: data[:time_from] || nil,
79
+ time_till: data[:time_till] || nil,
80
+ eventid_from: data[:eventid_from] || nil,
81
+ eventid_till: data[:eventid_till] || nil,
82
+ recent: data[:recent] || false,
83
+ sortfield: data[:sortfield] || ["eventid"],
84
+ sortorder: data[:sortorder] || "DESC",
85
+ countOutput: data[:countOutput] || nil,
86
+ output: "extend",
87
+ selectAcknowledges: "extend",
88
+ selectTags: "extend",
89
+ selectSuppressionData: "extend"
88
90
  }
89
91
  )
90
92
  end
@@ -118,16 +120,15 @@ class ZabbixManager
118
120
 
119
121
  def ack_event(eventids)
120
122
  # 请求后端
121
- result = @client.api_request(
123
+ @client.api_request(
122
124
  method: "event.acknowledge",
123
125
  params: {
124
126
  eventids: eventids,
125
- action: 2,
126
- message: "由 RUBY SCRIPT 自动关闭"
127
+ action: 2,
128
+ message: "由 RUBY SCRIPT 自动关闭"
127
129
  }
128
130
  )
129
131
  # 返回运行结果
130
- result
131
132
  end
132
133
  end
133
- end
134
+ end
@@ -1,17 +1,19 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class ZabbixManager
2
4
  class Proxies < Basic
3
5
  # The method name used for interacting with Proxies via Zabbix API
4
6
  #
5
7
  # @return [String]
6
8
  def method_name
7
- 'proxy'
9
+ "proxy"
8
10
  end
9
11
 
10
12
  # The id field name used for identifying specific Proxy 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 Proxy 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 Proxy object id that was deleted
23
25
  def delete(data)
24
- result = @client.api_request(method: 'proxy.delete', params: data)
25
- result.empty? ? nil : result['proxyids'][0].to_i
26
+ result = @client.api_request(method: "proxy.delete", params: data)
27
+ result.empty? ? nil : result["proxyids"][0].to_i
26
28
  end
27
29
 
28
30
  # Check if a Proxy object is readable using Zabbix API
@@ -32,7 +34,7 @@ class ZabbixManager
32
34
  # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
33
35
  # @return [Boolean] Returns true if the given proxies are readable
34
36
  def isreadable(data)
35
- @client.api_request(method: 'proxy.isreadable', params: data)
37
+ @client.api_request(method: "proxy.isreadable", params: data)
36
38
  end
37
39
 
38
40
  # Check if a Proxy object is writable using Zabbix API
@@ -42,7 +44,7 @@ class ZabbixManager
42
44
  # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
43
45
  # @return [Boolean] Returns true if the given proxies are writable
44
46
  def iswritable(data)
45
- @client.api_request(method: 'proxy.iswritable', params: data)
47
+ @client.api_request(method: "proxy.iswritable", params: data)
46
48
  end
47
49
 
48
50
  # 新增代理服务器查询接口
@@ -52,7 +54,7 @@ class ZabbixManager
52
54
 
53
55
  # 请求后端接口,只支持单个代理节点
54
56
  result = @client.api_request(
55
- method: 'proxy.get',
57
+ method: "proxy.get",
56
58
  params: {
57
59
  output: "extend",
58
60
  filter: {
@@ -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,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: '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
- result.map do |rule|
90
- rule['roleid']
91
- end.compact
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: '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