zabbixapi 3.1.0 → 3.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +9 -0
  3. data/CHANGELOG.md +5 -0
  4. data/{LICENSE → LICENSE.md} +1 -1
  5. data/README.md +53 -569
  6. data/lib/zabbixapi.rb +102 -65
  7. data/lib/zabbixapi/basic/basic_alias.rb +21 -4
  8. data/lib/zabbixapi/basic/basic_func.rb +56 -23
  9. data/lib/zabbixapi/basic/basic_init.rb +21 -4
  10. data/lib/zabbixapi/basic/basic_logic.rb +75 -18
  11. data/lib/zabbixapi/classes/actions.rb +8 -4
  12. data/lib/zabbixapi/classes/applications.rb +20 -6
  13. data/lib/zabbixapi/classes/configurations.rb +23 -17
  14. data/lib/zabbixapi/classes/errors.rb +2 -4
  15. data/lib/zabbixapi/classes/graphs.rb +65 -15
  16. data/lib/zabbixapi/classes/hostgroups.rb +12 -4
  17. data/lib/zabbixapi/classes/hosts.rb +36 -10
  18. data/lib/zabbixapi/classes/httptests.rb +24 -4
  19. data/lib/zabbixapi/classes/items.rb +24 -5
  20. data/lib/zabbixapi/classes/maintenance.rb +8 -4
  21. data/lib/zabbixapi/classes/mediatypes.rb +20 -13
  22. data/lib/zabbixapi/classes/proxies.rb +29 -8
  23. data/lib/zabbixapi/classes/screens.rb +41 -25
  24. data/lib/zabbixapi/classes/server.rb +8 -4
  25. data/lib/zabbixapi/classes/templates.rb +46 -43
  26. data/lib/zabbixapi/classes/triggers.rb +43 -16
  27. data/lib/zabbixapi/classes/unusable.rb +0 -2
  28. data/lib/zabbixapi/classes/usergroups.rb +33 -26
  29. data/lib/zabbixapi/classes/usermacros.rb +137 -31
  30. data/lib/zabbixapi/classes/users.rb +32 -10
  31. data/lib/zabbixapi/classes/valuemaps.rb +50 -0
  32. data/lib/zabbixapi/client.rb +61 -22
  33. data/lib/zabbixapi/version.rb +1 -1
  34. data/zabbixapi.gemspec +26 -23
  35. metadata +25 -73
  36. data/.gitignore +0 -7
  37. data/.rspec +0 -1
  38. data/.travis.yml +0 -41
  39. data/Gemfile +0 -3
  40. data/Gemfile.lock +0 -36
  41. data/Rakefile +0 -1
  42. data/json-1.x.Gemfile +0 -4
  43. data/json-1.x.Gemfile.lock +0 -28
  44. data/spec/action.rb +0 -89
  45. data/spec/application.rb +0 -83
  46. data/spec/basic_func.rb +0 -4
  47. data/spec/configuration.rb +0 -122
  48. data/spec/graph.rb +0 -135
  49. data/spec/host.rb +0 -176
  50. data/spec/hostgroup.rb +0 -55
  51. data/spec/httptest.rb +0 -136
  52. data/spec/item.rb +0 -134
  53. data/spec/maintenance.rb +0 -81
  54. data/spec/mediatype.rb +0 -50
  55. data/spec/query.rb +0 -18
  56. data/spec/screen.rb +0 -88
  57. data/spec/script.rb +0 -123
  58. data/spec/server.rb +0 -15
  59. data/spec/spec_helper.rb +0 -21
  60. data/spec/template.rb +0 -148
  61. data/spec/trigger.rb +0 -103
  62. data/spec/user.rb +0 -116
  63. data/spec/usergroup.rb +0 -85
  64. data/spec/usermacro.rb +0 -190
@@ -1,14 +1,22 @@
1
1
  class ZabbixApi
2
2
  class Items < Basic
3
-
3
+ # The method name used for interacting with Items via Zabbix API
4
+ #
5
+ # @return [String]
4
6
  def method_name
5
- "item"
7
+ 'item'
6
8
  end
7
9
 
10
+ # The id field name used for identifying specific Item objects via Zabbix API
11
+ #
12
+ # @return [String]
8
13
  def indentify
9
- "name"
14
+ 'name'
10
15
  end
11
16
 
17
+ # The default options used when creating Item objects via Zabbix API
18
+ #
19
+ # @return [Hash]
12
20
  def default_options
13
21
  {
14
22
  :name => nil,
@@ -42,10 +50,16 @@ class ZabbixApi
42
50
  :publickey => '',
43
51
  :privatekey => '',
44
52
  :params => '',
45
- :ipmi_sensor => ''
53
+ :ipmi_sensor => '',
46
54
  }
47
55
  end
48
56
 
57
+ # Get or Create Item object using Zabbix API
58
+ #
59
+ # @param data [Hash] Needs to include name and hostid to properly identify Items via Zabbix API
60
+ # @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
61
+ # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
62
+ # @return [Integer] Zabbix object id
49
63
  def get_or_create(data)
50
64
  log "[DEBUG] Call get_or_create with parameters: #{data.inspect}"
51
65
 
@@ -55,10 +69,15 @@ class ZabbixApi
55
69
  id
56
70
  end
57
71
 
72
+ # Create or update Item object using Zabbix API
73
+ #
74
+ # @param data [Hash] Needs to include name and hostid to properly identify Items via Zabbix API
75
+ # @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
76
+ # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
77
+ # @return [Integer] Zabbix object id
58
78
  def create_or_update(data)
59
79
  itemid = get_id(:name => data[:name], :hostid => data[:hostid])
60
80
  itemid ? update(data.merge(:itemid => itemid)) : create(data)
61
81
  end
62
-
63
82
  end
64
83
  end
@@ -1,13 +1,17 @@
1
1
  class ZabbixApi
2
2
  class Maintenance < Basic
3
-
3
+ # The method name used for interacting with Maintenances via Zabbix API
4
+ #
5
+ # @return [String]
4
6
  def method_name
5
- "maintenance"
7
+ 'maintenance'
6
8
  end
7
9
 
10
+ # The id field name used for identifying specific Maintenance objects via Zabbix API
11
+ #
12
+ # @return [String]
8
13
  def indentify
9
- "name"
14
+ 'name'
10
15
  end
11
-
12
16
  end
13
17
  end
@@ -1,27 +1,34 @@
1
1
  class ZabbixApi
2
2
  class Mediatypes < Basic
3
-
3
+ # The method name used for interacting with MediaTypes via Zabbix API
4
+ #
5
+ # @return [String]
4
6
  def method_name
5
- "mediatype"
7
+ 'mediatype'
6
8
  end
7
9
 
10
+ # The id field name used for identifying specific MediaType objects via Zabbix API
11
+ #
12
+ # @return [String]
8
13
  def indentify
9
- "description"
14
+ 'description'
10
15
  end
11
16
 
17
+ # The default options used when creating MediaType objects via Zabbix API
18
+ #
19
+ # @return [Hash]
12
20
  def default_options
13
21
  {
14
- :description => "", #Name
15
- :type => 0, #0 - Email, 1 - External script, 2 - SMS, 3 - Jabber, 100 - EzTexting
16
- :smtp_server => "",
17
- :smtp_helo => "",
18
- :smtp_email => "", #Email address of Zabbix server
19
- :exec_path => "", #Name of external script
20
- :gsm_modem => "", #Serial device name of GSM modem
21
- :username => "", #Jabber user name used by Zabbix server
22
- :passwd => "" #Jabber password used by Zabbix server
22
+ :description => '', # Name
23
+ :type => 0, # 0 - Email, 1 - External script, 2 - SMS, 3 - Jabber, 100 - EzTexting
24
+ :smtp_server => '',
25
+ :smtp_helo => '',
26
+ :smtp_email => '', # Email address of Zabbix server
27
+ :exec_path => '', # Name of external script
28
+ :gsm_modem => '', # Serial device name of GSM modem
29
+ :username => '', # Jabber user name used by Zabbix server
30
+ :passwd => '' # Jabber password used by Zabbix server
23
31
  }
24
32
  end
25
-
26
33
  end
27
34
  end
@@ -1,27 +1,48 @@
1
1
  class ZabbixApi
2
2
  class Proxies < Basic
3
-
3
+ # The method name used for interacting with Proxies via Zabbix API
4
+ #
5
+ # @return [String]
4
6
  def method_name
5
- "proxy"
7
+ 'proxy'
6
8
  end
7
9
 
10
+ # The id field name used for identifying specific Proxy objects via Zabbix API
11
+ #
12
+ # @return [String]
8
13
  def indentify
9
- "host"
14
+ 'host'
10
15
  end
11
16
 
