zabby 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -3,4 +3,5 @@
3
3
  Gemfile.lock
4
4
  pkg/*
5
5
  .idea
6
- .yardoc
6
+ .yardoc
7
+ /doc
@@ -0,0 +1 @@
1
+ lib/**/*.rb - LICENSE TODO.rdoc ChangeLog.rdoc
@@ -1,5 +1,16 @@
1
1
  = ChangeLog for Zabby
2
2
 
3
+ List of visible changes:
4
+
5
+ == v0.0.5 (2012/01/05)
6
+
7
+ * Better command file parsing and add rcfile support.
8
+ * Better handling of the default JSON RPC script name in the URL.
9
+ * Add a 'loggedin?' alias for 'logged_in?'.
10
+ * Ignore 'doc' directory.
11
+ * List of docs to generate with Yard is now specified in .yardopts.
12
+ * Improve Gemspec file.
13
+
3
14
  == v0.0.4 (2011/12/21)
4
15
 
5
16
  * Same as v0.0.3 that I could not publish on rubygems.org
@@ -25,6 +25,41 @@ Zabby has the following caracteristics:
25
25
  - Full featured IRB like shell included with Readline support. You can mix Zabbix instructions
26
26
  with Ruby calls transparently.
27
27
 
28
+ == Configuration
29
+
30
+ The file <tt>~/.zabbyrc</tt> is read on startup unless the option "<tt>--no-rcfile</tt>" is
31
+ used.
32
+
33
+ === Command line
34
+
35
+ --[no-]rcfile [CONFIG FILE]: Configuration file to load on startup. Default is '~/.zabbyrc'. With the 'no' prefix no configuration file will be loaded.
36
+ -f, --extra-file COMMAND_FILE: Execute the instructions in COMMAND_FILE
37
+
38
+ === Zabby configuration
39
+
40
+ The following settings can be configured with the '+set+' command:
41
+ [server] Zabbix webservice URL. If the URL does not end with <tt>.php</tt> then
42
+ <tt>/api_jsonrpc.php</tt> is appended automatically.
43
+ [user] User login with +API+ rights on the Zabbix Server. If the account does not have
44
+ +API+ access the connection will be refused by Zabbix.
45
+ [password] User password.
46
+ [proxy_host] HTTP proxy.SSL is supported and the certificate validity is not checked. *Optional*
47
+ [proxy_user] User authentication on the proxy. *Optional*
48
+ [proxy_password] User password on the proxy. *Optional*
49
+
50
+ === Sample ".zabbyrc"
51
+
52
+ This is a configuration <tt>.zabbyrc</tt> file example, it will be loaded at startup:
53
+
54
+ # Zabby configuration
55
+ set :server => "https://monitoring.example.com"
56
+ set :user => "api_user"
57
+ set :password => "s3cr3t"
58
+ set :proxy_host => "http://10.10.10.10"
59
+ set :proxy_user => "john"
60
+ set :proxy_password => "D0e"
61
+ login
62
+
28
63
  == Examples
29
64
 
30
65
  === API use
data/Rakefile CHANGED
@@ -3,7 +3,8 @@ require 'yard'
3
3
  Bundler::GemHelper.install_tasks
4
4
 
5
5
  YARD::Rake::YardocTask.new do |t|
6
- t.files = ['lib/**/*.rb', '-', 'LICENSE', 'TODO.rdoc', 'ChangeLog.rdoc']
6
+ # File list is defined in '.yardopts'
7
+ #t.files = ['lib/**/*.rb', '-', 'LICENSE', 'TODO.rdoc', 'ChangeLog.rdoc']
7
8
  #t.options = ['--any', '--extra', '--opts'] # optional
8
9
  end
9
10
 
@@ -9,21 +9,32 @@ ZABBY_ROOT = File.expand_path('../../lib', __FILE__)
9
9
  $: << ZABBY_ROOT unless $:.include?(ZABBY_ROOT)
10
10
 
11
11
  require 'zabby'
12
- require "optparse"
12
+ require 'optparse'
13
13
  require 'ostruct'
14
14
 
15
15
  options = OpenStruct.new
16
- options.file = nil
16
+ options.rcfile = File.expand_path('~/.zabbyrc')
17
+ options.extra_file = nil
17
18
 
18
19
  opts = OptionParser.new do |opts|
19
- opts.banner = "Usage: zabbysh [options]"
20
+ opts.banner = <<EOT
21
+ Usage: zabbysh [options] [script]
20
22
 
23
+ If no 'script' file is provided an interactive shell is started. Otherwise the script file
24
+ is executed. To load and execute a supplementary script file before the shell use the
25
+ '--extra-file' option.
26
+ EOT
21
27
  opts.separator ""
