zabbixapi 0.5.1 → 0.5.2a

Sign up to get free protection for your applications and to get access to all the features.
@@ -13,5 +13,59 @@ class ZabbixApi
13
13
  "description"
14
14
  end
15
15
 
16
+ def dump_by_id(data)
17
+ log "[DEBUG] Call dump_by_id with parametrs: #{data.inspect}"
18
+
19
+ @client.api_request(
20
+ :method => "trigger.get",
21
+ :params => {
22
+ :filter => {
23
+ key.to_sym => data[key.to_sym]
24
+ },
25
+ :output => "extend",
26
+ :select_items => "extend",
27
+ :select_functions => "extend",
28
+ :templated => 0
29
+ #:selectParentTemplates => "extend"
30
+ }
31
+ )
32
+ end
33
+
34
+ def update(data)
35
+ log "[DEBUG] Call update with parametrs: #{data.inspect}"
36
+
37
+ dump = {}
38
+ item_id = data[key.to_sym].to_i
39
+ dump_by_id(key.to_sym => data[key.to_sym]).each do |item|
40
+ dump = symbolize_keys(item) if item[key].to_i == data[key.to_sym].to_i
41
+ end
42
+
43
+ expression = dump[:items][0][:key_]+"."+dump[:functions][0][:function]+"("+dump[:functions][0][:parameter]+")"
44
+ dump[:expression] = dump[:expression].gsub(/{(\d*)}/,"{#{expression}}") #TODO ugly regexp
45
+ dump.delete(:functions)
46
+ dump.delete(:items)
47
+
48
+ old_expression = data[:expression]
49
+ data[:expression] = data[:expression].gsub(/{.*\:/,"{") #TODO ugly regexp
50
+ data.delete(:templateid)
51
+
52
+ log "[DEBUG] expression: #{expression}\n data: #{data[:expression]}"
53
+
54
+ if hash_equals?(dump, data)
55
+ log "[DEBUG] Equal keys #{dump} and #{data}, skip update"
56
+ item_id
57
+ else
58
+ data[:expression] = old_expression
59
+ data_update = array_flag ? [data] : data
60
+ data_update.delete(:triggerid)
61
+ # disable old trigger
62
+ log "[DEBUG] disable :" + @client.api_request(:method => "#{method_name}.update", :params => [{:triggerid=> data[:triggerid], :status => "1" }]).inspect
63
+ # create new trigger
64
+ result = @client.api_request(:method => "#{method_name}.update", :params => data_update)
65
+ parse_keys result
66
+ end
67
+
68
+ end
69
+
16
70
  end
17
71
  end
@@ -1,3 +1,3 @@
1
1
  class ZabbixApi
2
- VERSION = "0.5.1"
2
+ VERSION = "0.5.2a"
3
3
  end
data/spec/localhost.rb CHANGED
@@ -13,7 +13,7 @@ zbx = ZabbixApi.connect(
13
13
  :url => api_url,
14
14
  :user => api_login,
15
15
  :password => api_password,
16
- :debug => true
16
+ :debug => false
17
17
  )
18
18
 
19
19
  hostgroup = "hostgroup______1"
@@ -248,6 +248,36 @@ describe ZabbixApi do
248
248
  triggerid.should be_kind_of(Integer)
249
249
  end
250
250
 
251
+ it "TRIGGER: Create or update (not realy update)" do
252
+ zbx.triggers.create_or_update(
253
+ :description => trigger,
254
+ :expression => "{#{template}:proc.num[aaa].last(0)}<1",
255
+ :comments => "Bla-bla is faulty (disaster)",
256
+ :priority => 5,
257
+ :status => 0,
258
+ :templateid => 0,
259
+ :type => 0
260
+ ).should eq triggerid + 1
261
+ end
262
+
263
+
264
+ it "TRIGGER: Create or update (realy update)" do
265
+ zbx.triggers.create_or_update(
266
+ :description => trigger,
267
+ :expression => "{#{template}:proc.num[aaa].last(2)}<1",
268
+ :comments => "Bla-bla (2) is faulty (disaster)",
269
+ :priority => 5,
270
+ :status => 0,
271
+ :templateid => 0,
272
+ :type => 0
273
+ ).should eq triggerid + 1
274
+ end
275
+
276
+ it "TRIGGER: Get full data" do
277
+ dump = zbx.triggers.get_full_data(:description => trigger)
278
+ puts "dump: #{dump}"
279
+ end
280
+
251
281
  it "TRIGGER: Find" do
252
282
  zbx.triggers.get_id(:description => trigger).should eq triggerid + 1 # вау блять
253
283
  end
metadata CHANGED
@@ -1,8 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zabbixapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
5
- prerelease:
4
+ version: 0.5.2a
5
+ prerelease: 5
6
6
  platform: ruby
7
7
  authors:
8
8
  - Vasiliev D.V.
@@ -79,13 +79,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
79
79
  version: '0'
80
80
  segments:
81
81
  - 0
82
- hash: 3727156722468348692
82
+ hash: 4597790080164486813
83
83
  required_rubygems_version: !ruby/object:Gem::Requirement
84
84
  none: false
85
85
  requirements:
86
- - - ! '>='
86
+ - - ! '>'
87
87
  - !ruby/object:Gem::Version
88
- version: '0'
88
+ version: 1.3.1
89
89
  requirements: []
90
90
  rubyforge_project: zabbixapi
91
91
  rubygems_version: 1.8.24