Skip to content

Commit

Permalink
Merge pull request #1090 from ministryofjustice/DBA-683
Browse files Browse the repository at this point in the history
Update password fetching for MP
  • Loading branch information
bill-buchan authored Nov 5, 2024
2 parents 7ab4ca8 + 7ed9a75 commit 7f13744
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<TargetCollectionExt EXT_NAME="ME$STANDBY_PARAMETER_COMPARISON" EXT_VERSION="1" TARGET_TYPE="host"><CollectionItem NAME="ME$STANDBY_PARAMETER_COMPARISON" UPLOAD="YES">
<TargetCollectionExt EXT_NAME="ME$STANDBY_PARAMETER_COMPARISON" EXT_VERSION="2" TARGET_TYPE="host"><CollectionItem NAME="ME$STANDBY_PARAMETER_COMPARISON" UPLOAD="YES">
<Schedule>
<IntervalSchedule INTERVAL="12" TIME_UNIT="Hr"/>
</Schedule>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<MetricExtensionArchive name="MEAME$STANDBY_PARAMETER_COMPARISON">
<MetricExtension name="ME$STANDBY_PARAMETER_COMPARISON" type="host" version="1" is_repos="FALSE" display_name="Standby Parameter Comparison" description="Ensure Database Instance Parameters match between Primary and Standby" version_comment=" " metadata_digest="dc5139d6b2d0ecb83e08cbce088f9269" coll_digest="a75a4b544189577ab7b53bd9c5685cbe" attach_digest="6cce41a3a02083b8b36bb6d55edfbd25">
<MetricExtension name="ME$STANDBY_PARAMETER_COMPARISON" type="host" version="2" is_repos="FALSE" display_name="Standby Parameter Comparison" description="Ensure Database Instance Parameters match between Primary and Standby" version_comment=" " metadata_digest="dc5139d6b2d0ecb83e08cbce088f9269" coll_digest="a75a4b544189577ab7b53bd9c5685cbe" attach_digest="3c096ee11057c81750cdfce3c4bd9550">
<scripts name="compare_parameters.sh">
</scripts>
</MetricExtension>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<TargetMetadataExt EXT_NAME="ME$STANDBY_PARAMETER_COMPARISON" EXT_VERSION="1" TARGET_TYPE="host"><Metric NAME="ME$STANDBY_PARAMETER_COMPARISON" TYPE="TABLE">
<TargetMetadataExt EXT_NAME="ME$STANDBY_PARAMETER_COMPARISON" EXT_VERSION="2" TARGET_TYPE="host"><Metric NAME="ME$STANDBY_PARAMETER_COMPARISON" TYPE="TABLE">
<Display>
<Label NLSID="NLS_METRIC_hostME$STANDBY_PARAMETER_COMPARISON">Standby Parameter Comparison</Label>
<Description NLSID="NLS_DESCRIPTION_hostME$STANDBY_PARAMETER_COMPARISON">Ensure Database Instance Parameters match between Primary and Standby</Description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,32 @@

. ~/.bash_profile


# If run on an instance hosting OEM we need to explicitly set up the database environment
if grep "^EMREP:" /etc/oratab > /dev/null; then
export ORAENV_ASK=NO
export ORACLE_SID=EMREP
. oraenv >/dev/null
fi

function get_password()
{
USERNAME=$1
. /etc/environment && aws ssm get-parameters --region ${REGION} --with-decryption --name /${HMPPS_ENVIRONMENT}/${APPLICATION}/${HMPPS_ROLE}-database/db/oradb_${USERNAME,,}_password | jq -r '.Parameters[].Value'
if [[ "${ORACLE_SID}" == "EMREP" ]];
then
aws secretsmanager get-secret-value --secret-id "/oracle/database/EMREP/passwords" --region eu-west-2 --query SecretString --output text| jq -r .${USERNAME}
else
INSTANCEID=$(wget -q -O - http://169.254.169.254/latest/meta-data/instance-id)
APPLICATION=$(aws ec2 describe-tags --filters "Name=resource-id,Values=${INSTANCEID}" "Name=key,Values=application" --query "Tags[].Value" --output text)
DELIUS_ENVIRONMENT=$(aws ec2 describe-tags --filters "Name=resource-id,Values=${INSTANCEID}" "Name=key,Values=delius-environment" --query "Tags[].Value" --output text)
if [[ "${APPLICATION}" == "delius" ]];
then
aws secretsmanager get-secret-value --secret-id delius-core-${DELIUS_ENVIRONMENT}-oracle-db-dba-passwords --region eu-west-2 --query SecretString --output text| jq -r .${USERNAME}
else
APPLICATION_SUBTYPE=$(aws ec2 describe-tags --filters "Name=resource-id,Values=${INSTANCEID}" "Name=key,Values=database" --query "Tags[].Value" --output text | cut -d'_' -f1)
aws secretsmanager get-secret-value --secret-id ${APPLICATION}-${DELIUS_ENVIRONMENT}-oracle-${APPLICATION_SUBTYPE}-db-dba-passwords --region eu-west-2 --query SecretString --output text| jq -r .${USERNAME}
fi
fi
}

function get_jdbc()
Expand Down Expand Up @@ -249,7 +271,10 @@ SELECT
FROM
parameter_comparison e
WHERE
e.parameter_match != 'Y';
e.parameter_match != 'Y'
AND
e.name != '_bug32914795_bct_last_dba_buffer_size'; -- See MOS Note 3049433.1
EXIT
EOSQL
Expand All @@ -258,7 +283,13 @@ EOSQL
DBSNMP_PASSWORD=$(get_password dbsnmp)
SYS_PASSWORD=$(get_password sys)

for DB in $(echo -e "show configuration;" | dgmgrl / | grep "standby database" | cut -d'-' -f1)
do
report_differences ${ORACLE_SID} ${DB^^}
done
# We check that the ORACLE_SID is the primary database as we only want to run this check against the primary
PRIMARY_SID=$(echo -e "show configuration;" | dgmgrl / | grep "Primary database" | cut -d'-' -f1 | sed 's/ //g' | tr '[:upper:]' '[:lower:]')

if [[ "${ORACLE_SID,,}" == "${PRIMARY_SID}" ]];
then
for DB in $(echo -e "show configuration;" | dgmgrl / | grep "standby database" | cut -d'-' -f1)
do
report_differences ${ORACLE_SID} ${DB^^}
done
fi

0 comments on commit 7f13744

Please sign in to comment.