├── gems ├── zbxapi-0.1.1.gem ├── zbxapi-0.3.3.gem ├── zbxapi-0.1.291.gem ├── zbxapi-0.1.292.gem ├── zbxapi-0.1.294.gem ├── zbxapi-0.1.315.gem ├── zbxapi-0.1.319.gem ├── zbxapi-0.1.321.gem ├── zbxapi-0.1.324.gem ├── zbxapi-0.1.335.gem ├── zbxapi-0.1.344.gem └── zbxapi-0.1.386.gem ├── .gitignore ├── zbxapi ├── revision.rb ├── defines.rb ├── utils.rb ├── result.rb ├── exceptions.rb ├── api_exceptions.rb └── zdebug.rb ├── api_classes ├── dsl_alert.rb ├── dsl_dhost.rb ├── dsl_dcheck.rb ├── dsl_dservice.rb ├── dsl_configuration.rb ├── dsl_action.rb ├── dsl_drule.rb ├── dsl_maintenance.rb ├── dsl_hostinterface.rb ├── dsl_usermedia.rb ├── dsl_graph.rb ├── dsl_history.rb ├── dsl_event.rb ├── dsl_proxy.rb ├── dsl_item.rb ├── dsl_httptest.rb ├── dsl_mediatype.rb ├── dsl_template.rb ├── dsl_usergroup.rb ├── dsl_hostgroup.rb ├── dsl_user.rb ├── dsl_usermacro.rb ├── dsl_trigger.rb ├── dsl_host.rb └── api_dsl.rb ├── ts_local_vars.rb_template ├── api_tests ├── test_utilities.rb ├── tc_test_host.rb ├── tc_test_debug.rb └── tc_test_user.rb ├── zbxapi.gemspec ├── ts_all_tests.rb ├── result_test.rb ├── rakefile.rb ├── README.md ├── zbxapi.rb └── LICENSE /gems/zbxapi-0.1.1.gem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/red-tux/zbxapi/HEAD/gems/zbxapi-0.1.1.gem -------------------------------------------------------------------------------- /gems/zbxapi-0.3.3.gem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/red-tux/zbxapi/HEAD/gems/zbxapi-0.3.3.gem -------------------------------------------------------------------------------- /gems/zbxapi-0.1.291.gem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/red-tux/zbxapi/HEAD/gems/zbxapi-0.1.291.gem -------------------------------------------------------------------------------- /gems/zbxapi-0.1.292.gem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/red-tux/zbxapi/HEAD/gems/zbxapi-0.1.292.gem -------------------------------------------------------------------------------- /gems/zbxapi-0.1.294.gem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/red-tux/zbxapi/HEAD/gems/zbxapi-0.1.294.gem -------------------------------------------------------------------------------- /gems/zbxapi-0.1.315.gem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/red-tux/zbxapi/HEAD/gems/zbxapi-0.1.315.gem -------------------------------------------------------------------------------- /gems/zbxapi-0.1.319.gem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/red-tux/zbxapi/HEAD/gems/zbxapi-0.1.319.gem -------------------------------------------------------------------------------- /gems/zbxapi-0.1.321.gem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/red-tux/zbxapi/HEAD/gems/zbxapi-0.1.321.gem -------------------------------------------------------------------------------- /gems/zbxapi-0.1.324.gem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/red-tux/zbxapi/HEAD/gems/zbxapi-0.1.324.gem -------------------------------------------------------------------------------- /gems/zbxapi-0.1.335.gem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/red-tux/zbxapi/HEAD/gems/zbxapi-0.1.335.gem -------------------------------------------------------------------------------- /gems/zbxapi-0.1.344.gem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/red-tux/zbxapi/HEAD/gems/zbxapi-0.1.344.gem -------------------------------------------------------------------------------- /gems/zbxapi-0.1.386.gem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/red-tux/zbxapi/HEAD/gems/zbxapi-0.1.386.gem -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore Rubymine Files 2 | .idea 3 | .idea/* 4 | 5 | # Try to prevent uploading password information 6 | ts_local_vars.rb -------------------------------------------------------------------------------- /zbxapi/revision.rb: -------------------------------------------------------------------------------- 1 | #CHANGES TO THIS FILE WILL AUTOMATICALLY BE OVERWRITTEN 2 | #This file is autogenerated by the zbxapi rakefile. 3 | #This file contains the latest SVN revision number at the time 4 | #the rakefile was run 5 | 6 | ZBXAPI_VERSION="0.3.7" 7 | -------------------------------------------------------------------------------- /api_classes/dsl_alert.rb: -------------------------------------------------------------------------------- 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 | require "api_classes/api_dsl" 20 | 21 | class Alert < ZabbixAPI_Base 22 | 23 | end 24 | 25 | Alert.get 26 | 27 | -------------------------------------------------------------------------------- /api_classes/dsl_dhost.rb: -------------------------------------------------------------------------------- 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 | require "api_classes/api_dsl" 20 | 21 | class Dhost < ZabbixAPI_Base 22 | 23 | end 24 | 25 | Dhost.exists 26 | Dhost.get 27 | 28 | -------------------------------------------------------------------------------- /api_classes/dsl_dcheck.rb: -------------------------------------------------------------------------------- 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 | require "api_classes/api_dsl" 20 | 21 | class Dcheck < ZabbixAPI_Base 22 | 23 | end 24 | 25 | Dcheck.exists 26 | Dcheck.get 27 | 28 | -------------------------------------------------------------------------------- /api_classes/dsl_dservice.rb: -------------------------------------------------------------------------------- 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 | require "api_classes/api_dsl" 20 | 21 | class Dservice < ZabbixAPI_Base 22 | 23 | end 24 | 25 | Dservice.exists 26 | Dservice.get 27 | 28 | -------------------------------------------------------------------------------- /api_classes/dsl_configuration.rb: -------------------------------------------------------------------------------- 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 | require "api_classes/api_dsl" 20 | 21 | class Configuration < ZabbixAPI_Base 22 | 23 | end 24 | 25 | Configuration.export 26 | Configuration.import 27 | 28 | -------------------------------------------------------------------------------- /api_classes/dsl_action.rb: -------------------------------------------------------------------------------- 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 | require "api_classes/api_dsl" 20 | 21 | class Action < ZabbixAPI_Base 22 | 23 | end 24 | 25 | Action.create 26 | Action.delete 27 | Action.exists 28 | Action.get 29 | Action.update 30 | 31 | -------------------------------------------------------------------------------- /api_classes/dsl_drule.rb: -------------------------------------------------------------------------------- 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 | require "api_classes/api_dsl" 20 | 21 | class Drule < ZabbixAPI_Base 22 | 23 | end 24 | 25 | Drule.create 26 | Drule.delete 27 | Drule.exists 28 | Drule.get 29 | Drule.isreadable 30 | Drule.iswritable 31 | Drule.update 32 | 33 | -------------------------------------------------------------------------------- /api_classes/dsl_maintenance.rb: -------------------------------------------------------------------------------- 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 | require "api_classes/api_dsl" 20 | 21 | class Maintenance < ZabbixAPI_Base 22 | 23 | end 24 | 25 | Maintenance.create 26 | Maintenance.delete 27 | Maintenance.exists 28 | Maintenance.get 29 | Maintenance.update 30 | 31 | -------------------------------------------------------------------------------- /ts_local_vars.rb_template: -------------------------------------------------------------------------------- 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$ 21 | # $Revision$ 22 | ########################################## 23 | 24 | #This is the file which contains the variables used for unit testing 25 | #this file must be copied to "ts_local_vars.rb" to be used. 26 | 27 | $server="" 28 | $api_user="" 29 | $api_pass="" 30 | -------------------------------------------------------------------------------- /api_classes/dsl_hostinterface.rb: -------------------------------------------------------------------------------- 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 | require "api_classes/api_dsl" 20 | 21 | class Hostinterface < ZabbixAPI_Base 22 | 23 | end 24 | 25 | Hostinterface.create 26 | Hostinterface.delete 27 | Hostinterface.exists 28 | Hostinterface.get 29 | Hostinterface.massadd 30 | Hostinterface.replacehostinterfaces 31 | Hostinterface.update 32 | -------------------------------------------------------------------------------- /api_classes/dsl_usermedia.rb: -------------------------------------------------------------------------------- 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 -------------------------------------------------------------------------------- /api_classes/dsl_graph.rb: -------------------------------------------------------------------------------- 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_graph.rb 409 2012-09-11 23:39:58Z nelsonab $ 23 | # $Revision: 409 $ 24 | ########################################## 25 | #++ 26 | 27 | require "api_classes/api_dsl" 28 | 29 | class Graph < ZabbixAPI_Base 30 | actions :get, :create, :update, :delete 31 | end -------------------------------------------------------------------------------- /api_classes/dsl_history.rb: -------------------------------------------------------------------------------- 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_history.rb 337 2011-10-14 16:11:39Z nelsonab $ 23 | # $Revision: 337 $ 24 | ########################################## 25 | #++ 26 | 27 | require "api_classes/api_dsl" 28 | 29 | class History < ZabbixAPI_Base 30 | end 31 | 32 | History.get 33 | History.delete -------------------------------------------------------------------------------- /api_classes/dsl_event.rb: -------------------------------------------------------------------------------- 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_event.rb 340 2011-10-14 23:22:06Z nelsonab $ 23 | # $Revision: 340 $ 24 | ########################################## 25 | #++ 26 | 27 | require "api_classes/api_dsl" 28 | 29 | class Event < ZabbixAPI_Base 30 | end 31 | 32 | Event.get 33 | Event.acknowledge 34 | Event.delete -------------------------------------------------------------------------------- /api_classes/dsl_proxy.rb: -------------------------------------------------------------------------------- 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 33 | Proxy.create 34 | Proxy.delete 35 | Proxy.update 36 | -------------------------------------------------------------------------------- /api_classes/dsl_item.rb: -------------------------------------------------------------------------------- 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_item.rb 340 2011-10-14 23:22:06Z nelsonab $ 23 | # $Revision: 340 $ 24 | ########################################## 25 | #++ 26 | 27 | require "api_classes/api_dsl" 28 | 29 | class Item < ZabbixAPI_Base 30 | 31 | end 32 | 33 | Item.get 34 | Item.exists 35 | Item.create 36 | Item.update 37 | Item.delete -------------------------------------------------------------------------------- /api_classes/dsl_httptest.rb: -------------------------------------------------------------------------------- 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_hostgroup.rb 395 2012-05-18 03:49:48Z nelsonab $ 23 | # $Revision: 395 $ 24 | ########################################## 25 | #++ 26 | 27 | require "api_classes/api_dsl" 28 | 29 | class HttpTest < ZabbixAPI_Base 30 | end 31 | 32 | 33 | HttpTest.get 34 | HttpTest.create 35 | HttpTest.update 36 | HttpTest.delete 37 | -------------------------------------------------------------------------------- /api_classes/dsl_mediatype.rb: -------------------------------------------------------------------------------- 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_mediatype.rb 339 2011-10-14 18:57:38Z derekso $ 23 | # $Revision: 339 $ 24 | ########################################## 25 | #++ 26 | 27 | require "api_classes/api_dsl" 28 | 29 | class MediaType < ZabbixAPI_Base 30 | 31 | end 32 | 33 | MediaType.get 34 | MediaType.create 35 | MediaType.update 36 | MediaType.delete 37 | -------------------------------------------------------------------------------- /api_classes/dsl_template.rb: -------------------------------------------------------------------------------- 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 -------------------------------------------------------------------------------- /api_tests/test_utilities.rb: -------------------------------------------------------------------------------- 1 | #License:: LGPL 2.1 http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 2 | #Copyright:: Copyright (C) 2009,2010 Andrew Nelson nelsonab(at)red-tux(dot)net 3 | # 4 | #This library is free software; you can redistribute it and/or 5 | #modify it under the terms of the GNU Lesser General Public 6 | #License as published by the Free Software Foundation; either 7 | #version 2.1 of the License, or (at your option) any later version. 8 | # 9 | #This library 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 GNU 12 | #Lesser General Public License for more details. 13 | # 14 | #You should have received a copy of the GNU Lesser General Public 15 | #License along with this library; 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: test_utilities.rb 337 2011-10-14 16:11:39Z nelsonab $ 21 | # $Revision: 337 $ 22 | ########################################## 23 | 24 | #credit goes to: http://thinkingdigitally.com/archive/capturing-output-from-puts-in-ruby/ 25 | 26 | require 'stringio' 27 | 28 | module Kernel 29 | 30 | def capture_stdout 31 | out = StringIO.new 32 | $stdout = out 33 | yield 34 | return out 35 | ensure 36 | $stdout = STDOUT 37 | end 38 | 39 | end -------------------------------------------------------------------------------- /api_classes/dsl_usergroup.rb: -------------------------------------------------------------------------------- 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 -------------------------------------------------------------------------------- /api_classes/dsl_hostgroup.rb: -------------------------------------------------------------------------------- 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_hostgroup.rb 395 2012-05-18 03:49:48Z nelsonab $ 23 | # $Revision: 395 $ 24 | ########################################## 25 | #++ 26 | 27 | require "api_classes/api_dsl" 28 | 29 | class HostGroup < ZabbixAPI_Base 30 | end 31 | 32 | 33 | HostGroup.get 34 | HostGroup.exists 35 | HostGroup.create 36 | HostGroup.update 37 | HostGroup.delete 38 | HostGroup.massadd 39 | HostGroup.massupdate 40 | HostGroup.massremove -------------------------------------------------------------------------------- /api_classes/dsl_user.rb: -------------------------------------------------------------------------------- 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_user.rb 339 2011-10-14 18:57:38Z nelsonab $ 23 | # $Revision: 339 $ 24 | ########################################## 25 | #++ 26 | 27 | require "api_classes/api_dsl" 28 | 29 | class User < ZabbixAPI_Base 30 | 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 44 | -------------------------------------------------------------------------------- /api_classes/dsl_usermacro.rb: -------------------------------------------------------------------------------- 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 -------------------------------------------------------------------------------- /zbxapi/defines.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | 3 | #GPL 2.0 http://www.gnu.org/licenses/gpl-2.0.html 4 | #Zabbix CLI Tool and associated files 5 | #Copyright (C) 2009,2010 Andrew Nelson nelsonab(at)red-tux(dot)net 6 | # 7 | #This program is free software; you can redistribute it and/or 8 | #modify it under the terms of the GNU General Public License 9 | #as published by the Free Software Foundation; either version 2 10 | #of the License, or (at your option) any later version. 11 | # 12 | #This program is distributed in the hope that it will be useful, 13 | #but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | #GNU General Public License for more details. 16 | # 17 | #You should have received a copy of the GNU General Public License 18 | #along with this program; if not, write to the Free Software 19 | #Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 | 21 | ########################################## 22 | # Subversion information 23 | # $Id: defines.rb 337 2011-10-14 16:11:39Z nelsonab $ 24 | # $Revision: 337 $ 25 | ########################################## 26 | 27 | # Zabbix constants 28 | 29 | # Sysmap elements (Create Element Type drop down menu): 30 | ME_HOST=0 31 | ME_MAP=1 32 | ME_TRIGGER=2 33 | ME_HOSTGROUP=3 34 | ME_IMAGE=4 35 | 36 | # Sysmap connection draw type 37 | MC_DT_LINE=1 38 | MC_DT_BOLD=2 39 | MC_DT_DOT=3 40 | MC_DT_DASHED=4 41 | 42 | # Sysmap label location 43 | ML_BOTTOM=0 44 | ML_LEFT=1 45 | ML_RIGHT=2 46 | ML_TOP=3 47 | -------------------------------------------------------------------------------- /zbxapi/utils.rb: -------------------------------------------------------------------------------- 1 | #License:: LGPL 2.1 http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 2 | #Copyright:: Copyright (C) 2009,2010 Andrew Nelson nelsonab(at)red-tux(dot)net 3 | # 4 | #This library is free software; you can redistribute it and/or 5 | #modify it under the terms of the GNU Lesser General Public 6 | #License as published by the Free Software Foundation; either 7 | #version 2.1 of the License, or (at your option) any later version. 8 | # 9 | #This library 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 GNU 12 | #Lesser General Public License for more details. 13 | # 14 | #You should have received a copy of the GNU Lesser General Public 15 | #License along with this library; 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: utils.rb 337 2011-10-14 16:11:39Z nelsonab $ 21 | # $Revision: 337 $ 22 | ########################################## 23 | 24 | 25 | class Object 26 | #self.class_of? 27 | #Ruby's is_a? or kind_of? will only tell you the hierarchy of classes which 28 | #have been instantiated. 29 | def self.class_of?(obj) 30 | raise RuntimeError.new("Obj must be an uninstantiated class, often calling method \".class\" works") if obj.class!=Class 31 | return true if self==obj 32 | if self.superclass.respond_to?(:class_of?) 33 | self.superclass.class_of?(obj) 34 | else 35 | false 36 | end 37 | end 38 | end 39 | -------------------------------------------------------------------------------- /zbxapi.gemspec: -------------------------------------------------------------------------------- 1 | # -*- encoding: utf-8 -*- 2 | # stub: zbxapi 0.3.3 ruby . 3 | 4 | Gem::Specification.new do |s| 5 | s.name = "zbxapi" 6 | s.version = "0.3.11" 7 | 8 | s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= 9 | s.require_paths = ["."] 10 | s.authors = ["A. Nelson"] 11 | s.date = "2017-12-05" 12 | s.description = "Provides a straight forward interface to manipulate Zabbix servers using the Zabbix API." 13 | s.email = "nelsonab@red-tux.net" 14 | s.files = ["LICENSE", "api_classes/api_dsl.rb", "api_classes/dsl_action.rb", "api_classes/dsl_alert.rb", "api_classes/dsl_configuration.rb", "api_classes/dsl_dcheck.rb", "api_classes/dsl_dhost.rb", "api_classes/dsl_drule.rb", "api_classes/dsl_dservice.rb", "api_classes/dsl_event.rb", "api_classes/dsl_graph.rb", "api_classes/dsl_history.rb", "api_classes/dsl_host.rb", "api_classes/dsl_hostgroup.rb", "api_classes/dsl_hostinterface.rb", "api_classes/dsl_item.rb", "api_classes/dsl_mediatype.rb", "api_classes/dsl_proxy.rb", "api_classes/dsl_template.rb", "api_classes/dsl_trigger.rb", "api_classes/dsl_user.rb", "api_classes/dsl_usergroup.rb", "api_classes/dsl_usermacro.rb", "api_classes/dsl_usermedia.rb", "zbxapi.rb", "zbxapi/api_exceptions.rb", "zbxapi/exceptions.rb", "zbxapi/result.rb", "zbxapi/utils.rb", "zbxapi/zdebug.rb"] 15 | s.homepage = "https://github.com/red-tux/zbxapi" 16 | s.licenses = ["LGPL 2.1"] 17 | s.requirements = ["Requires json"] 18 | s.rubyforge_project = "zbxapi" 19 | s.rubygems_version = "2.5.2" 20 | s.summary = "Ruby wrapper to the Zabbix API" 21 | 22 | if s.respond_to? :specification_version then 23 | s.specification_version = 3 24 | 25 | if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then 26 | s.add_runtime_dependency(%q, [">= 0"]) 27 | else 28 | s.add_dependency(%q, [">= 0"]) 29 | end 30 | else 31 | s.add_dependency(%q, [">= 0"]) 32 | end 33 | end 34 | 35 | -------------------------------------------------------------------------------- /ts_all_tests.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | 3 | ##License:: GPL 2.0 http://www.gnu.org/licenses/gpl-2.0.html 4 | #Copyright:: Copyright (C) 2009,2010 Andrew Nelson nelsonab(at)red-tux(dot)net 5 | # 6 | #This program is free software; you can redistribute it and/or 7 | #modify it under the terms of the GNU General Public License 8 | #as published by the Free Software Foundation; either version 2 9 | #of the License, or (at your option) any later version. 10 | # 11 | #This program is distributed in the hope that it will be useful, 12 | #but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | #GNU General Public License for more details. 15 | # 16 | #You should have received a copy of the GNU General Public License 17 | #along with this program; if not, write to the Free Software 18 | #Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | 20 | ########################################## 21 | # Subversion information 22 | # $Id$ 23 | # $Revision$ 24 | ########################################## 25 | 26 | #$: << 27 | CURRENT_DIR=File.expand_path(File.join(File.dirname(__FILE__), '.')) 28 | $LOAD_PATH<ApiResult) 35 | @zbx_api.login(@api_user,@api_pass) 36 | 37 | end 38 | 39 | # Called after every test method runs. Can be used to tear 40 | # down fixture information. 41 | 42 | def teardown 43 | # Do nothing 44 | end 45 | 46 | # Fake test 47 | def test_01_create_host 48 | assert_nothing_raised(ZbxAPI_GeneralError) do 49 | result =@zbx_api.host.create({"host"=>"test_server", "dns"=>"host.example.com", "proxy_hostid"=>0, 50 | "groups"=>[{"groupid"=>1}], "useip"=>0}) 51 | # @@id=result["hostids"][0].to_i 52 | end 53 | 54 | end 55 | 56 | def test_02_get_host_with_no_arguments 57 | assert_nothing_raised(ArgumentError){result=@zbx_api.host.get} 58 | end 59 | 60 | def test_03_get_host_by_key_of_hash_as_symbol 61 | assert_nothing_raised(ZbxAPI_ParameterError){result=@zbx_api.host.get({:output=>"extend"})} 62 | end 63 | 64 | def test_99_delete_host 65 | id=-1 66 | assert_nothing_raised(ZbxAPI_GeneralError) do 67 | result=@zbx_api.host.get("filter"=>{"host"=>["test_server"]}) 68 | id = result[0]["hostid"].to_i 69 | end 70 | 71 | assert_nothing_raised(ZbxAPI_GeneralError) do 72 | @zbx_api.host.delete(id) 73 | end 74 | 75 | end 76 | end 77 | -------------------------------------------------------------------------------- /api_tests/tc_test_debug.rb: -------------------------------------------------------------------------------- 1 | #License:: LGPL 2.1 http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 2 | #Copyright:: Copyright (C) 2009,2010 Andrew Nelson nelsonab(at)red-tux(dot)net 3 | # 4 | #This library is free software; you can redistribute it and/or 5 | #modify it under the terms of the GNU Lesser General Public 6 | #License as published by the Free Software Foundation; either 7 | #version 2.1 of the License, or (at your option) any later version. 8 | # 9 | #This library 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 GNU 12 | #Lesser General Public License for more details. 13 | # 14 | #You should have received a copy of the GNU Lesser General Public 15 | #License along with this library; 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: tc_test_debug.rb 337 2011-10-14 16:11:39Z nelsonab $ 21 | # $Revision: 337 $ 22 | ########################################## 23 | 24 | require 'rubygems' 25 | require "test/unit" 26 | require "api_tests/test_utilities" 27 | require 'zbxapi/zdebug' 28 | 29 | class TC_Test_00_Debug < Test::Unit::TestCase 30 | include ZDebug 31 | 32 | # Called before every test method runs. Can be used 33 | # to set up fixture information. 34 | def setup 35 | set_debug_level(0) 36 | end 37 | 38 | # Called after every test method runs. Can be used to tear 39 | # down fixture information. 40 | 41 | def teardown 42 | 43 | end 44 | 45 | def test_00_debug_5 46 | out = capture_stdout do 47 | set_debug_level(0) 48 | debug(1,:msg=>"none",:var=>"none") 49 | end 50 | assert_equal("",out.string) 51 | end 52 | 53 | 54 | def test_00_debug_10 55 | out = capture_stdout do 56 | set_debug_level(1) 57 | debug(1) 58 | end 59 | assert_match(/^D1 \.\.\.\/api_tests\/tc_test_debug\.rb:(block in )?test_00_debug_10:\d+ $/,out.string) 60 | end 61 | 62 | def test_00_debug_15 63 | out = capture_stdout do 64 | set_debug_level(1) 65 | debug(1,:msg=>"none",:var=>"none") 66 | end 67 | assert_match(/^D1 \.\.\.\/api_tests\/tc_test_debug\.rb:(block in )?test_00_debug_15:\d+ none: none$/,out.string) 68 | end 69 | 70 | def test_00_debug_20 71 | out = capture_stdout do 72 | set_debug_level(1) 73 | debug(1,:var=>"Truncation Test",:truncate=>4) 74 | end 75 | assert_match(/^D1 \.\.\.\/api_tests\/tc_test_debug\.rb:(block in )?test_00_debug_20:\d+ Tru \.\.\.\.\. st$/,out.string) 76 | end 77 | 78 | def test_00_debug_25 79 | out = capture_stdout do 80 | set_debug_level(1) 81 | debug(1,:trace_depth=>3) 82 | end 83 | 84 | #puts out.string.length 85 | 86 | assert(out.string.length>=230,"at least 230 characters are expected from this debug test") 87 | end 88 | 89 | 90 | end 91 | -------------------------------------------------------------------------------- /result_test.rb: -------------------------------------------------------------------------------- 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 | #require 'zbxapi.rb' 20 | 21 | #$server="http://192.168.166.10" 22 | #$api_user="apitest" 23 | #$api_pass="apitest" 24 | 25 | #zbx_api = ZabbixAPI.new($server) 26 | #zbx_api.login($api_user,$api_pass) 27 | # 28 | #result=zbx_api.host.get({"output"=>"extend"}) 29 | #p result 30 | #p result.fields 31 | #p result.method_called 32 | #p result.params 33 | 34 | #class A 35 | # def method_missing(sym,*args) 36 | # p sym 37 | # A.new 38 | # end 39 | #end 40 | # 41 | #a=A.new 42 | # 43 | #p a.test 44 | #p a.test.two 45 | 46 | #class Base 47 | # @dyn_methods={} 48 | # @dyn_keys=[] 49 | # 50 | # def method_missing(sym,*args) 51 | # p sym 52 | # 53 | # if self.class.dkeys.index(sym) 54 | # self.class.dmethods[sym].call 55 | ## self.class.dmethods[sym].call(args) 56 | # else 57 | # super(sym,args) 58 | # end 59 | # end 60 | # 61 | # def self.dmethods 62 | # @dyn_methods 63 | # end 64 | # def self.addmethod(sym,block) 65 | # @dyn_methods={} if @dyn_methods.nil? 66 | # @dyn_methods.merge!({sym=>block}) 67 | # @dyn_keys=@dyn_methods.keys 68 | # end 69 | # 70 | # def self.dkeys 71 | # @dyn_keys 72 | # end 73 | # 74 | # def self.create_method(sym, &block) 75 | # self.addmethod(sym,block) 76 | # end 77 | # 78 | # def func 79 | # puts "my function" 80 | # end 81 | #end 82 | # 83 | #class CApiResult) 44 | @zbx_api.login(@api_user,@api_pass) 45 | end 46 | 47 | # Called after every test method runs. Can be used to tear 48 | # down fixture information. 49 | 50 | def teardown 51 | 52 | end 53 | 54 | def test_invalid_param 55 | assert_raise(ArgumentError) {@zbx_api.host.get("invalid")} 56 | end 57 | 58 | def test_00_bad_logins 59 | @zbx_api=ZabbixAPI.new("bad") 60 | assert_raise(ZbxAPI_ExceptionBadAuth) {@zbx_api.login("bad","pass")} 61 | 62 | @zbx_api=ZabbixAPI.new(@server) 63 | assert_raise(ZbxAPI_ExceptionBadAuth) {@zbx_api.login("bad",@api_pass)} 64 | end 65 | 66 | def test_01_create_user 67 | # result=@zbx_api.user.get({"extendoutput"=>true,"filter"=>{"alias"=>[$api_user]},"limit"=>100}) 68 | ## result.map! { |item| [item["alias"], item["type"]] } 69 | # assert_not_nil(result[0]) 70 | # assert_equal(3,result[0]["type"].to_i,"Create User requires admin privileges") 71 | result=nil 72 | assert_nothing_raised(ZbxAPI_GeneralError) {result=@zbx_api.user.create({"name"=>"zbxapi_test", "alias"=>"zbxapi", "passwd"=>"test"}) } 73 | 74 | @@test_user=result["userids"][0] 75 | end 76 | 77 | def test_02_addmedia 78 | #12-24-2010 Bug in the following: 79 | #https://support.zabbix.com/browse/ZBX-3340 80 | #Ruby API Library also has a bug which needs to be fixed (parameter checks don't follow API documentation) 81 | #@zbx_api.debug_level=5 82 | assert_nothing_raised(ZbxAPI_GeneralError) do 83 | result=@zbx_api.user.addmedia( 84 | {"userid"=>@@test_user,"active"=>2, 85 | "sendto"=>"me@me.com","severity"=>"123456"}) 86 | end 87 | end 88 | 89 | def test_99_delete_user 90 | result=nil 91 | assert_nothing_raised(ZbxAPI_GeneralError) do 92 | result=@zbx_api.user.delete({"userid"=>@@test_user}) 93 | end 94 | assert_equal(@@test_user,result["userids"][0]) 95 | end 96 | 97 | 98 | 99 | end -------------------------------------------------------------------------------- /zbxapi/exceptions.rb: -------------------------------------------------------------------------------- 1 | #License:: LGPL 2.1 http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 2 | #Copyright:: Copyright (C) 2009,2010 Andrew Nelson nelsonab(at)red-tux(dot)net 3 | # 4 | #This library is free software; you can redistribute it and/or 5 | #modify it under the terms of the GNU Lesser General Public 6 | #License as published by the Free Software Foundation; either 7 | #version 2.1 of the License, or (at your option) any later version. 8 | # 9 | #This library 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 GNU 12 | #Lesser General Public License for more details. 13 | # 14 | #You should have received a copy of the GNU Lesser General Public 15 | #License along with this library; 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: exceptions.rb 337 2011-10-14 16:11:39Z nelsonab $ 21 | # $Revision: 337 $ 22 | ########################################## 23 | 24 | require 'zbxapi/utils' 25 | require 'zbxapi/zdebug' 26 | 27 | #------------------------------------------------------------------------------ 28 | # 29 | # Class ZError 30 | # 31 | # This is the superclass for all Zabcon and ZabbixAPI exceptions. 32 | # 33 | #------------------------------------------------------------------------------ 34 | class ZError < RuntimeError 35 | 36 | include ZDebug 37 | 38 | attr_accessor :help_func, :message, :retry, :error_code 39 | 40 | # list of valid params 41 | # :help_func, the help function with more information for the exception 42 | # : retry, is the exception eligible for retry? 43 | def initialize(message=nil, params={}) 44 | @help_func=params[:help_func] 45 | @message=message 46 | @local_msg="Error" 47 | @retry = params[:retry] 48 | @error_code= params[:error_code] 49 | super(message) 50 | end 51 | 52 | def show_message 53 | puts "** #{self.class}" 54 | if @message.nil? && @help_func.nil? 55 | puts "** #{@local_msg}" 56 | puts 57 | else 58 | if !@message.nil? 59 | @message.each_line {|line| 60 | puts "** #{line}" 61 | } 62 | puts 63 | puts "---" if !@help_func.nil? 64 | end 65 | @help_func.call if !@help_func.nil? 66 | end 67 | end 68 | 69 | #show the backtrace, if override is true it will be shown even if there is a help function 70 | def show_backtrace(override=false) 71 | if @help_func.nil? || override 72 | puts "Backtrace:" 73 | puts backtrace.join("\n") 74 | end 75 | end 76 | def retry? 77 | #the following may be worthy of a sig on "The Daily WTF", but this guarantees a boolean gets returned. 78 | #@retry is not guaranteed to be a boolean. 79 | if @retry 80 | return true 81 | else 82 | return false 83 | end 84 | end 85 | end 86 | 87 | class ParameterError < ZError 88 | def initialize(message=nil, params=nil) 89 | super(message, params) 90 | @local_msg="Parameter Error" 91 | end 92 | end 93 | 94 | #---------------------------------------------------------- 95 | 96 | class ParameterError_Invalid < ZError 97 | def initialize(message=nil, params=nil) 98 | super(message, params) 99 | @local_msg="Invalid Parameters" 100 | end 101 | end 102 | 103 | class ParameterError_Missing < ZError 104 | def initialize(message=nil, params=nil) 105 | super(message, params) 106 | @local_msg="Missing required parameters" 107 | end 108 | end 109 | 110 | #---------------------------------------------------------- 111 | 112 | class ReturnError < ZError 113 | 114 | end 115 | -------------------------------------------------------------------------------- /api_classes/dsl_trigger.rb: -------------------------------------------------------------------------------- 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 | action :create do 31 | parameters "2.4" do 32 | add "triggerid","description","expression","comments","error","flags", 33 | "lastchange","priority","state","status","templateid","type","url", 34 | "value","dependencies" 35 | requires "description","expression" 36 | end 37 | end 38 | 39 | action :get do 40 | parameters "1.3", 41 | 'triggerids', "select_functions", "nodeids", "groupids", "templateids", 42 | "hostids", "itemids", "applicationids", "functions", "inherited", "templated", "monitored", 43 | "active", "maintenance", "withUnacknowledgedEvents", "withAcknowledgedEvents", 44 | "withLastEventUnacknowledged", "skipDependent", "editable", "lastChangeSince", 45 | "lastChangeTill", "filter", "group", "host", "only_true", "min_severity", "search", 46 | "startSearch", "excludeSearch", "searchWildcardsEnabled", "output", "expandData", 47 | "expandDescription", "select_groups", "select_hosts", "select_items", "select_dependencies", 48 | "countOutput", "groupOutput", "preservekeys", "sortfield", "sortorder", "limit" 49 | 50 | parameters "2.4" do 51 | add "triggerids","groupids","templateids","hostids","itemids", 52 | "applicationids","functions","group","host","inherited","templated", 53 | "monitored","active","maintenance","withUnacknowledgedEvents", 54 | "withAcknowledgedEvents","withLastEventUnacknowledged","skipDependent", 55 | "lastChangeSince","lastChangeTill","only_true","min_severity", 56 | "expandComment","expandDescription","expandExpression","selectGroups", 57 | "selectHosts","selectItems","selectFunctions","selectDependencies", 58 | "selectDiscoveryRule","selectLastEvent","filter","limitSelects", 59 | "sortfield","countOutput","editable","excludeSearch","limit","output", 60 | "preservekeys","search","searchByAny","searchWildcardsEnabled", 61 | "sortorder","startSearch" 62 | #deprecate "expandData" 63 | end 64 | end 65 | 66 | action :adddependencies do 67 | parameters "2.4" do 68 | add "triggerid","dependsOnTriggerid" 69 | requires "triggerid","dependsOnTriggerid" 70 | end 71 | end 72 | 73 | action :update do 74 | parameters "2.4" do 75 | add "triggerid","description","expression","comments","error","flags", 76 | "lastchange","priority","state","status","templateid","type","url", 77 | "value","dependencies" 78 | requires "description","expression" 79 | end 80 | end 81 | 82 | alias :addDependencies :adddependencies 83 | end 84 | 85 | Trigger.delete 86 | Trigger.deleteDependencies 87 | Trigger.exists 88 | 89 | -------------------------------------------------------------------------------- /zbxapi/api_exceptions.rb: -------------------------------------------------------------------------------- 1 | #License:: LGPL 2.1 http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 2 | #Copyright:: Copyright (C) 2009,2010 Andrew Nelson nelsonab(at)red-tux(dot)net 3 | # 4 | #This library is free software; you can redistribute it and/or 5 | #modify it under the terms of the GNU Lesser General Public 6 | #License as published by the Free Software Foundation; either 7 | #version 2.1 of the License, or (at your option) any later version. 8 | # 9 | #This library 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 GNU 12 | #Lesser General Public License for more details. 13 | # 14 | #You should have received a copy of the GNU Lesser General Public 15 | #License along with this library; 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: api_exceptions.rb 337 2011-10-14 16:11:39Z nelsonab $ 21 | # $Revision: 337 $ 22 | ########################################## 23 | 24 | #------------------------------------------------------------------------------ 25 | # 26 | # Class ZbxAP_ParameterError 27 | # 28 | # Exception class for parameter errors for Argument Processor calls. 29 | # 30 | #------------------------------------------------------------------------------ 31 | 32 | require 'zbxapi/zdebug' 33 | require 'zbxapi/exceptions' 34 | 35 | #------------------------------------------------------------------------------ 36 | # 37 | # Class ZbxAPI_ExceptionBadAuth 38 | # 39 | # Exception class for bad authentication information 40 | # 41 | #------------------------------------------------------------------------------ 42 | 43 | class ZbxAPI_ExceptionBadAuth < ZError 44 | end 45 | 46 | #------------------------------------------------------------------------------ 47 | # 48 | # Class ZbxAPI_ExceptionBadServerUrl 49 | # 50 | # Exception class for bad host url, also used for connection 51 | # refused errors 52 | # 53 | #------------------------------------------------------------------------------ 54 | 55 | class ZbxAPI_ExceptionBadServerUrl < RuntimeError 56 | end 57 | 58 | #------------------------------------------------------------------------------ 59 | # 60 | # Class ZbxAPI_ExceptionArgumentError 61 | # 62 | # Exception class for incorrect arguments to a method 63 | # 64 | #------------------------------------------------------------------------------ 65 | 66 | class ZbxAPI_ExceptionArgumentError < RuntimeError 67 | end 68 | 69 | #------------------------------------------------------------------------------ 70 | # 71 | # Class ZbxAPI_ParameterError 72 | # 73 | # Exception class for parameter errors for API calls. 74 | # 75 | #------------------------------------------------------------------------------ 76 | 77 | class ZbxAPI_ParameterError < RuntimeError 78 | end 79 | 80 | #------------------------------------------------------------------------------ 81 | # 82 | # Class ZbxAPI_ExceptionVersion 83 | # 84 | # Exception class for API version errors 85 | # 86 | #------------------------------------------------------------------------------ 87 | 88 | class ZbxAPI_ExceptionVersion < RuntimeError 89 | end 90 | 91 | #------------------------------------------------------------------------------ 92 | # 93 | # Class ZbxAPI_ExceptionLoginPermission 94 | # 95 | # Exception class for lack of API login permission 96 | # 97 | #------------------------------------------------------------------------------ 98 | 99 | class ZbxAPI_ExceptionLoginPermission < ZError 100 | def initialize(message=nil, params={}) 101 | super(message, params) 102 | @local_msg="This is also a general Zabbix API error number (Your error may not be a login error).\nTell the Zabbix devs to honor section 5.1 of the JSON-RPC 2.0 Spec." 103 | end 104 | end 105 | 106 | #------------------------------------------------------------------------------ 107 | # 108 | # Class ZbxAPI_ExceptionPermissionError 109 | # 110 | # Exception class for general API permissions errors 111 | # 112 | #------------------------------------------------------------------------------ 113 | 114 | class ZbxAPI_ExceptionPermissionError < ZError 115 | end 116 | 117 | #------------------------------------------------------------------------------ 118 | # 119 | # Class ZbxAPI_GeneralError 120 | # 121 | # Exception class for errors not encompassed in the above exceptions. 122 | # 123 | #------------------------------------------------------------------------------ 124 | 125 | class ZbxAPI_GeneralError < ZError 126 | end 127 | -------------------------------------------------------------------------------- /rakefile.rb: -------------------------------------------------------------------------------- 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$ 21 | # $Revision$ 22 | ########################################## 23 | 24 | require 'rubygems' 25 | require 'rake' 26 | require 'rdoc/task' 27 | require 'rubygems/package_task' 28 | require 'rake/testtask' 29 | require 'pp' 30 | 31 | #setup our search path or libraries 32 | $LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), '.')) 33 | 34 | def get_release_num 35 | if ENV["release_ver"].nil? 36 | revs=`git tag -l 'rev*' | sort -t. -k1,1n -k2,2n -k3,3n | grep -E '^rev([0-9]+\.){2}[0-9]+$'` 37 | revs=revs.gsub("\r","").gsub("rev","").split("\n") 38 | if revs.empty? 39 | fail '**** No release tags found, and ENV["release_ver"] is empty ****' 40 | end 41 | 42 | ENV["release_ver"]=revs[-1] 43 | end 44 | ENV["release_ver"] 45 | end 46 | task :default => [:test, :package] 47 | 48 | desc "Build a version of the Gem, but do not update version file or perform git changes" 49 | task :test_build do 50 | ENV["test_build"]=true.to_s #looks like ENV can only store strings 51 | end 52 | 53 | Rake::TestTask.new do |t| 54 | require "ts_local_vars" 55 | t.test_files = FileList['api_tests/tc*.rb'] 56 | t.verbose = true 57 | end 58 | 59 | desc "Skip the unit tests" 60 | task :skip_tests do 61 | Rake::Task[:test].clear 62 | end 63 | 64 | desc "Bump the revision number" 65 | task :bump_rev do 66 | rev_parts=get_release_num.split(".").map{ |i| Integer(i)} 67 | rev_parts[2]+=1 #0.1.2 68 | ENV["release_ver"]=rev_parts.join(".") 69 | end 70 | 71 | desc "Bump the minor version number" 72 | task :bump_minor do 73 | rev_parts=get_release_num.split(".").map{ |i| Integer(i)} 74 | rev_parts[1]+=1 #0.1.2 75 | rev_parts[2]=0 76 | ENV["release_ver"]=rev_parts.join(".") 77 | end 78 | 79 | desc "Bump the major version number" 80 | task :bump_major do 81 | rev_parts=get_release_num.split(".").map{ |i| Integer(i)} 82 | rev_parts[0]+=1 #0.1.2 83 | rev_parts[1]=0 84 | rev_parts[2]=0 85 | ENV["release_ver"]=rev_parts.join(".") 86 | end 87 | 88 | desc "Create Version Tag" 89 | task :tag_version do 90 | ver=get_release_num 91 | puts "Creating tag for version: #{ver}" 92 | `git tag -a rev#{ver} -m \"Release version: #{ver}\"` 93 | end 94 | 95 | desc "Update the revision to the release number" 96 | task :update_revision do 97 | if ENV["test_build"] 98 | puts "Test mode emabled, zbxapi/revision.rb file will not be generated" 99 | else 100 | open("zbxapi/revision.rb", "w") do |o| 101 | o.puts "#CHANGES TO THIS FILE WILL AUTOMATICALLY BE OVERWRITTEN" 102 | o.puts "#This file is autogenerated by the zbxapi rakefile." 103 | o.puts "#This file contains the latest SVN revision number at the time" 104 | o.puts "#the rakefile was run" 105 | o.puts 106 | o.puts "ZBXAPI_VERSION=\"#{ENV["release_ver"]}\"" 107 | # o.puts "ZBXAPI_REVISION=\"#{$rev}\"" 108 | end 109 | end 110 | end 111 | 112 | spec = Gem::Specification.new do |s| 113 | s.name = "zbxapi" 114 | s.rubyforge_project = "zbxapi" 115 | s.version = get_release_num 116 | s.authors = ["A. Nelson"] 117 | s.email = %q{nelsonab@red-tux.net} 118 | s.summary = %q{Ruby wrapper to the Zabbix API} 119 | s.homepage = %q{https://github.com/red-tux/zbxapi} 120 | s.description = %q{Provides a straight forward interface to manipulate Zabbix servers using the Zabbix API.} 121 | s.licenses = "LGPL 2.1" 122 | s.requirements = "Requires json" 123 | s.add_dependency('json') 124 | s.require_paths =["."] 125 | s.files = 126 | ["LICENSE", "zbxapi.rb", "zbxapi/zdebug.rb", "zbxapi/api_exceptions.rb", 127 | "zbxapi/exceptions.rb", "zbxapi/utils.rb", "zbxapi/result.rb", 128 | "api_classes/api_dsl.rb", 129 | # "zbxapi/revision.rb", 130 | Dir["api_classes/dsl*.rb"]].flatten 131 | end 132 | 133 | Gem::PackageTask.new(spec) do |pkg| 134 | pkg.package_dir = "gems" 135 | # pkg.version="#{ENV["release_ver"]}" 136 | # pkg.version = "0.1.#{$rev}" 137 | end 138 | -------------------------------------------------------------------------------- /zbxapi/zdebug.rb: -------------------------------------------------------------------------------- 1 | #License:: LGPL 2.1 http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 2 | #Copyright:: Copyright (C) 2009,2010 Andrew Nelson nelsonab(at)red-tux(dot)net 3 | # 4 | #This library is free software; you can redistribute it and/or 5 | #modify it under the terms of the GNU Lesser General Public 6 | #License as published by the Free Software Foundation; either 7 | #version 2.1 of the License, or (at your option) any later version. 8 | # 9 | #This library 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 GNU 12 | #Lesser General Public License for more details. 13 | # 14 | #You should have received a copy of the GNU Lesser General Public 15 | #License along with this library; 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: zdebug.rb 337 2011-10-14 16:11:39Z nelsonab $ 21 | # $Revision: 337 $ 22 | ########################################## 23 | 24 | module ZDebug 25 | 26 | # Either set_debug_level or set_facility_debug_level must be called before 27 | # the debug functions can be used. 28 | def set_debug_level(level) # sets the current debug level for printing messages 29 | @@debug_level=level 30 | 31 | # Create faciltiy_level if it's not created already 32 | @@facility_level= {} if !defined?(@@facility_level) 33 | end 34 | 35 | # facility is a symbol, level is an integer 36 | def set_facility_debug_level(facility,level) 37 | # Create faciltiy_level if it's not created already 38 | @@facility_level= {} if !defined?(@@facility_level) 39 | 40 | @@facility_level[facility]=level 41 | 42 | # Create debug level if it's not already created 43 | @@debug_level=0 if !defined?(@@debug_level) 44 | end 45 | 46 | def debug_level 47 | @@debug_level 48 | end 49 | 50 | # level - level to show message (Integer) 51 | # :var - variable to show (Object) 52 | # :msg - message to be prepended before variable (String) 53 | # :truncate - truncate var if it is over N characters 54 | # :overload - do not show or error if debug_level is not set 55 | # :facility - Which debug facility level should also be used 56 | # :stack_pos - Stack position to use for calling function information (0==last function) 57 | # :trace_depth - Show a backtrace of :trace_depth starting at :stack_pos 58 | def debug(level,args={}) 59 | variable=args[:var] || :zzempty 60 | message=args[:msg] || nil 61 | facility=args[:facility] || nil 62 | raise "Facility must be a symbol" if facility && facility.class!=Symbol 63 | truncate=args[:truncate] || 0 64 | raise "Truncate must be an Integer" if truncate.class!=Integer 65 | overload=(!args[:overload].nil? && args[:overload]==true) || false 66 | stack_pos=args[:stack_pos] || 0 67 | raise ":stack_pos must be an Integer" if stack_pos.class!=Integer 68 | backtrace_depth=args[:trace_depth] || 0 69 | 70 | return if overload 71 | raise "Call set_debug before using debug" if !defined?(@@debug_level) 72 | 73 | if facility 74 | facility_level=@@facility_level[facility] 75 | raise("Unknown facility type: #{facility.to_s}") if facility_level.nil? 76 | show_debug=level<=facility_level 77 | else 78 | show_debug=level<=@@debug_level 79 | end 80 | 81 | if show_debug 82 | 83 | if facility 84 | header="D#{level}(#{facility.to_s})" 85 | else 86 | header="D#{level}" 87 | end 88 | 89 | #Example: "./libs/lexer.rb:650:in `item'" 90 | #parse the caller array to determine who called us, what line, and what file 91 | caller[stack_pos]=~/(.*):(\d+):.*`(.*?)'/ 92 | 93 | if $1 94 | #sometimes the debug function gets called from within an exception block, in which cases the backtrace is not 95 | #available. 96 | path=$1 97 | debug_line=$2 98 | debug_func=$3 99 | path=path.split("/") 100 | 101 | if (len=path.length)>2 102 | debug_file=".../#{path[len-2]}/#{path[len-1]}" 103 | else 104 | debug_file=path 105 | end 106 | 107 | header+=" #{debug_file}:#{debug_func}:#{debug_line}" 108 | else 109 | header+=" --from exception--" 110 | end 111 | 112 | if variable.nil? 113 | strval="nil" 114 | elsif variable==:zzempty || variable=="" 115 | strval="" 116 | elsif variable.class==String 117 | strval=variable 118 | else 119 | strval=variable.inspect 120 | end 121 | 122 | if truncate>0 && truncate0 137 | backtrace=[] 138 | (stack_pos..stack_pos+backtrace_depth-1).each do |pos| 139 | pos+=2 #Need to offset current block 140 | next if pos>=caller.length 141 | 142 | caller[pos]=~/(.*):(\d+):.*`(.*?)'/ 143 | if $1 144 | #sometimes the debug function gets called from within an exception block, in which cases the backtrace is not 145 | #available. 146 | debug_line=$2 147 | debug_func=$3 148 | path=$1.split("/") #global vars are changed by split 149 | 150 | path= (len=path.length)>2 ? ".../#{path[len-2]}/#{path[len-1]}" : path 151 | backtrace<<"#{path}:#{debug_func}:#{debug_line}" 152 | else 153 | backtrace<<"Unknown" 154 | end 155 | end 156 | puts " Backtrace(#{stack_pos}..#{stack_pos+backtrace_depth-1}):["+backtrace.join("],[")+"]" 157 | end 158 | end 159 | end 160 | 161 | def debug_facility(facility,level,variable="",message=nil,truncate=nil) 162 | debug(level, :var=>variable, :msg=>message, :truncate=>truncate, :stack_pos=>1) 163 | end 164 | 165 | end # end Debug module 166 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | zbxapi The Zabbix API Interface in Ruby 2 | ======================================= 3 | [![Gem Version](https://badge.fury.io/rb/zbxapi.png)](http://badge.fury.io/rb/zbxapi) 4 | 5 | The ZbxAPI gem is designed to provide a straight forward interface to the 6 | Zabbix API in a Ruby friendly manner. 7 | 8 | Initialzing a connection is pretty straight forward: 9 | ```ruby 10 | require 'zbxapi' 11 | require 'pp' 12 | 13 | zabbix = ZabbixAPI.new("http://zabbix.example.com/", :verify_ssl => false, :http_timeout => 300 ) 14 | zabbix.login("api-user","api-pass") 15 | 16 | pp zabbix.history.get({'itemids'=>[1234,5678]}) 17 | ``` 18 | 19 | To get a list of valid objects, methods and parameters, use the api_info method. 20 | ```ruby 21 | #Show all of the available objects 22 | zabbix.api_info 23 | ["event", "graph", "user", "hostgroup", "usergroup","template", "proxy", "usermedia", 24 | "item", "history","trigger", "usermacro", "mediatype", "host"] 25 | 26 | #Show all of the available methods for the host object 27 | zabbix.api_info "host" 28 | ["update", "massAdd", "massUpdate", "massRemove", "get", "exists", "create", "delete"] 29 | 30 | #Show all of the valid parameters for the host.create method for the most recent 31 | #api version known 32 | zabbix.api_info "host.create" 33 | ["host", "name", "port", "status", "useip", "dns", "ip", "proxy_hostid", "useipmi", 34 | "ipmi_ip", "ipmi_port", "ipmi_authtype", "ipmi_privilege", "ipmi_username", 35 | "ipmi_password", "groups", "templates", "interfaces"] 36 | 37 | #Show the required parameters fo the host.create method for version 1.3 of the api 38 | server.api_info "host.create", :params=>:required,:version=>"1.3" 39 | ["groups", "interfaces"] 40 | ``` 41 | 42 | Extending the API library is fairly straight forward as well. 43 | 1. Create a file in the api_classes directory with the format of dsl_.rb 44 | 2. Inside the class file require the "api_dsl.rb" file 45 | 3. Inherit from the ZabbixAPI_Base class 46 | 47 | All of the methods below will create methods for the Host object. It is important to 48 | note that the example for Host.update creates the method behind the scenes. 49 | ```ruby 50 | 51 | class Host < ZabbixAPI_Base 52 | actions :massAdd, :massUpdate, :massRemove 53 | 54 | action :create do 55 | end 56 | end 57 | 58 | Host.update 59 | ``` 60 | 61 | To add a list of valid parameters to the Host.create method above use the following methods 62 | ```ruby 63 | action :create do 64 | parameters "1.3" do 65 | add "host","name","port","status","useip","dns","ip","proxy_hostid", 66 | "useipmi","ipmi_ip","ipmi_port","ipmi_authtype","ipmi_privilege", 67 | "ipmi_username","ipmi_password","groups","templates" 68 | requires "groups" 69 | end 70 | 71 | parameters "2.0" do 72 | inherit from "1.3" 73 | add "interfaces","macros" 74 | requires "interfaces" 75 | end 76 | 77 | parameters "2.4" do 78 | inherit from "2.0" 79 | add "hostid","available","description","disable_until","error", 80 | "errors_from","flags","inventory","ipmi_available","ipmi_disable_until", 81 | "ipmi_error","ipmi_errors_from","jmx_available","jmx_disable_until", 82 | "jmx_error","jmx_errors_from","maintenance_from","maintenance_status", 83 | "maintenance_type","maintenanceid","snmp_available", 84 | "snmp_disable_until","snmp_error","snmp_errors_from" 85 | remove "dns","ip","ipmi_ip","port","useip","useipmi" 86 | requires "host","groups","interfaces" 87 | endend 88 | ``` 89 | 90 | In the above example three sets of valid and required parameters are set up. 91 | One for versions 1.3, 2.0 and 2.4 of the API. The parameter list is 92 | automatically chosen by the API library based on the version string returned 93 | from the Zabbix server. If no valid or required parameters are given, no 94 | parameter checking is performed. In addition the library will chose the 95 | most recent parameter list if there is not one for the specific version 96 | of the Zabbix server, for instance if the API library only knows about 97 | 1.3, 2.0 and 2.4 and you are connecting to a 2.2 server, it will use the 98 | 2.0 list. If you connect to a 2.6 server, and no parameter list has been 99 | defined for 2.6, the 2.4 parameter list will be used. 100 | 101 | Sometimes it is useful to create an alias for a command. One example may be 102 | to have a method name in all lower case, or an easier to remember name for an 103 | existing method. 104 | ```ruby 105 | class Host < ZabbixAPI_Base 106 | action :massadd do 107 | parameters "2.4" do 108 | add "hosts","groups","interfaces","macros","templates" 109 | requires "hosts" 110 | end 111 | end 112 | 113 | action :massremove do 114 | parameters "2.4" do 115 | add "hostids","groupids","interfaces","macros","templateids", 116 | "templateids_clear" 117 | requires "hostids" 118 | end 119 | end 120 | 121 | api_alias :massAdd, :massadd 122 | alias massRemove massremove 123 | end 124 | ``` 125 | 126 | The above example will create two new methods "massAdd" and "massRemove", both of which 127 | map to their lower case variants. It is worth noting that api_alias is a built in DSL 128 | function and will in turn populate the internal list of aliased methods which is 129 | available for introspection via the api.aliases method. However the ruby keyword 130 | "alias" is also available and works, but it will not populate the internal aliased 131 | methods list. 132 | 133 | 134 | The library also supports some introspection. Below are some examples from irb: 135 | ```ruby 136 | 137 | irb(main):004:0> zabbix.host.api_methods.sort 138 | => [:create, :delete, :exists, :get, :massadd, :massremove, :massupdate, :update] 139 | 140 | irb(main):005:0> zabbix.host.valid_params(:create,"2.4").sort 141 | => ["available", "description", "disable_until", "error", "errors_from", "flags", 142 | "host", "hostid", "interfaces", "ipmi_authtype", "ipmi_available", 143 | "ipmi_disable_until", "ipmi_error", "ipmi_errors_from", "ipmi_ip", "ipmi_password", 144 | "ipmi_port", "ipmi_privilege", "ipmi_username", "jmx_available", "jmx_disable_until", 145 | "jmx_error", "jmx_errors_from", "macros", "maintenance_from", "maintenance_status", 146 | "maintenance_type", "maintenanceid", "name", "proxy_hostid", "snmp_available", 147 | "snmp_disable_until", "snmp_error", "snmp_errors_from", "status", "useipmi"] 148 | 149 | irb(main):006:0> zabbix.host.required_params(:create,"2.2") 150 | => ["groups", "interfaces"] 151 | 152 | irb(main):007:0> zabbix.host.required_params(:create,"2.4") 153 | => ["groups", "interfaces", "host"] 154 | 155 | irb(main):006:0> zabbix.host.api_methods.sort 156 | => [:create, :delete, :exists, :get, :massadd, :massremove, :massupdate, :update] 157 | 158 | irb(main):007:0> zabbix.host.api_aliases 159 | => {:massAdd=>:massadd, :massRemove=>:massremove, :massUpdate=>:massupdate} 160 | ``` 161 | -------------------------------------------------------------------------------- /api_classes/dsl_host.rb: -------------------------------------------------------------------------------- 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 | require "api_classes/api_dsl" 20 | 21 | class Host < ZabbixAPI_Base 22 | 23 | action :get do 24 | #arg_processor "1.3" do |params| 25 | # params["output"]="extend" 26 | # params 27 | #end 28 | 29 | parameters "1.3", 30 | "nodeids","groupids","hostids","templateids","itemids","triggerids", 31 | "graphids","proxyids","maintenanceids","dhostids","dserviceids", 32 | "monitored_hosts","templated_hosts","proxy_hosts","with_items", 33 | "with_monitored_items","with_historical_items","with_triggers", 34 | "with_monitored_triggers","with_httptests", 35 | "with_monitored_httptests","with_graphs","editable","filter", 36 | "search","startSearch","excludeSearch","searchWildcardsEnabled", 37 | "output","select_groups","selectParentTemplates","select_items", 38 | "select_triggers","select_graphs","select_applications", 39 | "selectInterfaces","select_macros","select_profile","countOutput", 40 | "groupOutput","preservekeys","sortfield","sortorder","limit", 41 | "extendoutput" 42 | 43 | parameters "2.0" do 44 | inherit from "1.3" 45 | add "selectGroups" 46 | end 47 | 48 | parameters "2.4" do 49 | add "groupids","applicationids","dserviceids","graphids","hostids", 50 | "httptestids","interfaceids","itemids","maintenanceids","monitored_hosts", 51 | "proxy_hosts","proxyids","templated_hosts","templateids","triggerids", 52 | "with_items","with_applications","with_graphs","with_httptests", 53 | "with_monitored_httptests","with_monitored_items", 54 | "with_monitored_triggers","with_simple_graph_items","with_triggers", 55 | "withInventory","selectGroups","selectApplications","selectDiscoveries", 56 | "selectDiscoveryRule","selectGraphs","selectHostDiscovery", 57 | "selectHttpTests","selectInterfaces","selectInventory","selectItems", 58 | "selectMacros","selectParentTemplates","selectScreens","selectTriggers", 59 | "filter","limitSelects","search","searchInventory","sortfield", 60 | "countOutput","editable","excludeSearch","limit","output","preservekeys", 61 | "searchByAny","searchWildcardsEnabled","sortorder","startSearch" 62 | end 63 | 64 | #parameters "3.0" do 65 | # inherit from "2.0" 66 | # remove "select_macros","preserve_keys","extendoutput" 67 | # add "test_param" 68 | # requires "test_param" 69 | #end 70 | end 71 | 72 | action :exists do 73 | parameters "1.3" do 74 | add "nodeids","hostid","host" 75 | end 76 | end 77 | 78 | action :create do 79 | parameters "1.3" do 80 | add "host","name","port","status","useip","dns","ip","proxy_hostid", 81 | "useipmi","ipmi_ip","ipmi_port","ipmi_authtype","ipmi_privilege", 82 | "ipmi_username","ipmi_password","groups","templates" 83 | requires "groups" 84 | end 85 | 86 | parameters "2.0" do 87 | inherit from "1.3" 88 | add "interfaces","macros" 89 | requires "interfaces" 90 | end 91 | 92 | parameters "2.4" do 93 | inherit from "2.0" 94 | add "hostid","available","description","disable_until","error","errors_from", 95 | "flags","inventory","ipmi_available","ipmi_disable_until","ipmi_error", 96 | "ipmi_errors_from","jmx_available","jmx_disable_until","jmx_error", 97 | "jmx_errors_from","maintenance_from","maintenance_status", 98 | "maintenance_type","maintenanceid","snmp_available","snmp_disable_until", 99 | "snmp_error","snmp_errors_from" 100 | remove "dns","ip","ipmi_ip","port","useip","useipmi" 101 | requires "host" 102 | end 103 | 104 | end 105 | 106 | action :delete do 107 | add_arg_processor "0" do |params| 108 | retval=nil 109 | if params.is_a?(Integer) 110 | retval=[{"hostid"=>params}] 111 | else 112 | retval=params 113 | end 114 | 115 | retval 116 | end 117 | end 118 | 119 | action :massadd do 120 | parameters "2.4" do 121 | add "hosts","groups","interfaces","macros","templates" 122 | requires "hosts" 123 | end 124 | end 125 | 126 | action :massremove do 127 | parameters "2.4" do 128 | add "hostids","groupids","interfaces","macros","templateids", 129 | "templateids_clear" 130 | requires "hostids" 131 | end 132 | end 133 | 134 | action :update do 135 | parameters "2.4" do 136 | add "host","hostid","host","available","description","disable_until","error", 137 | "errors_from","flags","ipmi_authtype","ipmi_available", 138 | "ipmi_disable_until","ipmi_error","ipmi_errors_from","ipmi_password", 139 | "ipmi_privilege","ipmi_username","jmx_available","jmx_disable_until", 140 | "jmx_error","jmx_errors_from","maintenance_from","maintenance_status", 141 | "maintenance_type","maintenanceid","name","proxy_hostid","snmp_available", 142 | "snmp_disable_until","snmp_error","snmp_errors_from","status", "templates", "groups" 143 | requires "host" 144 | end 145 | end 146 | 147 | action :massupdate do 148 | parameters "2.4" do 149 | add "hostid","host","hosts","available","description","disable_until","error", 150 | "errors_from","flags","ipmi_authtype","ipmi_available", 151 | "ipmi_disable_until","ipmi_error","ipmi_errors_from","ipmi_password", 152 | "ipmi_privilege","ipmi_username","jmx_available","jmx_disable_until", 153 | "jmx_error","jmx_errors_from","maintenance_from","maintenance_status", 154 | "maintenance_type","maintenanceid","name","proxy_hostid","snmp_available", 155 | "snmp_disable_until","snmp_error","snmp_errors_from","status" 156 | requires "host","hosts" 157 | end 158 | end 159 | 160 | api_alias :massAdd, :massadd 161 | api_alias :massRemove, :massremove 162 | api_alias :massUpdate, :massupdate 163 | end 164 | -------------------------------------------------------------------------------- /api_classes/api_dsl.rb: -------------------------------------------------------------------------------- 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: api_dsl.rb 409 2012-09-11 23:39:58Z nelsonab $ 23 | # $Revision: 409 $ 24 | ########################################## 25 | #++ 26 | 27 | require "zbxapi/zdebug" 28 | require "zbxapi/exceptions" 29 | require "pp" 30 | 31 | class ZabbixAPI_ParametersDSL 32 | class InvalidRequiredParameterblock} 130 | @validparams={} # {version=>[valid parameters]} 131 | @requiredparams={} # {version=>[required parameters]} 132 | @default=:default # Which is the default version to use 133 | @method_names={} 134 | @method_names["0"]="#{@apiclass}.#{@apimethod}".downcase 135 | @deprecated=nil 136 | @invalidated=nil 137 | end 138 | 139 | def login_not_required 140 | @login_required=false 141 | end 142 | 143 | #Deprecate this function starting at API version ver 144 | #If msg is nil the following will be printed: 145 | #"#{method} is deprecated for API versions #{ver} and higher" 146 | # Where method is the current method name for the API 147 | def deprecate(ver,msg=nil) 148 | #Deprecate can only be called once 149 | raise AlreadyUsedError.new("Deprecate can only be used once per method") if @deprecated 150 | @deprecated={ver=>(msg || "") } 151 | end 152 | 153 | def deprecate_dsl(msg) 154 | warn msg 155 | caller[1]=~/(.*:\d+):.*`(.*?)'/ 156 | warn "from: #{$1}" 157 | end 158 | 159 | #Invalidate this function starting at API version ver 160 | #This will raise the ZabbixAPI_Method::InvalidMethod exception 161 | #If msg is nil the following string will be used in the exception: 162 | #"#{method} is invalid for API versions #{ver} and higher" 163 | # Where method is the current method name for the API 164 | def invalidate(ver,msg=nil) 165 | #Invalidate can only be called once 166 | raise AlreadyUsedError.new("Invalidate can only be used once per method") if @deprecated 167 | @invalidated={ver=>(msg || "") } 168 | end 169 | 170 | #Allows for the override of the API method to be called 171 | #The default method is version 0 which can be overridden 172 | def method_override(ver,name) 173 | @method_names[ver]=name 174 | end 175 | 176 | #add_arg_processor 177 | #Creates an argument processor suitable for versions starting at ver 178 | #ver is a string denoting the starting version number this argument processor should be used on 179 | #This method also needs a block to be passed. The block 180 | def add_arg_processor(ver,&block) 181 | raise InvalidArity.new("Argument processor must accept one parameter") if block.arity !=1 182 | @arg_processors[ver]=block 183 | @default=ver 184 | end 185 | 186 | def get_arg_processor(ver) 187 | ver=get_version(ver,@arg_processors) 188 | return nil if ver.nil? 189 | @arg_processors[ver] 190 | end 191 | 192 | #calls the argument processor appropriate for ver 193 | #If no argument processor found, params are returned unchanged 194 | def call_arg_processor(ver,params={}) 195 | processor=get_arg_processor(ver) 196 | if processor.nil? 197 | params 198 | else 199 | processor.call(params) 200 | end 201 | end 202 | 203 | def add_valid_params(ver,params) 204 | deprecate_dsl("DSL statement add_valid_params is deprecated, use the parameters statement") 205 | @validparams[ver]=params 206 | end 207 | 208 | def add_required_params(ver,params) 209 | deprecate_dsl("DSL statement add_required_params is deprecated, use the parameters statement") 210 | @requiredparams[ver]=params 211 | end 212 | 213 | # Return the valid parameters for the method given version. 214 | # If version is nil, the highest version number available in the valid 215 | # parameters hash is used. 216 | # If ver is a version number, the closest version number in the valid 217 | # parameters hash which is less than or equal to is returned. 218 | # nil is returned is no valid parameters are found 219 | def get_valid_params(ver) 220 | ver=get_version(ver,@validparams) 221 | return nil if ver.nil? 222 | @validparams[ver] 223 | end 224 | 225 | def get_required_params(ver) 226 | ver=get_version(ver,@requiredparams) 227 | return nil if ver.nil? 228 | @requiredparams[ver] 229 | end 230 | 231 | def parameters(ver,*params,&block) 232 | parameters=ZabbixAPI_ParametersDSL.new(@validparams,@requiredparams) 233 | 234 | parameters.add(params) if !params.nil? 235 | parameters.instance_eval(&block) if !block.nil? 236 | @validparams[ver]=parameters.valid_params 237 | @requiredparams[ver]=parameters.required_params 238 | end 239 | 240 | def params_good?(server_version, params) 241 | debug(8,:msg=>"Server Version", :var=>server_version) 242 | var=params.is_a?(Hash) ? params.keys : params 243 | debug(8,:msg=>"Param keys", :var=>var) 244 | 245 | valid_params=get_valid_params(server_version) 246 | 247 | if valid_params #continue to see if there's a required param 248 | raise ArgumentError.new("Named Arguments (Hash) expected for #{@apiclass}.#{@apimethod},"\ 249 | " '#{params.class}' received: #{params.inspect}") if !params.is_a?(Hash) 250 | args=params.keys.map{|key|key.to_s} 251 | 252 | invalid_args=args-valid_params 253 | debug(9,:msg=>"Invalid args",:var=>invalid_args) 254 | raise ZbxAPI_ParameterError.new("Invalid parameters #{invalid_args.inspect}") if !invalid_args.empty? 255 | end 256 | 257 | required_params=get_required_params(server_version) 258 | # ver=get_version(server_version,@requiredparams) 259 | 260 | return true if required_params.nil? 261 | required_args=required_params.reject { |i| i.class==Array } 262 | required_or_args=required_params.reject { |i| i.class!=Array } 263 | 264 | missing_args=[] 265 | missing_args=required_args-args 266 | 267 | required_or_args.delete_if do |i| 268 | count=i.length 269 | missing_args<"Required Params",:var=>required_params) 273 | debug(9,:msg=>"Missing params",:var=>missing_args) 274 | 275 | if !missing_args.empty? 276 | msg=missing_args.map do |i| 277 | if i.class==Array 278 | "(#{i.join(" | ")})" 279 | else 280 | i 281 | end 282 | end.join(", ") 283 | raise ZbxAPI_ParameterError.new("Missing required arguments: #{msg}") 284 | end 285 | true 286 | end 287 | 288 | #This is the function that does the actual APIcall. 289 | def do(server,params={}) 290 | debug(7,:msg=>"Method Name",:var=>@method_names[@method_names.keys.sort.first]) 291 | debug(7,:msg=>"Server",:var=>server) 292 | debug(7,:msg=>"Params",:var=>params) 293 | 294 | ver=get_version(server.API_version,@method_names) 295 | name=@method_names[ver] 296 | 297 | debug(8,:msg=>"Method Name used",:var=>name) 298 | 299 | if @invalidated 300 | ver=get_version(server.API_version,@invalidated) 301 | if ver 302 | msg=@invalidated.values.first.empty? ? 303 | "#{name} is invalid for api versions #{@invalidated.keys.first} and higher" : @invalidated.values.first 304 | raise InvalidMethodError.new(msg) 305 | end 306 | end 307 | 308 | if @deprecated 309 | ver=get_version(server.API_version,@deprecated) 310 | if ver 311 | msg=@deprecated.values.first.empty? ? 312 | "#{name} is deprecated for api versions #{@deprecated.keys.first} and higher" : @deprecated.values.first 313 | warn("Warning: #{msg}") 314 | end 315 | end 316 | 317 | debug(8,:msg=>"Params before arg processor",:var=>params) 318 | params=call_arg_processor(server.API_version,params) 319 | debug(7,:msg=>"Params after arg processor",:var=>params) 320 | params_good?(server.API_version,params) 321 | server.api_call(name,params) 322 | end 323 | 324 | #returns the version number closest to server which is less than 325 | #or equal to server 326 | #If no versions exist in hash, nil is returned 327 | def get_version(server,hash) 328 | return nil if hash.nil? 329 | if server 330 | #server=server.split(".").map{|i| i.to_i } 331 | keys=hash.keys.sort do |a,b| 332 | aa=a.split(".") 333 | bb=b.split(".") 334 | last_pos=((aa.length > bb.length) ? aa.length : bb.length)-1 335 | pos=0 336 | while aa[pos].to_i==bb[pos].to_i 337 | break if pos>=last_pos 338 | pos+=1 339 | end 340 | (aa[pos].to_i<=>bb[pos].to_i) 341 | end 342 | 343 | keys.delete_if do |k| 344 | kk=k.split(".") 345 | ss=server.split(".") 346 | last_pos=((kk.length > ss.length) ? ss.length : ss.length)-1 347 | pos=0 348 | while kk[pos].to_i<=ss[pos].to_i 349 | break if pos>=last_pos 350 | pos+=1 351 | end 352 | kk[pos].to_i>ss[pos].to_i 353 | end 354 | 355 | if keys.empty? 356 | return nil 357 | else 358 | return keys.last 359 | end 360 | else 361 | sorted=hash.keys.sort do |a,b| 362 | aa=a.split(".") 363 | bb=b.split(".") 364 | last_pos=((aa.length > bb.length) ? aa.length : bb.length)-1 365 | pos=0 366 | while aa[pos].to_i==bb[pos].to_i 367 | break if pos>=last_pos 368 | pos+=1 369 | end 370 | (aa[pos].to_i<=>bb[pos].to_i) 371 | end 372 | sorted.last 373 | end 374 | end 375 | 376 | 377 | end 378 | 379 | class ZabbixAPI_Base 380 | def initialize(server) 381 | @server=server 382 | end 383 | 384 | def api_methods 385 | self.class.api_methods.keys 386 | end 387 | 388 | def api_aliases 389 | self.class.api_aliases 390 | end 391 | 392 | def valid_params(sym,ver=nil) 393 | api_method=self.class.api_methods[sym] 394 | return nil if api_method.nil? 395 | api_method.get_valid_params(ver) 396 | end 397 | 398 | def required_params(sym,ver=nil) 399 | api_method=self.class.api_methods[sym] 400 | return nil if api_method.nil? 401 | api_method.get_required_params(ver) 402 | end 403 | 404 | def self.method_missing(sym,&block) 405 | add(sym,&block) 406 | end 407 | 408 | def self.action(sym, &block) 409 | add(sym,&block) 410 | end 411 | 412 | def self.actions(*sym) 413 | sym.each {|s| add(s)} 414 | end 415 | 416 | def self.api_methods 417 | @api_methods 418 | end 419 | 420 | def self.api_aliases 421 | @api_aliases={} if @api_aliases.nil? 422 | @api_aliases 423 | end 424 | 425 | # Define an alias for an existing method. 426 | # From: the new method name 427 | # To: the existing method which the alias "from" will point to 428 | def self.api_alias(from,to) 429 | @api_aliases={} if @api_aliases.nil? 430 | @api_aliases[from]=to 431 | 432 | @api_methods[from]=@api_methods[to] 433 | 434 | define_method(from) do |params| 435 | self.class.api_methods[from].do(@server,params) 436 | end 437 | end 438 | 439 | def self.add(sym,&block) 440 | @api_methods={} if @api_methods.nil? 441 | @api_methods[sym]=ZabbixAPI_Method.new(self.to_s,sym.to_s) 442 | @api_methods[sym].instance_eval(&block) if !block.nil? 443 | 444 | #Create a method definition for the parameter in question. 445 | #params is not treated as an array, the splat operator 446 | #is there to allow for no parameters to be passed 447 | define_method(sym) do |*params| 448 | #The splat operator ensures we get an array, but we need 449 | #to test to ensure we receive one hash parameter 450 | if (params.length>1) 451 | raise ArgumentError.new("Hash or one argument expected for #{self.class}.#{sym.to_s}, received: #{params.inspect}") 452 | end 453 | self.class.api_methods[sym].do(@server,params.first||{}) 454 | end 455 | end 456 | end 457 | 458 | 459 | -------------------------------------------------------------------------------- /zbxapi.rb: -------------------------------------------------------------------------------- 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$ 23 | # $Revision$ 24 | ########################################## 25 | #++ 26 | 27 | #TODO Create class to capture resultant data 28 | 29 | class ZabbixAPI #create a stub to be defined later 30 | end 31 | 32 | #setup our search path or libraries 33 | $: << File.expand_path(File.join(File.dirname(__FILE__), '.')) 34 | 35 | #require 'zbxapi/revision' 36 | require 'zbxapi/zdebug' 37 | require 'zbxapi/api_exceptions.rb' 38 | require 'zbxapi/result' 39 | require 'uri' 40 | require 'net/https' 41 | require 'rubygems' 42 | require 'json' 43 | 44 | require "api_classes/api_dsl" 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 51 | 52 | def silence_warnings 53 | old_verbose, $VERBOSE = $VERBOSE, nil 54 | yield 55 | ensure 56 | $VERBOSE = old_verbose 57 | end 58 | 59 | #------------------------------------------------------------------------------ 60 | # 61 | # Class ZabbixAPI 62 | #++ 63 | # Main Zabbix API class. 64 | # 65 | #------------------------------------------------------------------------------ 66 | 67 | class ZabbixAPI 68 | 69 | include ZDebug 70 | 71 | attr_accessor :method, :params, :debug_level, :auth, :verify_ssl, :proxy_server 72 | 73 | class Redirect < Exception #:nodoc: all 74 | end 75 | 76 | public 77 | 78 | class << self 79 | public :define_method 80 | end 81 | 82 | # The initialization routine for the Zabbix API class 83 | # * url is a string defining the url to connect to, it should only point to the base url for Zabbix, not the api directory 84 | # * debug_level is the default level to be used for debug messages 85 | # Upon successful initialization the class will be set up to allow a connection to the Zabbix server 86 | # A connection however will not have been made, to actually connect to the Zabbix server use the login method 87 | #options: 88 | #Parameter Default Description 89 | #:debug 0 Debug Level 90 | #:returntype :result Return the value of "result" from the json result 91 | #:verify_ssl true Enable checking the SSL Cert 92 | def initialize(url,*args) 93 | options=args[0] 94 | options ||= {} 95 | if options.is_a?(Integer) 96 | warn "WARNING: Initialization has changed, backwards compatability is being used." 97 | warn "WARNING: Use ZabbixAPI.new(url,:debug=>n,:returntype=>:result) to have the" 98 | warn "WARNING: same capability as previous versions." 99 | warn "WARNING: This depreciated functionality will be removed in a future release" 100 | options={:debug=>0,:returntype=>:result} 101 | end 102 | 103 | #intialization of instance variables must happen inside of instantiation 104 | @id=0 105 | @auth='' 106 | @url=nil 107 | @verify_ssl=true 108 | @proxy_server=nil 109 | @custom_headers={} 110 | @user_name='' 111 | @password='' 112 | 113 | set_debug_level(options[:debug] || 0) 114 | @returntype=options[:returntype] || :result 115 | @orig_url=url #save the original url 116 | @url=URI.parse(url+'/api_jsonrpc.php') 117 | 118 | if options.has_key?:verify_ssl 119 | @verify_ssl=options[:verify_ssl] 120 | else 121 | @verify_ssl = true 122 | end 123 | 124 | if options.has_key?:http_timeout 125 | @http_timeout=options[:http_timeout] 126 | else 127 | #if not set, default http read_timeout=60 128 | @http_timeout=nil 129 | end 130 | 131 | if options.has_key?:custom_headers 132 | @custom_headers = options[:custom_headers] unless options[:custom_headers].nil? 133 | else 134 | @custom_headers = {} 135 | end 136 | 137 | #Generate the list of sub objects dynamically, from all objects 138 | #derived from ZabbixAPI_Base 139 | objects=true 140 | silence_warnings do 141 | objects=Object.constants.map do |i| 142 | obj=Object.const_get(i.intern) 143 | if obj.is_a?(Class) && ([ZabbixAPI_Base]-obj.ancestors).empty? 144 | obj 145 | else 146 | nil 147 | end 148 | end.compact-[ZabbixAPI_Base] 149 | end 150 | 151 | @objects={} 152 | 153 | objects.each do |i| 154 | i_s=i.to_s.downcase.intern 155 | @objects[i_s]=i.new(self) 156 | self.class.define_method(i_s) do 157 | instance_variable_get(:@objects)[i_s] 158 | end 159 | end 160 | 161 | @id=0 162 | 163 | debug(6,:msg=>"protocol: #{@url.scheme}, host: #{@url.host}") 164 | debug(6,:msg=>"port: #{@url.port}, path: #{@url.path}") 165 | debug(6,:msg=>"query: #{@url.query}, fragment: #{@url.fragment}") 166 | 167 | if block_given? 168 | yield(self) 169 | end 170 | end 171 | 172 | #Configure the information for the proxy server to be used to connect to the 173 | #Zabbix server 174 | def set_proxy(address,port,user=nil,password=nil) 175 | @proxy_server={:address=>address,:port=>port, 176 | :user=>user, :password=>password} 177 | return self 178 | end 179 | 180 | def self.get_version 181 | "#{ZBXAPI_VERSION}.#{ZBXAPI_REVISION}" 182 | end 183 | 184 | #wraps the given information into the appropriate JSON object 185 | #* method is a string 186 | #* params is a hash of the parameters for the method to be called 187 | #Returns a hash representing a Zabbix API JSON call 188 | def json_obj(method,params={}) 189 | obj = 190 | { 191 | 'jsonrpc'=>'2.0', 192 | 'method'=>method, 193 | 'params'=>params, 194 | 'auth'=>@auth, 195 | 'id'=>@id 196 | } 197 | 198 | # https://www.zabbix.com/documentation/2.4/manual/api/reference/apiinfo/version 199 | # https://www.zabbix.com/documentation/2.4/manual/api/reference/user/login 200 | # Zabbix Doc(2.4): This method is available to unauthenticated 201 | # users and must be called without the auth parameter 202 | # in the JSON-RPC request. 203 | debug(4, :var => method,:msg => "Method:") 204 | obj.delete("auth") if ["apiinfo.version", 205 | "user.login", 206 | ].any? { |str| method =~ /#{str}/i } 207 | 208 | debug(10, :msg=>"json_obj: #{obj}") 209 | return obj.to_json 210 | end 211 | 212 | 213 | #Performs a log in to the Zabbix server 214 | #* _user_ is a string with the username 215 | #* _password_ is a string with the user''s password 216 | #* _save_ tells the method to save the login details in internal class variables or not 217 | # 218 | #Raises: 219 | # 220 | #* Zbx_API_ExeeptionBadAuth is raised when one of the following conditions is met 221 | # 1. no-string variables were passed in 222 | # 1. no username or password was passed in or saved from a previous login 223 | # 1. login details were rejected by the server 224 | #* ZbxAPI_ExceptionBadServerUrl 225 | # 1. There was a socket error 226 | # 1. The url used to create the class was bad 227 | # 1. The connection to the server was refused 228 | def login(user='',password='',save=true) 229 | if user.class!=String or password.class!=String 230 | raise ZbxAPI_ExceptionBadAuth.new,'Login called with non-string values' 231 | end 232 | if (user!='' and password!='') then 233 | l_user = user 234 | l_password = password 235 | if save then 236 | @user_name=user 237 | @password=password 238 | end 239 | elsif (@user_name!='' and @password!='') then 240 | l_user = @user_name 241 | l_password = @password 242 | end 243 | 244 | #Somewhere in the 1.8.x cycle it was decided to do deprecate with user.authenticate 245 | #however it was not documented well, so we will try uer.login first, and fall 246 | #back to user.authenticate as user.login does not exist in 1.8.3 247 | login_methods=["user.login","user.authenticate"] 248 | 249 | begin 250 | result = do_request(json_obj(login_methods.first,{'user'=>l_user,'password'=>l_password})) 251 | @auth=result['result'] 252 | 253 | #setup the version variables 254 | @major,@minor=do_request(json_obj('apiinfo.version',{}))['result'].split('.') 255 | @major=@major.to_i 256 | @minor=@minor.to_i 257 | rescue ZbxAPI_ExceptionLoginPermission => e 258 | login_methods.delete_at(0) 259 | if !login_methods.empty? 260 | retry 261 | else 262 | raise ZbxAPI_ExceptionBadAuth.new('Invalid User or Password',:error_code=>e.error_code) 263 | end 264 | rescue SocketError 265 | raise ZbxAPI_ExceptionBadServerUrl.new("Socket Error") 266 | rescue JSON::ParserError 267 | raise ZbxAPI_ExceptionBadServerUrl 268 | rescue Errno::ECONNREFUSED 269 | raise ZbxAPI_ExceptionBadServerUrl 270 | rescue => e 271 | raise ZbxAPI_ExceptionBadAuth.new('General Login error, check host connectivity.') 272 | end 273 | 274 | return self 275 | end 276 | 277 | def logout 278 | do_request(json_obj('user.logout')) 279 | end 280 | 281 | # Tests to determine if the login information is still valid 282 | # returns: true if it is valid or false if it is not. 283 | def test_login 284 | if @auth!='' then 285 | result = do_request(json_obj('user.checkauth', 286 | {'sessionid'=>@auth})) 287 | if !result['result'] then 288 | @auth='' 289 | return false #auth hash bad 290 | end 291 | return true #auth hash good 292 | else 293 | return false 294 | end 295 | end 296 | 297 | #Returns true if a login was performed 298 | def loggedin? 299 | !(@auth=='' or @auth.nil?) 300 | end 301 | 302 | #wrapper to loggedin? 303 | #returns nothing, raises the exception ZbxAPI_ExceptionBadAuth if loggedin? returns false 304 | def checkauth 305 | raise ZbxAPI_ExceptionBadAuth, 'Not logged in' if !loggedin? 306 | end 307 | 308 | #returns the version number for the API from the server 309 | def API_version(options={}) 310 | return "#{@major}.#{@minor}" 311 | end 312 | 313 | # Provides raw access to the API via a small wrapper. 314 | # _method_ is the method to be called 315 | # _params_ are the parameters to be passed to the call 316 | # returns a hash of the results from the server 317 | def raw_api(method,params=nil) 318 | debug(6,:var=>method,:msg=>"method") 319 | debug(6,:var=>params,:msg=>"Parameters") 320 | 321 | checkauth 322 | checkversion(1,1) 323 | params={} if params==nil 324 | 325 | obj=do_request(json_obj(method,params)) 326 | return obj['result'] 327 | end 328 | 329 | # Function to test whether or not a function will work with the current API version of the server 330 | # If no options are presented the major and minor are assumed to be the minimum version 331 | # number suitable to run the function 332 | # Does not explicitly return anything, but raises ZbxAPI_ExceptionVersion if there is a problem 333 | def checkversion(major,minor,options=nil) 334 | caller[0]=~/`(.*?)'/ 335 | caller_func=$1 336 | 337 | raise ZbxAPI_ExceptionVersion, "#{caller_func} requires API version #{major}.#{minor} or higher" if major>@major or (minor>@minor and major>=@major) 338 | 339 | end 340 | 341 | #api_call 342 | #This is the main function for performing api requests 343 | #method is a string denoting the method to call 344 | #options is a hash of options to be passed to the function 345 | def api_call(method,options={}) 346 | debug(6,:msg=>"Method",:var=>method) 347 | debug(6,:msg=>"Options",:var=>options) 348 | 349 | obj=json_obj(method,options) 350 | result=do_request(obj) 351 | if @returntype==:result 352 | result["result"] 353 | else 354 | result.merge!({:method=>method, :params=>options}) 355 | @returntype.new(result) 356 | end 357 | end 358 | 359 | def api_info(request=:objects,*options) 360 | options = options[0] || {} 361 | version=options[:version] || nil 362 | request_type=options[:params] || :valid 363 | 364 | case request 365 | when :objects then 366 | @objects.keys.map { |k| k.to_s } 367 | else 368 | obj,meth=request.split(".") 369 | if meth then 370 | case request_type 371 | when :valid 372 | @objects[obj.intern].valid_params(meth.intern,version) 373 | when :required 374 | @objects[obj.intern].required_params(meth.intern,version) 375 | end 376 | else 377 | @objects[obj.intern].api_methods.map{ |m| m.to_s } 378 | end 379 | end 380 | end 381 | 382 | private 383 | 384 | #Select the http object to be used. 385 | def select_http_obj 386 | if @proxy_server 387 | http = Net::HTTP::Proxy(@proxy_server[:address],@proxy_server[:port], 388 | @proxy_server[:user],@proxy_server[:password]).new(@url.host,@url.port) 389 | else 390 | http = Net::HTTP.new(@url.host, @url.port) 391 | end 392 | http.use_ssl=true if @url.class==URI::HTTPS 393 | if !@verify_ssl 394 | http.verify_mode = OpenSSL::SSL::VERIFY_NONE if @url.class==URI::HTTPS 395 | end 396 | http.read_timeout=@http_timeout unless @http_timeout.nil? 397 | 398 | http 399 | end 400 | 401 | #Sends JSON encoded string to server 402 | #truncate_length determines how many characters at maximum should be displayed while debugging before 403 | #truncation should occur. 404 | def do_request(json_obj,truncate_length=5000) 405 | redirects=0 406 | begin # This is here for redirects 407 | http=select_http_obj 408 | response = nil 409 | # http.set_debug_output($stderr) #Uncomment to see low level HTTP debug 410 | headers={ 411 | 'Content-Type'=>'application/json-rpc', 412 | 'User-Agent'=>'Zbx Ruby CLI' 413 | }.merge(@custom_headers) 414 | 415 | debug(4,:msg=>"Sending: #{json_obj}") 416 | response = http.post(@url.path, json_obj,headers) 417 | debug(4,:msg=>"Response Code: #{response.code}") 418 | debug(4,:var=>response.body,:msg=>"Response Body",:truncate=>truncate_length) 419 | case response.code.to_i 420 | when 301 421 | puts "Redirecting to #{response['location']}" 422 | @url=URI.parse(response['location']) 423 | raise Redirect 424 | when 500 425 | raise ZbxAPI_GeneralError.new("Zabbix server returned an internal error\n Call: #{json_obj}", :retry=>true) 426 | end 427 | 428 | @id+=1 # increment the ID value for the API call 429 | 430 | # check return code and throw exception for error checking 431 | resp = JSON.parse(response.body) #parse the JSON Object so we can use it 432 | if !resp["error"].nil? 433 | errcode=resp["error"]["code"].to_i 434 | case errcode 435 | when -32602 then 436 | raise ZbxAPI_ExceptionLoginPermission.new(resp["error"],:error_code=>errcode,:retry=>true) 437 | when -32500 then 438 | raise ZbxAPI_ExceptionPermissionError.new(resp["error"],:error_code=>errcode,:retry=>true) 439 | else 440 | puts "other error" 441 | raise ZbxAPI_GeneralError, resp["error"] 442 | end 443 | end 444 | 445 | return resp 446 | 447 | rescue Redirect 448 | redirects+=1 449 | retry if redirects<=5 450 | raise ZbxAPI_GeneralError, "Too many redirects" 451 | rescue NoMethodError 452 | raise ZbxAPI_GeneralError.new("Unable to connect to #{@url.host}: \"#{e}\"", :retry=>false) 453 | end 454 | end 455 | end 456 | 457 | #****************************************************************************** 458 | 459 | 460 | if __FILE__ == $0 461 | require 'pp' 462 | 463 | zbx=ZabbixAPI.new("http://zabbix.example.com/") 464 | #zbx.set_proxy("localhost",3128) 465 | zbx.login("user","password") 466 | pp zbx.host.get("output"=>"extend") 467 | 468 | end 469 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 2.1, February 1999 3 | 4 | Copyright (C) 1991, 1999 Free Software Foundation, Inc. 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | [This is the first released version of the Lesser GPL. It also counts 10 | as the successor of the GNU Library Public License, version 2, hence 11 | the version number 2.1.] 12 | 13 | Preamble 14 | 15 | The licenses for most software are designed to take away your 16 | freedom to share and change it. By contrast, the GNU General Public 17 | Licenses are intended to guarantee your freedom to share and change 18 | free software--to make sure the software is free for all its users. 19 | 20 | This license, the Lesser General Public License, applies to some 21 | specially designated software packages--typically libraries--of the 22 | Free Software Foundation and other authors who decide to use it. You 23 | can use it too, but we suggest you first think carefully about whether 24 | this license or the ordinary General Public License is the better 25 | strategy to use in any particular case, based on the explanations below. 26 | 27 | When we speak of free software, we are referring to freedom of use, 28 | not price. Our General Public Licenses are designed to make sure that 29 | you have the freedom to distribute copies of free software (and charge 30 | for this service if you wish); that you receive source code or can get 31 | it if you want it; that you can change the software and use pieces of 32 | it in new free programs; and that you are informed that you can do 33 | these things. 34 | 35 | To protect your rights, we need to make restrictions that forbid 36 | distributors to deny you these rights or to ask you to surrender these 37 | rights. These restrictions translate to certain responsibilities for 38 | you if you distribute copies of the library or if you modify it. 39 | 40 | For example, if you distribute copies of the library, whether gratis 41 | or for a fee, you must give the recipients all the rights that we gave 42 | you. You must make sure that they, too, receive or can get the source 43 | code. If you link other code with the library, you must provide 44 | complete object files to the recipients, so that they can relink them 45 | with the library after making changes to the library and recompiling 46 | it. And you must show them these terms so they know their rights. 47 | 48 | We protect your rights with a two-step method: (1) we copyright the 49 | library, and (2) we offer you this license, which gives you legal 50 | permission to copy, distribute and/or modify the library. 51 | 52 | To protect each distributor, we want to make it very clear that 53 | there is no warranty for the free library. Also, if the library is 54 | modified by someone else and passed on, the recipients should know 55 | that what they have is not the original version, so that the original 56 | author's reputation will not be affected by problems that might be 57 | introduced by others. 58 | 59 | Finally, software patents pose a constant threat to the existence of 60 | any free program. We wish to make sure that a company cannot 61 | effectively restrict the users of a free program by obtaining a 62 | restrictive license from a patent holder. Therefore, we insist that 63 | any patent license obtained for a version of the library must be 64 | consistent with the full freedom of use specified in this license. 65 | 66 | Most GNU software, including some libraries, is covered by the 67 | ordinary GNU General Public License. This license, the GNU Lesser 68 | General Public License, applies to certain designated libraries, and 69 | is quite different from the ordinary General Public License. We use 70 | this license for certain libraries in order to permit linking those 71 | libraries into non-free programs. 72 | 73 | When a program is linked with a library, whether statically or using 74 | a shared library, the combination of the two is legally speaking a 75 | combined work, a derivative of the original library. The ordinary 76 | General Public License therefore permits such linking only if the 77 | entire combination fits its criteria of freedom. The Lesser General 78 | Public License permits more lax criteria for linking other code with 79 | the library. 80 | 81 | We call this license the "Lesser" General Public License because it 82 | does Less to protect the user's freedom than the ordinary General 83 | Public License. It also provides other free software developers Less 84 | of an advantage over competing non-free programs. These disadvantages 85 | are the reason we use the ordinary General Public License for many 86 | libraries. However, the Lesser license provides advantages in certain 87 | special circumstances. 88 | 89 | For example, on rare occasions, there may be a special need to 90 | encourage the widest possible use of a certain library, so that it becomes 91 | a de-facto standard. To achieve this, non-free programs must be 92 | allowed to use the library. A more frequent case is that a free 93 | library does the same job as widely used non-free libraries. In this 94 | case, there is little to gain by limiting the free library to free 95 | software only, so we use the Lesser General Public License. 96 | 97 | In other cases, permission to use a particular library in non-free 98 | programs enables a greater number of people to use a large body of 99 | free software. For example, permission to use the GNU C Library in 100 | non-free programs enables many more people to use the whole GNU 101 | operating system, as well as its variant, the GNU/Linux operating 102 | system. 103 | 104 | Although the Lesser General Public License is Less protective of the 105 | users' freedom, it does ensure that the user of a program that is 106 | linked with the Library has the freedom and the wherewithal to run 107 | that program using a modified version of the Library. 108 | 109 | The precise terms and conditions for copying, distribution and 110 | modification follow. Pay close attention to the difference between a 111 | "work based on the library" and a "work that uses the library". The 112 | former contains code derived from the library, whereas the latter must 113 | be combined with the library in order to run. 114 | 115 | GNU LESSER GENERAL PUBLIC LICENSE 116 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 117 | 118 | 0. This License Agreement applies to any software library or other 119 | program which contains a notice placed by the copyright holder or 120 | other authorized party saying it may be distributed under the terms of 121 | this Lesser General Public License (also called "this License"). 122 | Each licensee is addressed as "you". 123 | 124 | A "library" means a collection of software functions and/or data 125 | prepared so as to be conveniently linked with application programs 126 | (which use some of those functions and data) to form executables. 127 | 128 | The "Library", below, refers to any such software library or work 129 | which has been distributed under these terms. A "work based on the 130 | Library" means either the Library or any derivative work under 131 | copyright law: that is to say, a work containing the Library or a 132 | portion of it, either verbatim or with modifications and/or translated 133 | straightforwardly into another language. (Hereinafter, translation is 134 | included without limitation in the term "modification".) 135 | 136 | "Source code" for a work means the preferred form of the work for 137 | making modifications to it. For a library, complete source code means 138 | all the source code for all modules it contains, plus any associated 139 | interface definition files, plus the scripts used to control compilation 140 | and installation of the library. 141 | 142 | Activities other than copying, distribution and modification are not 143 | covered by this License; they are outside its scope. The act of 144 | running a program using the Library is not restricted, and output from 145 | such a program is covered only if its contents constitute a work based 146 | on the Library (independent of the use of the Library in a tool for 147 | writing it). Whether that is true depends on what the Library does 148 | and what the program that uses the Library does. 149 | 150 | 1. You may copy and distribute verbatim copies of the Library's 151 | complete source code as you receive it, in any medium, provided that 152 | you conspicuously and appropriately publish on each copy an 153 | appropriate copyright notice and disclaimer of warranty; keep intact 154 | all the notices that refer to this License and to the absence of any 155 | warranty; and distribute a copy of this License along with the 156 | Library. 157 | 158 | You may charge a fee for the physical act of transferring a copy, 159 | and you may at your option offer warranty protection in exchange for a 160 | fee. 161 | 162 | 2. You may modify your copy or copies of the Library or any portion 163 | of it, thus forming a work based on the Library, and copy and 164 | distribute such modifications or work under the terms of Section 1 165 | above, provided that you also meet all of these conditions: 166 | 167 | a) The modified work must itself be a software library. 168 | 169 | b) You must cause the files modified to carry prominent notices 170 | stating that you changed the files and the date of any change. 171 | 172 | c) You must cause the whole of the work to be licensed at no 173 | charge to all third parties under the terms of this License. 174 | 175 | d) If a facility in the modified Library refers to a function or a 176 | table of data to be supplied by an application program that uses 177 | the facility, other than as an argument passed when the facility 178 | is invoked, then you must make a good faith effort to ensure that, 179 | in the event an application does not supply such function or 180 | table, the facility still operates, and performs whatever part of 181 | its purpose remains meaningful. 182 | 183 | (For example, a function in a library to compute square roots has 184 | a purpose that is entirely well-defined independent of the 185 | application. Therefore, Subsection 2d requires that any 186 | application-supplied function or table used by this function must 187 | be optional: if the application does not supply it, the square 188 | root function must still compute square roots.) 189 | 190 | These requirements apply to the modified work as a whole. If 191 | identifiable sections of that work are not derived from the Library, 192 | and can be reasonably considered independent and separate works in 193 | themselves, then this License, and its terms, do not apply to those 194 | sections when you distribute them as separate works. But when you 195 | distribute the same sections as part of a whole which is a work based 196 | on the Library, the distribution of the whole must be on the terms of 197 | this License, whose permissions for other licensees extend to the 198 | entire whole, and thus to each and every part regardless of who wrote 199 | it. 200 | 201 | Thus, it is not the intent of this section to claim rights or contest 202 | your rights to work written entirely by you; rather, the intent is to 203 | exercise the right to control the distribution of derivative or 204 | collective works based on the Library. 205 | 206 | In addition, mere aggregation of another work not based on the Library 207 | with the Library (or with a work based on the Library) on a volume of 208 | a storage or distribution medium does not bring the other work under 209 | the scope of this License. 210 | 211 | 3. You may opt to apply the terms of the ordinary GNU General Public 212 | License instead of this License to a given copy of the Library. To do 213 | this, you must alter all the notices that refer to this License, so 214 | that they refer to the ordinary GNU General Public License, version 2, 215 | instead of to this License. (If a newer version than version 2 of the 216 | ordinary GNU General Public License has appeared, then you can specify 217 | that version instead if you wish.) Do not make any other change in 218 | these notices. 219 | 220 | Once this change is made in a given copy, it is irreversible for 221 | that copy, so the ordinary GNU General Public License applies to all 222 | subsequent copies and derivative works made from that copy. 223 | 224 | This option is useful when you wish to copy part of the code of 225 | the Library into a program that is not a library. 226 | 227 | 4. You may copy and distribute the Library (or a portion or 228 | derivative of it, under Section 2) in object code or executable form 229 | under the terms of Sections 1 and 2 above provided that you accompany 230 | it with the complete corresponding machine-readable source code, which 231 | must be distributed under the terms of Sections 1 and 2 above on a 232 | medium customarily used for software interchange. 233 | 234 | If distribution of object code is made by offering access to copy 235 | from a designated place, then offering equivalent access to copy the 236 | source code from the same place satisfies the requirement to 237 | distribute the source code, even though third parties are not 238 | compelled to copy the source along with the object code. 239 | 240 | 5. A program that contains no derivative of any portion of the 241 | Library, but is designed to work with the Library by being compiled or 242 | linked with it, is called a "work that uses the Library". Such a 243 | work, in isolation, is not a derivative work of the Library, and 244 | therefore falls outside the scope of this License. 245 | 246 | However, linking a "work that uses the Library" with the Library 247 | creates an executable that is a derivative of the Library (because it 248 | contains portions of the Library), rather than a "work that uses the 249 | library". The executable is therefore covered by this License. 250 | Section 6 states terms for distribution of such executables. 251 | 252 | When a "work that uses the Library" uses material from a header file 253 | that is part of the Library, the object code for the work may be a 254 | derivative work of the Library even though the source code is not. 255 | Whether this is true is especially significant if the work can be 256 | linked without the Library, or if the work is itself a library. The 257 | threshold for this to be true is not precisely defined by law. 258 | 259 | If such an object file uses only numerical parameters, data 260 | structure layouts and accessors, and small macros and small inline 261 | functions (ten lines or less in length), then the use of the object 262 | file is unrestricted, regardless of whether it is legally a derivative 263 | work. (Executables containing this object code plus portions of the 264 | Library will still fall under Section 6.) 265 | 266 | Otherwise, if the work is a derivative of the Library, you may 267 | distribute the object code for the work under the terms of Section 6. 268 | Any executables containing that work also fall under Section 6, 269 | whether or not they are linked directly with the Library itself. 270 | 271 | 6. As an exception to the Sections above, you may also combine or 272 | link a "work that uses the Library" with the Library to produce a 273 | work containing portions of the Library, and distribute that work 274 | under terms of your choice, provided that the terms permit 275 | modification of the work for the customer's own use and reverse 276 | engineering for debugging such modifications. 277 | 278 | You must give prominent notice with each copy of the work that the 279 | Library is used in it and that the Library and its use are covered by 280 | this License. You must supply a copy of this License. If the work 281 | during execution displays copyright notices, you must include the 282 | copyright notice for the Library among them, as well as a reference 283 | directing the user to the copy of this License. Also, you must do one 284 | of these things: 285 | 286 | a) Accompany the work with the complete corresponding 287 | machine-readable source code for the Library including whatever 288 | changes were used in the work (which must be distributed under 289 | Sections 1 and 2 above); and, if the work is an executable linked 290 | with the Library, with the complete machine-readable "work that 291 | uses the Library", as object code and/or source code, so that the 292 | user can modify the Library and then relink to produce a modified 293 | executable containing the modified Library. (It is understood 294 | that the user who changes the contents of definitions files in the 295 | Library will not necessarily be able to recompile the application 296 | to use the modified definitions.) 297 | 298 | b) Use a suitable shared library mechanism for linking with the 299 | Library. A suitable mechanism is one that (1) uses at run time a 300 | copy of the library already present on the user's computer system, 301 | rather than copying library functions into the executable, and (2) 302 | will operate properly with a modified version of the library, if 303 | the user installs one, as long as the modified version is 304 | interface-compatible with the version that the work was made with. 305 | 306 | c) Accompany the work with a written offer, valid for at 307 | least three years, to give the same user the materials 308 | specified in Subsection 6a, above, for a charge no more 309 | than the cost of performing this distribution. 310 | 311 | d) If distribution of the work is made by offering access to copy 312 | from a designated place, offer equivalent access to copy the above 313 | specified materials from the same place. 314 | 315 | e) Verify that the user has already received a copy of these 316 | materials or that you have already sent this user a copy. 317 | 318 | For an executable, the required form of the "work that uses the 319 | Library" must include any data and utility programs needed for 320 | reproducing the executable from it. However, as a special exception, 321 | the materials to be distributed need not include anything that is 322 | normally distributed (in either source or binary form) with the major 323 | components (compiler, kernel, and so on) of the operating system on 324 | which the executable runs, unless that component itself accompanies 325 | the executable. 326 | 327 | It may happen that this requirement contradicts the license 328 | restrictions of other proprietary libraries that do not normally 329 | accompany the operating system. Such a contradiction means you cannot 330 | use both them and the Library together in an executable that you 331 | distribute. 332 | 333 | 7. You may place library facilities that are a work based on the 334 | Library side-by-side in a single library together with other library 335 | facilities not covered by this License, and distribute such a combined 336 | library, provided that the separate distribution of the work based on 337 | the Library and of the other library facilities is otherwise 338 | permitted, and provided that you do these two things: 339 | 340 | a) Accompany the combined library with a copy of the same work 341 | based on the Library, uncombined with any other library 342 | facilities. This must be distributed under the terms of the 343 | Sections above. 344 | 345 | b) Give prominent notice with the combined library of the fact 346 | that part of it is a work based on the Library, and explaining 347 | where to find the accompanying uncombined form of the same work. 348 | 349 | 8. You may not copy, modify, sublicense, link with, or distribute 350 | the Library except as expressly provided under this License. Any 351 | attempt otherwise to copy, modify, sublicense, link with, or 352 | distribute the Library is void, and will automatically terminate your 353 | rights under this License. However, parties who have received copies, 354 | or rights, from you under this License will not have their licenses 355 | terminated so long as such parties remain in full compliance. 356 | 357 | 9. You are not required to accept this License, since you have not 358 | signed it. However, nothing else grants you permission to modify or 359 | distribute the Library or its derivative works. These actions are 360 | prohibited by law if you do not accept this License. Therefore, by 361 | modifying or distributing the Library (or any work based on the 362 | Library), you indicate your acceptance of this License to do so, and 363 | all its terms and conditions for copying, distributing or modifying 364 | the Library or works based on it. 365 | 366 | 10. Each time you redistribute the Library (or any work based on the 367 | Library), the recipient automatically receives a license from the 368 | original licensor to copy, distribute, link with or modify the Library 369 | subject to these terms and conditions. You may not impose any further 370 | restrictions on the recipients' exercise of the rights granted herein. 371 | You are not responsible for enforcing compliance by third parties with 372 | this License. 373 | 374 | 11. If, as a consequence of a court judgment or allegation of patent 375 | infringement or for any other reason (not limited to patent issues), 376 | conditions are imposed on you (whether by court order, agreement or 377 | otherwise) that contradict the conditions of this License, they do not 378 | excuse you from the conditions of this License. If you cannot 379 | distribute so as to satisfy simultaneously your obligations under this 380 | License and any other pertinent obligations, then as a consequence you 381 | may not distribute the Library at all. For example, if a patent 382 | license would not permit royalty-free redistribution of the Library by 383 | all those who receive copies directly or indirectly through you, then 384 | the only way you could satisfy both it and this License would be to 385 | refrain entirely from distribution of the Library. 386 | 387 | If any portion of this section is held invalid or unenforceable under any 388 | particular circumstance, the balance of the section is intended to apply, 389 | and the section as a whole is intended to apply in other circumstances. 390 | 391 | It is not the purpose of this section to induce you to infringe any 392 | patents or other property right claims or to contest validity of any 393 | such claims; this section has the sole purpose of protecting the 394 | integrity of the free software distribution system which is 395 | implemented by public license practices. Many people have made 396 | generous contributions to the wide range of software distributed 397 | through that system in reliance on consistent application of that 398 | system; it is up to the author/donor to decide if he or she is willing 399 | to distribute software through any other system and a licensee cannot 400 | impose that choice. 401 | 402 | This section is intended to make thoroughly clear what is believed to 403 | be a consequence of the rest of this License. 404 | 405 | 12. If the distribution and/or use of the Library is restricted in 406 | certain countries either by patents or by copyrighted interfaces, the 407 | original copyright holder who places the Library under this License may add 408 | an explicit geographical distribution limitation excluding those countries, 409 | so that distribution is permitted only in or among countries not thus 410 | excluded. In such case, this License incorporates the limitation as if 411 | written in the body of this License. 412 | 413 | 13. The Free Software Foundation may publish revised and/or new 414 | versions of the Lesser General Public License from time to time. 415 | Such new versions will be similar in spirit to the present version, 416 | but may differ in detail to address new problems or concerns. 417 | 418 | Each version is given a distinguishing version number. If the Library 419 | specifies a version number of this License which applies to it and 420 | "any later version", you have the option of following the terms and 421 | conditions either of that version or of any later version published by 422 | the Free Software Foundation. If the Library does not specify a 423 | license version number, you may choose any version ever published by 424 | the Free Software Foundation. 425 | 426 | 14. If you wish to incorporate parts of the Library into other free 427 | programs whose distribution conditions are incompatible with these, 428 | write to the author to ask for permission. For software which is 429 | copyrighted by the Free Software Foundation, write to the Free 430 | Software Foundation; we sometimes make exceptions for this. Our 431 | decision will be guided by the two goals of preserving the free status 432 | of all derivatives of our free software and of promoting the sharing 433 | and reuse of software generally. 434 | 435 | NO WARRANTY 436 | 437 | 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO 438 | WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. 439 | EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR 440 | OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY 441 | KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE 442 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 443 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE 444 | LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME 445 | THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 446 | 447 | 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN 448 | WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY 449 | AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU 450 | FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR 451 | CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE 452 | LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING 453 | RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A 454 | FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF 455 | SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 456 | DAMAGES. 457 | 458 | END OF TERMS AND CONDITIONS 459 | 460 | How to Apply These Terms to Your New Libraries 461 | 462 | If you develop a new library, and you want it to be of the greatest 463 | possible use to the public, we recommend making it free software that 464 | everyone can redistribute and change. You can do so by permitting 465 | redistribution under these terms (or, alternatively, under the terms of the 466 | ordinary General Public License). 467 | 468 | To apply these terms, attach the following notices to the library. It is 469 | safest to attach them to the start of each source file to most effectively 470 | convey the exclusion of warranty; and each file should have at least the 471 | "copyright" line and a pointer to where the full notice is found. 472 | 473 | 474 | Copyright (C) 475 | 476 | This library is free software; you can redistribute it and/or 477 | modify it under the terms of the GNU Lesser General Public 478 | License as published by the Free Software Foundation; either 479 | version 2.1 of the License, or (at your option) any later version. 480 | 481 | This library is distributed in the hope that it will be useful, 482 | but WITHOUT ANY WARRANTY; without even the implied warranty of 483 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 484 | Lesser General Public License for more details. 485 | 486 | You should have received a copy of the GNU Lesser General Public 487 | License along with this library; if not, write to the Free Software 488 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 489 | 490 | Also add information on how to contact you by electronic and paper mail. 491 | 492 | You should also get your employer (if you work as a programmer) or your 493 | school, if any, to sign a "copyright disclaimer" for the library, if 494 | necessary. Here is a sample; alter the names: 495 | 496 | Yoyodyne, Inc., hereby disclaims all copyright interest in the 497 | library `Frob' (a library for tweaking knobs) written by James Random Hacker. 498 | 499 | , 1 April 1990 500 | Ty Coon, President of Vice 501 | 502 | That's all there is to it! 503 | --------------------------------------------------------------------------------