zabbix_manager 5.0.5 → 5.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/.idea/vcs.xml +6 -0
  3. data/.idea/workspace.xml +2 -4
  4. data/.rubocop.yml +1 -1
  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 +5 -3
  15. data/lib/zabbix_manager/classes/events.rb +4 -3
  16. data/lib/zabbix_manager/classes/graphs.rb +11 -9
  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 +51 -49
  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 +17 -15
  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 +41 -37
  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 +21 -19
  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 +38 -28
  37. data/lib/zabbix_manager/version.rb +3 -1
  38. data/lib/zabbix_manager.rb +36 -35
  39. data/zabbix_manager-5.0.3.gem +0 -0
  40. data/zabbix_manager-5.0.4.gem +0 -0
  41. data/zabbix_manager-5.0.5.gem +0 -0
  42. metadata +9 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c2dd53cab35de67ecf4197410f9122102aaff9509c0860532fb751fb8d555d3f
4
- data.tar.gz: 9c3ffb719aabcbfc0db37dfd1f0932cb9478d59e7c5b100493894d090b26a897
3
+ metadata.gz: 1eba65965b358ec8595a777c899aa54dc1835945d17ad4d42687a22ce25d620f
4
+ data.tar.gz: 68b13154bce3b7b7f1fcb568dc5e5472fd1b196f19d1a244fb25230e79f4a9ad
5
5
  SHA512:
6
- metadata.gz: cfd62dce5eb71f75b04a2ffd6c115fa865185f29dd4a89b165beef09089be108c0d95e633457216e11d114e0b20cbd4e8cb5241c347adb78826a4f00047fe4c2
7
- data.tar.gz: dbc6eb6f1788dfb8e07c0f6816cea0ec535ee1a04b379c189dc5920b1b7d895ab7eb9ac9c4344a33b752516ec1778c7938336f7de9a12efe6d1eb088b3fc5b27
6
+ metadata.gz: f0f0ea55235d315c9ce971e26047866a1c2a57b78a88520e98cfb2e051a75aa888a98dcc12d7e36f7fcfbad947270d99cf33192aceb3287bdb098ced135c021c
7
+ data.tar.gz: 948831dfc8a7f1013b4835829c171e50376b185b965ba599990c9fe574a73a2d15c982badea135a58b9ed0b31701898c65b2a990f9ba923b1ca690ca68f5442a
data/.idea/vcs.xml ADDED
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="$PROJECT_DIR$" vcs="Git" />
5
+ </component>
6
+ </project>
data/.idea/workspace.xml CHANGED
@@ -4,10 +4,7 @@
4
4
  <option name="autoReloadType" value="SELECTIVE" />
5
5
  </component>
6
6
  <component name="ChangeListManager">
7
- <list default="true" id="9f25f96c-828f-4aea-8886-dcbae369ba60" name="变更" comment="">
8
- <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
9
- <change beforePath="$PROJECT_DIR$/lib/zabbix_manager/version.rb" beforeDir="false" afterPath="$PROJECT_DIR$/lib/zabbix_manager/version.rb" afterDir="false" />
10
- </list>
7
+ <list default="true" id="9f25f96c-828f-4aea-8886-dcbae369ba60" name="变更" comment="" />
11
8
  <option name="SHOW_DIALOG" value="false" />
12
9
  <option name="HIGHLIGHT_CONFLICTS" value="true" />
13
10
  <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
@@ -49,6 +46,7 @@
49
46
  <updated>1646727041577</updated>
50
47
  <workItem from="1646727043249" duration="3509000" />
51
48
  <workItem from="1646732978147" duration="8000" />
49
+ <workItem from="1646734414024" duration="13000" />
52
50
  </task>
53
51
  <servers />
54
52
  </component>
data/.rubocop.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  AllCops:
2
- TargetRubyVersion: 2.4
2
+ TargetRubyVersion: 2.7
3
3
 
4
4
  Style/StringLiterals:
5
5
  Enabled: true
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class ZabbixManager
2
4
  class Basic
3
5
  # Get Zabbix object data from API by id
@@ -1,16 +1,18 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class ZabbixManager
2
4
  class Basic
3
5
  # 新增 get_hostgroup_ids 方法,使用列表 flatten 功能拉平属组对象
4
6
  def get_hostgroup_ids(data)
5
7
  result = @client.api_request(
6
- method: 'hostgroup.get',
8
+ method: "hostgroup.get",
7
9
  params: {
8
10
  output: "extend",
9
11
  filter: {
10
12
  name: [data].flatten
11
13
  }
12
14
  }
13
- ).map { |item| { groupid: item['groupid'] } }
15
+ ).map { |item| { groupid: item["groupid"] } }
14
16
 
