zbxapi 0.1.291 → 0.1.292

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,88 @@
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, "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, "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, "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
@@ -0,0 +1,59 @@
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_History
33
+ #
34
+ # Class encapsulating history functions
35
+ #
36
+ # get
37
+ #
38
+ #******************************************************************************
39
+
40
+ class ZbxAPI_History
41
+
42
+ def initialize(server)
43
+ @server=server
44
+ end
45
+
46
+ #Get the history for an item.
47
+ # itemids is a required option
48
+ # example: get({"itemids"=>12345})
49
+ def get(options)
50
+ @server.checkauth
51
+ @server.checkversion(1,3)
52
+
53
+ raise ZbxAPI_ParameterError, "Missing 'itemid'", "History.get" if options["itemids"].nil?
54
+
55
+ p obj=@server.raw_api("history.get",options)
56
+ return obj['result']
57
+ end
58
+
59
+ end
@@ -0,0 +1,116 @@
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 create_template(options={})
75
+ checkauth
76
+ checkversion(1,3)
77
+
78
+ obj=do_request(json_obj('template.create',options))
79
+ obj['result']
80
+ end
81
+
82
+ # http://www.zabbix.com/documentation/1.8/api/objects/host#hostdelete
83
+ #Accepts a single host id or an array of host id's to be deleted
84
+ def delete(ids)
85
+ checkauth
86
+ checkversion(1,3)
87
+
88
+ obj=do_request(json_obj('host.delete',delete_helper("hostid",ids)))
89
+ obj['result']
90
+ end
91
+
92
+ def delete_template(ids)
93
+ checkauth
94
+ checkversion(1,3)
95
+
96
+ obj=do_request(json_obj('template.delete',delete_helper("templateid",ids)))
97
+ obj['result']
98
+ end
99
+
100
+ private
101
+
102
+ def delete_helper(id_type,ids)
103
+ if ids.class==Fixnum
104
+ ids=[ids]
105
+ elsif ids.class==Array
106
+ ids=ids
107
+ else
108
+ raise ZbxAPI_ParameterError, "ids parameter must be number or array"
109
+ end
110
+
111
+ ids.map do |id|
112
+ {id_type=>id}
113
+ end
114
+ end
115
+
116
+ end
@@ -0,0 +1,108 @@
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_HostGroup
32
+ #
33
+ # Class encapsulating User Group functions
34
+ #
35
+ # API Function Status
36
+ # get Basic function implemented
37
+ # getid
38
+ # create
39
+ # update
40
+ # delete
41
+ # addhosts
42
+ # removehost
43
+ # addgroupstohost
44
+ # updategroupstohost
45
+ #
46
+ #******************************************************************************
47
+
48
+ class ZbxAPI_HostGroup < ZbxAPI_Sub
49
+ def create(options={})
50
+ debug(8, "HostGroup.create Start")
51
+ checkauth
52
+ checkversion(1,1)
53
+
54
+ obj=do_request(json_obj('hostgroup.create',options))
55
+ return obj['result']
56
+ end
57
+
58
+ # alias function for code written against 1.0 API
59
+ def add(options={})
60
+ puts "WARNING API Function HostGroup.add is deprecated and will be removed in the future without further warning"
61
+ create(options)
62
+ end
63
+
64
+ def get(options={})
65
+ debug(8, "HostGroup.get Start")
66
+ checkauth
67
+ checkversion(1,1)
68
+
69
+ obj=do_request(json_obj('hostgroup.get',options))
70
+ return obj['result']
71
+ end
72
+
73
+ def getId(name)
74
+ puts "WARNING API Function HostGroup.getId is deprecated and will be removed in the future without further warning"
75
+ getObjects(name)
76
+ end
77
+
78
+ def getObjects(name)
79
+ debug(8, "HostGroup.getId Start")
80
+ checkauth
81
+ checkversion(1,1)
82
+
83
+ begin
84
+ if name.class==String
85
+ do_request(json_obj('hostgroup.getObjects',{"name"=>name}))['result']
86
+ elsif name.class==Array
87
+ valid = name.map {|item| item.class==String ? nil : false} # create a validation array of nils or false
88
+ valid.compact! # remove nils
89
+ raise ZbxAPI_ParameterError, "Expected a string or an array of strings" if !valid.empty?
90
+
91
+ results=[]
92
+ name.each do |item|
93
+ response=do_request(json_obj('hostgroup.getObjects',{"name"=>item}))
94
+ response['result'].each {|result| results << result } # Just in case the server returns an array
95
+ end
96
+ results
97
+ else
98
+ raise ZbxAPI_ParameterError, "Expected a string or an array of strings"
99
+ end
100
+ rescue ZbxAPI_GeneralError => e
101
+ if e.message["code"]==-32602
102
+ return 0
103
+ else
104
+ raise e
105
+ end
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,83 @@
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_Item
32
+ #
33
+ # Class encapsulating Item functions
34
+ #
35
+ # API Function Status
36
+ # get Basic Function working
37
+ # getid Function implemented
38
+ # create Function implemented
39
+ # update
40
+ # delete Function implemented - need to add type checking to input
41
+ #
42
+ #******************************************************************************
43
+
44
+ class ZbxAPI_Item < ZbxAPI_Sub
45
+ def get(options={})
46
+ checkauth
47
+ checkversion(1,1)
48
+
49
+ obj=do_request(json_obj('item.get',options))
50
+ return obj['result']
51
+ end
52
+
53
+ def getid(options)
54
+ checkauth
55
+ checkversion(1,1)
56
+
57
+ obj=do_request(json_obj('item.getid', options))
58
+ return obj['result']
59
+ end
60
+
61
+ def create(options)
62
+ debug(8,options)
63
+ checkauth
64
+ checkversion(1,1)
65
+
66
+ obj=do_request(json_obj('item.create', options))
67
+ return obj['result']
68
+ end
69
+
70
+ # Alias function for code written against 1.0 API
71
+ def add(options)
72
+ puts "WARNING API Function Item.add is deprecated and will be removed in the future without further warning"
73
+ create(options)
74
+ end
75
+
76
+ def delete(ids)
77
+ checkauth
78
+ checkversion(1,1)
79
+
80
+ obj=do_request(json_obj('item.delete', ids))
81
+ return obj['result']
82
+ end
83
+ end
@@ -0,0 +1,59 @@
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 'zbxapi'
28
+
29
+ # Class: Zbx_API_Sub
30
+ # Wrapper class to ensure all class calls goes to the parent object not the
31
+ # currently instantiated object.
32
+ # Also ensures class specific variable sanity for global functions
33
+ class ZbxAPI_Sub < ZabbixAPI #:nodoc: all
34
+ attr_accessor :parent
35
+
36
+ def initialize(parent)
37
+ @parent=parent
38
+ end
39
+
40
+ def checkauth
41
+ @parent.checkauth
42
+ end
43
+
44
+ def checkversion(major,minor,options=nil)
45
+ @parent.checkversion(major,minor,options)
46
+ end
47
+
48
+ def do_request(req)
49
+ return @parent.do_request(req)
50
+ end
51
+
52
+ def json_obj(method, param)
53
+ return @parent.json_obj(method, param)
54
+ end
55
+
56
+ def debug(level,param="",message=nil)
57
+ @parent.debug(level,param,message)
58
+ end
59
+ end
@@ -0,0 +1,91 @@
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_Sysmap
32
+ #
33
+ # Class encapsulating sysmap functions
34
+ #
35
+ # get Not implemented
36
+ # cr eate Basic implementation
37
+ #
38
+ #******************************************************************************
39
+
40
+ class ZbxAPI_Sysmap < ZbxAPI_Sub
41
+ def create(options={})
42
+ debug(8, "Sysmap.create Start")
43
+ checkauth
44
+ checkversion(1,1)
45
+
46
+ obj=do_request(json_obj('map.create',options))
47
+ return obj['result']
48
+ end
49
+
50
+ # Alias function for code written against 1.0 API
51
+ def add(options={})
52
+ puts "WARNING API Function Sysmap.add is deprecated and will be removed in the future without further warning"
53
+ create(options)
54
+ end
55
+
56
+ def addelement(options={})
57
+ debug(8, "Sysmap.addelement Start")
58
+ checkauth
59
+ checkversion(1,1)
60
+
61
+ obj=do_request(json_obj('map.addelement',options))
62
+ return obj['result']
63
+ end
64
+
65
+ def addlink(options={})
66
+ debug(8, "Sysmap.addlink Start")
67
+ checkauth
68
+ checkversion(1,1)
69
+
70
+ obj=do_request(json_obj('map.addlink',options))
71
+ return obj['result']
72
+ end
73
+
74
+ def getseid(options={})
75
+ debug(8, "Sysmap.getseid Start")
76
+ checkauth
77
+ checkversion(1,1)
78
+
79
+ obj=do_request(json_obj('map.getseid',options))
80
+ return obj['result']
81
+ end
82
+
83
+ def addlinktrigger(options={})
84
+ debug(8, "Sysmap.addlinktrigger Start")
85
+ checkauth
86
+ checkversion(1,1)
87
+
88
+ obj=do_request(json_obj('map.addlinktrigger',options))
89
+ return obj['result']
90
+ end
91
+ end
@@ -0,0 +1,71 @@
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_Trigger
32
+ #
33
+ # Class encapsulating trigger functions
34
+ #
35
+ # get Implemented
36
+ # getById Not implemented
37
+ # getId Not implemented
38
+ # create Implemented
39
+ # update Not implemented
40
+ # delete Not implemented
41
+ # addDependency Not implemented
42
+ #
43
+ #******************************************************************************
44
+
45
+
46
+ class ZbxAPI_Trigger < ZbxAPI_Sub
47
+ def get(options={})
48
+ debug(8, "Trigger.get Start")
49
+ checkauth
50
+ checkversion(1,1)
51
+
52
+ obj=do_request(json_obj('trigger.get',options))
53
+ return obj['result']
54
+ end
55
+
56
+ # Function name changed to reflect 1.1 API changes
57
+ def create(options={})
58
+ debug(8, "Trigger.create Start")
59
+ checkauth
60
+ checkversion(1,1)
61
+
62
+ obj=do_request(json_obj('trigger.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 Trigger.add is deprecated and will be removed in the future without further warning"
69
+ create(options)
70
+ end
71
+ end
@@ -0,0 +1,138 @@
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
+ # Class ZbxAPI_User
30
+ #
31
+ # Class encapsulating User functions
32
+ #
33
+ # API Function Status
34
+ # [get] Implemented, need error checking
35
+ # [authenticate] Will not implement here, belongs in ZabbixAPI main class
36
+ # [checkauth] Will not implement here, belongs in ZabbixAPI main class
37
+ # [getid] Implemented
38
+ # [create] Implemented, need to test more to find fewest items
39
+ # needed, input value testing needed
40
+ # [update]
41
+ #
42
+ # [addmedia]
43
+ #
44
+ # [deletemedia]
45
+ #
46
+ # [updatemedia]
47
+ # [delete] Implemented, checking of input values needed
48
+ #
49
+ # All functions expect a hash of options to add.
50
+ # If multiple users need to be manipulated it must be broken out into different calls
51
+
52
+ class ZbxAPI_User < ZbxAPI_Sub
53
+ def get(options={})
54
+ checkauth
55
+ checkversion(1,1)
56
+
57
+ obj=do_request(json_obj('user.get',options))
58
+ return obj['result']
59
+ end
60
+
61
+ def getid(username)
62
+ raise ZbxAPI_ExceptionArgumentError, "String argument expected" if username.class != String
63
+
64
+ checkauth
65
+ checkversion(1,1)
66
+
67
+ obj=do_request(json_obj('user.getid',{'alias'=>username}))
68
+ return obj['result']
69
+ end
70
+
71
+ def create(options)
72
+ checkauth
73
+ checkversion(1,1)
74
+
75
+ #Check input parameters
76
+
77
+ raise ZbxAPI_ParameterError, "Missing 'name' argument", "User.create" if options["name"].nil?
78
+ raise ZbxAPI_ParameterError, "Missing 'alias' argument", "User.create" if options["alias"].nil?
79
+ raise ZbxAPI_ParameterError, "Missing 'passwd' argument", "User.create" if options["passwd"].nil?
80
+
81
+ obj=do_request(json_obj('user.create',options))
82
+ return obj['result']
83
+ end
84
+
85
+ # Alias function name for code written to work against 1.0 API
86
+ # may be removed in future versions
87
+
88
+ def add(options)
89
+ puts "WARNING API Function User.add is deprecated and will be removed in the future without further warning"
90
+ create(options)
91
+ end
92
+
93
+ def delete(userid)
94
+ checkauth
95
+ checkversion(1,1)
96
+
97
+ obj=do_request(json_obj('user.delete',[userid]))
98
+ return obj['result']
99
+ end
100
+
101
+ def update(options)
102
+ checkauth
103
+ checkversion(1,1)
104
+
105
+ obj=do_request(json_obj('user.update',options))
106
+ return obj['result']
107
+ end
108
+
109
+ # addmedia expects a hash of the following variables
110
+ # userid, mediatypeid, sendto, severity, active, period
111
+ def addmedia(options)
112
+ debug(8, "User.addmedia Start")
113
+ checkauth
114
+ checkversion(1,1)
115
+
116
+ # p options
117
+
118
+ raise ZbxAPI_ParameterError, "Missing 'userid' argument", "User.addmedia" if options["userid"].nil?
119
+ raise ZbxAPI_ParameterError, "Missing 'mediatypeid' argument", "User.addmedia" if options["mediatypeid"].nil?
120
+ raise ZbxAPI_ParameterError, "Missing 'severity' argument", "User.addmedia" if options["severity"].nil?
121
+ raise ZbxAPI_ParameterError, "Missing 'active' argument", "User.addmedia" if options["active"].nil?
122
+ raise ZbxAPI_ParameterError, "Missing 'period' argument", "User.addmedia" if options["period"].nil?
123
+
124
+ args = {}
125
+ args["userid"]=options["userid"]
126
+ args["medias"]={}
127
+ args["medias"]["mediatypeid"]=options["mediatypeid"]
128
+ args["medias"]["sendto"]=options["sendto"]
129
+ args["medias"]["severity"]=options["severity"]
130
+ args["medias"]["active"]=options["active"]
131
+ args["medias"]["period"]=options["period"]
132
+
133
+ # p args
134
+
135
+ obj=do_request(json_obj('user.addMedia',args))
136
+ return obj['result']
137
+ end
138
+ end
@@ -0,0 +1,56 @@
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_UserGroup
32
+ #
33
+ # Class encapsulating User Group functions
34
+ #
35
+ # API Function Status
36
+ # get Basic function implemented
37
+ # getid
38
+ # create
39
+ # update
40
+ # updaterights
41
+ # addrights
42
+ # addusers
43
+ # removeusers
44
+ # delete
45
+ #
46
+ #******************************************************************************
47
+
48
+ class ZbxAPI_UserGroup < ZbxAPI_Sub
49
+ def get(options={})
50
+ checkauth
51
+ checkversion(1,1)
52
+
53
+ obj=do_request(json_obj('usergroup.get',options))
54
+ return obj['result']
55
+ end
56
+ end
data/zbxapi.rb CHANGED
@@ -19,13 +19,16 @@
19
19
  #--
20
20
  ##########################################
21
21
  # Subversion information
22
- # $Id: zbxapi.rb 290 2011-07-08 04:58:15Z nelsonab $
23
- # $Revision: 290 $
22
+ # $Id: zbxapi.rb 292 2011-07-08 06:15:38Z nelsonab $
23
+ # $Revision: 292 $
24
24
  ##########################################
25
25
  #++
26
26
 
27
27
  #TODO Create class to capture resultant data
28
28
 
29
+ class ZabbixAPI #create a stub to be defined later
30
+ end
31
+
29
32
  #setup our search path or libraries
30
33
  $: << File.expand_path(File.join(File.dirname(__FILE__), '.'))
31
34
 
@@ -279,7 +282,6 @@ class ZabbixAPI
279
282
 
280
283
  # check return code and throw exception for error checking
281
284
  resp = JSON.parse(response.body) #parse the JSON Object so we can use it
282
- raise
283
285
  if !resp["error"].nil?
284
286
  errcode=resp["error"]["code"].to_i
285
287
  case errcode
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: 605
4
+ hash: 595
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 291
10
- version: 0.1.291
9
+ - 292
10
+ version: 0.1.292
11
11
  platform: ruby
12
12
  authors:
13
13
  - A. Nelson
@@ -45,6 +45,16 @@ files:
45
45
  - libs/zdebug.rb
46
46
  - libs/api_exceptions.rb
47
47
  - libs/exceptions.rb
48
+ - api_classes/application.rb
49
+ - api_classes/history.rb
50
+ - api_classes/host.rb
51
+ - api_classes/host_group.rb
52
+ - api_classes/item.rb
53
+ - api_classes/sysmap.rb
54
+ - api_classes/trigger.rb
55
+ - api_classes/user.rb
56
+ - api_classes/user_group.rb
57
+ - api_classes/subclass_base.rb
48
58
  has_rdoc: true
49
59
  homepage: http://trac.red-tux.net/
50
60
  licenses: