Skip to content

Commit

Permalink
15293 FIX mk_oracle: fix custom sql sid matching
Browse files Browse the repository at this point in the history
Configuration variable `$SQLS_SIDS` can be used to define a comma seperated
list of sids for which the custom sql is executed.

Before this werk the custom sql was executed if the sid was a substring of one
of the elements of the list in `$SQLS_SIDS`.

Now custom sql is only executed if the sid is equal to the whole element
provided in `$SQLS_SIDS`.

Change-Id: I758f396dfccc7441bb7fbefb1d843d1d4ba35057
  • Loading branch information
BenediktSeidl committed Oct 18, 2023
1 parent 2a0b111 commit 1673a68
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
19 changes: 19 additions & 0 deletions .werks/15293
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Title: mk_oracle: fix custom sql sid matching
Class: fix
Compatible: compat
Component: agents
Date: 1695821082
Edition: cre
Knowledge: doc
Level: 1
State: unknown
Version: 2.2.0p13

Configuration variable `$SQLS_SIDS` can be used to define a comma seperated
list of sids for which the custom sql is executed.

Before this werk the custom sql was executed if the sid was a substring of one
of the elements of the list in `$SQLS_SIDS`.

Now custom sql is only executed if the sid is equal to the whole element
provided in `$SQLS_SIDS`.
10 changes: 7 additions & 3 deletions agents/plugins/mk_oracle
Original file line number Diff line number Diff line change
Expand Up @@ -2127,8 +2127,11 @@ unset_custom_sqls_vars() {
sid_matches_defined_sids() {
# first parameter is a list of coma separated values (SQLS_SIDS)
# second parameter is a single value (current sid)
sids=${1//,/ }
echo "$sids" | "${GREP}" -q "$2"

# split $1 into array on , or \n
IFS=',\n' read -ra sids_array <<<"$1"
# check if array contains $2
printf '%s\n' "${sids_array[@]}" | grep -F -x -- "$2"
}

do_custom_sqls() {
Expand All @@ -2141,8 +2144,9 @@ do_custom_sqls() {

$section

local sids="${SQLS_SIDS:-$custom_sqls_sids}"
# If SID is not part of sids we can skip the rest
if ! sid_matches_defined_sids "${SQLS_SIDS:-$custom_sqls_sids}" "$MK_SID"; then
if ! sid_matches_defined_sids "$sids" "$MK_SID"; then
logging -w "[${MK_SID}] [custom_sql] [${section}]" \
"Skipping this section, runs only on SIDs '$sids'"
unset_custom_sqls_vars
Expand Down
4 changes: 2 additions & 2 deletions tests/unit-shell/agents/plugins/test_mk_oracle.sh
Original file line number Diff line number Diff line change
Expand Up @@ -867,14 +867,14 @@ test_mk_oracle_mk_ora_db_connect_sqls_tnsalias_tnsping_ok_sid_specific_prefix_br
}

test_mk_oracle_sid_matches_defined_sids() {
assertTrue 'sid_matches_defined_sids "prefixed_value" "prefix"' # THIS IS BROKEN! TODO: should not match!
assertFalse 'sid_matches_defined_sids "prefixed_value" "prefix"'
assertTrue 'sid_matches_defined_sids "some,value,here" "value"'
assertFalse 'sid_matches_defined_sids "some,hello,here" "value"'
# documentation says, that customer may us "$SIDS" when the section should
# be executed for all elements, but this variable contains a newline
# seperated list of sids:
assertTrue 'sid_matches_defined_sids "some\nvalue\nhere" "value"'
assertTrue 'sid_matches_defined_sids "some\nprefixed_value\nhere" "value"' # THIS IS BROKEN! TODO: should not match!
assertFalse 'sid_matches_defined_sids "some\nprefixed_value\nhere" "value"'
}

# shellcheck disable=SC1090 # Can't follow
Expand Down

0 comments on commit 1673a68

Please sign in to comment.