zabbixapi 0.5.0 → 0.5.1a

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.
@@ -0,0 +1,68 @@
1
+ class ZabbixApi
2
+ class Screens < Basic
3
+
4
+ # 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
22
+
23
+ def method_name
24
+ "screen"
25
+ end
26
+
27
+ def indentify
28
+ "name"
29
+ end
30
+
31
+ def delete(data)
32
+ result = @client.api_request(:method => "screen.delete", :params => data)
33
+ result.empty? ? nil : result['screenids'][0].to_i
34
+ end
35
+
36
+ def get_or_create_for_host(data)
37
+ screen_name = data[:host].to_s + "_graphs"
38
+ graphids = data[:graphids]
39
+ screenitems = []
40
+ hsize = data[:hsize] || 3
41
+ valign = data[:valign] || 2
42
+ halign = data[:halign] || 2
43
+ vsize = data[:vsize] || ((graphids.size/hsize) + 1).to_i
44
+ screenid = get_id(:name => screen_name)
45
+ unless screenid
46
+ # Create screen
47
+ graphids.each_with_index do |graphid, index|
48
+ screenitems << {
49
+ :resourcetype => 0,
50
+ :resourceid => graphid,
51
+ :x => (index % hsize).to_i,
52
+ :y => (index % graphids.size/hsize).to_i,
53
+ :valign =>valign,
54
+ :halign =>halign
55
+ }
56
+ end
57
+ screenid = create(
58
+ :name => screen_name,
59
+ :hsize => hsize,
60
+ :vsize => vsize,
61
+ :screenitems => screenitems
62
+ )
63
+ end
64
+ screenid
65
+ end
66
+
67
+ end
68
+ end
File without changes
@@ -1,27 +1,19 @@
1
1
  class ZabbixApi
2
- class Templates
2
+ class Templates < Basic
3
3
 
4
- def initialize(client)
5
- @client = client
4
+ def array_flag
5
+ true
6
6
  end
7
7
 
8
- # Create template
9
- #
10
- # * *Args* :
11
- # - +data+ -> Hash with :host => "Template_Name" and :groups => array with hostgroup ids
12
- # * *Returns* :
13
- # - Nil or Integer
14
- def create(data)
15
- result = @client.api_request(:method => "template.create", :params => [data])
16
- result.empty? ? nil : result['templateids'][0].to_i
8
+ def method_name
9
+ "template"
17
10
  end
18
11
 
19
- # Add template
20
- # Synonym create
21
- def add(data)
22
- create(data)
12
+ def indentify
13
+ "host"
23
14
  end
24
15
 
16
+
25
17
  # Delete template
26
18
  #
27
19
  # * *Args* :
@@ -33,12 +25,6 @@ class ZabbixApi
33
25
  result.empty? ? nil : result['templateids'][0].to_i
34
26
  end
35
27
 
36
- # Destroy template
37
- # Synonym delete
38
- def destroy(data)
39
- delete(data)
40
- end
41
-
42
28
  # Return templateids linked with host
43
29
  #
44
30
  # * *Args* :
@@ -119,53 +105,5 @@ class ZabbixApi
119
105
  result.empty? ? false : true
120
106
  end
121
107
 
122
- # Return all templates
123
- #
124
- # * *Returns* :
125
- # - Hash with {"Template_Name1" => "templateid1", "Template_Name2" => "templateid2"}
126
- def all
127
- result = {}
128
- case @client.api_version
129
- when "1.2"
130
- @client.api_request(:method => "template.get", :params => {:output => "extend"}).values.each do |tmpl|
131
- result[tmpl['host']] = tmpl['hostid']
132
- end
133
- else
134
- @client.api_request(:method => "template.get", :params => {:output => "extend"}).each do |tmpl|
135
- result[tmpl['host']] = tmpl['hostid']
136
- end
137
- end
138
- result
139
- end
140
-
141
- # Return info about template
142
- #
143
- # * *Args* :
144
- # - +data+ -> Hash with :host => "Template name"
145
- # * *Returns* :
146
- # - Hash with template info
147
- def get_full_data(data)
148
- case @client.api_version
149
- when "1.2"
150
- # in this version returned id=>{...}
151
- result = @client.api_request(:method => "template.get", :params => {:filter => data, :output => "extend"})
152
- result.empty? ? [] : result.values
153
- else
154
- @client.api_request(:method => "template.get", :params => {:filter => data, :output => "extend"})
155
- end
156
- end
157
-
158
- # Return info about template
159
- #
160
- # * *Args* :
161
- # - +data+ -> Hash with :host => "Template name"
162
- # * *Returns* :
163
- # - Nil or Integer
164
- def get_id(data)
165
- templateid = nil
166
- get_full_data(data).each { |template| templateid = template['templateid'].to_i if template['host'] == data[:host] }
167
- templateid
168
- end
169
-
170
108
  end
