zabbixapi 3.1.0 → 3.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +9 -0
- data/CHANGELOG.md +5 -0
- data/{LICENSE → LICENSE.md} +1 -1
- data/README.md +53 -569
- data/lib/zabbixapi.rb +102 -65
- data/lib/zabbixapi/basic/basic_alias.rb +21 -4
- data/lib/zabbixapi/basic/basic_func.rb +56 -23
- data/lib/zabbixapi/basic/basic_init.rb +21 -4
- data/lib/zabbixapi/basic/basic_logic.rb +75 -18
- data/lib/zabbixapi/classes/actions.rb +8 -4
- data/lib/zabbixapi/classes/applications.rb +20 -6
- data/lib/zabbixapi/classes/configurations.rb +23 -17
- data/lib/zabbixapi/classes/errors.rb +2 -4
- data/lib/zabbixapi/classes/graphs.rb +65 -15
- data/lib/zabbixapi/classes/hostgroups.rb +12 -4
- data/lib/zabbixapi/classes/hosts.rb +36 -10
- data/lib/zabbixapi/classes/httptests.rb +24 -4
- data/lib/zabbixapi/classes/items.rb +24 -5
- data/lib/zabbixapi/classes/maintenance.rb +8 -4
- data/lib/zabbixapi/classes/mediatypes.rb +20 -13
- data/lib/zabbixapi/classes/proxies.rb +29 -8
- data/lib/zabbixapi/classes/screens.rb +41 -25
- data/lib/zabbixapi/classes/server.rb +8 -4
- data/lib/zabbixapi/classes/templates.rb +46 -43
- data/lib/zabbixapi/classes/triggers.rb +43 -16
- data/lib/zabbixapi/classes/unusable.rb +0 -2
- data/lib/zabbixapi/classes/usergroups.rb +33 -26
- data/lib/zabbixapi/classes/usermacros.rb +137 -31
- data/lib/zabbixapi/classes/users.rb +32 -10
- data/lib/zabbixapi/classes/valuemaps.rb +50 -0
- data/lib/zabbixapi/client.rb +61 -22
- data/lib/zabbixapi/version.rb +1 -1
- data/zabbixapi.gemspec +26 -23
- metadata +25 -73
- data/.gitignore +0 -7
- data/.rspec +0 -1
- data/.travis.yml +0 -41
- data/Gemfile +0 -3
- data/Gemfile.lock +0 -36
- data/Rakefile +0 -1
- data/json-1.x.Gemfile +0 -4
- data/json-1.x.Gemfile.lock +0 -28
- data/spec/action.rb +0 -89
- data/spec/application.rb +0 -83
- data/spec/basic_func.rb +0 -4
- data/spec/configuration.rb +0 -122
- data/spec/graph.rb +0 -135
- data/spec/host.rb +0 -176
- data/spec/hostgroup.rb +0 -55
- data/spec/httptest.rb +0 -136
- data/spec/item.rb +0 -134
- data/spec/maintenance.rb +0 -81
- data/spec/mediatype.rb +0 -50
- data/spec/query.rb +0 -18
- data/spec/screen.rb +0 -88
- data/spec/script.rb +0 -123
- data/spec/server.rb +0 -15
- data/spec/spec_helper.rb +0 -21
- data/spec/template.rb +0 -148
- data/spec/trigger.rb +0 -103
- data/spec/user.rb +0 -116
- data/spec/usergroup.rb +0 -85
- data/spec/usermacro.rb +0 -190
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b599a8aaa780e38de4d2e21751373fd6395844cb
|
4
|
+
data.tar.gz: 54ac862491660755bec3da1543b1900e55ab5728
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d702d07347f1c43801cb3382a86736481665df41cc8d32d07688077fc01e3ab778ae7956bbcbe9d01f5934638221d501d17e7ae5fe375f8715e9023be8785c9b
|
7
|
+
data.tar.gz: 435776e8bf0f5a62af5908a377036f144f6816872dbc457daf5e7bafb133cf712d8227d46bfd3c7f256be5c8fea79f7f2f8b5f17d428a7663539fa05d1aeca89
|
data/.yardopts
ADDED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
## 3.2.0
|
2
|
+
[PR #77](https://github.com/express42/zabbixapi/pull/77) Add support for Valuemap (Thanks @julienlevasseur)
|
3
|
+
|
4
|
+
[PR #80](https://github.com/express42/zabbixapi/pull/80) Hide password then raising error (Thanks @bbaugher)
|
5
|
+
|
1
6
|
## 3.1.0
|
2
7
|
[PR #68](https://github.com/express42/zabbixapi/pull/68) Add support for scripts (Thanx @jrbeilke)
|
3
8
|
|
data/{LICENSE → LICENSE.md}
RENAMED
data/README.md
CHANGED
@@ -1,586 +1,60 @@
|
|
1
1
|
# Ruby Zabbix Api Module
|
2
2
|
|
3
|
-
|
3
|
+
[![Gem Version](http://img.shields.io/gem/v/zabbixapi.svg)][gem]
|
4
|
+
[![Build Status](http://img.shields.io/travis/express42/zabbixapi.svg)][travis]
|
4
5
|
|
5
|
-
[
|
6
|
+
[gem]: https://rubygems.org/gems/zabbixapi
|
7
|
+
[travis]: https://travis-ci.org/express42/zabbixapi
|
6
8
|
|
7
|
-
|
8
|
-
* 1.8.2 (api version 1.2) /zabbixapi 0.6.x [branch zabbix1.8](https://github.com/express42/zabbixapi/tree/zabbix1.8)
|
9
|
-
* 1.8.9 (api version 1.3) /zabbixapi 0.6.x [branch zabbix1.8](https://github.com/express42/zabbixapi/tree/zabbix1.8)
|
10
|
-
* 2.0.x (api version 1.4 -> 2.0.10) /zabbixapi 2.0.x [branch zabbix2.0](https://github.com/express42/zabbixapi/tree/zabbix2.0)
|
11
|
-
* 2.2.x (api version 2.2.x) /zabbixapi 2.2.x [branch zabbix2.2](https://github.com/express42/zabbixapi/tree/zabbix2.2)
|
12
|
-
* 2.4.x (api version 2.2.x) /zabbixapi 2.4.x [master](https://github.com/express42/zabbixapi/)
|
13
|
-
* 3.0.x (api version 3.0.x) /zabbixapi 2.4.x [master](https://github.com/express42/zabbixapi/)
|
14
|
-
* 3.2.x (api version 3.2.x) /zabbixapi 2.4.x [master](https://github.com/express42/zabbixapi/)
|
15
|
-
|
16
|
-
Because Zabbix 3.0 is a main branch of Zabbix, so master of zabbixapi supports this version of zabbix.
|
17
|
-
|
18
|
-
## Version policy
|
19
|
-
|
20
|
-
Zabbixapi has next version policy:
|
21
|
-
* for zabbix 1.8.9 and below you should use zabbixapi 0.6.x
|
22
|
-
* for zabbix 2.0.x you should use zabbixapi 2.0.y
|
23
|
-
* for zabbix 2.2.x you should use zabbixapi 2.2.y
|
24
|
-
* for zabbix 2.4.x you should use zabbixapi 2.4.y
|
25
|
-
* for zabbix 3.0.x you should use zabbixapi 3.0.y and ruby >= 2
|
26
|
-
|
27
|
-
The PATCH (third digit) version of zabbixapi should not correspond to PATCH version of zabbix, for example
|
28
|
-
zabbixapi-2.0.x should works with all version of zabbix 2.0.y
|
29
|
-
|
30
|
-
We support only two last versions of zabbix (2.4 and 3.0), so you should consider zabbixapi 0.6.x, 2.0.x and 2.2.x depricated.
|
9
|
+
Simple and lightweight ruby module for working with [Zabbix][Zabbix] via the [Zabbix API][Zabbix API]
|
31
10
|
|
32
11
|
## Installation
|
33
|
-
|
34
|
-
gem install zabbixapi
|
35
|
-
```
|
36
|
-
|
37
|
-
## Getting Started
|
38
|
-
|
39
|
-
### Connect
|
40
|
-
```ruby
|
41
|
-
require "zabbixapi"
|
42
|
-
|
43
|
-
zbx = ZabbixApi.connect(
|
44
|
-
:url => 'http://localhost/zabbix/api_jsonrpc.php',
|
45
|
-
:user => 'Admin',
|
46
|
-
:password => 'zabbix'
|
47
|
-
)
|
48
|
-
# use basic_auth
|
49
|
-
zbx = ZabbixApi.connect(
|
50
|
-
:url => 'http://localhost/zabbix/api_jsonrpc.php',
|
51
|
-
:user => 'Admin',
|
52
|
-
:password => 'zabbix',
|
53
|
-
:http_password => 'foo',
|
54
|
-
:http_user => 'bar'
|
55
|
-
)
|
56
|
-
```
|
57
|
-
### Create Hostgroup
|
58
|
-
```ruby
|
59
|
-
zbx.hostgroups.create(:name => "hostgroup")
|
60
|
-
```
|
61
|
-
|
62
|
-
### Create Template
|
63
|
-
```ruby
|
64
|
-
zbx.templates.create(
|
65
|
-
:host => "template",
|
66
|
-
:groups => [:groupid => zbx.hostgroups.get_id(:name => "hostgroup")]
|
67
|
-
)
|
68
|
-
```
|
69
|
-
|
70
|
-
### Create Application
|
71
|
-
```ruby
|
72
|
-
zbx.applications.create(
|
73
|
-
:name => application,
|
74
|
-
:hostid => zbx.templates.get_id(:host => "template")
|
75
|
-
)
|
76
|
-
```
|
77
|
-
|
78
|
-
### Create Item
|
79
|
-
```ruby
|
80
|
-
zbx.items.create(
|
81
|
-
:name => "item",
|
82
|
-
:description => "item",
|
83
|
-
:key_ => "proc.num[aaa]",
|
84
|
-
:type => 6,
|
85
|
-
:value_type => 6,
|
86
|
-
:hostid => zbx.templates.get_id(:host => "template"),
|
87
|
-
:applications => [zbx.applications.get_id(:name => "application")]
|
88
|
-
)
|
89
|
-
# or use (lib merge json):
|
90
|
-
zbx.items.create_or_update(
|
91
|
-
:name => "item",
|
92
|
-
:description => "item",
|
93
|
-
:key_ => "proc.num[aaa]",
|
94
|
-
:type => 6,
|
95
|
-
:value_type => 4,
|
96
|
-
:hostid => zbx.templates.get_id(:host => "template"),
|
97
|
-
:applications => [zbx.applications.get_id(:name => "application")]
|
98
|
-
)
|
99
|
-
```
|
100
|
-
|
101
|
-
### Update Item
|
102
|
-
```ruby
|
103
|
-
zbx.items.update(
|
104
|
-
:itemid => zbx.items.get_id(:name => "item"),
|
105
|
-
:status => 0
|
106
|
-
)
|
107
|
-
#You can check item:
|
108
|
-
puts zbx.items.get_full_data(:name => "item")
|
109
|
-
```
|
110
|
-
|
111
|
-
### Create host
|
112
|
-
```ruby
|
113
|
-
zbx.hosts.create(
|
114
|
-
:host => host.fqdn,
|
115
|
-
:interfaces => [
|
116
|
-
{
|
117
|
-
:type => 1,
|
118
|
-
:main => 1,
|
119
|
-
:ip => '10.0.0.1',
|
120
|
-
:dns => 'server.example.org',
|
121
|
-
:port => 10050,
|
122
|
-
:useip => 0
|
123
|
-
}
|
124
|
-
],
|
125
|
-
:groups => [ :groupid => zbx.hostgroups.get_id(:name => "hostgroup") ]
|
126
|
-
)
|
127
|
-
|
128
|
-
#or use:
|
129
|
-
zbx.hosts.create_or_update(
|
130
|
-
:host => host.fqdn,
|
131
|
-
:interfaces => [
|
132
|
-
{
|
133
|
-
:type => 1,
|
134
|
-
:main => 1,
|
135
|
-
:ip => '10.0.0.1',
|
136
|
-
:dns => 'server.example.org',
|
137
|
-
:port => 10050,
|
138
|
-
:useip => 0
|
139
|
-
}
|
140
|
-
],
|
141
|
-
:groups => [ :groupid => zbx.hostgroups.get_id(:name => "hostgroup") ]
|
142
|
-
)
|
143
|
-
```
|
144
|
-
|
145
|
-
### Update host
|
146
|
-
```ruby
|
147
|
-
zbx.hosts.update(
|
148
|
-
:hostid => zbx.hosts.get_id(:host => "hostname"),
|
149
|
-
:status => 0
|
150
|
-
)
|
151
|
-
#You can check host:
|
152
|
-
puts zbx.hosts.get_full_data(:host => "hostname")
|
153
|
-
|
154
|
-
# Zabbixapi checks that new object differ from one in zabbix. But if you
|
155
|
-
# want to update nested arguments (like interfaces), you should use second argument.
|
156
|
-
# For example:
|
157
|
-
|
158
|
-
zbx.hosts.update({
|
159
|
-
:hostid => zbx.hosts.get_id(:host => "hostname"),
|
160
|
-
:interfaces => [
|
161
|
-
{
|
162
|
-
:type => 1,
|
163
|
-
:main => 1,
|
164
|
-
:ip => '10.0.0.1',
|
165
|
-
:dns => 'server.example.org',
|
166
|
-
:port => 10050,
|
167
|
-
:useip => 0
|
168
|
-
}
|
169
|
-
]}, true)
|
170
|
-
|
171
|
-
|
172
|
-
```
|
173
|
-
|
174
|
-
|
175
|
-
```ruby
|
176
|
-
zbx.hosts.delete zbx.hosts.get_id(:host => "hostname")
|
177
|
-
```
|
178
|
-
|
179
|
-
### Create graph
|
180
|
-
```ruby
|
181
|
-
gitems = {
|
182
|
-
:itemid => zbx.items.get_id(:name => "item"),
|
183
|
-
:calc_fnc => "2",
|
184
|
-
:type => "0",
|
185
|
-
:periods_cnt => "5"
|
186
|
-
}
|
187
|
-
|
188
|
-
zbx.graphs.create(
|
189
|
-
:gitems => [gitems],
|
190
|
-
:show_triggers => "0",
|
191
|
-
:name => "graph",
|
192
|
-
:width => "900",
|
193
|
-
:height => "200",
|
194
|
-
:hostid => zbx.templates.get_id(:host => "template")
|
195
|
-
)
|
196
|
-
```
|
12
|
+
gem install zabbixapi
|
197
13
|
|
198
|
-
|
199
|
-
|
200
|
-
zbx.graphs.update(
|
201
|
-
:graphid => zbx.graphs.get_id(:name => "graph"),
|
202
|
-
:ymax_type => 1
|
203
|
-
)
|
204
|
-
#Also you can use:
|
205
|
-
gitems = {
|
206
|
-
:itemid => zbx.items.get_id(:name => "item"),
|
207
|
-
:calc_fnc => "3",
|
208
|
-
:type => "0",
|
209
|
-
:periods_cnt => "5"
|
210
|
-
}
|
211
|
-
zbx.graphs.create_or_update(
|
212
|
-
:gitems => [gitems],
|
213
|
-
:show_triggers => "1",
|
214
|
-
:name => graph,
|
215
|
-
:width => "900",
|
216
|
-
:height => "200",
|
217
|
-
:hostid => zbx.templates.get_id(:host => "template")
|
218
|
-
)
|
219
|
-
```
|
220
|
-
### Get ids by host ###
|
221
|
-
```ruby
|
222
|
-
zbx.graphs.get_ids_by_host(:host => "hostname")
|
223
|
-
#You can filter graph name:
|
224
|
-
zbx.graphs.get_ids_by_host(:host => "hostname", filter => "CPU")
|
225
|
-
```
|
14
|
+
## Documentation
|
15
|
+
[http://rdoc.info/gems/zabbixapi][documentation]
|
226
16
|
|
227
|
-
|
228
|
-
```ruby
|
229
|
-
zbx.graphs.delete(zbx.graphs.get_id(:name => "graph"))
|
230
|
-
```
|
17
|
+
[documentation]: http://rdoc.info/gems/zabbixapi
|
231
18
|
|
232
|
-
|
233
|
-
|
234
|
-
zbx.templates.get_ids_by_host( :hostids => [zbx.hosts.get_id(:host => "hostname")] )
|
235
|
-
#returned array:
|
236
|
-
#[
|
237
|
-
# "10",
|
238
|
-
# "1021"
|
239
|
-
#]
|
240
|
-
```
|
19
|
+
## Examples
|
20
|
+
[https://github.com/express42/zabbixapi/tree/master/examples][examples]
|
241
21
|
|
242
|
-
|
243
|
-
```ruby
|
244
|
-
zbx.templates.mass_add(
|
245
|
-
:hosts_id => [zbx.hosts.get_id(:host => "hostname")],
|
246
|
-
:templates_id => [111, 214]
|
247
|
-
)
|
248
|
-
zbx.templates.mass_remove(
|
249
|
-
:hosts_id => [zbx.hosts.get_id(:host => "hostname")],
|
250
|
-
:templates_id => [111, 214]
|
251
|
-
)
|
252
|
-
```
|
22
|
+
[examples]: https://github.com/express42/zabbixapi/tree/master/examples
|
253
23
|
|
254
|
-
|
255
|
-
|
256
|
-
zbx.triggers.create(
|
257
|
-
:description => "trigger",
|
258
|
-
:expression => "{template:proc.num[aaa].last(0)}<1",
|
259
|
-
:comments => "Bla-bla is faulty (disaster)",
|
260
|
-
:priority => 5,
|
261
|
-
:status => 0,
|
262
|
-
:hostid => zbx.templates.get_id(:host => "template"),
|
263
|
-
:type => 0,
|
264
|
-
:tags => [
|
265
|
-
{
|
266
|
-
:tag => "process",
|
267
|
-
:value => "aaa"
|
268
|
-
},
|
269
|
-
{
|
270
|
-
:tag => "error",
|
271
|
-
:value => ""
|
272
|
-
}
|
273
|
-
]
|
274
|
-
)
|
275
|
-
```
|
24
|
+
## Version Policy
|
25
|
+
We support only two last versions of zabbix (3.0 and 3.2), so you should consider zabbixapi 0.6.x, 2.0.x, 2.2.x, and 2.4.x deprecated.
|
276
26
|
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
},
|
285
|
-
:templated => true,
|
286
|
-
:output => "extend"
|
287
|
-
}
|
288
|
-
)
|
289
|
-
```
|
27
|
+
* Zabbix 1.8.2 (api version 1.2) | zabbixapi 0.6.x | [branch zabbix1.8](https://github.com/express42/zabbixapi/tree/zabbix1.8)
|
28
|
+
* Zabbix 1.8.9 (api version 1.3) | zabbixapi 0.6.x | [branch zabbix1.8](https://github.com/express42/zabbixapi/tree/zabbix1.8)
|
29
|
+
* Zabbix 2.0.x (api version 1.4 -> 2.0.10) | zabbixapi 2.0.x | [branch zabbix2.0](https://github.com/express42/zabbixapi/tree/zabbix2.0)
|
30
|
+
* Zabbix 2.2.x (api version 2.2.x) | zabbixapi 2.2.x | [branch zabbix2.2](https://github.com/express42/zabbixapi/tree/zabbix2.2)
|
31
|
+
* Zabbix 2.4.x (api version 2.2.x) | zabbixapi 2.4.x | [branch zabbix2.4](https://github.com/express42/zabbixapi/tree/zabbix2.4)
|
32
|
+
* Zabbix 3.0.x (api version 3.0.x) | zabbixapi 3.0.x | [master](https://github.com/express42/zabbixapi/)
|
33
|
+
* Zabbix 3.2.x (api version 3.2.x) | zabbixapi 3.0.x | [master](https://github.com/express42/zabbixapi/)
|
290
34
|
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
:name => "web scenario",
|
295
|
-
:hostid => zbx.templates.get_id(:host => "template"),
|
296
|
-
:applicationid => zbx.applications.get_id(:name => "application"),
|
297
|
-
:steps => [
|
298
|
-
{
|
299
|
-
:name => "step",
|
300
|
-
:url => "http://localhost/zabbix/",
|
301
|
-
:status_codes => 200,
|
302
|
-
:no => 1
|
303
|
-
}
|
304
|
-
]
|
305
|
-
)
|
306
|
-
# or use (lib merge json):
|
307
|
-
zbx.httptests.create_or_update(
|
308
|
-
:name => "web scenario",
|
309
|
-
:hostid => zbx.templates.get_id(:host => "template"),
|
310
|
-
:applicationid => zbx.applications.get_id(:name => "application"),
|
311
|
-
:steps => [
|
312
|
-
{
|
313
|
-
:name => "step",
|
314
|
-
:url => "http://localhost/zabbix/",
|
315
|
-
:status_codes => 200,
|
316
|
-
:no => 1
|
317
|
-
},
|
318
|
-
{
|
319
|
-
:name => "step 2",
|
320
|
-
:url => "http://localhost/zabbix/index.php",
|
321
|
-
:status_codes => 200,
|
322
|
-
:no => 2
|
323
|
-
}
|
324
|
-
]
|
325
|
-
)
|
326
|
-
```
|
35
|
+
## Supported Ruby Versions
|
36
|
+
This library aims to support and is [tested against][travis] the following Ruby
|
37
|
+
versions:
|
327
38
|
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
#You can check web scenario:
|
335
|
-
puts zbx.httptests.get_full_data(:name => "web scenario")
|
39
|
+
* Ruby 2.0
|
40
|
+
* Ruby 2.1
|
41
|
+
* Ruby 2.2
|
42
|
+
* Ruby 2.3
|
43
|
+
* Ruby 2.4
|
44
|
+
* JRuby 9.1.6.0
|
336
45
|
|
337
|
-
|
338
|
-
```ruby
|
339
|
-
zbx.actions.create(
|
340
|
-
:name => "trigger action",
|
341
|
-
:eventsource => '0', # event source is a triggerid
|
342
|
-
:status => '0', # action is enabled
|
343
|
-
:esc_period => '120', # how long each step should take
|
344
|
-
:def_shortdata => "Email header",
|
345
|
-
:def_longdata => "Email content",
|
346
|
-
:maintenance_mode => '1',
|
347
|
-
:filter => {
|
348
|
-
:evaltype => '1', # perform 'and' between the conditions
|
349
|
-
:conditions => [
|
350
|
-
{
|
351
|
-
:conditiontype => '3', # trigger name
|
352
|
-
:operator => '2', # like
|
353
|
-
:value => 'pattern' # the pattern
|
354
|
-
},
|
355
|
-
{
|
356
|
-
:conditiontype => '4', # trigger severity
|
357
|
-
:operator => '5', # >=
|
358
|
-
:value => '3' # average
|
359
|
-
}
|
360
|
-
]
|
361
|
-
},
|
362
|
-
:operations => [
|
363
|
-
{
|
364
|
-
:operationtype => '0', # send message
|
365
|
-
:opmessage_grp => [ # who the message will be sent to
|
366
|
-
{
|
367
|
-
:usrgrpid => '2'
|
368
|
-
}
|
369
|
-
],
|
370
|
-
:opmessage => {
|
371
|
-
:default_msg => '0', # use default message
|
372
|
-
:mediatypeid => '1' # email id
|
373
|
-
}
|
374
|
-
}
|
375
|
-
],
|
376
|
-
:recovery_operations => [
|
377
|
-
{
|
378
|
-
:operationtype => '11', # send recovery message
|
379
|
-
:opmessage_grp => [ # who the message will be sent to
|
380
|
-
{
|
381
|
-
:usrgrpid => '2'
|
382
|
-
}
|
383
|
-
],
|
384
|
-
:opmessage => {
|
385
|
-
:default_msg => '0', # use default message
|
386
|
-
:mediatypeid => '1' # email id
|
387
|
-
}
|
388
|
-
}
|
389
|
-
]
|
390
|
-
)
|
391
|
-
# In Zabbix 3.2 and higher actions now have a maintenance_mode property which pauses notifications during host maintenance
|
392
|
-
# A separate action condition for Maintenance status = not in “maintenance” is no longer needed
|
393
|
-
```
|
46
|
+
If something doesn't work on one of these versions, it's a bug.
|
394
47
|
|
395
|
-
|
396
|
-
|
397
|
-
zbx.users.create(
|
398
|
-
:alias => "Test user",
|
399
|
-
:name => "username",
|
400
|
-
:surname => "usersername",
|
401
|
-
:passwd => "password"
|
402
|
-
)
|
403
|
-
```
|
48
|
+
This library may inadvertently work (or seem to work) on other Ruby versions,
|
49
|
+
however support will only be provided for the versions listed above.
|
404
50
|
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
zbx.graphs.delete(zbx.graphs.get_id(:name => "graph"))
|
413
|
-
```
|
414
|
-
|
415
|
-
### Create screen for host ###
|
416
|
-
```ruby
|
417
|
-
zbx.screens.get_or_create_for_host(
|
418
|
-
:screen_name => "screen_name",
|
419
|
-
:graphids => zbx.graphs.get_ids_by_host(:host => "hostname")
|
420
|
-
)
|
421
|
-
```
|
422
|
-
|
423
|
-
### Delete screen ###
|
424
|
-
```ruby
|
425
|
-
zbx.screens.delete(
|
426
|
-
:screen_id => 1, # or screen_id => [1, 2]
|
427
|
-
)
|
428
|
-
```
|
429
|
-
|
430
|
-
or
|
431
|
-
|
432
|
-
```ruby
|
433
|
-
zbx.screens.delete(
|
434
|
-
:screen_name => "foo screen", # or screen_name => ["foo screen", "bar screen"]
|
435
|
-
)
|
436
|
-
````
|
437
|
-
|
438
|
-
### Create UserGroup, add user and set permission ###
|
439
|
-
```ruby
|
440
|
-
zbx.usergroups.get_or_create(:name => "Some user group")
|
441
|
-
zbx.usergroups.add_user(
|
442
|
-
:usrgrpids => [zbx.usergroups.get_id(:name => "Some user group")],
|
443
|
-
:userids => [zbx.users.get_id(:alias => "user")]
|
444
|
-
)
|
445
|
-
# set write and read permissions for UserGroup on all hostgroups
|
446
|
-
zbx.usergroups.set_perms(
|
447
|
-
:usrgrpid => zbx.usergroups.get_or_create(:name => "Some user group"),
|
448
|
-
:hostgroupids => zbx.hostgroups.all.values, # kind_of Array
|
449
|
-
:permission => 3 # 2- read (by default) and 3 - write and read
|
450
|
-
)
|
451
|
-
```
|
452
|
-
|
453
|
-
### Create MediaType and add it to user ###
|
454
|
-
```ruby
|
455
|
-
zbx.mediatypes.create_or_update(
|
456
|
-
:description => "mediatype",
|
457
|
-
:type => 0, # 0 - Email, 1 - External script, 2 - SMS, 3 - Jabber, 100 - EzTexting,
|
458
|
-
:smtp_server => "127.0.0.1",
|
459
|
-
:smtp_email => "zabbix@test.com"
|
460
|
-
)
|
461
|
-
zbx.users.add_medias(
|
462
|
-
:userids => [zbx.users.get_id(:alias => "user")],
|
463
|
-
:media => [
|
464
|
-
{
|
465
|
-
:mediatypeid => zbx.mediatypes.get_id(:description => "mediatype"),
|
466
|
-
:sendto => "test@test",
|
467
|
-
:active => 0,
|
468
|
-
:period => "1-7,00:00-24:00", # 1-7 days and 00:00-24:00 hours
|
469
|
-
:severity => "56"
|
470
|
-
}
|
471
|
-
]
|
472
|
-
)
|
473
|
-
```
|
474
|
-
|
475
|
-
### Update media ###
|
476
|
-
```ruby
|
477
|
-
zbx.users.update_medias(
|
478
|
-
:userids => [zbx.users.get_id(:alias => "user")],
|
479
|
-
:media => [
|
480
|
-
{
|
481
|
-
:mediatypeid => zbx.mediatypes.get_id(:description => "mediatype"),
|
482
|
-
:sendto => "test@test",
|
483
|
-
:active => 0,
|
484
|
-
:period => "1-7,00:00-24:00", # 1-7 days and 00:00-24:00 hours
|
485
|
-
:severity => "56"
|
486
|
-
}
|
487
|
-
]
|
488
|
-
)
|
489
|
-
```
|
490
|
-
|
491
|
-
### Create Script
|
492
|
-
```ruby
|
493
|
-
zbx.scripts.create(
|
494
|
-
:name => 'Hostname',
|
495
|
-
:command => 'hostname'
|
496
|
-
)
|
497
|
-
# or use (lib merge json):
|
498
|
-
zbx.scripts.create_or_update(
|
499
|
-
:name => 'Hostname',
|
500
|
-
:command => 'hostname',
|
501
|
-
:description => 'Show the system hostname'
|
502
|
-
)
|
503
|
-
```
|
504
|
-
|
505
|
-
### Update Script
|
506
|
-
```ruby
|
507
|
-
zbx.scripts.update(
|
508
|
-
:httptestid => zbx.scripts.get_id(:name => 'Hostname'),
|
509
|
-
:execute_on => 0
|
510
|
-
)
|
511
|
-
#You can check script:
|
512
|
-
puts zbx.scripts.get_full_data(:name => 'Hostname')
|
513
|
-
|
514
|
-
|
515
|
-
### Create proxy
|
516
|
-
#### Active proxy
|
517
|
-
```ruby
|
518
|
-
zbx.proxies.create(
|
519
|
-
:host => "Proxy 1",
|
520
|
-
:status => 5
|
521
|
-
)
|
522
|
-
```
|
523
|
-
|
524
|
-
#### Passive Proxy
|
525
|
-
```ruby
|
526
|
-
zbx.proxies.create(
|
527
|
-
:host => "Passive proxy",
|
528
|
-
:status => 6,
|
529
|
-
:interfaces => [
|
530
|
-
:ip => "127.0.0.1",
|
531
|
-
:dns => "",
|
532
|
-
:useip => 1,
|
533
|
-
:port => 10051
|
534
|
-
]
|
535
|
-
)
|
536
|
-
```
|
537
|
-
|
538
|
-
### Export object
|
539
|
-
|
540
|
-
```ruby
|
541
|
-
zbx.configurations.export(
|
542
|
-
:format => "xml",
|
543
|
-
:options => {
|
544
|
-
:templates => [zbx.templates.get_id(:host => "template")]
|
545
|
-
}
|
546
|
-
)
|
547
|
-
```
|
548
|
-
|
549
|
-
### Import object
|
550
|
-
|
551
|
-
```ruby
|
552
|
-
zbx.configurations.import(
|
553
|
-
:format => "xml",
|
554
|
-
:rules => {
|
555
|
-
:templates => {
|
556
|
-
:createMissing => true,
|
557
|
-
:updateExisting => true
|
558
|
-
},
|
559
|
-
:items => {
|
560
|
-
:createMissing => true,
|
561
|
-
:updateExisting => true
|
562
|
-
}
|
563
|
-
},
|
564
|
-
:source => "<!--?xml version=\"1.0\" encoding=\"UTF-8\"?--><zabbix_export><version>2.0</version><date>2012-04-18T11:20:14Z</date><groups><group><name>Zabbix servers</name></group></groups><hosts><host><host>Export host</host><name>Export host</name><proxyid>0</proxyid><status>0</status><ipmi_authtype>-1</ipmi_authtype><ipmi_privilege>2</ipmi_privilege><ipmi_username></ipmi_username><ipmi_password></ipmi_password><templates></templates><groups><group><name>Zabbix servers</name></group></groups><interfaces><interface><default>1</default><type>1</type><useip>1</useip><ip>127.0.0.1</ip><dns></dns><port>10050</port><interface_ref>if1</interface_ref></interface></interfaces><applications><application><name>Application</name></application></applications><items><item><name>Item</name><type>0</type><snmp_community></snmp_community><multiplier>0</multiplier><snmp_oid></snmp_oid><key>item.key</key><delay>30</delay><history>90</history><trends>365</trends><status>0</status><value_type>3</value_type><allowed_hosts></allowed_hosts><units></units><delta>0</delta><snmpv3_securityname></snmpv3_securityname><snmpv3_securitylevel>0</snmpv3_securitylevel><snmpv3_authpassphrase></snmpv3_authpassphrase><snmpv3_privpassphrase></snmpv3_privpassphrase><formula>1</formula><delay_flex></delay_flex><params></params><ipmi_sensor></ipmi_sensor><data_type>0</data_type><authtype>0</authtype><username></username><password></password><publickey></publickey><privatekey></privatekey><port></port><description></description><inventory_link>0</inventory_link><applications><application><name>Application</name></application></applications><valuemap></valuemap><interface_ref>if1</interface_ref></item></items><discovery_rules></discovery_rules><macros></macros><inventory></inventory></host></hosts><triggers><trigger><expression>{Export host:item.key.last(0)}=0</expression><name>Trigger</name><url></url><status>0</status><priority>2</priority><description>Host trigger</description><type>0</type><dependencies></dependencies></trigger></triggers><graphs><graph><name>Graph</name><width>900</width><height>200</height><yaxismin>0.0000</yaxismin><yaxismax>100.0000</yaxismax><show_work_period>1</show_work_period><show_triggers>1</show_triggers><type>0</type><show_legend>1</show_legend><show_3d>0</show_3d><percent_left>0.0000</percent_left><percent_right>0.0000</percent_right><ymin_type_1>0</ymin_type_1><ymax_type_1>0</ymax_type_1><ymin_item_1>0</ymin_item_1><ymax_item_1>0</ymax_item_1><graph_items><graph_item><sortorder>0</sortorder><drawtype>0</drawtype><color>C80000</color><yaxisside>0</yaxisside><calc_fnc>7</calc_fnc><type>0</type><item><host>Export host</host><key>item.key</key></item></graph_item></graph_items></graph></graphs></zabbix_export>"
|
565
|
-
)
|
566
|
-
```
|
567
|
-
|
568
|
-
### User and global macros
|
569
|
-
```ruby
|
570
|
-
zbx.usermacros.create(
|
571
|
-
:hostid => zbx.hosts.get_id( :host => "Zabbix server" ),
|
572
|
-
:macro => "{$ZZZZ}",
|
573
|
-
:value => 1.1.1.1
|
574
|
-
)
|
575
|
-
```
|
576
|
-
|
577
|
-
### Custom queries
|
578
|
-
```ruby
|
579
|
-
zbx.query(
|
580
|
-
:method => "apiinfo.version",
|
581
|
-
:params => {}
|
582
|
-
)
|
583
|
-
```
|
51
|
+
If you would like this library to support another Ruby version or
|
52
|
+
implementation, you may volunteer to be a maintainer. Being a maintainer
|
53
|
+
entails making sure all tests run and pass on that implementation. When
|
54
|
+
something breaks on your implementation, you will be responsible for providing
|
55
|
+
patches in a timely fashion. If critical issues for a particular implementation
|
56
|
+
exist at the time of a major release, support for that Ruby version may be
|
57
|
+
dropped.
|
584
58
|
|
585
59
|
## Dependencies
|
586
60
|
|
@@ -591,11 +65,21 @@ zbx.query(
|
|
591
65
|
## Contributing
|
592
66
|
|
593
67
|
* Fork the project.
|
594
|
-
* Make your feature addition or bug fix, write tests.
|
68
|
+
* Make your feature addition or bug fix, write tests, write documentation/examples.
|
595
69
|
* Commit, do not mess with rakefile, version.
|
596
70
|
* Make a pull request.
|
597
71
|
|
598
72
|
## Zabbix documentation
|
599
73
|
|
600
|
-
* [Zabbix Project Homepage]
|
601
|
-
* [Zabbix
|
74
|
+
* [Zabbix Project Homepage][Zabbix]
|
75
|
+
* [Zabbix API docs][Zabbix API]
|
76
|
+
|
77
|
+
[Zabbix]: https://www.zabbix.com
|
78
|
+
[Zabbix API]: https://www.zabbix.com/documentation/3.2/manual/api
|
79
|
+
|
80
|
+
## Copyright
|
81
|
+
Copyright (c) 2015-2017 Express 42
|
82
|
+
|
83
|
+
See [LICENSE][] for details.
|
84
|
+
|
85
|
+
[license]: LICENSE.md
|