zbxapi 0.1.398 → 0.2.415

Sign up to get free protection for your applications and to get access to all the features.
@@ -17,8 +17,8 @@
17
17
 
18
18
  ##########################################
19
19
  # Subversion information
20
- # $Id: api_exceptions.rb 319 2011-09-25 21:53:30Z nelsonab $
21
- # $Revision: 319 $
20
+ # $Id: api_exceptions.rb 337 2011-10-14 16:11:39Z nelsonab $
21
+ # $Revision: 337 $
22
22
  ##########################################
23
23
 
24
24
  #------------------------------------------------------------------------------
@@ -17,8 +17,8 @@
17
17
 
18
18
  ##########################################
19
19
  # Subversion information
20
- # $Id: exceptions.rb 319 2011-09-25 21:53:30Z nelsonab $
21
- # $Revision: 319 $
20
+ # $Id: exceptions.rb 337 2011-10-14 16:11:39Z nelsonab $
21
+ # $Revision: 337 $
22
22
  ##########################################
23
23
 
24
24
  require 'zbxapi/utils'
@@ -0,0 +1,74 @@
1
+ #License:: GPL 2.0 http://www.gnu.org/licenses/gpl-2.0.html
2
+ #Copyright:: Copyright (C) 2009,2010 Andrew Nelson nelsonab(at)red-tux(dot)net
3
+ #
4
+ #This program is free software; you can redistribute it and/or
5
+ #modify it under the terms of the GNU General Public License
6
+ #as published by the Free Software Foundation; either version 2
7
+ #of the License, or (at your option) any later version.
8
+ #
9
+ #This program is distributed in the hope that it will be useful,
10
+ #but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ #GNU General Public License for more details.
13
+ #
14
+ #You should have received a copy of the GNU General Public License
15
+ #along with this program; if not, write to the Free Software
16
+ #Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
+
18
+ ##########################################
19
+ # Subversion information
20
+ # $Id: result.rb 395 2012-05-18 03:49:48Z nelsonab $
21
+ # $Revision: 395 $
22
+ ##########################################
23
+
24
+ require 'zbxapi/zdebug'
25
+ require 'zbxapi/exceptions'
26
+ #require 'json'
27
+ require 'pp'
28
+
29
+ class ApiResult < Array
30
+ include ZDebug
31
+
32
+ class InvalidResult < ZError
33
+ end
34
+
35
+ class ErrorMessage <ZError
36
+ end
37
+
38
+ attr_accessor :fields, :params, :method_called
39
+
40
+ def initialize(values={})
41
+ raise InvalidResult.new if values["result"].nil?
42
+
43
+ @params=values[:params]
44
+ values.delete(:params) if values.key?(:params)
45
+ @method_called=values[:method]
46
+ values.delete(:method) if values.key?(:method)
47
+
48
+ @id=values["id"]
49
+ if values["result"].class!=Array
50
+ super([values["result"]])
51
+ else
52
+ super(values["result"])
53
+ end
54
+ @fields=self.first.keys.map{|i| i.intern }
55
+ end
56
+
57
+ def method_missing(sym,*args)
58
+ if @fields.index(sym)
59
+ p @fields
60
+ map {|i| i[sym.to_s]}
61
+ else
62
+ super(sym,*args)
63
+ end
64
+ end
65
+
66
+
67
+ def [](*args)
68
+ index=args[0]
69
+ return self if index=="result"
70
+ return self.first[index] if index.is_a?(String)
71
+ super(*args)
72
+ end
73
+
74
+ end
@@ -17,8 +17,8 @@
17
17
 
18
18
  ##########################################
19
19
  # Subversion information
20
- # $Id: utils.rb 319 2011-09-25 21:53:30Z nelsonab $
21
- # $Revision: 319 $
20
+ # $Id: utils.rb 337 2011-10-14 16:11:39Z nelsonab $
21
+ # $Revision: 337 $
22
22
  ##########################################