17
+ # Delete Proxy object using Zabbix API
18
+ #
19
+ # @param data [Array] Should include array of proxyid's
20
+ # @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
21
+ # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
22
+ # @return [Integer] The Proxy object id that was deleted
12
23
  def delete(data)
13
- result = @client.api_request(:method => "proxy.delete", :params => data)
24
+ result = @client.api_request(:method => 'proxy.delete', :params => data)
14
25
  result.empty? ? nil : result['proxyids'][0].to_i
15
26
  end
16
27
 
28
+ # Check if a Proxy object is readable using Zabbix API
29
+ #
30
+ # @param data [Array] Should include array of proxyid's
31
+ # @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
32
+ # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
33
+ # @return [Boolean] Returns true if the given proxies are readable
17
34
  def isreadable(data)
18
- result = @client.api_request(:method => "proxy.isreadable", :params => data)
35
+ @client.api_request(:method => 'proxy.isreadable', :params => data)
19
36
  end
20
37
 
38
+ # Check if a Proxy object is writable using Zabbix API
39
+ #
40
+ # @param data [Array] Should include array of proxyid's
41
+ # @raise [ApiError] 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 [Boolean] Returns true if the given proxies are writable
21
44
  def iswritable(data)
22
- result = @client.api_request(:method => "proxy.iswritable", :params => data)
45
+ @client.api_request(:method => 'proxy.iswritable', :params => data)
23
46
  end
24
-
25
47
  end
26
48
  end
27
-
@@ -1,38 +1,55 @@
1
1
  class ZabbixApi
2
2
  class Screens < Basic
3
-
4
3
  # extracted from frontends/php/include/defines.inc.php
5
- #SCREEN_RESOURCE_GRAPH => 0,
6
- #SCREEN_RESOURCE_SIMPLE_GRAPH => 1,
7
- #SCREEN_RESOURCE_MAP => 2,
8
- #SCREEN_RESOURCE_PLAIN_TEXT => 3,
9
- #SCREEN_RESOURCE_HOSTS_INFO => 4,
10
- #SCREEN_RESOURCE_TRIGGERS_INFO => 5,
11
- #SCREEN_RESOURCE_SERVER_INFO => 6,
12
- #SCREEN_RESOURCE_CLOCK => 7,
13
- #SCREEN_RESOURCE_SCREEN => 8,
14
- #SCREEN_RESOURCE_TRIGGERS_OVERVIEW => 9,
15
- #SCREEN_RESOURCE_DATA_OVERVIEW => 10,
16
- #SCREEN_RESOURCE_URL => 11,
17
- #SCREEN_RESOURCE_ACTIONS => 12,
18
- #SCREEN_RESOURCE_EVENTS => 13,
19
- #SCREEN_RESOURCE_HOSTGROUP_TRIGGERS => 14,
20
- #SCREEN_RESOURCE_SYSTEM_STATUS => 15,
21
- #SCREEN_RESOURCE_HOST_TRIGGERS => 16
4
+ # SCREEN_RESOURCE_GRAPH => 0,
5
+ # SCREEN_RESOURCE_SIMPLE_GRAPH => 1,
6
+ # SCREEN_RESOURCE_MAP => 2,
7
+ # SCREEN_RESOURCE_PLAIN_TEXT => 3,
8
+ # SCREEN_RESOURCE_HOSTS_INFO => 4,
9
+ # SCREEN_RESOURCE_TRIGGERS_INFO => 5,
10
+ # SCREEN_RESOURCE_SERVER_INFO => 6,
11
+ # SCREEN_RESOURCE_CLOCK => 7,
12
+ # SCREEN_RESOURCE_SCREEN => 8,
13
+ # SCREEN_RESOURCE_TRIGGERS_OVERVIEW => 9,
14
+ # SCREEN_RESOURCE_DATA_OVERVIEW => 10,
15
+ # SCREEN_RESOURCE_URL => 11,
16
+ # SCREEN_RESOURCE_ACTIONS => 12,
17
+ # SCREEN_RESOURCE_EVENTS => 13,
18
+ # SCREEN_RESOURCE_HOSTGROUP_TRIGGERS => 14,
19
+ # SCREEN_RESOURCE_SYSTEM_STATUS => 15,
20
+ # SCREEN_RESOURCE_HOST_TRIGGERS => 16
22
21
 
22
+ # The method name used for interacting with Screens via Zabbix API
23
+ #
24
+ # @return [String]
23
25
  def method_name
24
- "screen"
26
+ 'screen'
25
27
  end
