Compare commits
3 Commits
cc218af2e0
...
be168c03ba
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
be168c03ba | ||
|
|
df8e6bb79b | ||
|
|
4d3caf98c1 |
14
src/app.py
14
src/app.py
@ -49,8 +49,18 @@ def get_logs():
|
||||
if issue_type not in config:
|
||||
return jsonify({"error": "Invalid issue type"})
|
||||
issue_config = config[issue_type]
|
||||
response = {log.get('log_file').split('*')[0]: read_log_from_dir(*split_directory_and_file(log.get('log_file')), log['lines']) if '*' in log.get('log_file') else read_log(log['log_file'], log['lines']) for log in issue_config['logs']}
|
||||
response.update({comm.get('tag'): os.popen(comm.get('comm')).read() for comm in issue_config['commands']})
|
||||
# response = {log.get('log_file').split('*')[0]: read_log_from_dir(*split_directory_and_file(log.get('log_file')), log['lines']) if '*' in log.get('log_file') else read_log(log['log_file'], log['lines']) for log in issue_config['logs']}
|
||||
# response.update({comm.get('tag'): os.popen(comm.get('comm')).read() for comm in issue_config['commands']})
|
||||
|
||||
response = {
|
||||
log.get('log_file').split('*')[0]: f"```\n{read_log_from_dir(*split_directory_and_file(log.get('log_file')), log['lines'])}\n```" if '*' in log.get('log_file') else f"```\n{read_log(log['log_file'], log['lines'])}\n```"
|
||||
for log in issue_config['logs']
|
||||
}
|
||||
response.update({
|
||||
comm.get('tag'): f"```\n{os.popen(comm.get('comm')).read()}\n```" for comm in issue_config['commands']
|
||||
})
|
||||
|
||||
|
||||
except Exception as e:
|
||||
return jsonify({"error": str(e)})
|
||||
return jsonify(response)
|
||||
|
||||
@ -1,4 +1,27 @@
|
||||
{
|
||||
"APEX Upgrade Request": {
|
||||
"commands": [
|
||||
{
|
||||
"comm": "df -h | head -n 1 && df -h | grep '^/dev/sd'",
|
||||
"tag": "disk_usage"
|
||||
},
|
||||
{
|
||||
"comm": "/opt/ticket-ai/src/scripts/tablespaceUsage.sh;sleep 5;cat /tmp/tablespace_usage.tmp",
|
||||
"tag": "tablespace_usage"
|
||||
},
|
||||
{
|
||||
"comm": "/opt/ticket-ai/src/scripts/apexUsage.sh;sleep 5;cat /tmp/apex_usage.tmp",
|
||||
"tag": "apex_usage"
|
||||
}
|
||||
],
|
||||
"logs": [
|
||||
{
|
||||
"log_file": "/opt/oracle/diag/rdbms/xe/XE/trace/alert_XE.log",
|
||||
"lines": 10
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
"Server Performance Problem": {
|
||||
"commands": [
|
||||
{
|
||||
|
||||
76
src/scripts/apexUsage.sh
Executable file
76
src/scripts/apexUsage.sh
Executable file
@ -0,0 +1,76 @@
|
||||
#!/bin/bash
|
||||
|
||||
# File paths for output
|
||||
OUTPUT_FILE="/tmp/apex_usage.tmp"
|
||||
PDB_LIST_FILE="/tmp/pdb_list.tmp"
|
||||
> "$OUTPUT_FILE" # Clear the output file before starting
|
||||
touch $OUTPUT_FILE
|
||||
chown oracle $OUTPUT_FILE
|
||||
|
||||
# Function to execute the APEX usage query in a specific container
|
||||
run_query() {
|
||||
local container_name="$1"
|
||||
su - oracle -s /bin/bash -c "
|
||||
sqlplus -s / as sysdba <<EOF >> \"$OUTPUT_FILE\"
|
||||
whenever sqlerror exit sql.sqlcode;
|
||||
set echo on
|
||||
set heading on
|
||||
SET UNDERLINE '='
|
||||
set feedback off
|
||||
set linesize 150
|
||||
|
||||
-- Switch to the specified container
|
||||
ALTER SESSION SET CONTAINER = $container_name;
|
||||
|
||||
-- Print the container name for clarity
|
||||
PROMPT APEX usage for container: $container_name;
|
||||
|
||||
SELECT
|
||||
OWNER,
|
||||
SUM(BYTES) / (1024 * 1024) AS MB_USED
|
||||
FROM
|
||||
DBA_SEGMENTS
|
||||
WHERE
|
||||
OWNER LIKE 'APEX%' -- Replace with your APEX schema name
|
||||
GROUP BY
|
||||
OWNER;
|
||||
|
||||
|
||||
exit;
|
||||
EOF
|
||||
"
|
||||
}
|
||||
|
||||
# Run the query for the CDB (root container)
|
||||
# echo "Gathering APEX usage for CDB (root container)..." >> "$OUTPUT_FILE"
|
||||
# run_query 'CDB\$ROOT'
|
||||
|
||||
# Get a list of all PDBs, excluding PDB$SEED, and write to a temporary file
|
||||
su - oracle -s /bin/bash -c "
|
||||
sqlplus -s / as sysdba <<'EOF'
|
||||
set heading off
|
||||
set feedback off
|
||||
set pagesize 0
|
||||
spool $PDB_LIST_FILE
|
||||
SELECT NAME FROM v\$pdbs WHERE NAME NOT IN ('PDB\$SEED');
|
||||
spool off
|
||||
exit;
|
||||
EOF
|
||||
"
|
||||
|
||||
# Verify that the PDB_LIST_FILE was created and contains data
|
||||
if [[ -f "$PDB_LIST_FILE" && -s "$PDB_LIST_FILE" ]]; then
|
||||
# Read each valid PDB name from the temporary file
|
||||
while IFS= read -r PDB; do
|
||||
PDB=$(echo "$PDB" | xargs) # Trim any leading/trailing whitespace
|
||||
if [[ -n "$PDB" ]]; then
|
||||
echo "Gathering APEX usage for PDB: $PDB..." >> "$OUTPUT_FILE"
|
||||
run_query "$PDB"
|
||||
fi
|
||||
done < "$PDB_LIST_FILE"
|
||||
else
|
||||
echo "No PDBs found or could not access v\$pdbs view" >> "$OUTPUT_FILE"
|
||||
fi
|
||||
|
||||
# Clean up the temporary file
|
||||
rm -f "$PDB_LIST_FILE"
|
||||
@ -4,6 +4,8 @@
|
||||
OUTPUT_FILE="/tmp/tablespace_usage.tmp"
|
||||
PDB_LIST_FILE="/tmp/pdb_list.tmp"
|
||||
> "$OUTPUT_FILE" # Clear the output file before starting
|
||||
touch $OUTPUT_FILE
|
||||
chown oracle $OUTPUT_FILE
|
||||
|
||||
# Function to execute the tablespace usage query in a specific container
|
||||
run_query() {
|
||||
@ -13,6 +15,8 @@ run_query() {
|
||||
whenever sqlerror exit sql.sqlcode;
|
||||
set echo off
|
||||
set heading on
|
||||
SET UNDERLINE '='
|
||||
set feedback off
|
||||
set linesize 150
|
||||
|
||||
-- Switch to the specified container
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user