zabbixapi 0.5.4 → 0.5.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -109,7 +109,7 @@ zbx.hosts.update(
109
109
  puts zbx.hosts.get_full_data(:host => "hostname")
110
110
  ```
111
111
 
112
- ### Delete host
112
+
113
113
  ```ruby
114
114
  zbx.hosts.delete zbx.hosts.get_id(:host => "hostname")
115
115
  ```
@@ -228,6 +228,21 @@ zbx.screens.get_or_create_for_host(
228
228
  )
229
229
  ```
230
230
 
231
+ ### Delete screen ###
232
+ ```ruby
233
+ zbx.screens.delete(
234
+ :screen_id => 1, # or screen_id => [1, 2]
235
+ )
236
+ ```
237
+
238
+ or
239
+
240
+ ```ruby
241
+ zbx.screens.delete(
242
+ :screen_name => "foo screen", # or screen_name => ["foo screen", "bar screen"]
243
+ )
244
+ ````
245
+
231
246
  ### Create UserGroup, add user and set permission ###
232
247
  ```ruby
233
248
  zbx.usergroups.get_or_create(:name => "Some user group")
@@ -29,9 +29,21 @@ class ZabbixApi
29
29
 
30
30
  def get_ids_by_host(data)
31
31
  ids = []
32
+ graphs = Hash.new
32
33
  result = @client.api_request(:method => "graph.get", :params => {:filter => {:host => data[:host]}, :output => "extend"})
33
34
  result.each do |graph|
34
- ids << graph['graphid']
35
+ num = graph['graphid']
36
+ name = graph['name']
37
+ graphs[name] = num
38
+ filter = data[:filter]
39
+
40
+ unless filter.nil?
41
+ if /#{filter}/ =~ name
42
+ ids.push(graphs[name])
43
+ end
44
+ else
45
+ ids.push(graphs[name])
46
+ end
35
47
  end
36
48
  ids
37
49
  end
@@ -29,18 +29,40 @@ class ZabbixApi
29
29
  end
30
30
 
31
31
  def delete(data)
32
- result = @client.api_request(:method => "screen.delete", :params => [data] )
32
+ screen_name = data[:screen_name]
33
+ screen_id = data[:screen_id]
34
+
35
+ unless screen_name.nil?
36
+ unless screen_name.instance_of?(Array)
37
+ screen_id = get_id(:name => screen_name)
38
+ else
39
+ screen_id = []
40
+ screen_name.each do |name|
41
+ screen_id << get_id(:name => name)
42
+ end
43
+ end
44
+ end
45
+
46
+ unless screen_id.instance_of?(Array)
47
+ screen_id = [screen_id, screen_id]
48
+ end
49
+
50
+ result = @client.api_request(:method => "screen.delete", :params => screen_id)
33
51
  result.empty? ? nil : result['screenids'][0].to_i
34
52
  end
35
53
 
36
54
  def get_or_create_for_host(data)
37
- screen_name = data[:host].to_s + "_graphs"
55
+ screen_name = data[:screen_name]
38
56
  graphids = data[:graphids]
39
57
  screenitems = []
40
58
  hsize = data[:hsize] || 3
41
59
  valign = data[:valign] || 2
42
60
  halign = data[:halign] || 2
43
- vsize = data[:vsize] || ((graphids.size/hsize) + 1).to_i
61
+ rowspan = data[:rowspan] || 0
62
+ colspan = data[:colspan] || 0
63
+ height = data[:height] || 320 # default 320
64
+ width = data[:width] || 200 # default 200
65
+ vsize = data[:vsize] || (graphids.size/hsize).to_i
44
66
  screenid = get_id(:name => screen_name)
45
67
  unless screenid
46
68
  # Create screen
@@ -50,8 +72,12 @@ class ZabbixApi
50
72
  :resourceid => graphid,
51
73
  :x => (index % hsize).to_i,
52
74
  :y => (index % graphids.size/hsize).to_i,
53
- :valign =>valign,
54
- :halign =>halign
75
+ :valign => valign,
76
+ :halign => halign,
77
+ :rowspan => rowspan,
78
+ :colspan => colspan,
79
+ :height => height,
80
+ :width => width
55
81
  }
56
82
  end
