Class: Fluent::Auditify::Command::Auditify

Inherits:
Object
  • Object
show all
Defined in:
lib/fluent/auditify/command/auditify.rb

Instance Method Summary collapse

Constructor Details

#initializeAuditify

Returns a new instance of Auditify.



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
71
72
# File 'lib/fluent/auditify/command/auditify.rb', line 12

def initialize
  @parser = OptionParser.new
  @parser.banner = "Usage: fluent-auditify [options]"
  @parser.version = Fluent::Auditify::VERSION

  @options = {
    verbose: false,
    syntax_check: true,
    upgrade_config: :v1,
    config: "fluentd.conf",
    log_level: Logger::INFO,
    color: true,
    fluentd_version: :auto,
    config_version: :v1,
    mask_only: false
  }
  @parser.on('-u [CONFIG_VERSION]', '--upgrade-config [CONFIG_VERSION]',
            "Upgrade Fluentd configuration to CONFIG_VERSION (default: v1)", :v1) { |v|
    unless v
    # assume v1 by default
    else
      unless %w(v1).include?(v)
        puts "ERROR: The value of -u CONFIG_VERSION must be v1"
        exit 1
      end
      @options[:upgrade_config] = v.intern
    end
  }
  @parser.on('-s', '--syntax-check',
            "Enable syntax check", TrueClass) { |v|
    @options[:syntax_check] = v
  }

  @parser.on('-c CONFIG_FILE', '--config CONFIG_FILE',
             "Specify configuration file") { |v|
    @options[:config] = v
  }
  @parser.on('-v', '--[no-]verbose',
            "Run verbosely") { |v|
    @options[:verbose] = v
  }
  @parser.on('--fluentd-version VERSION', "Specify Fluentd version (default: auto)") { |v|
    @options[:fluentd_version] = v
  }
  @parser.on('--log-level LOG_LEVEL', "Specify log level (default: INFO)") { |v|
    @options[:log_level] = Fluent::Auditify::Log.to_logger_level(v)
  }
  @parser.on('--report-format FORMAT', "Simplify format in error. (default: auto)") { |v|
    @options[:reporter] = Fluent::Auditify::Reporter.to_report_format(v)
  }
  @parser.on('--config-version VERSION', "Simplify Fluentd configuration version. (default: auto)") { |v|
    unless %w(v0 v1).include?(v)
      puts Pastel.new.bright_red.on_black('ERROR') + ": The value of --config-version CONFIG_VERSION must be v0 or v1"
      exit 1
    end
    @options[:config_version] = v.intern
  }
  @parser.on('--mask-only', "Run in mask mode") { |v|
    @options[:mask_only] = v
  }
end

Instance Method Details

#run(argv) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/fluent/auditify/command/auditify.rb', line 74

def run(argv)
  begin
    @parser.parse!(argv)
  rescue OptionParser::ParseError, OptionParser::InvalidOption => e
    puts Pastel.new.bright_red.on_black('ERROR') + ": fluent-auditify: #{e.message}"
    return false
  end

  if @options[:syntax_check]
    opts = {
      color: @options[:color],
      log_level: @options[:log_level]
    }
    runner = Fluent::Auditify::SyntaxChecker.new(@options)
    return runner.run(@options)
  elsif @options[:upgrade_config]
  end
  true
end