new filters for searching logs with MID

This commit is contained in:
georglauterbach 2024-01-16 19:19:19 +01:00
parent 9c621f1bd9
commit 74d63af683
No known key found for this signature in database
GPG key ID: F367F7C43C118578

View file

@ -58,3 +58,40 @@ function _service_log_should_contain_string() {
_filter_service_log "${SERVICE}" "${STRING}"
assert_success
}
# Filters the mail log according to MID (Message-ID) and prints lines
# of the mail log that fit Postfix's queue ID for the given message ID.
#
# @param ${1} = message ID part before '@'
function _print_mail_log_of_queue_id_from_mid() {
# The unique ID Postfix (and other services) use may be different in length
# on different systems. Hence, we use a range to safely capture it.
local QUEUE_ID_REGEX='[A-Z0-9]{9,12}'
local MID=$(__construct_mid "${1:?Left-hand side of MID missing}")
shift 1
_wait_for_empty_mail_queue_in_container
QUEUE_ID=$(_exec_in_container tac /var/log/mail.log \
| grep -E "postfix/cleanup.*: ${QUEUE_ID_REGEX}:.*message-id=${MID}" \
| grep -E --only-matching --max-count 1 "${QUEUE_ID_REGEX}" || :)
# We perform plausibility checks on the IDs.
assert_not_equal "${QUEUE_ID}" ''
run echo "${QUEUE_ID}"
assert_line --regexp "^${QUEUE_ID_REGEX}$"
_filter_service_log 'mail' "${QUEUE_ID}"
}
# Filters the mail log according to MID (Message-ID) and prints lines
# of the mail log that fit lines with the pattern `msgid=${1}@dms-test`.
#
# @param ${1} = message ID part before '@'
function _print_mail_log_for_msgid() {
local MID=$(__construct_mid "${1:?Left-hand side of MID missing}")
shift 1
_filter_service_log 'mail' "msgid=${MID}"
}