zabbixapi 0.5.8 → 0.5.9

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.
data/README.md CHANGED
@@ -1,13 +1,13 @@
1
1
  #Ruby Zabbix Api Module
2
2
 
3
- Simple and lightweight ruby module for work with zabbix api
3
+ Simple and lightweight ruby module for work with zabbix api
4
4
 
5
5
  [![Build Status](https://travis-ci.org/vadv/zabbixapi.png)](https://travis-ci.org/vadv/zabbixapi)
6
6
 
7
- #####Now worked with zabbix
7
+ #####Now worked with zabbix
8
8
  * 1.8.2 (api version 1.2)
9
9
  * 1.8.9 (api version 1.3)
10
- * 2.0.4 (api version 2.0.4) [unstable]
10
+ * 2.0.x (api version 1.4 -> 2.0.6) [unstable]
11
11
 
12
12
  ## Installation
13
13
  ```
@@ -25,7 +25,7 @@ zbx = ZabbixApi.connect(
25
25
  :user => 'Admin',
26
26
  :password => 'zabbix'
27
27
  )
28
- # use basic_auth
28
+ # use basic_auth
29
29
  zbx = ZabbixApi.connect(
30
30
  :url => 'http://localhost/zabbix/api_jsonrpc.php',
31
31
  :user => 'Admin',
@@ -83,7 +83,7 @@ zbx.items.update(
83
83
  puts zbx.items.get_full_data(:description => "item")
84
84
  ```
85
85
 
86
- ### Create host
86
+ ### Create host (1.8)
87
87
  ```ruby
88
88
  zbx.hosts.add(
89
89
  :host => "hostname",
@@ -99,6 +99,40 @@ zbx.hosts.create_or_update(
99
99
  )
100
100
  ```
101
101
 
102
+ ### Create host (2.0 and later)
103
+ ```ruby
104
+ zbx.hosts.create(
105
+ :host => host.fqdn,
106
+ :interfaces => [
107
+ {
108
+ :type => 1,
109
+ :main => 1,
110
+ :ip => '10.0.0.1',
111
+ :dns => 'server.example.org',
112
+ :port => 10050,
113
+ :useip => 0
114
+ }
115
+ ],
116
+ :groups => [ :groupid => zbx.hostgroups.get_id(:name => "hostgroup") ]
117
+ )
118
+
119
+ #or use:
120
+ zbx.hosts.create_or_update(
121
+ :host => host.fqdn,
122
+ :interfaces => [
123
+ {
124
+ :type => 1,
125
+ :main => 1,
126
+ :ip => '10.0.0.1',
127
+ :dns => 'server.example.org',
128
+ :port => 10050,
129
+ :useip => 0
130
+ }
131
+ ],
132
+ :groups => [ :groupid => zbx.hostgroups.get_id(:name => "hostgroup") ]
133
+ )
134
+ ```
135
+
102
136
  ### Update host
103
137
  ```ruby
104
138
  zbx.hosts.update(
@@ -117,7 +151,7 @@ zbx.hosts.delete zbx.hosts.get_id(:host => "hostname")
117
151
  ### Create graph
118
152
  ```ruby
119
153
  gitems = {
120
- :itemid => zbx.items.get_id(:description => "item"),
154
+ :itemid => zbx.items.get_id(:description => "item"),
121
155
  :calc_fnc => "2",
122
156
  :type => "0",
123
157
  :periods_cnt => "5"
@@ -135,12 +169,12 @@ zbx.graphs.create(
135
169
  ### Update graph
136
170
  ```ruby
137
171
  zbx.graphs.update(
138
- :graphid => zbx.graphs.get_id( :name => "graph"),
172
+ :graphid => zbx.graphs.get_id( :name => "graph"),
139
173
  :ymax_type => 1
140
174
  )
141
175
  #Also you can use:
142
176
  gitems = {
143
- :itemid => zbx.items.get_id(:description => item),
177
+ :itemid => zbx.items.get_id(:description => item),
144
178
  :calc_fnc => "3",
145
179
  :type => "0",
146
180
  :periods_cnt => "5"
@@ -173,7 +207,7 @@ zbx.templates.get_ids_by_host( :hostids => [zbx.hosts.get_id(:host => "hostname"
173
207
  # "Templatename" => "10",
174
208
  # "Templatename" => "1021"
175
209
  #}
176
- ```
210
+ ```
177
211
 
178
212
  ### Mass (Un)Link host with templates
179
213
  ```ruby
@@ -262,7 +296,7 @@ zbx.usergroups.set_perm(
262
296
  ```ruby
263
297
  zbx.mediatypes.create_or_update(
264
298
  :description => "mediatype",
265
- :type => 0, # 0 - Email, 1 - External script, 2 - SMS, 3 - Jabber, 100 - EzTexting,
299
+ :type => 0, # 0 - Email, 1 - External script, 2 - SMS, 3 - Jabber, 100 - EzTexting,
266
300
  :smtp_server => "127.0.0.1",
267
301
  :smtp_email => "zabbix@test.com"
268
302
  )
@@ -270,9 +304,9 @@ zbx.users.add_medias(
270
304
  :userids => [zbx.users.get_id(:name => "user")],
271
305
  :media => [
272
306
  {
273
- :mediatypeid => zbx.mediatypes.get_id(:description => "mediatype"),
274
- :sendto => "test@test",
275
- :active => 0,
307
+ :mediatypeid => zbx.mediatypes.get_id(:description => "mediatype"),
308
+ :sendto => "test@test",
309
+ :active => 0,
276
310
  :period => "1-7,00:00-24:00", # 1-7 days and 00:00-24:00 hours
277
311
  :severity => "56"
278
312
  }
@@ -283,7 +317,7 @@ zbx.users.add_medias(
283
317
  ### Custom queries
284
318
  ```ruby
285
319
  zbx.query(
286
- :method => "apiinfo.version",
320
+ :method => "apiinfo.version",
287
321
  :params => {}
288
322
  )
289
323
  ```
@@ -304,4 +338,4 @@ zbx.query(
304
338
  ## Zabbix documentation
305
339
 
306
340
  * [Zabbix Project Homepage](http://zabbix.com/)
307
- * [Zabbix Api docs](http://www.zabbix.com/documentation/1.8/api)
341
+ * [Zabbix Api docs](http://www.zabbix.com/documentation/1.8/api)
data/lib/zabbixapi.rb CHANGED
@@ -23,7 +23,7 @@ class ZabbixApi
23
23
  case @client.api_version
24
24
  when "1.3", "1.2"
25
25
  apidir = "1.8"
26
- when "1.4", "2.0.4", "2.0.5"
26
+ when "1.4", "2.0.4", "2.0.5", "2.0.6"
27
27
  apidir = "2.0"
28
28
  else
29
29
  raise "unknown Api version!"
@@ -16,11 +16,5 @@ class ZabbixApi
16
16
  def key
17
17
  "groupid"
18
18
  end
19
-
20
- def delete(data)
21
- result = @client.api_request(:method => "hostgroup.delete", :params => [:groupid => data])
22
- result.empty? ? nil : result['groupids'][0].to_i
23
- end
24
-
25
19
  end
26
20
  end
@@ -16,20 +16,10 @@ class ZabbixApi
16
16
  def default_options
17
17
  {
18
18
  :host => nil,
19
- :port => 10050,
20
- :status => 1,
21
- :useip => 1,
22
- :dns => '',
23
- :ip => '0.0.0.0',
24
- :proxy_hostid => 0,
19
+ :interfaces => [],
20
+ :status => 0,
21
+ :available => 1,
25
22
  :groups => [],
26
- :useipmi => 0,
27
- :ipmi_ip => '',
28
- :ipmi_port => 623,
29
- :ipmi_authtype => 0,
30
- :ipmi_privilege => 0,
31
- :ipmi_username => '',
32
- :ipmi_password => ''
33
23
  }
34
24
  end
35
25
 
@@ -45,18 +35,8 @@ class ZabbixApi
45
35
  end
46
36
 
47
37
  def create_or_update(data)
48
- # https://www.zabbix.com/documentation/2.2/manual/api/reference/host/create
49
- # interfaces :(
50
- data_new = data.clone
51
-
52
- data_new[:interfaces] = {}
53
-
54
- %w( type main useip ip dns port ).each do |key|
55
- data_new[:interfaces][key.to_sym] = data_new[key.to_sym]
56
- end
57
- puts "#{data_new.inspect}"
58
- hostid = get_id(:host => data_new[:host])
59
- hostid ? update(data_new.merge(:hostid => hostid)) : create(data_new)
38
+ hostid = get_id(:host => data[:host])
39
+ hostid ? update(data.merge(:hostid => hostid)) : create(data)
60
40
  end
61
41
 
62
42
  end
@@ -1,3 +1,3 @@
1
1
  class ZabbixApi
2
- VERSION = "0.5.8"
2
+ VERSION = "0.5.9"
3
3
  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.5.8
4
+ version: 0.5.9
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-04-18 00:00:00.000000000 Z
12
+ date: 2013-04-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json