23
23
 
24
24
 
@@ -17,8 +17,8 @@
17
17
 
18
18
  ##########################################
19
19
  # Subversion information
20
- # $Id: zdebug.rb 324 2011-09-26 08:53:11Z nelsonab $
21
- # $Revision: 324 $
20
+ # $Id: zdebug.rb 337 2011-10-14 16:11:39Z nelsonab $
21
+ # $Revision: 337 $
22
22
  ##########################################
23
23
 
24
24
  module ZDebug
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zbxapi
3
3
  version: !ruby/object:Gem::Version
4
- hash: 775
5
- prerelease:
4
+ hash: 809
5
+ prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
9
- - 398
10
- version: 0.1.398
8
+ - 2
9
+ - 415
10
+ version: 0.2.415
11
11
  platform: ruby
12
12
  authors:
13
13
  - A. Nelson
@@ -15,7 +15,8 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-05-22 00:00:00 Z
18
+ date: 2012-09-22 00:00:00 -04:00
19
+ default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: json
@@ -44,20 +45,23 @@ files:
44
45
  - zbxapi/zdebug.rb
45
46
  - zbxapi/api_exceptions.rb
46
47
  - zbxapi/exceptions.rb
47
- - zbxapi/revision.rb
48
48
  - zbxapi/utils.rb
49
- - api_classes/application.rb
50
- - api_classes/history.rb
51
- - api_classes/host.rb
52
- - api_classes/host_group.rb
53
- - api_classes/item.rb
54
- - api_classes/proxy.rb
55
- - api_classes/graph.rb
56
- - api_classes/sysmap.rb
57
- - api_classes/trigger.rb
58
- - api_classes/user.rb
59
- - api_classes/user_group.rb
60
- - api_classes/subclass_base.rb
49
+ - zbxapi/result.rb
50
+ - api_classes/api_dsl.rb
51
+ - api_classes/dsl_event.rb
52
+ - api_classes/dsl_graph.rb
53
+ - api_classes/dsl_history.rb
54
+ - api_classes/dsl_host.rb
55
+ - api_classes/dsl_hostgroup.rb
56
+ - api_classes/dsl_item.rb
57
+ - api_classes/dsl_proxy.rb
58
+ - api_classes/dsl_template.rb
59
+ - api_classes/dsl_trigger.rb
60
+ - api_classes/dsl_user.rb
61
+ - api_classes/dsl_usergroup.rb
62
+ - api_classes/dsl_usermacro.rb
63
+ - api_classes/dsl_usermedia.rb
64
+ has_rdoc: true
61
65
  homepage: http://trac.red-tux.net/
62
66
  licenses:
63
67
  - LGPL 2.1
@@ -87,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
87
91
  requirements:
88
92
  - Requires json
89
93
  rubyforge_project: zbxapi
90
- rubygems_version: 1.8.15
94
+ rubygems_version: 1.3.7
91
95
  signing_key:
92
96
  specification_version: 3
93
97
  summary: Ruby wrapper to the Zabbix API
