Module: Zabby::ShellHelpers
- Included in:
- Runner
- Defined in:
- lib/zabby/shell_helpers.rb
Overview
Useful helper methods for the Zabbix Shell. Methods added to this module are available in the scripting language and commande line. The following instance variable should be available to helper methods:
-
@config: Zabby::Config instance
-
@connection: Zabby::Connection instance
Class Method Summary collapse
-
.desc(text) ⇒ Object
Save the documentation for a method about to be defined.
-
.helpers_doc ⇒ Object
Show the Shell helpers documentation.
-
.method_added(method) ⇒ Object
Push helper documentation for the method just defined in a hash.
Instance Method Summary collapse
- #help ⇒ Object
- #logged_in? ⇒ Boolean (also: #loggedin?)
- #login ⇒ Object
- #logout ⇒ Object
- #set(key_value = nil) ⇒ Object
- #version ⇒ Object
- #zabbix_classes ⇒ Object
Class Method Details
.desc(text) ⇒ Object
Save the documentation for a method about to be defined.
21 22 23 |
# File 'lib/zabby/shell_helpers.rb', line 21 def self.desc(text) @last_doc = text end |
.helpers_doc ⇒ Object
Show the Shell helpers documentation
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/zabby/shell_helpers.rb', line 38 def self.helpers_doc help = <<EOT Available commands: ================== EOT @helpers_doc.each do |name, text| help += name + ":\n" help += '-' * name.size + "\n" help += text + "\n\n" end help end |
.method_added(method) ⇒ Object
TODO:
Display functions in alphabetical or arbitrary order.
Push helper documentation for the method just defined in a hash.
28 29 30 31 32 33 34 35 |
# File 'lib/zabby/shell_helpers.rb', line 28 def self.method_added(method) if @last_doc.nil? @helpers_doc[method.id2name] = "** UNDOCUMENTED FUNCTION **" else @helpers_doc[method.id2name] = @last_doc @last_doc = nil end end |
Instance Method Details
#help ⇒ Object
98 99 100 |
# File 'lib/zabby/shell_helpers.rb', line 98 def help puts Zabby::ShellHelpers.helpers_doc end |
#logged_in? ⇒ Boolean Also known as: loggedin?
80 81 82 |
# File 'lib/zabby/shell_helpers.rb', line 80 def logged_in? @connection.logged_in? end |
#login ⇒ Object
70 71 72 |
# File 'lib/zabby/shell_helpers.rb', line 70 def login @connection.login(@config) end |
#logout ⇒ Object
75 76 77 |
# File 'lib/zabby/shell_helpers.rb', line 75 def logout @connection.logout end |
#set(key_value = nil) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/zabby/shell_helpers.rb', line 56 def set(key_value = nil) if key_value.nil? @config.list elsif [ String, Symbol ].include?(key_value.class) puts "#{key_value} = #{@config.send(key_value)}" elsif key_value.instance_of? Hash key = key_value.keys.first value = key_value[key] @config.send(key, value) end end |
#version ⇒ Object
88 89 90 |
# File 'lib/zabby/shell_helpers.rb', line 88 def version Zabby::VERSION end |
#zabbix_classes ⇒ Object
93 94 95 |
# File 'lib/zabby/shell_helpers.rb', line 93 def zabbix_classes Zabby::ZClass.zabbix_classes end |