15
17
  # 检查是是否存在
16
18
  result.empty? ? nil : result.flatten
@@ -20,19 +22,19 @@ class ZabbixManager
20
22
  def get_or_create_hostgroups(data)
21
23
  [data].flatten.each do |item|
22
24
  # 是否存在设备属组,不存在则新建
23
- begin
24
- result = get_hostgroup_ids(item)
25
+
26
+ result = get_hostgroup_ids(item)
27
+ if result.nil?
25
28
  @client.api_request(
26
- method: 'hostgroup.create',
29
+ method: "hostgroup.create",
27
30
  params: {
28
31
  name: item
29
32
  }
30
- ) if result.nil?
31
- rescue => e
32
- ap e
33
+ )
33
34
  end
35
+ rescue StandardError => e
36
+ ap e
34
37
  end
35
38
  end
36
-
37
39
  end
38
40
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class ZabbixManager
2
4
  class Basic
3
5
  # Log messages to stdout when debugging
@@ -26,12 +28,13 @@ class ZabbixManager
26
28
  # @param object [Array, Hash]
27
29
  # @return [Array, Hash]
28
30
  def symbolize_keys(object)
29
- if object.is_a?(Array)
31
+ case object
32
+ when Array
30
33
  object.each_with_index do |val, index|
31
34
  object[index] = symbolize_keys(val)
32
35
  end
33
- elsif object.is_a?(Hash)
34
- object.keys.each do |key|
36
+ when Hash
37
+ object.each_key do |key|
35
38
  object[key.to_sym] = symbolize_keys(object.delete(key))
36
39
  end
37
40
  end
@@ -62,9 +65,10 @@ class ZabbixManager
62
65
  result = []
63
66
 
64
67
  array.each do |e|
65
- if e.is_a?(Array)
68
+ case e
69
+ when Array
66
70
  result.push(normalize_array(e))
67
- elsif e.is_a?(Hash)
71
+ when Hash
68
72
  result.push(normalize_hash(e))
69
73
  else
70
74
  result.push(e.to_s)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class ZabbixManager
2
4
  class Basic
3
5
  # Initializes a new Basic object with ZabbixManager Client
@@ -12,7 +14,7 @@ class ZabbixManager
12
14
  #
13
15
  # @raise [ManagerError] Basic object does not directly support method_name
14
16
  def method_name
15
- raise ManagerError.new("Can't call method_name here")
17
+ raise ManagerError, "Can't call method_name here"
16
18
  end
17
19
 
18
20
  # Placeholder for inherited objects to provide default options
@@ -26,21 +28,21 @@ class ZabbixManager
26
28
  #
27
29
  # @return [String]
28
30
  def keys
29
- key + 's'
31
+ "#{key}s"
30
32
  end
31
33
 
32
34
  # Returns the object's id field name (identify) based on method_name + id
33
35
  #
34
36
  # @return [String]
35
37
  def key
36
- method_name + 'id'
38
+ "#{method_name}id"
37
39
  end
38
40
 
39
41
  # Placeholder for inherited objects to provide object-specific id field name
40
42
  #
41
43
  # @raise [ManagerError] Basic object does not directly support identify
42
44
  def identify
43
- raise ManagerError.new("Can't call identify here")
45
+ raise ManagerError, "Can't call identify here"
44
46
  end
45
47
  end
46
48
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class ZabbixManager
2
4
  class Basic
3
5
  # Create new Zabbix object using API (with defaults)
@@ -96,7 +98,7 @@ class ZabbixManager
96
98
  filter: {
97
99
  identify.to_sym => data[identify.to_sym]
98
100
  },
99
- output: 'extend'
101
+ output: "extend"
100
102
  }
101
103
  )
102
104
  end
@@ -131,7 +133,7 @@ class ZabbixManager
131
133
  filter: {
132
134
  key.to_sym => data[key.to_sym]
133
135
  },
134
- output: 'extend'
136
+ output: "extend"
135
137
  }
136
138
  )
137
139
  end
@@ -145,7 +147,7 @@ class ZabbixManager
145
147
  result = {}
146
148
  @client.api_request(
147
149
  method: "#{method_name}.get",
148
- params: { output: 'extend' }
150
+ params: { output: "extend" }
149
151
  ).each do |item|
150
152
  result[item[identify]] = item[key]
151
153
  end
