zabbixapi 3.0.0 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 491a14fb3d69c78a072b5f67a72fa1410835a7c6
4
- data.tar.gz: 4f19756c236c435d6f253943182e8d123442e7c1
3
+ metadata.gz: 62d0c2a77a20181c6c206a4ef0f326816c9cd393
4
+ data.tar.gz: 5f56649ab7a8db90bd5ce3cf9bcd6960f9ee1c08
5
5
  SHA512:
6
- metadata.gz: 36562b8555de03cff58f5e7d1b73daa12e5c3d3dfd990ddff49077b6f47470b915ccaa389c8b719f4f8681ed5cf1cf8b319ca892a6d234d183e633d0c71db04c
7
- data.tar.gz: bf90b9d74bde43345caf3e66cb36f9bd059e2595e0e4fa454ec1395752b7b59e6d5d70640db1a110702b8faa0ca35e6504c34313e39f60c77f55443f983d4c03
6
+ metadata.gz: 8f2be925d94ce9d47224cf6724cfbaa4a686bb846ee773919e5561632913340e80846af20e6f43a2d68e85b42ed53505dd4c6a79087c76d015e6973f107627e1
7
+ data.tar.gz: aba85f76d861928efa429139f9aff3ecef58f6a0d6599de0c48905675eab6753f73df764b61f15d1a5b3d0c626f397b556b32a096d0b67d06f3d99be3aebeb88
@@ -1,3 +1,6 @@
1
+ ## 3.1.0
2
+ [PR #68](https://github.com/express42/zabbixapi/pull/68) Add support for scripts (Thanx @jrbeilke)
3
+
1
4
  ## 2.4.9
2
5
 
3
6
  [PR #55](https://github.com/express42/zabbixapi/pull/55) Add 3.2.x support (Thanx @jrbeilke)
data/README.md CHANGED
@@ -31,7 +31,7 @@ We support only two last versions of zabbix (2.4 and 3.0), so you should conside
31
31
 
32
32
  ## Installation
33
33
  ```
34
- gem install zabbixapi -v 2.4.7
34
+ gem install zabbixapi
35
35
  ```
36
36
 
37
37
  ## Getting Started
@@ -488,6 +488,30 @@ zbx.users.update_medias(
488
488
  )
489
489
  ```
490
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
+
491
515
  ### Create proxy
492
516
  #### Active proxy
493
517
  ```ruby
@@ -26,6 +26,7 @@ require "zabbixapi/classes/usermacros"
26
26
  require "zabbixapi/classes/users"
27
27
  require "zabbixapi/classes/configurations"
28
28
  require "zabbixapi/classes/actions"
29
+ require "zabbixapi/classes/scripts"
29
30
 
30
31
  class ZabbixApi
31
32
 
@@ -119,4 +120,8 @@ class ZabbixApi
119
120
  @actions ||= Actions.new(@client)
120
121
  end
121
122
 
123
+ def scripts
124
+ @scripts ||= Scripts.new(@client)
125
+ end
126
+
122
127
  end
@@ -0,0 +1,27 @@
1
+ class ZabbixApi
2
+ class Scripts < Basic
3
+
4
+ def method_name
5
+ "script"
6
+ end
7
+
8
+ def indentify
9
+ "name"
10
+ end
11
+
12
+ def execute(data)
13
+ @client.api_request(
14
+ :method => "script.execute",
15
+ :params => {
16
+ :scriptid => data[:scriptid],
17
+ :hostid => data[:hostid]
18
+ }
19
+ )
20
+ end
21
+
22
+ def getscriptsbyhost(data)
23
+ @client.api_request(:method => "script.getscriptsbyhosts", :params => data)
24
+ end
25
+
26
+ end
27
+ end
@@ -1,3 +1,3 @@
1
1
  class ZabbixApi
2
- VERSION = "3.0.0"
2
+ VERSION = "3.1.0"
3
3
  end
@@ -0,0 +1,123 @@
1
+ #encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe 'script' do
6
+ before :all do
7
+ @hostid = zbx.hosts.get_id(:host => 'Zabbix server')
8
+ end
9
+
10
+ context 'when name not exists' do
11
+ before do
12
+ @script = gen_name 'script'
13
+ end
14
+
15
+ describe 'create' do
16
+ it "should return integer id" do
17
+ scriptid = zbx.scripts.create(
18
+ :name => @script,
19
+ :command => 'hostname',
20
+ )
21
+ expect(scriptid).to be_kind_of(Integer)
22
+ end
23
+ end
24
+
25
+ describe 'get_id' do
26
+ it "should return nil" do
27
+ expect(zbx.scripts.get_id(:name => @script)).to be_kind_of(NilClass)
28
+ end
29
+ end
30
+ end
31
+
32
+ context 'when name exists' do
33
+ before :all do
34
+ @script = gen_name 'script'
35
+ @scriptid = zbx.scripts.create(
36
+ :name => @script,
37
+ :command => 'hostname',
38
+ )
39
+ end
40
+
41
+ describe 'get_or_create' do
42
+ it "should return id of script" do
43
+ expect(zbx.scripts.get_or_create(
44
+ :name => @script,
45
+ :command => 'hostname',
46
+ )).to eq @scriptid
47
+ end
48
+ end
49
+
50
+ describe 'get_full_data' do
51
+ it "should contains created script" do
52
+ expect(zbx.scripts.get_full_data(:name => @script)[0]).to include("name" => @script)
53
+ end
54
+ end
55
+
56
+ describe 'get_id' do
57
+ it "should return id of script" do
58
+ expect(zbx.scripts.get_id(:name => @script)).to eq @scriptid
59
+ end
60
+ end
61
+
62
+ it "should raise error on no identity given" do
63
+ expect { zbx.scripts.get_id({}) }.to raise_error(ZabbixApi::ApiError)
64
+ end
65
+
66
+ describe 'update' do
67
+ it "should return id" do
68
+ expect(zbx.scripts.update(
69
+ :scriptid => zbx.scripts.get_id(:name => @script),
70
+ :enable_confirmation => 1,
71
+ :confirmation => 'Are you sure you would like to show the system hostname?'
72
+ )).to eq @scriptid
73
+ end
74
+ end
75
+
76
+ describe 'create_or_update' do
77
+ it "should update existing script" do
78
+ expect(zbx.scripts.get_or_create(
79
+ :name => @script,
80
+ :command => 'hostname',
81
+ )).to eq @scriptid
82
+ end
83
+
84
+ it "should create script" do
85
+ new_script_id = zbx.scripts.get_or_create(
86
+ :name => @script + "____1",
87
+ :command => 'hostname',
88
+ )
89
+
90
+ expect(new_script_id).to be_kind_of(Integer)
91
+ expect(new_script_id).to be > @scriptid
92
+ end
93
+ end
94
+
95
+ # TODO: see if we can get this test working with travis ci (passes on standalone zabbix server)
96
+ #describe 'execute' do
97
+ # it "should return success response" do
98
+ # expect(zbx.scripts.execute(:scriptid => @scriptid, :hostid => @hostid)).to include("response" => "success")
99
+ # end
100
+ #end
101
+
102
+ describe 'getscriptsbyhost' do
103
+ it "should return object with hostid and script" do
104
+ expect(zbx.scripts.getscriptsbyhost([@hostid])[@hostid.to_s].select { |script| script[:name] == @script}).to_not be_nil
105
+ end
106
+ end
107
+
108
+ describe 'delete' do
109
+ before :all do
110
+ @result = zbx.scripts.delete(@scriptid)
111
+ end
112
+
113
+ it "should return deleted id" do
114
+ expect(@result).to eq @scriptid
115
+ end
116
+
117
+ it "should delete script from zabbix" do
118
+ expect(zbx.scripts.get_id(:name => @script)).to be_nil
119
+ end
120
+ end
121
+
122
+ end
123
+ 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: 3.0.0
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vasiliev D.V.
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-01-30 00:00:00.000000000 Z
12
+ date: 2017-02-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
@@ -90,6 +90,7 @@ files:
90
90
  - lib/zabbixapi/classes/mediatypes.rb
91
91
  - lib/zabbixapi/classes/proxies.rb
92
92
  - lib/zabbixapi/classes/screens.rb
93
+ - lib/zabbixapi/classes/scripts.rb
93
94
  - lib/zabbixapi/classes/server.rb
94
95
  - lib/zabbixapi/classes/templates.rb
95
96
  - lib/zabbixapi/classes/triggers.rb
@@ -112,6 +113,7 @@ files:
112
113
  - spec/mediatype.rb
113
114
  - spec/query.rb
114
115
  - spec/screen.rb
116
+ - spec/script.rb
115
117
  - spec/server.rb
116
118
  - spec/spec_helper.rb
117
119
  - spec/template.rb
@@ -140,7 +142,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
140
142
  version: '0'
141
143
  requirements: []
142
144
  rubyforge_project: zabbixapi
143
- rubygems_version: 2.5.2
145
+ rubygems_version: 2.6.10
144
146
  signing_key:
145
147
  specification_version: 4
146
148
  summary: Realization for Zabbix API.
@@ -158,6 +160,7 @@ test_files:
158
160
  - spec/mediatype.rb
159
161
  - spec/query.rb
160
162
  - spec/screen.rb
163
+ - spec/script.rb
161
164
  - spec/server.rb
162
165
  - spec/spec_helper.rb
163
166
  - spec/template.rb