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.
- data/api_classes/api_dsl.rb +308 -0
- data/api_classes/{history.rb → dsl_event.rb} +8 -33
- data/api_classes/dsl_graph.rb +31 -0
- data/api_classes/dsl_history.rb +33 -0
- data/api_classes/dsl_host.rb +49 -0
- data/api_classes/{proxy.rb → dsl_hostgroup.rb} +13 -20
- data/api_classes/{user_group.rb → dsl_item.rb} +10 -29
- data/api_classes/dsl_proxy.rb +32 -0
- data/api_classes/dsl_template.rb +39 -0
- data/api_classes/dsl_trigger.rb +48 -0
- data/api_classes/{subclass_base.rb → dsl_user.rb} +16 -32
- data/api_classes/dsl_usergroup.rb +39 -0
- data/api_classes/dsl_usermacro.rb +39 -0
- data/api_classes/dsl_usermedia.rb +32 -0
- data/zbxapi.rb +105 -100
- data/zbxapi/api_exceptions.rb +2 -2
- data/zbxapi/exceptions.rb +2 -2
- data/zbxapi/result.rb +74 -0
- data/zbxapi/utils.rb +2 -2
- data/zbxapi/zdebug.rb +2 -2
- metadata +24 -20
- data/api_classes/application.rb +0 -88
- data/api_classes/graph.rb +0 -77
- data/api_classes/host.rb +0 -124
- data/api_classes/host_group.rb +0 -108
- data/api_classes/item.rb +0 -92
- data/api_classes/sysmap.rb +0 -91
- data/api_classes/trigger.rb +0 -71
- data/api_classes/user.rb +0 -138
- data/zbxapi/revision.rb +0 -7
|
@@ -19,29 +19,22 @@
|
|
|
19
19
|
#--
|
|
20
20
|
##########################################
|
|
21
21
|
# Subversion information
|
|
22
|
-
# $Id:
|
|
23
|
-
# $Revision:
|
|
22
|
+
# $Id: dsl_hostgroup.rb 395 2012-05-18 03:49:48Z nelsonab $
|
|
23
|
+
# $Revision: 395 $
|
|
24
24
|
##########################################
|
|
25
25
|
#++
|
|
26
26
|
|
|
27
|
-
require "api_classes/
|
|
27
|
+
require "api_classes/api_dsl"
|
|
28
28
|
|
|
29
|
+
class HostGroup < ZabbixAPI_Base
|
|
30
|
+
end
|
|
29
31
|
|
|
30
|
-
#******************************************************************************
|
|
31
|
-
#
|
|
32
|
-
# Class ZbxAPI_Proxy
|
|
33
|
-
#
|
|
34
|
-
# Class encapsulating proxy functions
|
|
35
|
-
#
|
|
36
|
-
# get
|
|
37
|
-
#
|
|
38
|
-
#******************************************************************************
|
|
39
32
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
33
|
+
HostGroup.get
|
|
34
|
+
HostGroup.exists
|
|
35
|
+
HostGroup.create
|
|
36
|
+
HostGroup.update
|
|
37
|
+
HostGroup.delete
|
|
38
|
+
HostGroup.massadd
|
|
39
|
+
HostGroup.massupdate
|
|
40
|
+
HostGroup.massremove
|
|
@@ -19,38 +19,19 @@
|
|
|
19
19
|
#--
|
|
20
20
|
##########################################
|
|
21
21
|
# Subversion information
|
|
22
|
-
# $Id:
|
|
23
|
-
# $Revision:
|
|
22
|
+
# $Id: dsl_item.rb 340 2011-10-14 23:22:06Z nelsonab $
|
|
23
|
+
# $Revision: 340 $
|
|
24
24
|
##########################################
|
|
25
25
|
#++
|
|
26
26
|
|
|
27
|
-
require "api_classes/
|
|
27
|
+
require "api_classes/api_dsl"
|
|
28
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)
|
|
29
|
+
class Item < ZabbixAPI_Base
|
|
52
30
|
|
|
53
|
-
obj=do_request(json_obj('usergroup.get',options))
|
|
54
|
-
return obj['result']
|
|
55
|
-
end
|
|
56
31
|
end
|
|
32
|
+
|
|
33
|
+
Item.get
|
|
34
|
+
Item.exists
|
|
35
|
+
Item.create
|
|
36
|
+
Item.update
|
|
37
|
+
Item.delete
|
|
@@ -0,0 +1,32 @@
|
|
|
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: dsl_proxy.rb 395 2012-05-18 03:49:48Z nelsonab $
|
|
23
|
+
# $Revision: 395 $
|
|
24
|
+
##########################################
|
|
25
|
+
#++
|
|
26
|
+
|
|
27
|
+
require "api_classes/api_dsl"
|
|
28
|
+
|
|
29
|
+
class Proxy < ZabbixAPI_Base
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
Proxy.get
|
|
@@ -0,0 +1,39 @@
|
|
|
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: dsl_template.rb 340 2011-10-14 23:22:06Z nelsonab $
|
|
23
|
+
# $Revision: 340 $
|
|
24
|
+
##########################################
|
|
25
|
+
#++
|
|
26
|
+
|
|
27
|
+
require "api_classes/api_dsl"
|
|
28
|
+
|
|
29
|
+
class Template < ZabbixAPI_Base
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
Template.get
|
|
33
|
+
Template.exists
|
|
34
|
+
Template.create
|
|
35
|
+
Template.update
|
|
36
|
+
Template.delete
|
|
37
|
+
Template.massadd
|
|
38
|
+
Template.massupdate
|
|
39
|
+
Template.massremove
|
|
@@ -0,0 +1,48 @@
|
|
|
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: dsl_trigger.rb 395 2012-05-18 03:49:48Z nelsonab $
|
|
23
|
+
# $Revision: 395 $
|
|
24
|
+
##########################################
|
|
25
|
+
#++
|
|
26
|
+
|
|
27
|
+
require "api_classes/api_dsl"
|
|
28
|
+
|
|
29
|
+
class Trigger < ZabbixAPI_Base
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
Trigger.addDependencies
|
|
33
|
+
Trigger.create
|
|
34
|
+
Trigger.delete
|
|
35
|
+
Trigger.deleteDependencies
|
|
36
|
+
Trigger.exists
|
|
37
|
+
Trigger.get do
|
|
38
|
+
add_valid_params "1.3", ['triggerids', "select_functions", "nodeids", "groupids", "templateids",
|
|
39
|
+
"hostids", "itemids", "applicationids", "functions", "inherited", "templated", "monitored",
|
|
40
|
+
"active", "maintenance", "withUnacknowledgedEvents", "withAcknowledgedEvents",
|
|
41
|
+
"withLastEventUnacknowledged", "skipDependent", "editable", "lastChangeSince",
|
|
42
|
+
"lastChangeTill", "filter", "group", "host", "only_true", "min_severity", "search",
|
|
43
|
+
"startSearch", "excludeSearch", "searchWildcardsEnabled", "output", "expandData",
|
|
44
|
+
"expandDescription", "select_groups", "select_hosts", "select_items", "select_dependencies",
|
|
45
|
+
"countOutput", "groupOutput", "preservekeys", "sortfield", "sortorder", "limit"]
|
|
46
|
+
end
|
|
47
|
+
Trigger.update
|
|
48
|
+
|
|
@@ -19,41 +19,25 @@
|
|
|
19
19
|
#--
|
|
20
20
|
##########################################
|
|
21
21
|
# Subversion information
|
|
22
|
-
# $Id:
|
|
23
|
-
# $Revision:
|
|
22
|
+
# $Id: dsl_user.rb 339 2011-10-14 18:57:38Z nelsonab $
|
|
23
|
+
# $Revision: 339 $
|
|
24
24
|
##########################################
|
|
25
25
|
#++
|
|
26
26
|
|
|
27
|
-
require
|
|
27
|
+
require "api_classes/api_dsl"
|
|
28
28
|
|
|
29
|
-
|
|
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
|
|
29
|
+
class User < ZabbixAPI_Base
|
|
35
30
|
|
|
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,args={})
|
|
57
|
-
@parent.debug(level,args)
|
|
58
|
-
end
|
|
59
31
|
end
|
|
32
|
+
|
|
33
|
+
User.get
|
|
34
|
+
User.create
|
|
35
|
+
User.update
|
|
36
|
+
User.updateprofile
|
|
37
|
+
User.delete
|
|
38
|
+
User.addmedia
|
|
39
|
+
User.updatemedia
|
|
40
|
+
User.deletemedia
|
|
41
|
+
User.authenticate
|
|
42
|
+
User.login
|
|
43
|
+
User.logout
|
|
@@ -0,0 +1,39 @@
|
|
|
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: dsl_usergroup.rb 340 2011-10-14 23:22:06Z nelsonab $
|
|
23
|
+
# $Revision: 340 $
|
|
24
|
+
##########################################
|
|
25
|
+
#++
|
|
26
|
+
|
|
27
|
+
require "api_classes/api_dsl"
|
|
28
|
+
|
|
29
|
+
class UserGroup < ZabbixAPI_Base
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
UserGroup.get
|
|
33
|
+
UserGroup.exists
|
|
34
|
+
UserGroup.create
|
|
35
|
+
UserGroup.update
|
|
36
|
+
UserGroup.delete
|
|
37
|
+
UserGroup.massadd
|
|
38
|
+
UserGroup.massupdate
|
|
39
|
+
UserGroup.massremove
|
|
@@ -0,0 +1,39 @@
|
|
|
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: dsl_usermacro.rb 340 2011-10-14 23:22:06Z nelsonab $
|
|
23
|
+
# $Revision: 340 $
|
|
24
|
+
##########################################
|
|
25
|
+
#++
|
|
26
|
+
|
|
27
|
+
require "api_classes/api_dsl"
|
|
28
|
+
|
|
29
|
+
class UserMacro < ZabbixAPI_Base
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
UserMacro.get
|
|
33
|
+
UserMacro.createglobal
|
|
34
|
+
UserMacro.updateglobal
|
|
35
|
+
UserMacro.deleteglobal
|
|
36
|
+
UserMacro.deletehostmacro
|
|
37
|
+
UserMacro.massadd
|
|
38
|
+
UserMacro.massupdate
|
|
39
|
+
UserMacro.massremove
|
|
@@ -0,0 +1,32 @@
|
|
|
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: dsl_usermedia.rb 340 2011-10-14 23:22:06Z nelsonab $
|
|
23
|
+
# $Revision: 340 $
|
|
24
|
+
##########################################
|
|
25
|
+
#++
|
|
26
|
+
|
|
27
|
+
require "api_classes/api_dsl"
|
|
28
|
+
|
|
29
|
+
class UserMedia < ZabbixAPI_Base
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
UserMedia.get
|
data/zbxapi.rb
CHANGED
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
#--
|
|
20
20
|
##########################################
|
|
21
21
|
# Subversion information
|
|
22
|
-
# $Id: zbxapi.rb
|
|
23
|
-
# $Revision:
|
|
22
|
+
# $Id: zbxapi.rb 413 2012-09-12 07:22:27Z nelsonab $
|
|
23
|
+
# $Revision: 413 $
|
|
24
24
|
##########################################
|
|
25
25
|
#++
|
|
26
26
|
|
|
@@ -29,34 +29,25 @@
|
|
|
29
29
|
class ZabbixAPI #create a stub to be defined later
|
|
30
30
|
end
|
|
31
31
|
|
|
32
|
-
class ZbxAPI_Sub < ZabbixAPI #create a stub to be defined later
|
|
33
|
-
end
|
|
34
|
-
|
|
35
32
|
#setup our search path or libraries
|
|
36
33
|
$: << File.expand_path(File.join(File.dirname(__FILE__), '.'))
|
|
37
34
|
|
|
38
|
-
require 'zbxapi/revision'
|
|
35
|
+
#require 'zbxapi/revision'
|
|
39
36
|
require 'zbxapi/zdebug'
|
|
40
37
|
require 'zbxapi/api_exceptions.rb'
|
|
38
|
+
require 'zbxapi/result'
|
|
41
39
|
require 'uri'
|
|
42
|
-
#require 'net/http'
|
|
43
40
|
require 'net/https'
|
|
44
41
|
require 'rubygems'
|
|
45
42
|
require 'json'
|
|
46
|
-
require 'pp'
|
|
47
43
|
|
|
48
|
-
require "api_classes/
|
|
49
|
-
require "api_classes/graph"
|
|
50
|
-
require "api_classes/history"
|
|
51
|
-
require "api_classes/host"
|
|
52
|
-
require "api_classes/host_group"
|
|
53
|
-
require "api_classes/item"
|
|
54
|
-
require "api_classes/proxy"
|
|
55
|
-
require "api_classes/sysmap"
|
|
56
|
-
require "api_classes/trigger"
|
|
57
|
-
require "api_classes/user"
|
|
58
|
-
require "api_classes/user_group"
|
|
44
|
+
require "api_classes/api_dsl"
|
|
59
45
|
|
|
46
|
+
#Dynamicly load all API description files
|
|
47
|
+
dir=File.dirname(__FILE__)+"/api_classes/"
|
|
48
|
+
Dir[dir + 'dsl_*.rb'].each do |file|
|
|
49
|
+
require dir+File.basename(file, File.extname(file))
|
|
50
|
+
end
|
|
60
51
|
|
|
61
52
|
|
|
62
53
|
#------------------------------------------------------------------------------
|
|
@@ -73,18 +64,15 @@ class ZabbixAPI
|
|
|
73
64
|
|
|
74
65
|
attr_accessor :method, :params, :debug_level, :auth, :verify_ssl
|
|
75
66
|
|
|
76
|
-
#subordinate class
|
|
77
|
-
attr_accessor :user # [User#new]
|
|
78
|
-
#subordinate class
|
|
79
|
-
attr_accessor :usergroup, :host, :item, :hostgroup, :application, :trigger, :sysmap, :history, :proxy, :graph
|
|
80
67
|
@id=0
|
|
81
68
|
@auth=''
|
|
82
69
|
@url=nil
|
|
83
|
-
@verify_ssl
|
|
70
|
+
@verify_ssl=true
|
|
84
71
|
|
|
85
72
|
private
|
|
86
73
|
@user_name=''
|
|
87
74
|
@password=''
|
|
75
|
+
@proxy_server=nil
|
|
88
76
|
|
|
89
77
|
|
|
90
78
|
class Redirect < Exception #:nodoc: all
|
|
@@ -92,37 +80,76 @@ class ZabbixAPI
|
|
|
92
80
|
|
|
93
81
|
public
|
|
94
82
|
|
|
83
|
+
class << self
|
|
84
|
+
public :define_method
|
|
85
|
+
end
|
|
86
|
+
|
|
95
87
|
# The initialization routine for the Zabbix API class
|
|
96
88
|
# * url is a string defining the url to connect to, it should only point to the base url for Zabbix, not the api directory
|
|
97
89
|
# * debug_level is the default level to be used for debug messages
|
|
98
90
|
# Upon successful initialization the class will be set up to allow a connection to the Zabbix server
|
|
99
91
|
# A connection however will not have been made, to actually connect to the Zabbix server use the login method
|
|
100
|
-
|
|
101
|
-
|
|
92
|
+
#options:
|
|
93
|
+
#Parameter Default Description
|
|
94
|
+
#:debug 0 Debug Level
|
|
95
|
+
#:returntype :result Return the value of "result" from the json result
|
|
96
|
+
#:verify_ssl true Enable checking the SSL Cert
|
|
97
|
+
def initialize(url,*args)
|
|
98
|
+
options=args[0]
|
|
99
|
+
options ||= {}
|
|
100
|
+
if options.is_a?(Fixnum)
|
|
101
|
+
warn "WARNING: Initialization has changed, backwards compatability is being used."
|
|
102
|
+
warn "WARNING: Use ZabbixAPI.new(url,:debug=>n,:returntype=>:result) to have the"
|
|
103
|
+
warn "WARNING: same capability as previous versions."
|
|
104
|
+
warn "WARNING: This depreciated functionality will be removed in a future release"
|
|
105
|
+
options={:debug=>0,:returntype=>:result}
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
set_debug_level(options[:debug] || 0)
|
|
109
|
+
@returntype=options[:returntype] || :result
|
|
110
|
+
@verify_ssl=options[:verify_ssl] || true
|
|
102
111
|
@orig_url=url #save the original url
|
|
103
112
|
@url=URI.parse(url+'/api_jsonrpc.php')
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
113
|
+
|
|
114
|
+
#Generate the list of sub objects dynamically, from all objects
|
|
115
|
+
#derived from ZabbixAPI_Base
|
|
116
|
+
objects=Object.constants.map do |i|
|
|
117
|
+
obj=Object.const_get(i.intern)
|
|
118
|
+
if obj.is_a?(Class) && ([ZabbixAPI_Base]-obj.ancestors).empty?
|
|
119
|
+
obj
|
|
120
|
+
else
|
|
121
|
+
nil
|
|
122
|
+
end
|
|
123
|
+
end.compact-[ZabbixAPI_Base]
|
|
124
|
+
|
|
125
|
+
@objects={}
|
|
126
|
+
|
|
127
|
+
objects.each do |i|
|
|
128
|
+
i_s=i.to_s.downcase.intern
|
|
129
|
+
@objects[i_s]=i.new(self)
|
|
130
|
+
self.class.define_method(i_s) do
|
|
131
|
+
instance_variable_get(:@objects)[i_s]
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
|
|
115
135
|
@id=0
|
|
116
|
-
@http_proxy=nil
|
|
117
136
|
|
|
118
137
|
debug(6,:msg=>"protocol: #{@url.scheme}, host: #{@url.host}")
|
|
119
138
|
debug(6,:msg=>"port: #{@url.port}, path: #{@url.path}")
|
|
120
139
|
debug(6,:msg=>"query: #{@url.query}, fragment: #{@url.fragment}")
|
|
140
|
+
|
|
141
|
+
if block_given?
|
|
142
|
+
puts "block"
|
|
143
|
+
yield(self)
|
|
144
|
+
end
|
|
121
145
|
end
|
|
122
146
|
|
|
147
|
+
#Configure the information for the proxy server to be used to connect to the
|
|
148
|
+
#Zabbix server
|
|
123
149
|
def set_proxy(address,port,user=nil,password=nil)
|
|
124
|
-
@
|
|
125
|
-
|
|
150
|
+
@proxy_server={:address=>address,:port=>port,
|
|
151
|
+
:user=>user, :password=>password}
|
|
152
|
+
return self
|
|
126
153
|
end
|
|
127
154
|
|
|
128
155
|
def self.get_version
|
|
@@ -188,7 +215,7 @@ class ZabbixAPI
|
|
|
188
215
|
@auth=result['result']
|
|
189
216
|
|
|
190
217
|
#setup the version variables
|
|
191
|
-
@major,@minor=do_request(json_obj('
|
|
218
|
+
@major,@minor=do_request(json_obj('APIInfo.version',{}))['result'].split('.')
|
|
192
219
|
@major=@major.to_i
|
|
193
220
|
@minor=@minor.to_i
|
|
194
221
|
rescue ZbxAPI_ExceptionLoginPermission => e
|
|
@@ -207,6 +234,8 @@ class ZabbixAPI
|
|
|
207
234
|
rescue => e
|
|
208
235
|
raise ZbxAPI_ExceptionBadAuth.new('General Login error, check host connectivity.')
|
|
209
236
|
end
|
|
237
|
+
|
|
238
|
+
return self
|
|
210
239
|
end
|
|
211
240
|
|
|
212
241
|
def logout
|
|
@@ -274,15 +303,36 @@ class ZabbixAPI
|
|
|
274
303
|
|
|
275
304
|
end
|
|
276
305
|
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
306
|
+
#api_call
|
|
307
|
+
#This is the main function for performing api requests
|
|
308
|
+
#method is a string denoting the method to call
|
|
309
|
+
#options is a hash of options to be passed to the function
|
|
310
|
+
def api_call(method,options={})
|
|
311
|
+
debug(6,:msg=>"Method",:var=>method)
|
|
312
|
+
debug(6,:msg=>"Options",:var=>options)
|
|
313
|
+
|
|
314
|
+
obj=json_obj(method,options)
|
|
315
|
+
result=do_request(obj)
|
|
316
|
+
if @returntype==:result
|
|
317
|
+
result["result"]
|
|
318
|
+
else
|
|
319
|
+
result.merge!({:method=>method, :params=>options})
|
|
320
|
+
@returntype.new(result)
|
|
321
|
+
end
|
|
322
|
+
end
|
|
323
|
+
|
|
324
|
+
private
|
|
325
|
+
|
|
326
|
+
#Select the http object to be used.
|
|
327
|
+
def select_http_obj
|
|
328
|
+
if @proxy_server
|
|
329
|
+
http = Net::HTTP::Proxy(@proxy_server[:address],@proxy_server[:port],
|
|
330
|
+
@proxy_server[:user],@proxy_server[:password]).new(@url.host,@url.port)
|
|
281
331
|
else
|
|
282
332
|
http = Net::HTTP.new(@url.host, @url.port)
|
|
283
333
|
end
|
|
284
334
|
http.use_ssl=true if @url.class==URI::HTTPS
|
|
285
|
-
if
|
|
335
|
+
if !@verify_ssl
|
|
286
336
|
http.verify_mode = OpenSSL::SSL::VERIFY_NONE if @url.class==URI::HTTPS
|
|
287
337
|
end
|
|
288
338
|
http
|
|
@@ -294,8 +344,9 @@ class ZabbixAPI
|
|
|
294
344
|
def do_request(json_obj,truncate_length=5000)
|
|
295
345
|
redirects=0
|
|
296
346
|
begin # This is here for redirects
|
|
297
|
-
http=
|
|
347
|
+
http=select_http_obj
|
|
298
348
|
response = nil
|
|
349
|
+
# http.set_debug_output($stderr) #Uncomment to see low level HTTP debug
|
|
299
350
|
headers={'Content-Type'=>'application/json-rpc',
|
|
300
351
|
'User-Agent'=>'Zbx Ruby CLI'}
|
|
301
352
|
debug(4,:msg=>"Sending: #{json_obj}")
|
|
@@ -310,7 +361,6 @@ class ZabbixAPI
|
|
|
310
361
|
when 500
|
|
311
362
|
raise ZbxAPI_GeneralError.new("Zabbix server returned an internal error\n Call: #{json_obj}", :retry=>true)
|
|
312
363
|
end
|
|
313
|
-
# end
|
|
314
364
|
|
|
315
365
|
@id+=1 # increment the ID value for the API call
|
|
316
366
|
|
|
@@ -335,13 +385,11 @@ class ZabbixAPI
|
|
|
335
385
|
redirects+=1
|
|
336
386
|
retry if redirects<=5
|
|
337
387
|
raise ZbxAPI_GeneralError, "Too many redirects"
|
|
338
|
-
rescue NoMethodError
|
|
339
|
-
raise ZbxAPI_GeneralError.new("Unable to connect to #{@url.host}
|
|
388
|
+
rescue NoMethodError
|
|
389
|
+
raise ZbxAPI_GeneralError.new("Unable to connect to #{@url.host}: \"#{e}\"", :retry=>false)
|
|
340
390
|
end
|
|
341
391
|
end
|
|
342
392
|
|
|
343
|
-
private
|
|
344
|
-
|
|
345
393
|
def setup_connection
|
|
346
394
|
@http=Net::HTTP.new(@url.host, @url.port)
|
|
347
395
|
http.use_ssl=true if @url.class==URI::HTTPS
|
|
@@ -352,54 +400,11 @@ end
|
|
|
352
400
|
|
|
353
401
|
|
|
354
402
|
if __FILE__ == $0
|
|
403
|
+
require 'pp'
|
|
355
404
|
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
puts
|
|
361
|
-
puts "Getting user groups"
|
|
362
|
-
p zbx_api.usergroup.get
|
|
363
|
-
|
|
364
|
-
puts
|
|
365
|
-
puts "testing user.get"
|
|
366
|
-
zbx_api.debug_level=8
|
|
367
|
-
p zbx_api.user.get()
|
|
368
|
-
p zbx_api.user.get({"extendoutput"=>true})
|
|
369
|
-
zbx_api.debug_level=0
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
puts
|
|
373
|
-
puts "Getting by username, admin, number should be seen"
|
|
374
|
-
p zbx_api.user.getid('admin')
|
|
375
|
-
puts "Trying a bogus username"
|
|
376
|
-
p zbx_api.user.getid('bogus')
|
|
377
|
-
|
|
378
|
-
puts
|
|
379
|
-
puts "adding the user 'test' to Zabbix"
|
|
380
|
-
uid= zbx_api.user.create(
|
|
381
|
-
[{ "name"=>"test",
|
|
382
|
-
"alias"=>"testapiuser",
|
|
383
|
-
"password"=>"test",
|
|
384
|
-
"url"=>"",
|
|
385
|
-
"autologin"=>0,
|
|
386
|
-
"autologout"=>900,
|
|
387
|
-
"theme"=>"default.css",
|
|
388
|
-
"refresh"=>60,
|
|
389
|
-
"rows_per_page"=>50,
|
|
390
|
-
"lang"=>"en_GB",
|
|
391
|
-
"type"=>3}])
|
|
392
|
-
p uid
|
|
393
|
-
puts "Deleting userid #{uid.keys[0]}"
|
|
394
|
-
p zbx_api.user.delete(uid.values[0])
|
|
395
|
-
|
|
396
|
-
puts
|
|
397
|
-
puts "getting items"
|
|
398
|
-
p zbx_api.item.get
|
|
399
|
-
|
|
400
|
-
puts
|
|
401
|
-
puts "getting items by host"
|
|
402
|
-
puts "host: #{hosts.values[0]}"
|
|
403
|
-
p items=zbx_api.item.get({'hostids'=>hosts.values[0]})
|
|
405
|
+
zbx=ZabbixAPI.new("http://zabbix.example.com/")
|
|
406
|
+
#zbx.set_proxy("localhost",3128)
|
|
407
|
+
zbx.login("user","password")
|
|
408
|
+
pp zbx.host.get("output"=>"extend")
|
|
404
409
|
|
|
405
410
|
end
|