-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Nomis: DSOS-2318: add collectd db monitoring (#384)
* tidy up * readme * add collectd-oracle-db-connected role * Add audit role * Commit changes made by code formatters --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
0db24ea
commit af38c1b
Showing
15 changed files
with
163 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Role for enabling audit daemon |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
- name: Install audit package | ||
yum: | ||
name: audit | ||
state: present | ||
lock_timeout: 60 | ||
retries: 3 | ||
delay: 10 | ||
|
||
- name: Start auditd | ||
service: | ||
name: auditd | ||
state: started | ||
enabled: yes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
- import_tasks: audit.yml | ||
tags: | ||
- amibuild | ||
- ec2provision | ||
- ec2patch | ||
when: ansible_distribution in ['RedHat', 'OracleLinux'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
collectd_script_path: /usr/local/bin | ||
collectd_script_name: collectd_oracle_db_connected | ||
collectd_script_user: oracle | ||
collectd_script_interval: 60 |
10 changes: 10 additions & 0 deletions
10
ansible/roles/collectd-oracle-db-connected/handlers/main.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
- name: restart collectd | ||
ansible.builtin.service: | ||
name: collectd | ||
state: restarted | ||
|
||
- name: restart plugin script | ||
ansible.builtin.shell: | | ||
pkill -u {{ collectd_script_user }} -f {{ collectd_script_path }}/{{ collectd_script_name }}.sh | ||
failed_when: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
dependencies: | ||
- role: get-ec2-facts | ||
- role: amazon-cloudwatch-agent-collectd |
18 changes: 18 additions & 0 deletions
18
ansible/roles/collectd-oracle-db-connected/tasks/configure_collectd.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
--- | ||
- name: copy collectd config | ||
ansible.builtin.template: | ||
src: "{{ collectd_script_name }}.conf.j2" | ||
dest: "/etc/collectd.d/{{ collectd_script_name }}.conf" | ||
owner: root | ||
mode: 0644 | ||
notify: | ||
- restart collectd | ||
|
||
- name: copy collectd plugin script | ||
ansible.builtin.template: | ||
src: "{{ collectd_script_name }}.sh.j2" | ||
dest: "{{ collectd_script_path }}/{{ collectd_script_name }}.sh" | ||
owner: root | ||
mode: 0755 | ||
notify: | ||
- restart plugin script |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
- import_tasks: configure_collectd.yml | ||
tags: | ||
- ec2provision | ||
- ec2patch | ||
when: ansible_distribution in ['RedHat', 'OracleLinux'] |
File renamed without changes.
65 changes: 65 additions & 0 deletions
65
ansible/roles/collectd-oracle-db-connected/templates/collectd_oracle_db_connected.sh.j2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#!/bin/bash | ||
# Managed by collectd-oracle-db-connected ansible role | ||
# If manually editing, just kill script and collectd will respawn | ||
# e.g. pkill -u {{ collectd_script_user }} -f {{ collectd_script_path }}/{{ collectd_script_name }}.sh | ||
|
||
HOSTNAME="${HOSTNAME:-localhost}" | ||
INTERVAL="${INTERVAL:-{{ collectd_script_interval }}}" | ||
|
||
if [[ "$(whoami)" != "oracle" ]] | ||
then | ||
echo "This script is expected to be run as the Oracle user" 1>&2 | ||
exit 1 | ||
fi | ||
|
||
# We need to make sure this is in the path | ||
export PATH=${PATH}:/usr/local/bin | ||
|
||
get_sids() { | ||
aws ec2 describe-tags --filters "Name=resource-id,Values={{ ansible_ec2_instance_id }}" "Name=key,Values=oracle-sids" --query Tags[0].Value --output=text | ||
} | ||
|
||
db_connected() { | ||
# DB resources names are usually 'ora.${DB}.db' but some have a suffix after ${DB} | ||
DB="$(crsctl status resource | grep -m1 -i ora\.${SID}.*\.db | cut -f2 -d=)" | ||
|
||
# Check added to alert on not having a database resource BEFORE trying to get it's status | ||
if [[ -z "$DB" ]] | ||
then | ||
echo "Failed to find a database resource for ${SID}" 1>&2 | ||
return 1 | ||
fi | ||
|
||
# Worth noting here that crsctl exits with code 0 even if you try and find details of a database that doesn't exist | ||
STATUS=$(timeout $INTERVAL crsctl status resource ${DB} -v | grep STATE_DETAILS | cut -f2 -d= | cut -f1 -d,) | ||
|
||
case ${STATUS} in | ||
"Open") | ||
return 0 | ||
;; | ||
"Open,Readonly") | ||
return 0 | ||
;; | ||
"Mounted (Closed)") | ||
return 0 | ||
;; | ||
*) | ||
# If this check returns a non-zero value then the database is not connected | ||
return 1 | ||
;; | ||
esac | ||
} | ||
|
||
ORACLE_SID="+ASM" | ||
ORAENV_ASK="NO" | ||
. oraenv > /dev/null | ||
|
||
while sleep "$INTERVAL"; do | ||
SIDS=$(get_sids) | ||
if [[ "$SIDS" != "None" ]]; then | ||
for SID in $(get_sids); do | ||
db_connected $SID >/dev/null 2>&1 | ||
echo "PUTVAL $HOSTNAME/exec-db_connected/bool-$SID interval=$INTERVAL N:$?" | ||
done | ||
fi | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
ansible/roles/collectd-service-metrics/templates/collectd_service_metrics.conf.j2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
LoadPlugin exec | ||
<Plugin exec> | ||
Exec "{{ collectd_script_user }}" "{{ collectd_script_path }}/{{ collectd_script_name }}.sh" | ||
</Plugin> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--- | ||
collectd_selinux_permissive: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters