Skip to content
This repository was archived by the owner on Sep 12, 2024. It is now read-only.

Commit 1d7c660

Browse files
shpimpalsimathih
authored andcommitted
OMS Agent custom log wildcard issue fix (#517)
1 parent 3b2dfed commit 1d7c660

File tree

3 files changed

+35
-28
lines changed

3 files changed

+35
-28
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ nxOMSCustomLog:
425425

426426
nxOMSSudoCustomLog:
427427
rm -rf output/staging; \
428-
VERSION="2.1"; \
428+
VERSION="2.2"; \
429429
PROVIDERS="nxOMSSudoCustomLog"; \
430430
STAGINGDIR="output/staging/$@/DSCResources"; \
431431
cat Providers/Modules/$@.psd1 | sed "s@<MODULE_VERSION>@$${VERSION}@" > intermediate/Modules/$@.psd1; \

Providers/Modules/CustomLog/Plugin/in_sudo_tail.rb

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ class SudoTail < Input
1313
def initialize
1414
super
1515
@command = nil
16-
@paths = []
1716
end
1817

1918
attr_accessor :command
@@ -99,30 +98,8 @@ def receive_log(line)
9998
$log.info "#{line}" if line.start_with?('INFO')
10099
end
101100

102-
def readable_path(path)
103-
if system("sudo test -r #{path}")
104-
OMS::Log.info_once("Following tail of #{path}")
105-
return path
106-
else
107-
OMS::Log.warn_once("#{path} is not readable. Cannot tail the file.")
108-
end
109-
end
110-
111101
def set_system_command
112-
@paths = @path.split(',').map {|path| path.strip }
113-
date = Time.now
114-
paths = ""
115-
@paths.each { |path|
116-
path = date.strftime(path)
117-
if path.include?('*')
118-
Dir.glob(path).select { |p|
119-
paths += readable_path(p) + " "
120-
}
121-
else
122-
paths += readable_path(path) + " "
123-
end
124-
}
125-
@command = "sudo " << RUBY_DIR << TAILSCRIPT << paths << " -p #{@pos_file}"
102+
@command = "sudo " << RUBY_DIR << TAILSCRIPT << @path << " -p #{@pos_file}"
126103
end
127104

128105
def run_periodic
@@ -139,7 +116,6 @@ def run_periodic
139116
end
140117
until @finished
141118
begin
142-
sleep @run_interval
143119
Open3.popen3(@command) {|writeio, readio, errio, wait_thread|
144120
writeio.close
145121
while line = readio.gets
@@ -152,6 +128,7 @@ def run_periodic
152128

153129
wait_thread.value #wait until child process terminates
154130
}
131+
sleep @run_interval
155132
rescue
156133
$log.error "sudo_tail failed to run or shutdown child proces", error => $!.to_s, :error_class => $!.class.to_s
157134
$log.warn_backtrace $!.backtrace

Providers/Modules/CustomLog/Plugin/tailfilereader.rb

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,38 @@ def initialize(paths)
2020

2121
attr_reader :paths
2222

23+
def file_exists(path)
24+
if system("sudo test -f #{path}")
25+
@log.info "Following tail of #{path}"
26+
return path
27+
else
28+
@log.warn "#{path} does not exist. Cannot tail the file."
29+
return nil
30+
end
31+
end
32+
33+
def expand_paths()
34+
arr_paths = @paths.split(',').map {|path| path.strip }
35+
date = Time.now
36+
expanded_paths = []
37+
arr_paths.each { |path|
38+
path = date.strftime(path)
39+
if path.include?('*')
40+
Dir.glob(path).select { |p|
41+
@log.info "Following tail of #{p}"
42+
expanded_paths << p
43+
}
44+
else
45+
file = file_exists(path)
46+
expanded_paths << file unless file.nil?
47+
end
48+
}
49+
return expanded_paths
50+
end
51+
2352
def start
24-
start_watchers(@paths) unless @paths.empty?
53+
paths = expand_paths()
54+
start_watchers(paths) unless paths.empty?
2555
end
2656

2757
def shutdown
@@ -365,7 +395,7 @@ def read_inode
365395
end
366396
end.parse!
367397

368-
a = Tailscript::NewTail.new(ARGV)
398+
a = Tailscript::NewTail.new(ARGV[0])
369399
a.start
370400
a.shutdown
371401
end

0 commit comments

Comments
 (0)