Class: Fluent::Auditify::Plugin::Conf
- Inherits:
-
Base
- Object
- Base
- Fluent::Auditify::Plugin::Conf
show all
- Defined in:
- lib/fluent/auditify/plugin/conf.rb
Direct Known Subclasses
ConfBufferFile, ConfBufferFileSingle, ConfBufferMemory, ConfFilterGrep, ConfFilterParser, ConfFilterRecordTransformer, ConfFilterStdout, ConfInExec, ConfInForward, ConfInHttp, ConfInMonitorAgent, ConfInSample, ConfInSyslog, ConfInTail, ConfInTcp, ConfInUdp, ConfInUnix, ConfOutBuffer, ConfOutCopy, ConfOutExec, ConfOutExecFilter, ConfOutFile, ConfOutForward, ConfOutHttp, ConfOutNull, ConfOutRelabel, ConfOutRewriteTagFilter, ConfOutRoundrobin, ConfOutSecondaryFile, ConfOutStdout, ConfPluginParams, ConfPluginType, MaskSecrets, V1DuplicatedId
Instance Attribute Summary
Attributes inherited from Base
#log
Instance Method Summary
collapse
Constructor Details
#initialize ⇒ Conf
9
10
11
|
# File 'lib/fluent/auditify/plugin/conf.rb', line 9
def initialize
super
end
|
Instance Method Details
#artifact ⇒ Object
92
93
94
|
# File 'lib/fluent/auditify/plugin/conf.rb', line 92
def artifact
Plugin.artifact
end
|
#conf?(path) ⇒ Boolean
33
34
35
|
# File 'lib/fluent/auditify/plugin/conf.rb', line 33
def conf?(path)
path.end_with?('.conf')
end
|
#disabled? ⇒ Boolean
21
22
23
|
# File 'lib/fluent/auditify/plugin/conf.rb', line 21
def disabled?
@disabled
end
|
#file_get_contents(path, lines: false, include: false) ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/fluent/auditify/plugin/conf.rb', line 52
def file_get_contents(path, lines: false, include: false)
contents = []
if lines
if include
contents = read_with_include_directive(path)
else
File.open(path) do |f|
f.readlines.each_with_index do |line, index|
contents << {line: index, content: line, path: path}
end
end
end
else
if include
contents = read_with_include_directive(path).collect do |entry|
entry[:content]
end.join
else
contents = File.open(path) do |f| f.read end
end
end
contents
end
|
#file_readlines_each(conf) ⇒ Object
76
77
78
79
80
81
82
|
# File 'lib/fluent/auditify/plugin/conf.rb', line 76
def file_readlines_each(conf)
File.open(conf) do |f|
f.readlines.each_with_index do |line, index|
yield line, index
end
end
end
|
#guilty(level, message, options = {}) ⇒ Object
84
85
86
|
# File 'lib/fluent/auditify/plugin/conf.rb', line 84
def guilty(level, message, options={})
Plugin.guilty(level, message, options)
end
|
#parse(config_path, options = {}) ⇒ Object
25
26
27
|
# File 'lib/fluent/auditify/plugin/conf.rb', line 25
def parse(config_path, options={})
raise NotImplementedError
end
|
#plugin_defs(type, plugin_name) ⇒ Object
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
# File 'lib/fluent/auditify/plugin/conf.rb', line 96
def plugin_defs(type, plugin_name)
spec = {}
begin
IO.popen(['fluent-plugin-config-format', '--compact', '--format', 'json', type, plugin_name]) do |io|
json = JSON.parse(io.read)
json.each do |klass, defs|
next if klass == 'plugin_helpers'
next if klass == "Fluent::Plugin::#{type[0].upcase}#{type[1..]}"
next if klass.split('::').count != 3
spec = defs
end
end
rescue => e
log.error("failed to get plugin specification: #{e.message}")
end
spec
end
|
#polish(object) ⇒ Object
88
89
90
|
# File 'lib/fluent/auditify/plugin/conf.rb', line 88
def polish(object)
Plugin.polish(object)
end
|
#read_with_include_directive(path) ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/fluent/auditify/plugin/conf.rb', line 37
def read_with_include_directive(path)
contents = []
File.open(path) do |f|
f.readlines.each_with_index do |line, index|
if line.strip.start_with?('@include')
target = File.expand_path(line.split.last, File.dirname(path))
contents = (contents << file_get_contents(target, lines: true, include: true)).flattern
else
contents << {line: index, content: line, path: path}
end
end
end
contents
end
|
#supported_file_extension? ⇒ Boolean
17
18
19
|
# File 'lib/fluent/auditify/plugin/conf.rb', line 17
def supported_file_extension?
[:conf]
end
|
13
14
15
|
# File 'lib/fluent/auditify/plugin/conf.rb', line 13
def supported_platform?
raise NotImplementedError
end
|
#surround_text(path, line_num, range: 2, replace: nil) ⇒ Object
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
# File 'lib/fluent/auditify/plugin/conf.rb', line 114
def surround_text(path, line_num, range: 2, replace: nil)
lines = file_get_contents(path)
min = line_num - range > 0 ? line - 2 : 0
max = line_num + range < lines.size ? line_num + range : lines.size - 1
content = ""
min.upto(max).each_with_index do |line, index|
if replace
if min + index + 1 == line_num
content << "#{replace}\n"
else
content << "#{min + index + 1}: #{lines[min + index].chomp}\n"
end
else
content << "#{min + index + 1}: #{lines[min + index].chomp}\n"
end
end
content
end
|
#yaml?(path) ⇒ Boolean
29
30
31
|
# File 'lib/fluent/auditify/plugin/conf.rb', line 29
def yaml?(path)
path.end_with?('.yml', '.yaml')
end
|