22
28
  opts.separator "Specific options:"
23
29
 
24
- opts.on("-f", "--file COMMAND_FILE",
30
+ opts.on("--[no-]rcfile [CONFIG FILE]",
31
+ "Configuration file to load on startup. Default is '~/.zabbyrc'." +
32
+ " With the 'no' prefix no configuration file will be loaded.") do |file|
33
+ options.rcfile = file || nil
34
+ end
35
+ opts.on("-f", "--extra-file COMMAND_FILE",
25
36
  "Execute the instructions in COMMAND_FILE") do |file|
26
- options.file = file
37
+ options.extra_file = file
27
38
  end
28
39
 
29
40
  opts.separator ""
@@ -45,24 +56,43 @@ EOT
45
56
  end
46
57
  end
47
58
 
48
- opts.parse!(ARGV)
49
-
59
+ # Parse options, extract script to execute and initialize Zabby.
60
+ begin
61
+ opts.parse!(ARGV)
62
+ rescue OptionParser::ParseError => e
63
+ STDERR.puts("ERROR: #{e.message}.")
64
+ STDERR.puts opts
65
+ exit 1
66
+ end
67
+ script = ARGV.first
50
68
  z = Zabby.init
51
69
 
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)}"
70
+ # Read & execute startup file and/or command file. The true/false indicates if
71
+ # we should fail in case the file does not exist.
72
+ [ [ options.rcfile, false ], [ options.extra_file, true ], [ script, true ] ].each do |file, fail_on_missing|
73
+ if file.nil?
74
+ # Do nothing
75
+ elsif File.exist?(file)
76
+ begin
77
+ z.run(file)
78
+ rescue SystemExit
79
+ exit 0
80
+ rescue Exception => e
81
+ puts "Exception #{e.class} -> #{e.message}"
82
+ e.backtrace.each do |t|
83
+ puts " #{::File.expand_path(t)}"
84
+ end
85
+ exit 1
61
86
  end
62
- exit 1
87
+ elsif fail_on_missing # File is missing but do not fail for '.zabbyrc'
88
+ raise RuntimeError, "Missing Zabby script '#{file}'."
63
89
  end
64
90
  end
65
91
 
66
- # We end up here even if a command file is provided if it doesn't end with "exit"
67
- z.shell
92
+
93
+ # We start the shell if a command file is not provided
94
+ if script.nil?
95
+ z.shell
96
+ end
97
+
68
98
  exit 0
@@ -5,6 +5,9 @@
5
5
 
6
6
  module Zabby
7
7
  class Connection
8
+ # Name of the Zabbix RPC script
9
+ JSONRPC_SCRIPT = "/api_jsonrpc.php"
10
+
8
11
  attr_reader :uri, :request_path, :user, :password, :proxy_host, :proxy_user, :proxy_password
9
12
  attr_reader :auth
10
13
  attr_reader :request_id
@@ -30,7 +33,7 @@ module Zabby
30
33
  @proxy_user = config.proxy_user
31
34
  @proxy_password = config.proxy_password
32
35
  end
33
- @request_path = @uri.path.empty? ? "/api_jsonrpc.php" : @uri.path
36
+ @request_path = @uri.path[-4,4] == '.php' ? @uri.path : @uri.path + JSONRPC_SCRIPT
34
37
  authenticate
35
38
  end
36
39
 
@@ -67,6 +70,7 @@ module Zabby
67
70
  }
68
71
  end
69
72
 
73
+ # Perform an authenticated request
70
74
  def perform_request(element, action, params)
71
75
  raise AuthenticationError.new("Not logged in") if !logged_in?
72
76
 
@@ -117,6 +117,7 @@ module Zabby
117
117
  def logged_in?
118
118
  @connection.logged_in?
119
119
  end
120
+ alias_method :loggedin?, :logged_in?
120
121
 
121
122
  def version
122
123
  Zabby::VERSION
@@ -127,7 +128,7 @@ module Zabby
127
128
  def run(command_file = nil, &block)
128
129
  unless command_file.nil?
129
130
  commands = File.read(command_file)
130
- instance_eval(commands)
131
+ instance_eval(commands, command_file, 1)
131
132
  end
132
133
  instance_eval(&block) if block_given?
133
134
  end
@@ -174,4 +175,4 @@ module Zabby
174
175
  end
175
176
  end
176
177
  end
177
- end
178
+ end
@@ -4,5 +4,5 @@
4
4
  # License:: Simplified BSD License
5
5
 
6
6
  module Zabby
7
- VERSION = "0.0.4"
7
+ VERSION = "0.0.5"
8
8
  end