171
109
  end
@@ -0,0 +1,17 @@
1
+ class ZabbixApi
2
+ class Triggers < Basic
3
+
4
+ def array_flag
5
+ true
6
+ end
7
+
8
+ def method_name
9
+ "trigger"
10
+ end
11
+
12
+ def indentify
13
+ "name"
14
+ end
15
+
16
+ end
17
+ end
@@ -1,25 +1,20 @@
1
1
  class ZabbixApi
2
- class Usergroups
2
+ class Usergroups < Basic
3
3
 
4
- def initialize(client)
5
- @client = client
4
+ def array_flag
5
+ true
6
6
  end
7
7
 
8
- # Create UserGroup
9
- #
10
- # * *Args* :
11
- # - +data+ -> Hash with :name => "UserGroup"
12
- # * *Returns* :
13
- # - Nil or Integer
14
- def create(data)
15
- result = @client.api_request(:method => "usergroup.create", :params => data)
16
- result ? result['usrgrpids'][0].to_i : nil
8
+ def method_name
9
+ "usergroup"
10
+ end
11
+
12
+ def key
13
+ "usrgrpid"
17
14
  end
18
15
 
19
- # Add UserGroup
20
- # Synonym create
21
- def add(data)
22
- create(data)
16
+ def indentify
17
+ "name"
23
18
  end
24
19
 
25
20
  # Delete UserGroup
@@ -33,44 +28,6 @@ class ZabbixApi
33
28
  result ? result['usrgrpids'][0].to_i : nil
34
29
  end
35
30
 
36
- # Destroy UserGroup
37
- # Synonym delete
38
- def destroy(data)
39
- delete(data)
40
- end
41
-
42
- # Get UserGroup info
43
- #
44
- # * *Args* :
45
- # - +data+ -> Hash with :name => "UserGroup"
46
- # * *Returns* :
47
- # - Nil or Integer
48
- def get_full_data(data)
49
- @client.api_request(
50
- :method => "usergroup.get",
51
- :params => {
52
- :filter => [data[:name]],
53
- :output => "extend"
54
- }
55
- )
56
- end
57
-
58
- def get(data)
59
- get_full_data(data)
60
- end
61
-
62
- # Return usrgrpid
63
- #
64
- # * *Args* :
65
- # - +data+ -> Hash with :name => "UserGroup"
66
- # * *Returns* :
67
- # - Nil or Integer
68
- def get_id(data)
69
- result = get_full_data(data)
70
- usrgrpid = nil
71
- result.each { |usr| usrgrpid = usr['usrgrpid'].to_i if usr['name'] == data[:name] }
72
- usrgrpid
73
- end
74
31
 
75
32
  # Return usrgrpid
76
33
  #
@@ -0,0 +1,32 @@
1
+ class ZabbixApi
2
+ class Users < Basic
3
+
4
+ def method_name
5
+ "user"
6
+ end
7
+
8
+ def keys
9
+ "userids"
10
+ end
11
+
12
+ def key
13
+ "userid"
14
+ end
15
+
16
+ def indentify
17
+ "name"
18
+ end
19
+
20
+ def add_medias(data)
21
+ result = @client.api_request(
22
+ :method => "user.addMedia",
23
+ :params => {
24
+ :users => data[:userids].map { |t| {:userid => t} },
25
+ :medias => data[:media]
26
+ }
27
+ )
28
+ result ? result['userids'][0].to_i : nil
29
+ end
30
+
31
+ end
32
+ end
@@ -5,7 +5,7 @@ class ZabbixApi
5
5
  class Client