57
83
  screenid = create(
@@ -37,10 +37,12 @@ class ZabbixApi
37
37
  graphs[name] = num
38
38
  filter = data[:filter]
39
39
 
40
- unless #{filter}
40
+ unless filter.nil?
41
41
  if /#{filter}/ =~ name
42
42
  ids.push(graphs[name])
43
43
  end
44
+ else
45
+ ids.push(graphs[name])
44
46
  end
45
47
  end
46
48
  ids
@@ -29,7 +29,25 @@ class ZabbixApi
29
29
  end
30
30
 
31
31
  def delete(data)
32
- result = @client.api_request(:method => "screen.delete", :params => data)
32
+ screen_name = data[:screen_name]
33
+ screen_id = data[:screen_id]
34
+
35
+ unless screen_name.nil?
36
+ unless screen_name.instance_of?(Array)
37
+ screen_id = get_id(:name => screen_name)
38
+ else
39
+ screen_id = []
40
+ screen_name.each do |name|
41
+ screen_id << get_id(:name => name)
42
+ end
43
+ end
44
+ end
45
+
46
+ unless screen_id.instance_of?(Array)
47
+ screen_id = [screen_id, screen_id]
48
+ end
49
+
50
+ result = @client.api_request(:method => "screen.delete", :params => screen_id)
33
51
  result.empty? ? nil : result['screenids'][0].to_i
34
52
  end
35
53
 
@@ -48,10 +48,19 @@ class ZabbixApi
48
48
 
49
49
  def http_request(body)
50
50
  uri = URI.parse(@options[:url])
51
+
51
52
  if @proxy_uri.nil?
52
53
  http = Net::HTTP.Proxy(@proxy_host, @proxy_port, @proxy_user, @proxy_pass).new(uri.host, uri.port)
54
+ if uri.port == 443
55
+ http.use_ssl = true
56
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
57
+ end
53
58
  else
54
59
  http = Net::HTTP.new(uri.host, uri.port)
60
+ if uri.port == 443
61
+ http.use_ssl = true
62
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
63
+ end
55
64
  end
56
65
  request = Net::HTTP::Post.new(uri.request_uri)
57
66
  request.basic_auth @options[:http_user], @options[:http_password] if @options[:http_user]
@@ -1,3 +1,3 @@
1
1
  class ZabbixApi
2
- VERSION = "0.5.4"
2
+ VERSION = "0.5.6"
3
3
  end
data/spec/run.rb CHANGED
@@ -19,6 +19,7 @@ template = "template"
19
19
  application = "application"
20
20
  item = "item"
21
21
  host = "hostname"
22
+ screen_name = "screen_name"
22
23
  trigger = "trigger"
23
24
  user = "user"
24
25
  user2 = "user2"
@@ -325,7 +326,7 @@ describe ZabbixApi do
325
326
 
326
327
  it "SCREEN: Get or create for host" do
327
328
  screenid = zbx.screens.get_or_create_for_host(
328
- :host => host,
329
+ :screen_name => screen_name,
329
330
  :graphids => zbx.graphs.get_ids_by_host(:host => host)
330
331
  )
331
332
  screenid.should be_kind_of(Integer)
@@ -339,9 +340,7 @@ describe ZabbixApi do
339
340
  end
340
341
 
341
342
  it "SCREEN: Delete" do
342
- zbx.screens.delete(
343
- zbx.screens.get_id(:name => "#{host}_graphs")
344
- ).should eq screenid
343
+ zbx.screens.delete(:screen_id => screenid).should eq screenid
345
344
  end
346
345
 
347
346
  it "GRAPH: Delete" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zabbixapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.4
4
+ version: 0.5.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-30 00:00:00.000000000 Z
12
+ date: 2013-02-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
@@ -96,9 +96,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
96
96
  - - ! '>='
97
97
  - !ruby/object:Gem::Version
98
98
  version: '0'
99
- segments:
100
- - 0
101
- hash: -402697987343714468
102
99
  required_rubygems_version: !ruby/object:Gem::Requirement
103
100
  none: false
104
101
  requirements:
@@ -107,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
104
  version: '0'
108
105
  requirements: []
109
106
  rubyforge_project: zabbixapi
110
- rubygems_version: 1.8.24
107
+ rubygems_version: 1.8.25
111
108
  signing_key:
112
109
  specification_version: 3
113
110
  summary: Realization for Zabbix API.