@@ -13,10 +13,11 @@ Gem::Specification.new do |s|
13
13
  s.authors = ["Farzad FARID"]
14
14
  s.email = ["ffarid@pragmatic-source.com"]
15
15
  s.homepage = "http://zabby.org/"
16
- s.summary = %q{Ruby Zabbix API and command line interface}
16
+ s.summary = %q{Ruby Zabbix API, scripting language and command line interface}
17
17
  s.description = %q{Zabby is a Zabby API and CLI. It provides a provisioning tool for
18
18
  creating, updating and querying Zabbix objects (hosts, items, triggers, etc.) through the web
19
19
  service.}
20
+ s.license = "Simplified BSD"
20
21
 
21
22
  s.rubyforge_project = "zabby"
22
23
 
@@ -24,6 +25,7 @@ service.}
24
25
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
25
26
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
26
27
  s.require_paths = ["lib"]
28
+ s.extra_rdoc_files = [ "TODO.rdoc", "ChangeLog.rdoc" ]
27
29
  s.add_runtime_dependency "json"
28
30
  s.add_development_dependency "bundler", ">= 1.0.0"
29
31
  s.add_development_dependency "rspec", ">= 2.0.0"
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zabby
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 4
10
- version: 0.0.4
9
+ - 5
10
+ version: 0.0.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Farzad FARID
@@ -15,8 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-12-21 00:00:00 +01:00
19
- default_executable:
18
+ date: 2012-01-05 00:00:00 Z
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
21
  name: json
@@ -91,10 +90,12 @@ executables:
91
90
  - zabbysh
92
91
  extensions: []
93
92
 
94
- extra_rdoc_files: []
95
-
93
+ extra_rdoc_files:
94
+ - TODO.rdoc
95
+ - ChangeLog.rdoc
96
96
  files:
97
97
  - .gitignore
98
+ - .yardopts
98
99
  - ChangeLog.rdoc
99
100
  - Gemfile
100
101
  - LICENSE
@@ -103,31 +104,6 @@ files:
103
104
  - TODO.rdoc
104
105
  - bin/zabbyrb
105
106
  - bin/zabbysh
106
- - doc/Zabby.html
107
- - doc/Zabby/AuthenticationError.html
108
- - doc/Zabby/Config.html
109
- - doc/Zabby/ConfigurationError.html
110
- - doc/Zabby/Connection.html
111
- - doc/Zabby/ResponseCodeError.html
112
- - doc/Zabby/Runner.html
113
- - doc/Zabby/ZObject.html
114
- - doc/_index.html
115
- - doc/class_list.html
116
- - doc/css/common.css
117
- - doc/css/full_list.css
118
- - doc/css/style.css
119
- - doc/file.ChangeLog.html
120
- - doc/file.LICENSE.html
121
- - doc/file.README.html
122
- - doc/file.TODO.html
123
- - doc/file_list.html
124
- - doc/frames.html
125
- - doc/index.html
126
- - doc/js/app.js
127
- - doc/js/full_list.js
128
- - doc/js/jquery.js
129
- - doc/method_list.html
130
- - doc/top-level-namespace.html
131
107
  - lib/zabby.rb
132
108
  - lib/zabby/config.rb
133
109
  - lib/zabby/connection.rb
@@ -137,10 +113,9 @@ files:
137
113
  - lib/zabby/zobject.rb
138
114
  - spec/spec_helper.rb
139
115
  - zabby.gemspec
140
- has_rdoc: true
141
116
  homepage: http://zabby.org/
142
- licenses: []
143
-
117
+ licenses:
118
+ - Simplified BSD
144
119
  post_install_message:
145
120
  rdoc_options: []
146
121
 
@@ -167,9 +142,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
167
142
  requirements: []
168
143
 
169
144
  rubyforge_project: zabby
170
- rubygems_version: 1.4.2
145
+ rubygems_version: 1.8.10
171
146
  signing_key:
172
147
  specification_version: 3
173
- summary: Ruby Zabbix API and command line interface
148
+ summary: Ruby Zabbix API, scripting language and command line interface
174
149
  test_files:
175
150
  - spec/spec_helper.rb
151
+ has_rdoc:
@@ -1,208 +0,0 @@
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/zobject.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>, <span class='object_link'><a href="Zabby/ZObject.html" title="Zabby::ZObject (class)">ZObject</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.4&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
- 22
182
- 23
183
- 24</pre>
184
- </td>
185
- <td>
186
- <pre class="code"><span class="info file"># File 'lib/zabby.rb', line 22</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_instance identifier id'>instance</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 Wed Dec 21 12:25:12 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>