Skip to content

Commit

Permalink
Remove unicode ans ansi color codes from ps
Browse files Browse the repository at this point in the history
  • Loading branch information
metacoma committed Sep 15, 2023
1 parent 8f85da9 commit b5ad7f4
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions inventory/targets/vector.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ parameters:
.input = msg.message.input
.output = msg.message.output
.host = msg.host
.metadata = msg.message.metadata
del(.message)
kafka-linestream-to-elasticsearch:
Expand Down Expand Up @@ -188,6 +187,19 @@ parameters:
input = {}
ps1 = {}
end
local function remove_unicode_ansi_sequences(input)
return input:gsub('%[%?[0-9][0-9][0-9][0-9][a-z]', ''):gsub('\27', '')
end
local function extract_ps(data)
if (string.match(data, "^%S+@%S+:")) then
print("match")
return data:gsub("^([^@]+)@([^:]+).*", "%1@%2")
end
return data
end
function process(event, emit)
ch = event.log.message
tmux_pane_id = event.log.metadata.tmux.pane_id
Expand All @@ -201,12 +213,13 @@ parameters:
-- we found a space character and the line matches the prompt regex
-- skip sent mesage if ps1 is empty, usually it's a first io-context document in the stream
if (data[tmux_pane_id] ~= nil and event.log.message.input ~= "" and data[tmux_pane_id] ~= {}) then
event.log.metadata.ps1_start_raw = ps1_data
event.log.metadata.ps1_end_raw = line[tmux_pane_id]
event.log.message = {
ps1_start = ps1_data,
ps1_end = line[tmux_pane_id],
ps1_start = extract_ps((remove_unicode_ansi_sequences(ps1_data))),
ps1_end = extract_ps((remove_unicode_ansi_sequences(line[tmux_pane_id]))),
input = input[tmux_pane_id],
output = table.concat(data[tmux_pane_id]),
metadata = event.log.metadata
}
emit(event)
end
Expand Down

0 comments on commit b5ad7f4

Please sign in to comment.