@@ -165,7 +167,7 @@ class ZabbixManager
165
167
  data = symbolize_keys(data) if data.key?(identify)
166
168
  # raise an error if identify name was not supplied
167
169
  name = data[identify.to_sym]
168
- raise ManagerError.new("#{identify} not supplied in call to get_id") if name.nil?
170
+ raise ManagerError, "#{identify} not supplied in call to get_id" if name.nil?
169
171
 
170
172
  result = @client.api_request(
171
173
  method: "#{method_name}.get",
@@ -174,7 +176,7 @@ class ZabbixManager
174
176
  output: [key, identify]
175
177
  }
176
178
  )
177
- id = nil
179
+ id = nil
178
180
  result.each { |item| id = item[key].to_i if item[identify] == data[identify.to_sym] }
179
181
  id
180
182
  end
@@ -1,17 +1,19 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class ZabbixManager
2
4
  class Actions < Basic
3
5
  # The method name used for interacting with Actions via Zabbix API
4
6
  #
5
7
  # @return [String]
6
8
  def method_name
7
- 'action'
9
+ "action"
8
10
  end
9
11
 
10
12
  # The id field name used for identifying specific Action 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
  # Get full/extended Action object data from API
@@ -29,11 +31,11 @@ class ZabbixManager
29
31
  filter: {
30
32
  identify.to_sym => data[identify.to_sym]
31
33
  },
32
- output: 'extend',
34
+ output: "extend",
33
35
  selectOperations: "extend",
34
36
  selectRecoveryOperations: "extend",
35
37
  selectAcknowledgeOperations: "extend",
36
- selectFilter: "extend",
38
+ selectFilter: "extend"
37
39
  }
38
40
  )
39
41
  end
@@ -1,17 +1,19 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class ZabbixManager
2
4
  class Applications < Basic
3
5
  # The method name used for interacting with Applications via Zabbix API
4
6
  #
5
7
  # @return [String]
6
8
  def method_name
7
- 'application'
9
+ "application"
8
10
  end
9
11
 
10
12
  # The id field name used for identifying specific Application 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
  # Get or Create Application object using Zabbix API
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class ZabbixManager
2
4
  class Configurations < Basic
3
5
  # @return [Boolean]
@@ -9,14 +11,14 @@ class ZabbixManager
9
11
  #
10
12
  # @return [String]
11
13
  def method_name
12
- 'configuration'
14
+ "configuration"
13
15
  end
14
16
 
15
17
  # The id field name used for identifying specific Configuration objects via Zabbix API
16
18
  #
17
19
  # @return [String]
18
20
  def identify
19
- 'host'
21
+ "host"
20
22
  end
21
23
 
22
24
  # Export configuration data using Zabbix API
@@ -26,7 +28,7 @@ class ZabbixManager
26
28
  # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
27
29
  # @return [Hash]
28
30
  def export(data)
29
- @client.api_request(method: 'configuration.export', params: data)
31
+ @client.api_request(method: "configuration.export", params: data)
30
32
  end
31
33
 
32
34
  # Import configuration data using Zabbix API
@@ -36,7 +38,7 @@ class ZabbixManager
36
38
  # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
37
39
  # @return [Hash]
38
40
  def import(data)
39
- @client.api_request(method: 'configuration.import', params: data)
41
+ @client.api_request(method: "configuration.import", params: data)
40
42
  end
41
43
  end
42
44
  end
@@ -1,17 +1,19 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class ZabbixManager
2
4
  class Drules < Basic
3
5
  # The method name used for interacting with Drules via Zabbix API
4
6
  #
5
7
  # @return [String]
6
8
  def method_name
7
- 'drule'
9
+ "drule"
8
10
  end
9
11
 
10
12
  # The id field name used for identifying specific Drule 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 Drule objects via Zabbix API
@@ -22,7 +24,7 @@ class ZabbixManager
22
24
  name: nil,
23
25
  iprange: nil,
24
26
  delay: 3600,
25
- status: 0,
27
+ status: 0
26
28
  }
27
29
  end
28
30
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class ZabbixManager
2
4
  class BaseError < RuntimeError
3
5
  attr_accessor :response, :error, :error_message
@@ -9,11 +11,11 @@ class ZabbixManager
9
11
  set_error! if @response
10
12
  end
11
13
 
12
- private
14
+ private
13
15
 
14
16
  def set_error!
15
- @error = @response['error']
16
- @error_message = "#{@error['message']}: #{@error['data']}"
17
+ @error = @response["error"]
18
+ @error_message = "#{@error["message"]}: #{@error["data"]}"
17
19
  rescue StandardError