@@ -1,88 +0,0 @@
1
- # Title:: Zabbix API Ruby Library
2
- # License:: LGPL 2.1 http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
3
- # Copyright:: Copyright (C) 2009,2010 Andrew Nelson nelsonab(at)red-tux(dot)net
4
- #
5
- # This library is free software; you can redistribute it and/or
6
- # modify it under the terms of the GNU Lesser General Public
7
- # License as published by the Free Software Foundation; either
8
- # version 2.1 of the License, or (at your option) any later version.
9
- #
10
- # This library is distributed in the hope that it will be useful,
11
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
- # Lesser General Public License for more details.
14
- #
15
- # You should have received a copy of the GNU Lesser General Public
16
- # License along with this library; if not, write to the Free Software
17
- # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
-
19
- #--
20
- ##########################################
21
- # Subversion information
22
- # $Id: zbxapi.rb 281 2011-04-06 18:10:16Z nelsonab $
23
- # $Revision: 281 $
24
- ##########################################
25
- #++
26
-
27
- require "api_classes/subclass_base"
28
-
29
- #******************************************************************************
30
-
31
- #
32
- # Class ZbxAPI_Application
33
- #
34
- # Class encapsulating application functions
35
- #
36
- # API Function Status
37
- # get Not implemented
38
- # getById Implemented
39
- # getId Not implemented
40
- # create Not implemented
41
- # update Not implemented
42
- # delete Not implemented
43
- #
44
- #******************************************************************************
45
-
46
-
47
- class ZbxAPI_Application < ZbxAPI_Sub
48
- def get(options={})
49
- debug(8, :msg=>"Application.get Start")
50
- checkauth
51
- checkversion(1,1)
52
-
53
- obj=do_request(json_obj('application.get',options))
54
- return obj['result']
55
- end
56
-
57
- def create(options={})
58
- debug(8, :msg=>"Application.create Start")
59
- checkauth
60
- checkversion(1,1)
61
-
62
- obj=do_request(json_obj('application.create',options))
63
- return obj['result']
64
- end
65
-
66
- # Alias function for code written against 1.0 API
67
- def add(options={})
68
- puts "WARNING API Function Application.add is deprecated and will be removed in the future without further warning"
69
- create(options)
70
- end
71
-
72
- def getid(options={})
73
- debug(8, :msg=>"Application.getid Start")
74
- checkauth
75
- checkversion(1,1)
76
-
77
- begin
78
- obj=do_request(json_obj('application.getid',options))
79
- rescue ZbxAPI_GeneralError => e
80
- if e.message["code"]==-32400
81
- return 0
82
- else
83
- raise e
84
- end
85
- end
86
- return obj['result']
87
- end
88
- end
@@ -1,77 +0,0 @@
1
- # Title:: Zabbix API Ruby Library
2
- # License:: LGPL 2.1 http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
3
- # Copyright:: Copyright (C) 2009-2012 Andrew Nelson nelsonab(at)red-tux(dot)net
4
- #
5
- # This library is free software; you can redistribute it and/or
6
- # modify it under the terms of the GNU Lesser General Public
7
- # License as published by the Free Software Foundation; either
8
- # version 2.1 of the License, or (at your option) any later version.
9
- #
10
- # This library is distributed in the hope that it will be useful,
11
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
- # Lesser General Public License for more details.
14
- #
15
- # You should have received a copy of the GNU Lesser General Public
16
- # License along with this library; if not, write to the Free Software
17
- # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
-
19
- #--
20
- ##########################################
21
- # Subversion information
22
- # $Id$
23
- # $Revision$
24
- ##########################################
25
- #++
26
-
27
- require "api_classes/subclass_base"
28
-
29
- #******************************************************************************
30
- #
31
- # Class ZbxAPI_Item
32
- #
33
- # Class encapsulating Item functions
34
- #
35
- # API Function Status
36
- # get Function implemented
37
- # create Function implemented
38
- # update Function implemented
39
- # delete Function implemented - need to add type checking to input
40
- #
41
- #******************************************************************************
42
-
43
- class ZbxAPI_Graph < ZbxAPI_Sub
44
- def get(options={})
45
- checkauth
46
- checkversion(1,1)
47
-
48
- obj=do_request(json_obj('graph.get',options))
49
- return obj['result']
50
- end
51
-
52
- def create(options)
53
- debug(8,:var=>options)
54
- checkauth
55
- checkversion(1,1)
56
-
57
- obj=do_request(json_obj('graph.create', options))
58
- return obj['result']
59
- end
60
-
61
- def update(options)
62
- debug(8,:var=>options)
63
- checkauth
64
- checkversion(1,1)
65
-
66
- obj=do_request(json_obj('graph.update', options))
67
- return obj['result']
68
- end
69
-
70
- def delete(ids)
71
- checkauth
72
- checkversion(1,1)
73
-
74
- obj=do_request(json_obj('graph.delete', ids))
75
- return obj['result']
76
- end
77
- end
@@ -1,124 +0,0 @@
1
- # Title:: Zabbix API Ruby Library
2
- # License:: LGPL 2.1 http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
3
- # Copyright:: Copyright (C) 2009,2010 Andrew Nelson nelsonab(at)red-tux(dot)net
4
- #
5
- # This library is free software; you can redistribute it and/or
6
- # modify it under the terms of the GNU Lesser General Public
7
- # License as published by the Free Software Foundation; either
8
- # version 2.1 of the License, or (at your option) any later version.
9
- #
10
- # This library is distributed in the hope that it will be useful,
11
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
- # Lesser General Public License for more details.
14
- #
15
- # You should have received a copy of the GNU Lesser General Public
16
- # License along with this library; if not, write to the Free Software
17
- # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
-
19
- #--
20
- ##########################################
21
- # Subversion information
22
- # $Id: zbxapi.rb 281 2011-04-06 18:10:16Z nelsonab $
23
- # $Revision: 281 $
24
- ##########################################
25
- #++
26
-
27
- require "api_classes/subclass_base"
28
-
29
- #******************************************************************************
30
- #
31
- # Class ZbxAPI_Host
32
- #
33
- # Class encapsulating Host and template functions
34
- #
35
- # API Function Status
36
- # get Basic function implemented
37
- # getid
38
- # create Basic function implemented 20091020
39
- # update
40
- # massupdate
41
- # delete Implimented
42
- #
43
- # template.create implemented as host.create_template
44
- # template.get implemented as host.get_template
45
- # template.delete implemented as host.delete_template
46
- #
47
- #******************************************************************************
48
-
49
- class ZbxAPI_Host < ZbxAPI_Sub
50
- def get(options={})
51
- checkauth
52
- checkversion(1,1)
53
-
54
- obj=do_request(json_obj('host.get',options))
55
- obj['result']
56
- end
57
-
58
- def get_template(options={})
59
- checkauth
60
- checkversion(1,3)
61
-
62
- obj=do_request(json_obj('template.get',options))
63
- obj['result']
64
- end
65
-
66
- def create(options={})
67
- checkauth
68
- checkversion(1,1)
69
-
70
- obj=do_request(json_obj('host.create',options))
71
- obj['result']
72
- end
73
-
74
- def update(options={})
75
- checkauth
76
- checkversion(1,3)
77
-
78
- obj=do_request(json_obj('host.update',options))
79
- obj['result']
80
- end
81
-
82
- def create_template(options={})
83
- checkauth
84
- checkversion(1,3)
85
-
86
- obj=do_request(json_obj('template.create',options))
87
- obj['result']
88
- end
89
-
90
- # http://www.zabbix.com/documentation/1.8/api/objects/host#hostdelete
91
- #Accepts a single host id or an array of host id's to be deleted
92
- def delete(ids)
93
- checkauth
94
- checkversion(1,3)
95
-
96
- obj=do_request(json_obj('host.delete',delete_helper("hostid",ids)))
97
- obj['result']
98
- end
99
-
100
- def delete_template(ids)
101
- checkauth
102
- checkversion(1,3)
103
-
104
- obj=do_request(json_obj('template.delete',delete_helper("templateid",ids)))
105
- obj['result']
106
- end
107
-
108
- private
109
-
110
- def delete_helper(id_type,ids)
111
- if ids.class==Fixnum
112
- ids=[ids]
113
- elsif ids.class==Array
114
- ids=ids
115
- else
116
- raise ZbxAPI_ParameterError, "ids parameter must be number or array"
117
- end
118
-
119
- ids.map do |id|
120
- {id_type=>id}
121
- end
122
- end
123
-
124
- end