26
28
 
29
+ # The id field name used for identifying specific Screen objects via Zabbix API
30
+ #
31
+ # @return [String]
27
32
  def indentify
28
- "name"
33
+ 'name'
29
34
  end
30
35
 
36
+ # Delete Screen object using Zabbix API
37
+ #
38
+ # @param data [String, Array] Should include id's of the screens to delete
39
+ # @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
40
+ # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
41
+ # @return [Integer] Zabbix object id
31
42
  def delete(data)
32
- result = @client.api_request(:method => "screen.delete", :params => [data])
43
+ result = @client.api_request(:method => 'screen.delete', :params => [data])
33
44
  result.empty? ? nil : result['screenids'][0].to_i
34
45
  end
35
46
 
47
+ # Get or Create Screen object for Host using Zabbix API
48
+ #
49
+ # @param data [Hash] Needs to include screen_name and graphids to properly identify Screens via Zabbix API
50
+ # @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
51
+ # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
52
+ # @return [Integer] Zabbix object id
36
53
  def get_or_create_for_host(data)
37
54
  screen_name = data[:screen_name]
38
55
  graphids = data[:graphids]
@@ -44,7 +61,7 @@ class ZabbixApi
44
61
  colspan = data[:colspan] || 1
45
62
  height = data[:height] || 320 # default 320
46
63
  width = data[:width] || 200 # default 200
47
- vsize = data[:vsize] || [1, (graphids.size/hsize).to_i].max
64
+ vsize = data[:vsize] || [1, (graphids.size / hsize).to_i].max
48
65
  screenid = get_id(:name => screen_name)
49
66
 
50
67
  unless screenid
@@ -54,13 +71,13 @@ class ZabbixApi
54
71
  :resourcetype => 0,
55
72
  :resourceid => graphid,
56
73
  :x => (index % hsize).to_i,
57
- :y => (index % graphids.size/hsize).to_i,
74
+ :y => (index % graphids.size / hsize).to_i,
58
75
  :valign => valign,
59
76
  :halign => halign,
60
77
  :rowspan => rowspan,
61
78
  :colspan => colspan,
62
79
  :height => height,
63
- :width => width
80
+ :width => width,
64
81
  }
65
82
  end
