zabbixapi 0.4.5 → 0.4.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -63,7 +63,7 @@ class ZabbixApi
63
63
  def _request(body)
64
64
  puts "[DEBUG] Send request: #{body}" if @options[:debug]
65
65
  result = JSON.parse(http_request(body))
66
- raise "Server answer API error: #{result['error'].inspect} on request: #{body}" if result['error']
66
+ raise "Server answer API error:\n #{JSON.pretty_unparse(result['error'])}\n on request:\n #{JSON.pretty_unparse(JSON.parse(body))}" if result['error']
67
67
  result['result']
68
68
  end
69
69
 
@@ -46,7 +46,19 @@ class ZabbixApi
46
46
 
47
47
  def create_or_update(data)
48
48
  graphid = get_id(:name => data[:name], :templateid => data[:templateid])
49
- graphid ? update(data.merge(:graphid => graphid)) : create(data)
49
+ graphid ? _update(data.merge(:graphid => graphid)) : create(data)
50
+ end
51
+
52
+ def _update(data)
53
+ data.delete(:name)
54
+ update(data)
55
+ end
56
+
57
+ def get_or_create(data)
58
+ unless graphid = get_id(:name => data[:name], :templateid => data[:templateid])
59
+ graphid = create(data)
60
+ end
61
+ graphid
50
62
  end
51
63
 
52
64
  def update(data)
@@ -1,3 +1,3 @@
1
1
  class ZabbixApi
2
- VERSION = "0.4.5"
2
+ VERSION = "0.4.6"
3
3
  end
data/spec/localhost.rb CHANGED
@@ -234,6 +234,22 @@ describe ZabbixApi, "test_api" do
234
234
  ).should be_kind_of(Integer)
235
235
  end
236
236
 
237
+ it "GRAPH: Create or get" do
238
+ gitems = {
239
+ :itemid => zbx.items.get_id(:description => item),
240
+ :calc_fnc => "2",
241
+ :type => "0",
242
+ :periods_cnt => "5"
243
+ }
244
+ zbx.graphs.get_or_create(
245
+ :gitems => [gitems],
246
+ :show_triggers => "0",
247
+ :name => graph,
248
+ :width => "900",
249
+ :height => "200"
250
+ ).should be_kind_of(Integer)
251
+ end
252
+
237
253
  it "GRAPH: Find gititems" do
238
254
  zbx.graphs.get_items( zbx.graphs.get_id(:name => graph) )
239
255
  end
data/spec/run.rb CHANGED
@@ -24,6 +24,8 @@ graph = "graph"
24
24
 
25
25
  puts "### Zabbix API server version #{zbx.server.version} ###"
26
26
 
27
+ puts "### Zabbix API server version #{zbx.server.version} ###"
28
+
27
29
  describe ZabbixApi, "test_api" do
28
30
 
29
31
  it "SERVER: Get version api" do
@@ -42,7 +44,7 @@ describe ZabbixApi, "test_api" do
42
44
  zbx.hostgroups.get_id(:name => "#{hostgroup}______").should be_kind_of(NilClass)
43
45
  end
44
46
 
45
- it "HOSTGROUP: Get or create" do
47
+ it "HOSTGROUP: Create or get" do
46
48
  zbx.hostgroups.get_or_create(:name => hostgroup).should be_kind_of(Integer)
47
49
  end
48
50
 
@@ -230,6 +232,22 @@ describe ZabbixApi, "test_api" do
230
232
  ).should be_kind_of(Integer)
231
233
  end
232
234
 
235
+ it "GRAPH: Create or get" do
236
+ gitems = {
237
+ :itemid => zbx.items.get_id(:description => item),
238
+ :calc_fnc => "2",
239
+ :type => "0",
240
+ :periods_cnt => "5"
241
+ }
242
+ zbx.graphs.get_or_create(
243
+ :gitems => [gitems],
244
+ :show_triggers => "0",
245
+ :name => graph,
246
+ :width => "900",
247
+ :height => "200"
248
+ ).should be_kind_of(Integer)
249
+ end
250
+
233
251
  it "GRAPH: Find gititems" do
234
252
  zbx.graphs.get_items( zbx.graphs.get_id(:name => graph) )
235
253
  end
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.4.5
4
+ version: 0.4.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -56,7 +56,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
56
56
  version: '0'
57
57
  segments:
58
58
  - 0
59
- hash: -3133925998824390450
59
+ hash: -225172883572635253
60
60
  required_rubygems_version: !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements: