Skip to content

Commit

Permalink
Add since time support to journalctl logs
Browse files Browse the repository at this point in the history
Signed-off-by: black-dragon74 <[email protected]>
  • Loading branch information
black-dragon74 committed Apr 4, 2024
1 parent a35de68 commit fb57ee3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
6 changes: 3 additions & 3 deletions collection-scripts/gather_ceph_logs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ for ns in $namespaces; do
oc debug nodes/"${node}" <<CMDS
chroot /host
cd var/log
journalctl --since "2 days ago" | gzip > journal_"${node}".gz
journalctl -k -o short-iso-precise --utc --no-hostname | gzip > kernel_"${node}".gz
journalctl --since "${JCTL_FILTER_ARGS}" | gzip > journal_"${node}".gz
journalctl --since "${JCTL_FILTER_ARGS}" -k -o short-iso-precise --utc --no-hostname | gzip > kernel_"${node}".gz
exit
CMDS
done
Expand Down Expand Up @@ -75,4 +75,4 @@ CMDS
done

dbglog "ceph core dump collection completed"
done
done
21 changes: 21 additions & 0 deletions collection-scripts/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,27 @@ parse_since_time() {
if [ -n "${FILTER_ARGS}" ]; then
export LOG_FILTER_ARGS="${FILTER_ARGS}"
fi

# Journalctl doesn't support the same type of since and
# since-time args. Adapt the logic for journalctl
local JRNL_FILTER=""

if [ -n "${MUST_GATHER_SINCE:-}" ]; then
JRNL_FILTER="${MUST_GATHER_SINCE} ago"
fi

# This section adapts an ISO time like: 2024-04-04T09:23:26Z
# To 2024-04-04 09:23:26, a format that journalctl is happy with
if [ -n "${MUST_GATHER_SINCE_TIME:-}" ]; then
JRNL_FILTER=$(echo "${MUST_GATHER_SINCE_TIME}" | sed 's/T/ /; s/Z//')
fi

# If the var is unset, export the default as 2 days ago
if [ -n "${JRNL_FILTER}" ]; then
export JCTL_FILTER_ARGS="${JRNL_FILTER}"
else
export JCTL_FILTER_ARGS="2 days ago"
fi
}

# Export the functions so that the file needs to be sourced only once
Expand Down

0 comments on commit fb57ee3

Please sign in to comment.