zbxapi 0.1.398 → 0.2.415

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.
@@ -1,108 +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_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, :msg=>"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, :msg=>"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, :msg=>"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
@@ -1,92 +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_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,:var=>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
- def update(options)
71
- debug(8,:var=>options)
72
- checkauth
73
- checkversion(1,1)
74
-
75
- obj=do_request(json_obj('item.update', options))
76
- return obj['result']
77
- end
78
-
79
- # Alias function for code written against 1.0 API
80
- def add(options)
81
- puts "WARNING API Function Item.add is deprecated and will be removed in the future without further warning"
82
- create(options)
83
- end
84
-
85
- def delete(ids)
86
- checkauth
87
- checkversion(1,1)
88
-
89
- obj=do_request(json_obj('item.delete', ids))
90
- return obj['result']
91
- end
92
- end
@@ -1,91 +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_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, :msg=>"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, :msg=>"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, :msg=>"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, :msg=>"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, :msg=>"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
@@ -1,71 +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_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, :msg=>"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, :msg=>"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
@@ -1,138 +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
- # 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, :msg=>"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