Module: Zabby::ShellHelpers

Included in:
Runner
Defined in:
lib/rbZabbix/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

Instance Method Summary collapse

Class Method Details

.desc(text) ⇒ Object

Save the documentation for a method about to be defined.

Parameters:

  • text (String)

    Documentation of the method following the call to “desc”



21
22
23
# File 'lib/rbZabbix/shell_helpers.rb', line 21

def self.desc(text)
  @last_doc = text
end

.helpers_docObject

Show the Shell helpers documentation



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/rbZabbix/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.

Parameters:

  • method (Symbol)

    Helper method to document



28
29
30
31
32
33
34
35
# File 'lib/rbZabbix/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

#helpObject



98
99
100
# File 'lib/rbZabbix/shell_helpers.rb', line 98

def help
  puts Zabby::ShellHelpers.helpers_doc
end

#logged_in?Boolean Also known as: loggedin?

Returns:

  • (Boolean)


80
81
82
# File 'lib/rbZabbix/shell_helpers.rb', line 80

def logged_in?
  @connection.logged_in?
end

#loginObject



70
71
72
# File 'lib/rbZabbix/shell_helpers.rb', line 70

def 
  @connection.(@config)
end

#logoutObject



75
76
77
# File 'lib/rbZabbix/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/rbZabbix/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

#versionObject



88
89
90
# File 'lib/rbZabbix/shell_helpers.rb', line 88

def version
  Zabby::VERSION
end

#zabbix_classesObject



93
94
95
# File 'lib/rbZabbix/shell_helpers.rb', line 93

def zabbix_classes
  Zabby::ZClass.zabbix_classes
end