Class: SnmpDumper::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/runner.rb

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Runner

Returns a new instance of Runner.



9
10
11
12
13
14
15
16
17
# File 'lib/runner.rb', line 9

def initialize(argv)
  begin
    @config = Config.new(argv)
    rescue Exception => e
      STDERR.puts e.message
      STDERR.puts e.backtrace.join("\n") if $DEBUG
      exit(-1)
    end
end

Instance Method Details

#runObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/runner.rb', line 19

def run
  begin
    ## interactive shell?
    if !$stdin.tty? || @config.options.in_filename then
      walker = SnmpwalkReader.new(@config.options)
    else
      walker = Walker.new(@config.options)
    end

    dumper = SnmpDumper.const_get(@config.options.dumper)::new(@config.options)

    walker.walk(dumper)

    if @config.options.out_filename
      File.open(@config.options.out_filename, 'w') { |f| f.write(dumper.dump) }  
    else
      puts dumper.dump
    end

  rescue Exception => e
    STDERR.puts e.message
    STDERR.puts e.backtrace.join("\n") if $DEBUG
    exit(-1)
  end
  exit(0)
end