18
20
  @error = nil
19
21
  @error_message = nil
@@ -1,18 +1,19 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class ZabbixManager
2
4
  class Events < Basic
3
5
  # The method name used for interacting with Events via Zabbix API
4
6
  #
5
7
  # @return [String]
6
8
  def method_name
7
- 'event'
9
+ "event"
8
10
  end
9
11
 
10
12
  # The id field name used for identifying specific Event objects via Zabbix API
11
13
  #
12
14
  # @return [String]
13
15
  def identify
14
- 'name'
16
+ "name"
15
17
  end
16
-
17
18
  end
18
19
  end
@@ -1,17 +1,19 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class ZabbixManager
2
4
  class Graphs < Basic
3
5
  # The method name used for interacting with Graphs via Zabbix API
4
6
  #
5
7
  # @return [String]
6
8
  def method_name
7
- 'graph'
9
+ "graph"
8
10
  end
9
11
 
10
12
  # The id field name used for identifying specific Graph 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
  # Get full/extended Graph data from Zabbix API
@@ -29,7 +31,7 @@ class ZabbixManager
29
31
  search: {
30
32
  identify.to_sym => data[identify.to_sym]
31
33
  },
32
- output: 'extend'
34
+ output: "extend"
33
35
  }
34
36
  )
35
37
  end
@@ -42,18 +44,18 @@ class ZabbixManager
42
44
  # @return [Array] Returns array of Graph ids
43
45
  def get_ids_by_host(data)
44
46
  result = @client.api_request(
45
- method: 'graph.get',
47
+ method: "graph.get",
46
48
  params: {
47
49
  filter: {
48
50
  host: data[:host]
49
51
  },
50
- output: 'extend'
52
+ output: "extend"
51
53
  }
52
54
  )
53
55
 
54
56
  result.map do |graph|
55
- num = graph['graphid']
56
- name = graph['name']
57
+ num = graph["graphid"]
58
+ name = graph["name"]
57
59
  filter = data[:filter]
58
60
 
59
61
  num if filter.nil? || /#{filter}/ =~ name
@@ -68,10 +70,10 @@ class ZabbixManager
68
70
  # @return [Hash]
69
71
  def get_items(data)
70
72
  @client.api_request(
71
- method: 'graphitem.get',
73
+ method: "graphitem.get",
72
74
  params: {
73
75
  graphids: [data],
74
- output: 'extend'
76
+ output: "extend"
75
77
  }
76
78
  )
77
79
  end
@@ -1,37 +1,39 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class ZabbixManager
2
4
  class HostGroups < Basic
3
5
  # The method name used for interacting with HostGroups via Zabbix API
4
6
  #
5
7
  # @return [String]
6
8
  def method_name
7
- 'hostgroup'
9
+ "hostgroup"
8
10
  end
9
11
 
10
12
  # The id field name used for identifying specific HostGroup 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 HostGroup objects via Zabbix API
18
20
  #
19
21
  # @return [String]
20
22
  def key
21
- 'groupid'
23
+ "groupid"
22
24
  end
23
25
 
24
26
  # 新增 get_hostgroup_ids 方法,使用列表 flatten 功能拉平属组对象
25
27
  def get_hostgroup_ids(data)
26
28
  result = @client.api_request(
27
- method: 'hostgroup.get',
29
+ method: "hostgroup.get",
28
30
  params: {
29
31
  output: "extend",
30
32
  filter: {
31
33
  name: [data].flatten
32
34
  }
33
35
  }
34
- ).map { |item| { groupid: item['groupid'] } }
36
+ ).map { |item| { groupid: item["groupid"] } }
35
37
 
36
38
  # 检查是是否存在
37
39
  result.empty? ? nil : result.flatten
@@ -41,17 +43,17 @@ class ZabbixManager
41
43
  def get_or_create_hostgroups(data)
42
44
  # 是否存在设备属组,不存在则新建
43
45
  [data].flatten.each do |item|
44
- begin
45
- result = get_hostgroup_ids(item)
46
+ result = get_hostgroup_ids(item)
47
+ if result.nil?
46
48
  @client.api_request(
47
- method: 'hostgroup.create',
49
+ method: "hostgroup.create",
48
50
  params: {
49
51
  name: item
50
52
  }
51
- ) if result.nil?
52
- rescue => e
53
- ap e
53
+ )
54
54
  end
55
+ rescue StandardError => e
56
+ ap e
55
57
  end
56
58
  end
57
59
  end