Skip to content

Commit

Permalink
fixed directory issues
Browse files Browse the repository at this point in the history
  • Loading branch information
codeperfectplus committed Sep 30, 2024
1 parent de45e22 commit e15cd9d
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 12 deletions.
4 changes: 2 additions & 2 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1042,8 +1042,8 @@ function install_alert_manager() {
ALERT_MANAGER_SCRIPT=$(find "$EXTRACT_DIR" -name start_alertmanager.sh)
echo "Initializing Alert Manager $INIT_ALERT_MANAGER_SCRIPT"
echo "Starting Alert Manager $ALERT_MANAGER_SCRIPT"
bash $INIT_ALERT_MANAGER_SCRIPT
bash $ALERT_MANAGER_SCRIPT
sudo -u "$USER_NAME" bash "$INIT_ALERT_MANAGER_SCRIPT"
sudo -u "$USER_NAME" bash "$ALERT_MANAGER_SCRIPT"
}

# update the code to the latest version
Expand Down
6 changes: 3 additions & 3 deletions src/scripts/initialization/init_alertmanager.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/bin/bash

# Set the path for the Alertmanager configuration file
ALERTMANAGER_CONFIG_FILE="prometheus_config/alertmanager.yml"
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
PROMETHEUS_CONFIG_DIR="$(dirname "$(dirname "$(dirname "$SCRIPT_DIR")")")/prometheus_config"
ALERTMANAGER_CONFIG_FILE="$PROMETHEUS_CONFIG_DIR/alertmanager.yml"
IP_ADDRESS=$(hostname -I | awk '{print $1}')
# take slack_webhook from .env file
SLACK_WEBHOOK_URL=$(grep SLACK_WEBHOOK_URL .env | cut -d '=' -f2)

# Create the Alertmanager configuration
cat > "$ALERTMANAGER_CONFIG_FILE" <<EOL
Expand Down
21 changes: 17 additions & 4 deletions src/scripts/start_alertmanager.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,31 @@ error_exit() {
exit 1
}

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
# 2 directories up
CONFIG_DIR="$(dirname "$(dirname "$SCRIPT_DIR")")"/prometheus_config
# Configuration variables
ALERTMANAGER_CONTAINER_NAME="alertmanager"
ALERTMANAGER_IMAGE="prom/alertmanager:latest"
ALERTMANAGER_PORT="9093"
ALERTMANAGER_CONFIG_DIR="$(pwd)/prometheus_config"
ALERTMANAGER_CONFIG_FILE="$ALERTMANAGER_CONFIG_DIR/alertmanager.yml"
ALERTMANAGER_CONFIG_FILE="$CONFIG_DIR/alertmanager.yml"
echo $ALERTMANAGER_CONFIG_FILE
ALERTMANAGER_DATA_DIR="/home/$(whoami)/.database/alertmanager"
NETWORK_NAME="flask-prometheus-net"
INIT_ALERTMANAGER_SH="$SCRIPT_DIR/initialization/init_alertmanager.sh"

# Ensure config and data directories exist
# Verify the script exists
if [ ! -f "$INIT_ALERTMANAGER_SH" ]; then
echo "Script $INIT_ALERTMANAGER_SH does not exist."
exit 1
fi

call INIT_ALERTMANAGER_SH
bash $INIT_ALERTMANAGER_SH

Ensure config and data directories exist
log "Creating necessary directories if they don't exist."
mkdir -p "$ALERTMANAGER_CONFIG_DIR" || error_exit "Failed to create $ALERTMANAGER_CONFIG_DIR"
mkdir -p "$CONFIG_DIR" || error_exit "Failed to create $CONFIG_DIR"
mkdir -p "$ALERTMANAGER_DATA_DIR" || error_exit "Failed to create $ALERTMANAGER_DATA_DIR"

# Sample configuration for alertmanager.yml
Expand Down
2 changes: 1 addition & 1 deletion src/templates/graphs/historical_alerts_metrics.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ <h1>Alerts Bar Graph</h1>
});

const instances = Object.keys(instanceSeverityCount);
const severityLevels = ['info', 'warning']; // Define the severity levels
const severityLevels = [...new Set(alertData.map(alert => alert.severity))]; // Extract unique severity levels dynamically
const datasets = severityLevels.map(severity => {
return {
label: severity,
Expand Down
2 changes: 0 additions & 2 deletions src/templates/other/alert_history.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ <h2>
<thead class="thead-dark">
<tr>
<th>ID</th>
<th>Alert Status</th>
<th>Alert Name</th>
<th>Start Time</th>
<th>Instance</th>
Expand All @@ -59,7 +58,6 @@ <h2>
{% for alert in alerts %}
<tr>
<td>{{ alert.id }}</td>
<td>{{ alert.alert_status }}</td>
<td>{{ alert.alert_name }}</td>
<td>{{ alert.start_time }}</td>
<td>{{ alert.instance }}</td>
Expand Down

0 comments on commit e15cd9d

Please sign in to comment.