66
83
  screenid = create(
@@ -72,6 +89,5 @@ class ZabbixApi
72
89
  end
73
90
  screenid
74
91
  end
75
-
76
92
  end
77
93
  end
@@ -1,12 +1,16 @@
1
1
  class ZabbixApi
2
2
  class Server
3
+ # @return [String]
4
+ attr_reader :version
3
5
 
4
- attr :version
5
-
6
+ # Initializes a new Server object with ZabbixApi Client and fetches Zabbix Server API version
7
+ #
8
+ # @param client [ZabbixApi::Client]
9
+ # @return [ZabbixApi::Client]
10
+ # @return [String] Zabbix API version number
6
11
  def initialize(client)
7
12
  @client = client
8
- @version = @client.api_request(:method => "apiinfo.version", :params => {})
13
+ @version = @client.api_request(:method => 'apiinfo.version', :params => {})
9
14
  end
10
-
11
15
  end
12
16
  end
@@ -1,46 +1,50 @@
1
1
  class ZabbixApi
2
2
  class Templates < Basic
3
-
3
+ # The method name used for interacting with Templates via Zabbix API
4
+ #
5
+ # @return [String]
4
6
  def method_name
5
- "template"
7
+ 'template'
6
8
  end
7
9
 
10
+ # The id field name used for identifying specific Template objects via Zabbix API
11
+ #
12
+ # @return [String]
8
13
  def indentify
9
- "host"
14
+ 'host'
10
15
  end
11
16
 
12
-
13
- # Delete template
17
+ # Delete Template object using Zabbix API
14
18
  #
15
- # * *Args* :
16
- # - +data+ -> Hash with :host => "Template_Name"
17
- # * *Returns* :
18
- # - Nil or Integer
19
+ # @param data [Array] Should include array of templateid's
20
+ # @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
21
+ # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
22
+ # @return [Integer] The Template object id that was deleted
19
23
  def delete(data)
20
- result = @client.api_request(:method => "template.delete", :params => [data])
24
+ result = @client.api_request(:method => 'template.delete', :params => [data])
21
25
  result.empty? ? nil : result['templateids'][0].to_i
22
26
  end
23
27
 
24
- # Return templateids linked with host
28
+ # Get Template ids for Host from Zabbix API
25
29
  #
26
- # * *Args* :
27
- # - +data+ -> Hash with :hostids => [hostid]
28
- # * *Returns* :
29
- # - Array with templateids
30
+ # @param data [Hash] Should include host value to query for matching templates
31
+ # @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
32
+ # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
33
+ # @return [Array] Returns array of Template ids
30
34
  def get_ids_by_host(data)
31
35
  result = []
32
- @client.api_request(:method => "template.get", :params => data).each do |tmpl|
36
+ @client.api_request(:method => 'template.get', :params => data).each do |tmpl|
33
37
  result << tmpl['templateid']
34
38
  end
35
39
  result
36
40
  end
37
41
 
38
- # Return templateid
42
+ # Get or Create Template object using Zabbix API
39
43
  #
40
- # * *Args* :
41
- # - +data+ -> Hash with :host => "Template_Name" and :groups => array with hostgroup ids
42
- # * *Returns* :
43
- # - Integer
44
+ # @param data [Hash] Needs to include host to properly identify Templates via Zabbix API
45
+ # @raise [ApiError] 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 [Integer] Zabbix object id
44
48
  def get_or_create(data)
45
49
  unless (templateid = get_id(:host => data[:host]))
46
50
  templateid = create(data)
@@ -48,58 +52,57 @@ class ZabbixApi
48
52
  templateid
49
53
  end
50
54
 
51
- # Analog Zabbix api call massUpdate
55
+ # Mass update Templates for Hosts using Zabbix API
52
56
  #
53
- # * *Args* :
54
- # - +data+ -> Hash with :hosts_id => [hostid1, hostid2 ...], and :templates_id => [templateid1, templateid2 ...]
55
- # * *Returns* :
56
- # - True or False
57
+ # @param data [Hash] Should include hosts_id array and templates_id array
58
+ # @raise [ApiError] 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 [Boolean]
57
61
  def mass_update(data)
58
62
  result = @client.api_request(
59
- :method => "template.massUpdate",
63
+ :method => 'template.massUpdate',
60
64
  :params => {
61
65
  :hosts => data[:hosts_id].map { |t| {:hostid => t} },
62
- :templates => data[:templates_id].map { |t| {:templateid => t} }
66
+ :templates => data[:templates_id].map { |t| {:templateid => t} },
63
67
  }
64
68
  )
65
69
  result.empty? ? false : true
66
70
  end
67
71
 
68
- # Analog Zabbix api call massAdd
72
+ # Mass add Templates to Hosts using Zabbix API
69
73
  #
70
- # * *Args* :
71
- # - +data+ -> Hash with :hosts_id => [hostid1, hostid2 ...], and :templates_id => [templateid1, templateid2 ...]
72
- # * *Returns* :
73
- # - True or False
74
+ # @param data [Hash] Should include hosts_id array and templates_id array
75
+ # @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
76
+ # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
77
+ # @return [Boolean]
74
78
  def mass_add(data)
75
79
  result = @client.api_request(
76
- :method => "template.massAdd",
80
+ :method => 'template.massAdd',
77
81
  :params => {
78
82
  :hosts => data[:hosts_id].map { |t| {:hostid => t} },
79
- :templates => data[:templates_id].map { |t| {:templateid => t} }
83
+ :templates => data[:templates_id].map { |t| {:templateid => t} },
80
84
  }
81
85
  )
82
86
  result.empty? ? false : true
83
87
  end
84
88
 
85
- # Analog Zabbix api call massRemove
89
+ # Mass remove Templates to Hosts using Zabbix API
86
90
  #
87
- # * *Args* :
88
- # - +data+ -> Hash with :hosts_id => [hostid1, hostid2 ...], and :templates_id => [templateid1, templateid2 ...]
89
- # * *Returns* :
90
- # - True or False
91
+ # @param data [Hash] Should include hosts_id array and templates_id array
92
+ # @raise [ApiError] 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 [Boolean]
91
95
  def mass_remove(data)
92
96
  result = @client.api_request(
93
- :method => "template.massRemove",
97
+ :method => 'template.massRemove',
94
98
  :params => {
95
99
  :hostids => data[:hosts_id],
96
100
  :templateids => data[:templates_id],
97
101
  :groupids => data[:group_id],
98
- :force => 1
102
+ :force => 1,
99
103
  }
100
104
  )
101
105
  result.empty? ? false : true
102
106
  end
103
-
104
107
  end
105
108
  end