6
6
 
7
7
  def id
8
- Random.rand(100000)
8
+ @id = @id + 1
9
9
  end
10
10
 
11
11
  def api_version
@@ -24,13 +24,14 @@ class ZabbixApi
24
24
 
25
25
  def initialize(options = {})
26
26
  @options = options
27
- @auth_hash = auth
27
+ @id = 1
28
28
  unless ENV['http_proxy'].nil?
29
29
  @proxy_uri = URI.parse(ENV['http_proxy'])
30
30
  @proxy_host = @proxy_uri.host
31
31
  @proxy_port = @proxy_uri.port
32
32
  @proxy_user, @proxy_pass = @proxy_uri.userinfo.split(/:/) if @proxy_uri.userinfo
33
33
  end
34
+ @auth_hash = auth
34
35
  end
35
36
 
36
37
  def message_json(body)
@@ -52,6 +53,7 @@ class ZabbixApi
52
53
  http = Net::HTTP.Proxy(@proxy_host, @proxy_port, @proxy_user, @proxy_pass).new(uri.host, uri.port)
53
54
  end
54
55
  request = Net::HTTP::Post.new(uri.request_uri)
56
+ request.basic_auth @options[:http_user], @options[:http_password] if @options[:http_user]
55
57
  request.add_field('Content-Type', 'application/json-rpc')
56
58
  request.body = body
57
59
  response = http.request(request)
@@ -1,3 +1,3 @@
1
1
  class ZabbixApi
2
- VERSION = "0.5.0"
2
+ VERSION = "0.5.1a"
3
3
  end
data/spec/localhost.rb CHANGED
@@ -311,7 +311,7 @@ describe ZabbixApi, "test_api" do
311
311
  end
312
312
 
313
313
  it "GRAPH: Delete" do
314
- zbx.graphs.delete(zbx.graphs.get_id(:name => graph)).should be_kind_of(Integer)
314
+ zbx.graphs.delete(zbx.graphs.get_id(:name => graph)).should be_kind_of(TrueClass)
315
315
  end
316
316
 
317
317
  it "TRIGGER: Delete" do
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zabbixapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
5
- prerelease:
4
+ version: 0.5.1a
5
+ prerelease: 5
6
6
  platform: ruby
7
7
  authors:
8
8
  - Vasiliev D.V.
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-06 00:00:00.000000000 Z
12
+ date: 2012-12-18 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Allows you to work with zabbix api from ruby.
15
15
  email:
@@ -26,20 +26,24 @@ files:
26
26
  - README.md
27
27
  - Rakefile
28
28
  - lib/zabbixapi.rb
29
- - lib/zabbixapi/applications.rb
29
+ - lib/zabbixapi/basic/basic_alias.rb
30
+ - lib/zabbixapi/basic/basic_func.rb
31
+ - lib/zabbixapi/basic/basic_init.rb
32
+ - lib/zabbixapi/basic/basic_logic.rb
33
+ - lib/zabbixapi/classes/applications.rb
34
+ - lib/zabbixapi/classes/errors.rb
35
+ - lib/zabbixapi/classes/graphs.rb
36
+ - lib/zabbixapi/classes/hostgroups.rb
37
+ - lib/zabbixapi/classes/hosts.rb
38
+ - lib/zabbixapi/classes/items.rb
39
+ - lib/zabbixapi/classes/mediatypes.rb
40
+ - lib/zabbixapi/classes/screens.rb
41
+ - lib/zabbixapi/classes/server.rb
42
+ - lib/zabbixapi/classes/templates.rb
43
+ - lib/zabbixapi/classes/triggers.rb
44
+ - lib/zabbixapi/classes/usergroups.rb
45
+ - lib/zabbixapi/classes/users.rb
30
46
  - lib/zabbixapi/client.rb
31
- - lib/zabbixapi/errors.rb
32
- - lib/zabbixapi/graphs.rb
33
- - lib/zabbixapi/hostgroups.rb
34
- - lib/zabbixapi/hosts.rb
35
- - lib/zabbixapi/items.rb
36
- - lib/zabbixapi/mediatypes.rb
37
- - lib/zabbixapi/screens.rb
38
- - lib/zabbixapi/server.rb
39
- - lib/zabbixapi/templates.rb
40
- - lib/zabbixapi/triggers.rb
41
- - lib/zabbixapi/usergroups.rb
42
- - lib/zabbixapi/users.rb
43
47
  - lib/zabbixapi/version.rb
44
48
  - spec/localhost.rb
45
49
  - spec/run.rb
@@ -59,13 +63,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
59
63
  version: '0'
60
64
  segments:
61
65
  - 0
62
- hash: 2044765958080736329
66
+ hash: -2980579901879141751
63
67
  required_rubygems_version: !ruby/object:Gem::Requirement
64
68
  none: false
65
69
  requirements:
66
- - - ! '>='
70
+ - - ! '>'
67
71
  - !ruby/object:Gem::Version
68
- version: '0'
72
+ version: 1.3.1
69
73
  requirements: []
70
74
  rubyforge_project: zabbixapi
71
75
  rubygems_version: 1.8.24
@@ -1,83 +0,0 @@
1
- class ZabbixApi
2
- class Graphs
3
-
4
- def initialize(client)
5
- @client = client
6
- end
7
-
8
- def create(data)
9
- result = @client.api_request(:method => "graph.create", :params => [data])
10
- result.empty? ? nil : result['graphids'][0].to_i
11
- end
12
-
13
- def add(data)
14
- create(data)
15
- end
16
-
17
- def delete(data)
18
- result = @client.api_request(:method => "graph.delete", :params => [data])
19
- case @client.api_version
20
- when "1.3"
21
- result ? 1 : nil #return "true" or "false" for this api version
22
- else
23
- result.empty? ? nil : result['graphids'][0].to_i
24
- end
25
- end
26
-
27
- def destroy(data)
28
- delete(data)
29
- end
30
-
31
- def get_full_data(data)
32
- @client.api_request(:method => "graph.get", :params => {:search => {:name => data}, :output => "extend"})
33
- end
34
-
35
- def get_ids_by_host(data)
36
- ids = []
37
- result = @client.api_request(:method => "graph.get", :params => {:filter => {:host => data[:host]}, :output => "extend"})
38
- result.each do |graph|
39
- ids << graph['graphid']
40
- end
41
- ids
42
- end
43
-
44
- def get_items(data)
45
- @client.api_request(:method => "graphitem.get", :params => { :graphids => [data], :output => "extend" } )
46
- end
47
-
48
- def get_id(data)
49
- result = @client.api_request(:method => "graph.get", :params => {:filter => {:name=> data[:name]}, :output => "extend"})
50
- graphid = nil
51
- result.each { |graph| graphid = graph['graphid'].to_i if graph['name'] == data[:name] }
52
- graphid
53
- end
54
-
55
- def create_or_update(data)
56
- graphid = get_id(:name => data[:name], :templateid => data[:templateid])
57
- graphid ? _update(data.merge(:graphid => graphid)) : create(data)
58
- end
59
-
60
- def _update(data)
61
- data.delete(:name)
62
- update(data)
63
- end
64
-
65
- def get_or_create(data)
66
- unless graphid = get_id(:name => data[:name], :templateid => data[:templateid])
67
- graphid = create(data)
68
- end
69
- graphid
70
- end
71
-
72
- def update(data)
73
- case @client.api_version
74
- when "1.2"
75
- @client.api_request(:method => "graph.update", :params => data)
76
- else
77
- result = @client.api_request(:method => "graph.update", :params => data)
78
- result.empty? ? nil : result['graphids'][0].to_i
79
- end
80
- end
81
-
82
- end
83
- end