summaryrefslogtreecommitdiff
path: root/lib/oxidized/config.rb
blob: 36d9d73aa6bf25ad29eb99465cd6ba4e7d851757 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
module Oxidized
  require 'asetus'
  class NoConfig < OxidizedError; end
  class InvalidConfig < OxidizedError; end
  class Config
    Root      = ENV['OXIDIZED_HOME'] || File.join(ENV['HOME'], '.config', 'oxidized')
    Crash     = File.join Root, 'crash'
    Log       = File.join Root, 'logs'
    InputDir  = File.join Directory, %w(lib oxidized input)
    OutputDir = File.join Directory, %w(lib oxidized output)
    ModelDir  = File.join Directory, %w(lib oxidized model)
    SourceDir = File.join Directory, %w(lib oxidized source)
    HookDir   = File.join Directory, %w(lib oxidized hook)
    Sleep     = 1

    def self.load(cmd_opts = {})
      asetus = Asetus.new(name: 'oxidized', load: false, key_to_s: true)
      Oxidized.asetus = asetus

      asetus.default.username      = 'username'
      asetus.default.password      = 'password'
      asetus.default.model         = 'junos'
      asetus.default.resolve_dns   = true # if false, don't resolve DNS to IP
      asetus.default.interval      = 3600
      asetus.default.use_syslog    = false
      asetus.default.debug         = false
      asetus.default.threads       = 30
      asetus.default.timeout       = 20
      asetus.default.retries       = 3
      asetus.default.prompt        = /^([\w.@-]+[#>]\s?)$/
      asetus.default.rest          = '127.0.0.1:8888' # or false to disable
      asetus.default.next_adds_job = false            # if true, /next adds job, so device is fetched immmeiately
      asetus.default.vars          = {}               # could be 'enable'=>'enablePW'
      asetus.default.groups        = {}               # group level configuration
      asetus.default.models        = {}               # model level configuration
      asetus.default.pid           = File.join(Oxidized::Config::Root, 'pid')

      asetus.default.input.default      = 'ssh, telnet'
      asetus.default.input.debug        = false # or String for session log file
      asetus.default.input.ssh.secure   = false # complain about changed certs
      asetus.default.input.ftp.passive  = true  # ftp passive mode
      asetus.default.input.utf8_encoded = true  # configuration is utf8 encoded or ascii-8bit

      asetus.default.output.default = 'file'  # file, git
      asetus.default.source.default = 'csv'   # csv, sql

      asetus.default.model_map = {
        'cisco'   => 'ios',
        'juniper' => 'junos',
      }

      begin
        asetus.load # load system+user configs, merge to Config.cfg
      rescue => error
        raise InvalidConfig, "Error loading config: #{error.message}"
      end

      raise NoConfig, 'edit ~/.config/oxidized/config' if asetus.create

      # override if comand line flag given
      asetus.cfg.debug = cmd_opts[:debug] if cmd_opts[:debug]

      asetus
    end
  end

  class << self
    attr_accessor :mgr, :Hooks
  end
end