Class: Zabby::Runner
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
Class Method Summary collapse
-
.create_zobject(name, zmethods) ⇒ Object
Create a method mapping a Zabbix object.
Instance Method Summary collapse
-
#initialize(&block) ⇒ Runner
constructor
A new instance of Runner.
- #logged_in? ⇒ Boolean (also: #loggedin?)
- #login ⇒ Object
- #logout ⇒ Object
- #run(command_file = nil, &block) ⇒ Object
- #set(key_value = nil) ⇒ Object
- #setup(&block) ⇒ Object
-
#shell ⇒ Object
Execute an irb like shell in which we can type Zabby commands.
- #version ⇒ Object
Constructor Details
#initialize(&block) ⇒ Runner
Returns a new instance of Runner.
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/zabby/runner.rb', line 75 def initialize &block @config = Zabby::Config.new &block @connection = Zabby::Connection.new @pure_binding = instance_eval "binding" @zobject = {} # List of Zabbix Object if Object.const_defined?(:Readline) @readline = true Readline.basic_word_break_characters = "" Readline.completion_append_character = nil #Readline.completion_proc = completion_proc $last_res = nil else @readline = false end end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
18 19 20 |
# File 'lib/zabby/runner.rb', line 18 def config @config end |
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
18 19 20 |
# File 'lib/zabby/runner.rb', line 18 def connection @connection end |
Class Method Details
Instance Method Details
#logged_in? ⇒ Boolean Also known as: loggedin?
117 118 119 |
# File 'lib/zabby/runner.rb', line 117 def logged_in? @connection.logged_in? end |
#login ⇒ Object
109 110 111 |
# File 'lib/zabby/runner.rb', line 109 def login @connection.login(@config) end |
#logout ⇒ Object
113 114 115 |
# File 'lib/zabby/runner.rb', line 113 def logout @connection.logout end |
#run(command_file = nil, &block) ⇒ Object
128 129 130 131 132 133 134 |
# File 'lib/zabby/runner.rb', line 128 def run(command_file = nil, &block) unless command_file.nil? commands = File.read(command_file) instance_eval(commands, command_file, 1) end instance_eval(&block) if block_given? end |
#set(key_value = nil) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/zabby/runner.rb', line 97 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 |
#setup(&block) ⇒ Object
93 94 95 |
# File 'lib/zabby/runner.rb', line 93 def setup &block @config.setup &block end |
#shell ⇒ Object
Execute an irb like shell in which we can type Zabby commands.
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/zabby/runner.rb', line 137 def shell raise RuntimeError.new("Shell cannot run because 'readline' is missing.") if !@readline puts "Zabby Shell #{Zabby::VERSION}" puts puts "** This is a simple irb like Zabbix Shell. Multiline commands do not work for e.g. **" loop do cmd = Readline.readline('zabby> ') exit(0) if cmd.nil? or cmd == 'exit' next if cmd == "" Readline::HISTORY.push(cmd) execute(cmd) end end |