Skip to content

Commit

Permalink
Merge pull request #1134 from ministryofjustice/DBA-817
Browse files Browse the repository at this point in the history
Dba 817
  • Loading branch information
ranbeersingh1 authored Nov 26, 2024
2 parents dade188 + e4d6833 commit cf7e676
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
2 changes: 1 addition & 1 deletion ansible/roles/oracle-oms-setup/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ application_groups:
- nomis
- oasys
- corporate-staff-rostering
- nomis-combined-reporting
- hmpps-oem
probation:
- delius
- delius-mis
- iaps
- hmpps-oem

emctl: "{{ oem_agent_base }}/agent_inst/bin/emctl"

Expand Down
12 changes: 10 additions & 2 deletions ansible/roles/oracle-oms-setup/tasks/create_jobs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@
owner: oracle
group: oinstall

- name: Flatten Application Groups Dictionary
set_fact:
application_groups_flatten: |
{% for application_group in application_groups -%}
{{ application_group }}:{% for application in application_groups[application_group] -%}{{ application }}{%if not loop.last %},{% else %}|{% endif %}
{%- endfor %}
{%- endfor %}
- name: Template OEM Job Property Files
ansible.builtin.template:
src: "{{ oem_job }}"
Expand All @@ -45,8 +53,8 @@
loop_var: oem_job
vars:
oem_hostname: "{{ ansible_hostname }}"
job_name: "Backup Report for Delius"
reported_applications: "delius,hmpps-oem"
job_name: "Backup Report"
reported_applications: "{{ application_groups_flatten | regex_replace('\\n','')}}"

- name: Create Jobs from OEM Property Files
become_user: oracle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,15 +222,16 @@ variable.large_os_script=<<MULTILINE
#
#

REPORTED_APPLICATIONS="{{ reported_applications }}"

get_message(){

# Supply comma-separated list of applications for whose databases we are interested in reporting on
# You can leave this unset if you want all databases, but notice that we have a hard-coded limit
# of 45 application databases per report (due to Slack restrictions)
APPLICATIONS=delius,delius-mis,hmpps-oem
# Ensure the list is quoted
APPLICATIONS=$(echo $APPLICATIONS | sed "s/[^,]\+/'&'/g")

echo "$APPLICATIONS"

OMR=$(awk -F: '/EMREP/{print $1}' /etc/oratab)

[[ -z $OMR ]] && echo "Oracle EM OMR database not found" && exit 1
Expand Down Expand Up @@ -261,7 +262,7 @@ EOSQL
)

DATABASE_LIST=$(echo "${DATABASE_TARGETS}" | sed "s/[^,]\+/'&'/g")
[[ -z $DATABASE_TARGETS ]] && DATABASE_TARGETS="ALL_DATABASES"
[[ -z $DATABASE_TARGETS ]] && DATABASE_LIST="ALL_DATABASES"

CATALOG=$(awk -F: '/RCVCAT/{print $1}' /etc/oratab)

Expand Down Expand Up @@ -442,15 +443,23 @@ UNPIVOT (backup_report_data FOR s IN (s1 AS 1,s2 AS 2))
;
EOSQL
)

MESSAGE=$(echo "$MESSAGE" | sed 's/\\\\n/\\n/g')
echo "$MESSAGE"
}

SECRET_ARN="arn:aws:secretsmanager:eu-west-2:$(aws sts get-caller-identity | jq -r '.Account'):secret:/oracle/database/EMREP/shared-passwords"
SECRET_VALUE=$(aws secretsmanager get-secret-value --secret-id "${SECRET_ARN}" --query SecretString --output json)
SLACK_TOKEN=$(echo ${SECRET_VALUE} | jq -r | jq -r 'to_entries[] | select(.key=="slack_token").value')

curl -X POST "https://slack.com/api/chat.postMessage" -H "accept: application/json" -d token=${SLACK_TOKEN} -d channel="#delius-aws-oracle-backups" -d text="Backup Report" -d blocks="$MESSAGE" -d icon_emoji=database
IFS="|"
for LINE in $REPORTED_APPLICATIONS
do
APPLICATION_GROUP=$( echo $LINE | cut -d: -f1)
APPLICATIONS=$( echo $LINE | cut -d: -f2)
[[ "${APPLICATION_GROUP}" == "probation" ]] && SLACK_CHANNEL="#delius-aws-oracle-backups" || SLACK_CHANNEL="#nomis-aws-oracle-backups"
get_message
curl -X POST "https://slack.com/api/chat.postMessage" -H "accept: application/json" -d token=${SLACK_TOKEN} -d channel="$SLACK_CHANNEL" -d text="Backup Report" -d blocks="$MESSAGE" -d icon_emoji=database
done
MULTILINE


Expand Down

0 comments on commit cf7e676

Please sign in to comment.