zabby 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .idea
6
+ .yardoc
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in zabby.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,49 @@
1
+ Copyright 2011 Farzad FARID / Pragmatic Source. All rights reserved.
2
+
3
+ Redistribution and use in source and binary forms, with or without modification, are
4
+ permitted provided that the following conditions are met:
5
+
6
+ 1. Redistributions of source code must retain the above copyright notice, this list of
7
+ conditions and the following disclaimer.
8
+
9
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list
10
+ of conditions and the following disclaimer in the documentation and/or other materials
11
+ provided with the distribution.
12
+
13
+ THIS SOFTWARE IS PROVIDED BY PRAGMATIC SOURCE ''AS IS'' AND ANY EXPRESS OR IMPLIED
14
+ WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
15
+ FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL PRAGMATIC SOURCE OR
16
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
17
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
18
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
19
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
20
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
21
+ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
+
23
+ The views and conclusions contained in the software and documentation are those of the
24
+ authors and should not be interpreted as representing official policies, either expressed
25
+ or implied, of Pragmatic Source.
26
+
27
+ OTHER LICENSES COVERING PORTIONS OF CODE
28
+ ========================================
29
+
30
+ Portions of code in "Zabbix::Running" were inspired by Rush (https://github.com/adamwiggins/rush):
31
+
32
+ Copyright (c) 2010 Adam Wiggins
33
+
34
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this
35
+ software and associated documentation files (the "Software"), to deal in the Software
36
+ without restriction, including without limitation the rights to use, copy, modify,
37
+ merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
38
+ permit persons to whom the Software is furnished to do so, subject to the following
39
+ conditions:
40
+
41
+ The above copyright notice and this permission notice shall be included in all copies
42
+ or substantial portions of the Software.
43
+
44
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
45
+ INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
46
+ PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
47
+ FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
48
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
49
+ DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,137 @@
1
+ = Zabby
2
+
3
+ Zabby[http://zabby.org] is a Ruby library and client for Zabbix[http://www.zabbix.com/]. It provides a simple and
4
+ clean interface to the {Zabbix Web Services}[http://www.zabbix.com/documentation/1.8/api].
5
+
6
+ == Goals
7
+
8
+ There already are Ruby Zabbix libraries but some of them are unfinished (and apparently
9
+ abandonned) and some other's code is too complicated or poorly designed. This is why I decided
10
+ to write another tool for which my primary goal is to keep the code design, the user interaction
11
+ and application interface clean and simple.
12
+
13
+ Zabby has the following caracteristics:
14
+ - Works both as a Ruby API and a command line tool.
15
+ - Uses an internal Ruby DSL (Domain Specific Langage) that give access to the full power of
16
+ Ruby scripting in your configurarion files. No need for a specific configuration language.
17
+ - Simple design: avoids spaghetti code, WTF and facepalm, unlike some other
18
+ Ruby Zabbix libraries.
19
+
20
+ == Features
21
+
22
+ - Low level Ruby API that maps every Zabbix API (JSON RPC) to Ruby hashes.
23
+ - Higher level Ruby DSL, both available in pure Ruby and for writing configuration files.
24
+ - Supports authenticated HTTP proxies.
25
+ - Full featured IRB like shell included with Readline support. You can mix Zabbix instructions
26
+ with Ruby calls transparently.
27
+
28
+ == Examples
29
+
30
+ === API use
31
+
32
+ The barebone API can be used in Ruby like this:
33
+
34
+ require "rubygems"
35
+ require "zabby"
36
+ require "pp"
37
+
38
+ z = Zabby.init do
39
+ host "https://monitoring.example.com"
40
+ user "api_user"
41
+ password "s3cr3t"
42
+ proxy_host "http://10.10.10.10"
43
+ proxy_user "john"
44
+ proxy_password "D0e"
45
+ end
46
+ z.login
47
+
48
+ pp z.connection.perform_request("host", "get", { "filter" => { "host" => "master.example.com" } })
49
+ pp z.connection.perform_request("item", "get", { "host" => "master.example.com", "output" => "shorten" })
50
+
51
+ - The _host_, _user_ and _passord_ are necessary.
52
+ - If you don't provide the path to the JSON-RPC script "/api_jsonrpc.php" is appended
53
+ to the URI automatically.
54
+ - The <em>proxy_*</em> settings are optionnal.
55
+
56
+ === Shell
57
+
58
+ *zabbysh* is an simple Zabbix Shell. It runs either interactively or
59
+ can be used to execute a command file with the "-f CMD_FILE" option.
60
+
61
+ If the command file does not end with "exit" then the program drops into
62
+ the shell after executing the file.
63
+
64
+ *zabbysh* provides Readline support but does no support advanced IRB features likes
65
+ multi-lines instructions.
66
+
67
+ *zabbyrb* is another Zabbix Shell based on *IRB*. It provides the whole power of IRB
68
+ but may be less stable than zabbysh because the IRB API is poorly documented and hard
69
+ to use.
70
+
71
+ ==== Interactive shell
72
+
73
+ # zabbysh
74
+ zabby> set host "https://monitoring.example.com"
75
+ zabby> set user "api_user"
76
+ zabby> set password "s3cr3t"
77
+ zabby> set proxy_host "http://10.10.10.10"
78
+ zabby> set proxy_user "john"
79
+ zabby> set proxy_password "D0e"
80
+ zabby> login
81
+ zabby> logged_in?
82
+ zabby> host.get "filter" => { "host" => "monitor.example.com" }, "output" => "extend"
83
+ zabby> item.get "host" => "monitor.example.com", "output" => "refer"
84
+ zabby> [...]
85
+ zabby> logout
86
+ zabby> exit
87
+
88
+ ==== Execute a command script
89
+
90
+ Create a file and put the same instructions as above in it, then execute *zabbysh*:
91
+
92
+ # zabbysh --file my_zabbix_commands.txt
93
+
94
+ == Requirements
95
+
96
+ - Ruby 1.8.5. It basically runs anywhere!
97
+ - JSON library: 'json' or 'json_pure'
98
+ - OptionParser
99
+ - Readline (optionnal, used by the interactive shell)
100
+
101
+ == References
102
+
103
+ - Main web site: http://zabby.org
104
+ - GitHub projet: https://github.com/Pragmatic-Source/zabby
105
+
106
+ == Contributing
107
+
108
+ All contributions are welcome. You can either open a ticket on Github, send a pull request
109
+ with a patch or send an email to the author.
110
+
111
+ == Author
112
+
113
+ Farzad FARID mailto:ffarid@pragmatic-source.com
114
+
115
+ === Thanks to
116
+
117
+ - Jean-Hadrien Chabran (jhchabran): Advices on code design.
118
+ - Nicolas Blanco (slainer68): Advices on code design and Triple Facepalming after reading other Ruby/Zabbix code.
119
+ - Renaud Chaput (renchap): For suggesting the "zabby" name.
120
+
121
+ === Sources of inspiration
122
+
123
+ - Adam Wiggins's Rush[https://github.com/adamwiggins/rush] for the interactive shell.
124
+ - Other Zabbix Ruby libraries (only the good parts ;) ):
125
+
126
+ zabcon[http://trac.red-tux.net/]::
127
+ Zabcon is a command line interface for Zabbix written in Ruby
128
+
129
+ rzabbix[http://github.com/neerfri/rzabbix]::
130
+ Zabbix API client for Ruby
131
+
132
+ rubix[https://github.com/dhruvbansal/rubix]::
133
+ Rubix is a Ruby client for Zabbix
134
+
135
+ == License
136
+
137
+ This software is release under the <b>Simplified BSD license</b>. See the LICENSE file.
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require 'bundler'
2
+ require 'yard'
3
+ Bundler::GemHelper.install_tasks
4
+
5
+ YARD::Rake::YardocTask.new do |t|
6
+ t.files = ['lib/**/*.rb', '-', 'LICENSE']
7
+ #t.options = ['--any', '--extra', '--opts'] # optional
8
+ end
data/bin/zabbyrb ADDED
@@ -0,0 +1,86 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- encoding: utf-8 -*-
3
+ # Author:: Farzad FARID (<ffarid@pragmatic-source.com>)
4
+ # Copyright:: Copyright (c) 2011 Farzad FARID
5
+ # License:: Simplified BSD License
6
+
7
+ # This is an experimental Zabby Shell based on IRB. It is still buggy and the code
8
+ # is very nasty because IRB is poorly documented and hard to use as a library. Use
9
+ # with care.
10
+ #
11
+ # Ugly IRB initialisation inspired by Shef (Chef's CLI) and a article on
12
+ # StackOverflow : http://stackoverflow.com/questions/4189818/how-to-run-irb-start-in-context-of-current-class
13
+
14
+ ZABBY_ROOT = File.expand_path('../../lib', __FILE__)
15
+ $: << ZABBY_ROOT unless $:.include?(ZABBY_ROOT)
16
+
17
+ require 'zabby'
18
+ require 'optparse'
19
+ require 'ostruct'
20
+ require 'irb'
21
+ require 'irb/completion'
22
+
23
+
24
+ module ZabbyRB
25
+ def self.irb_conf
26
+ @irb_conf || IRB.conf
27
+ end
28
+
29
+ def self.configure_irb
30
+ irb_conf[:MAIN_CONTEXT] = IRB::Irb.new.context
31
+ irb_conf[:HISTORY_FILE] = "~/.zabby_history"
32
+ irb_conf[:SAVE_HISTORY] = 1000
33
+
34
+ irb_conf[:IRB_RC] = lambda do |conf|
35
+ m = conf.main
36
+ leader = "(#{m.class.to_s})"
37
+
38
+ def m.help
39
+ puts "Help??"
40
+ end
41
+
42
+ # Hack without which "exit" brings us back to the main IRB context instead
43
+ # of exiting.
44
+ def m.exit
45
+ Kernel.exit
46
+ end
47
+
48
+ conf.prompt_c = "Zabby#{leader} > "
49
+ conf.return_format = " => %s \n"
50
+ conf.prompt_i = "Zabby#{leader} > "
51
+ conf.prompt_n = "Zabby#{leader} ?> "
52
+ conf.prompt_s = "Zabby#{leader}%l> "
53
+ end
54
+ end
55
+
56
+ def self.init
57
+ configure_irb
58
+
59
+ puts <<EOT
60
+ Zabby Shell #{Zabby::VERSION}, irb based shell.
61
+
62
+ run `help' for help, `exit' or ^D to quit.
63
+
64
+ ** THIS IS AN EXPERIMENTAL SHELL, IT MAY BE UNSTABLE. USE WITH CARE. **
65
+ Please use 'zabbysh' instead and report a bug if 'zabbyrb' does not
66
+ work correctly.
67
+ EOT
68
+ end
69
+ end
70
+
71
+ module IRB
72
+ class << self
73
+ alias :run_original_config :run_config
74
+
75
+ def run_config
76
+ run_original_config
77
+ ZabbyRB.init
78
+ end
79
+ end
80
+ end
81
+
82
+ IRB.setup nil
83
+ #IRB.conf[:MAIN_CONTEXT] = IRB::Irb.new.context
84
+ require 'irb/ext/multi-irb'
85
+ IRB.irb nil, Zabby.init
86
+ IRB.start
data/bin/zabbysh ADDED
@@ -0,0 +1,68 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- encoding: utf-8 -*-
3
+ # Author:: Farzad FARID (<ffarid@pragmatic-source.com>)
4
+ # Copyright:: Copyright (c) 2011 Farzad FARID
5
+ # License:: Simplified BSD License
6
+
7
+
8
+ ZABBY_ROOT = File.expand_path('../../lib', __FILE__)
9
+ $: << ZABBY_ROOT unless $:.include?(ZABBY_ROOT)
10
+
11
+ require 'zabby'
12
+ require "optparse"
13
+ require 'ostruct'
14
+
15
+ options = OpenStruct.new
16
+ options.file = nil
17
+
18
+ opts = OptionParser.new do |opts|
19
+ opts.banner = "Usage: zabbysh [options]"
20
+
21
+ opts.separator ""
22
+ opts.separator "Specific options:"
23
+
24
+ opts.on("-f", "--file COMMAND_FILE",
25
+ "Execute the instructions in COMMAND_FILE") do |file|
26
+ options.file = file
27
+ end
28
+
29
+ opts.separator ""
30
+ opts.separator "Common options:"
31
+
32
+
33
+ opts.on_tail("-h", "--help", "Show this message") do
34
+ puts opts
35
+ exit
36
+ end
37
+
38
+ opts.on_tail("--version", "Show version") do
39
+ puts <<EOT
40
+ Zabby #{Zabby::VERSION}
41
+ Copyright (c) 2011 Farzad FARID / Pragmatic Source
42
+ License: Simplified BSD
43
+ EOT
44
+ exit
45
+ end
46
+ end
47
+
48
+ opts.parse!(ARGV)
49
+
50
+ z = Zabby.init
51
+
52
+ if options.file
53
+ begin
54
+ z.run(options.file)
55
+ rescue SystemExit
56
+ exit 0
57
+ rescue Exception => e
58
+ puts "Exception #{e.class} -> #{e.message}"
59
+ e.backtrace.each do |t|
60
+ puts " #{::File.expand_path(t)}"
61
+ end
62
+ exit 1
63
+ end
64
+ end
65
+
66
+ # We end up here even if a command file is provided if it doesn't end with "exit"
67
+ z.shell
68
+ exit 0
data/doc/Zabby.html ADDED
@@ -0,0 +1,208 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
+ <head>
5
+ <meta http-equiv="Content-Type" content="text/html; charset=fr_fr" />
6
+ <title>
7
+ Module: Zabby
8
+
9
+ &mdash; Documentation by YARD 0.7.4
10
+
11
+ </title>
12
+
13
+ <link rel="stylesheet" href="css/style.css" type="text/css" media="screen" charset="utf-8" />
14
+
15
+ <link rel="stylesheet" href="css/common.css" type="text/css" media="screen" charset="utf-8" />
16
+
17
+ <script type="text/javascript" charset="utf-8">
18
+ relpath = '';
19
+ if (relpath != '') relpath += '/';
20
+ </script>
21
+
22
+ <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
23
+
24
+ <script type="text/javascript" charset="utf-8" src="js/app.js"></script>
25
+
26
+
27
+ </head>
28
+ <body>
29
+ <script type="text/javascript" charset="utf-8">
30
+ if (window.top.frames.main) document.body.className = 'frames';
31
+ </script>
32
+
33
+ <div id="header">
34
+ <div id="menu">
35
+
36
+ <a href="_index.html">Index (Z)</a> &raquo;
37
+
38
+
39
+ <span class="title">Zabby</span>
40
+
41
+
42
+ <div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
43
+ </div>
44
+
45
+ <div id="search">
46
+
47
+ <a id="class_list_link" href="#">Class List</a>
48
+
49
+ <a id="method_list_link" href="#">Method List</a>
50
+
51
+ <a id="file_list_link" href="#">File List</a>
52
+
53
+ </div>
54
+ <div class="clear"></div>
55
+ </div>
56
+
57
+ <iframe id="search_frame"></iframe>
58
+
59
+ <div id="content"><h1>Module: Zabby
60
+
61
+
62
+
63
+ </h1>
64
+
65
+ <dl class="box">
66
+
67
+
68
+
69
+
70
+
71
+
72
+
73
+
74
+ <dt class="r1 last">Defined in:</dt>
75
+ <dd class="r1 last">lib/zabby/config.rb<span class="defines">,<br />
76
+ lib/zabby.rb,<br /> lib/zabby/runner.rb,<br /> lib/zabby/version.rb,<br /> lib/zabby/connection.rb,<br /> lib/zabby/exceptions.rb</span>
77
+ </dd>
78
+
79
+ </dl>
80
+ <div class="clear"></div>
81
+
82
+ <h2>Overview</h2><div class="docstring">
83
+ <div class="discussion">
84
+ <table>
85
+ <tr><td valign="top">Author:</td><td>Farzad FARID (&lt;ffarid@pragmatic-source.com&gt;)
86
+
87
+ </td></tr>
88
+ <tr><td valign="top">Copyright:</td><td>Copyright &#169; 2011 Farzad FARID
89
+
90
+ </td></tr>
91
+ <tr><td valign="top">License:</td><td>Simplified BSD License
92
+
93
+ </td></tr>
94
+ </table>
95
+
96
+
97
+ </div>
98
+ </div>
99
+ <div class="tags">
100
+
101
+
102
+ </div><h2>Defined Under Namespace</h2>
103
+ <p class="children">
104
+
105
+
106
+
107
+
108
+ <strong class="classes">Classes:</strong> <span class='object_link'><a href="Zabby/AuthenticationError.html" title="Zabby::AuthenticationError (class)">AuthenticationError</a></span>, <span class='object_link'><a href="Zabby/Config.html" title="Zabby::Config (class)">Config</a></span>, <span class='object_link'><a href="Zabby/ConfigurationError.html" title="Zabby::ConfigurationError (class)">ConfigurationError</a></span>, <span class='object_link'><a href="Zabby/Connection.html" title="Zabby::Connection (class)">Connection</a></span>, <span class='object_link'><a href="Zabby/ResponseCodeError.html" title="Zabby::ResponseCodeError (class)">ResponseCodeError</a></span>, <span class='object_link'><a href="Zabby/Runner.html" title="Zabby::Runner (class)">Runner</a></span>
109
+
110
+
111
+ </p>
112
+
113
+ <h2>Constant Summary</h2>
114
+
115
+ <dl class="constants">
116
+
117
+ <dt id="VERSION-constant" class="">VERSION =
118
+
119
+ </dt>
120
+ <dd><pre class="code"><span class='string val'>&quot;0.0.1&quot;</span>
121
+ </pre></dd>
122
+
123
+ </dl>
124
+
125
+
126
+
127
+
128
+
129
+
130
+
131
+ <h2>
132
+ Class Method Summary
133
+ <small>(<a href="#" class="summary_toggle">collapse</a>)</small>
134
+ </h2>
135
+
136
+ <ul class="summary">
137
+
138
+ <li class="public ">
139
+ <span class="summary_signature">
140
+
141
+ <a href="#init-class_method" title="init (class method)">+ (Object) <strong>init</strong>(&amp;block) </a>
142
+
143
+
144
+
145
+ </span>
146
+
147
+
148
+
149
+
150
+
151
+
152
+
153
+
154
+ <span class="summary_desc"><div class='inline'></div></span>
155
+
156
+ </li>
157
+
158
+
159
+ </ul>
160
+
161
+
162
+
163
+
164
+ <div id="class_method_details" class="method_details_list">
165
+ <h2>Class Method Details</h2>
166
+
167
+
168
+ <div class="method_details first">
169
+ <p class="signature first" id="init-class_method">
170
+
171
+ + (<tt>Object</tt>) <strong>init</strong>(&amp;block)
172
+
173
+
174
+
175
+ </p><table class="source_code">
176
+ <tr>
177
+ <td>
178
+ <pre class="lines">
179
+
180
+
181
+ 20
182
+ 21
183
+ 22</pre>
184
+ </td>
185
+ <td>
186
+ <pre class="code"><span class="info file"># File 'lib/zabby.rb', line 20</span>
187
+
188
+ <span class='rubyid_def def kw'>def</span> <span class='rubyid_self self kw'>self</span><span class='dot token'>.</span><span class='rubyid_init identifier id'>init</span> <span class='bitand op'>&amp;</span><span class='rubyid_block identifier id'>block</span>
189
+ <span class='rubyid_Zabby constant id'>Zabby</span><span class='colon2 op'>::</span><span class='rubyid_Runner constant id'>Runner</span><span class='dot token'>.</span><span class='rubyid_new identifier id'>new</span> <span class='bitand op'>&amp;</span><span class='rubyid_block identifier id'>block</span>
190
+ <span class='rubyid_end end kw'>end</span>
191
+ </pre>
192
+ </td>
193
+ </tr>
194
+ </table>
195
+ </div>
196
+
197
+ </div>
198
+
199
+ </div>
200
+
201
+ <div id="footer">
202
+ Generated on Mon Dec 19 13:31:47 2011 by
203
+ <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
204
+ 0.7.4 (ruby-1.8.7).
205
+ </div>
206
+
207
+ </body>
208
+ </html>