Auto Installer in Atlassian Confluence Integration via Log Source
Aquila–Atlassian Confluence Integration via log source automation
An Auto Installer for Aquila–Atlassian Confluence Integration via log source automation builds upon the structured authentication and API connectivity defined in the referenced guide, but shifts the configuration process into a fully automated workflow. Instead of manually executing each setup step, the integration leverages automated scripts or installers to establish secure communication with Confluence using OAuth 2.0 (3LO) and API keys, enabling systems to authenticate and interact with Confluence APIs seamlessly. OAuth 2.0 serves as a secure authorization mechanism that allows external applications to access Confluence resources on behalf of a user or service account without exposing credentials, while API keys provide an additional method for authenticated requests . By embedding these processes into automation, the installer can dynamically configure credentials, register applications, and connect log sources to Atlassian Confluence, ensuring that system events are automatically transferred to our back-end. This approach not only simplifies deployment but also enhances consistency, scalability, and real-time incident tracking within integrated environments.
Prerequisites:
- Service User (linux user)
- Service Group (linux group)
- Atlassian Confluence Cloud ID
- Atlassian Confluence User Email (Admin)
- API key
Creating the setup installer
Linux:
- Login to the Log Collector.
- Open Terminal and type the following commands.
-
cd Documents -
nano setup.sh
-
- Paste this Script.
-
#!/bin/bash # ============================================================================= # AQUILA - Atlassian Confluence Integration Setup Script # Automates: API Token Config, Bash Wrapper, Systemd Service/Timer, Logrotate # ============================================================================= set -euo pipefail # ----------------------------------------------- # Colors for output # ----------------------------------------------- RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' CYAN='\033[0;36m' NC='\033[0m' # No Color log_info() { echo -e "${CYAN}[INFO]${NC} $1"; } log_ok() { echo -e "${GREEN}[OK]${NC} $1"; } log_warn() { echo -e "${YELLOW}[WARN]${NC} $1"; } log_error() { echo -e "${RED}[ERROR]${NC} $1"; exit 1; } # ----------------------------------------------- # Root check # ----------------------------------------------- if [[ "$EUID" -ne 0 ]]; then log_error "Please run this script as root or with sudo." fi # ============================================================================= # STEP 1: Collect User Inputs # ============================================================================= echo "" echo -e "${CYAN}============================================================${NC}" echo -e "${CYAN} AQUILA - Atlassian Confluence Integration Setup ${NC}" echo -e "${CYAN}============================================================${NC}" echo "" read -rp "Enter the Linux username to run the service (e.g. testing-confluence): " SERVICE_USER read -rp "Enter the Linux group for the service user (e.g. testing-confluence): " SERVICE_GROUP # Validate user exists, create if not if ! id "$SERVICE_USER" &>/dev/null; then log_warn "User '$SERVICE_USER' does not exist. Creating system user..." useradd --system --no-create-home --shell /usr/sbin/nologin \ --comment "AQUILA Confluence Service Account" "$SERVICE_USER" groupadd --system "$SERVICE_GROUP" 2>/dev/null || true usermod -aG "$SERVICE_GROUP" "$SERVICE_USER" log_ok "Created system user: $SERVICE_USER" fi HOME_DIR=$(eval echo "~$SERVICE_USER") CONFLUENCE_DIR="$HOME_DIR/confluence" read -rp "Enter Confluence Cloud ID: " CLOUD_ID read -rp "Enter Atlassian Admin Email: " USER_EMAIL read -rsp "Enter API Key (input hidden): " API_KEY echo "" read -rp "Enter polling interval in seconds (default 600 for 10 min): " POLL_INTERVAL POLL_INTERVAL="${POLL_INTERVAL:-600}" FLAT_FILE="$CONFLUENCE_DIR/flattened.json" LOCK_FILE="/var/lock/confluence-events.lock" # ============================================================================= # STEP 2: Create Required Directories # ============================================================================= log_info "Creating required directories..." mkdir -p "$CONFLUENCE_DIR" chown -R "$SERVICE_USER:$SERVICE_GROUP" "$CONFLUENCE_DIR" chmod 750 "$CONFLUENCE_DIR" log_ok "Created: $CONFLUENCE_DIR" # ============================================================================= # STEP 3: Create the Confluence Audit Wrapper Script # ============================================================================= log_info "Creating Confluence audit wrapper script at /usr/local/bin/confluence_audit.sh ..." cat > /usr/local/bin/confluence_audit.sh <<EOF #!/bin/bash set -euo pipefail # ---------------------------- # Config # ---------------------------- FLAT_FILE="${FLAT_FILE}" LOCK_FILE="${LOCK_FILE}" CLOUD_ID="${CLOUD_ID}" USER_EMAIL="${USER_EMAIL}" API_KEY="${API_KEY}" LIMIT=1000 # Number of items per page START=0 # Index of the first item (0-based) # Ensure only one instance runs at a time exec 200>"\$LOCK_FILE" flock -n 200 || exit 1 TMP_FILE=\$(mktemp) TOTAL_FETCHED=0 echo "Starting Confluence audit log fetch (limit=\$LIMIT per page)..." # ---------------------------- # Pagination loop (start + limit) # ---------------------------- while true; do echo "Fetching page: start=\$START, limit=\$LIMIT..." RESPONSE=\$(curl -s --request GET \\ --url "https://api.atlassian.com/ex/confluence/\$CLOUD_ID/wiki/rest/api/audit?start=\$START&limit=\$LIMIT" \\ --user "\$USER_EMAIL:\$API_KEY" \\ --header "Accept: application/json") # ---------------------------- # Validate JSON # ---------------------------- if ! echo "\$RESPONSE" | jq . >/dev/null 2>&1; then echo "Error: API did not return valid JSON at start=\$START" rm -f "\$TMP_FILE" exit 1 fi # Count results on this page PAGE_COUNT=\$(echo "\$RESPONSE" | jq '(.results // []) | length') # No more records — stop paginating if [[ "\$PAGE_COUNT" -eq 0 ]]; then echo "No more records found. Stopping pagination." break fi # Flatten page results and append to temp file echo "\$RESPONSE" | jq -c ' (.results // [])[] ' >> "\$TMP_FILE" TOTAL_FETCHED=\$(( TOTAL_FETCHED + PAGE_COUNT )) echo " → Fetched \$PAGE_COUNT records (total so far: \$TOTAL_FETCHED)" # If page returned fewer than LIMIT, we've reached the last page if [[ "\$PAGE_COUNT" -lt "\$LIMIT" ]]; then echo "Last page reached (returned \$PAGE_COUNT < \$LIMIT)." break fi # Advance to next page START=\$(( START + LIMIT )) done # ---------------------------- # Write final output to flat file # ---------------------------- if [[ -s "\$TMP_FILE" ]]; then mv "\$TMP_FILE" "\$FLAT_FILE" echo "Flattened \$TOTAL_FETCHED total records into \$FLAT_FILE" else echo "Warning: No records fetched. \$FLAT_FILE not updated." rm -f "\$TMP_FILE" fi EOF chmod +x /usr/local/bin/confluence_audit.sh chown "$SERVICE_USER:$SERVICE_GROUP" /usr/local/bin/confluence_audit.sh log_ok "Wrapper script created and permissions set." # ============================================================================= # STEP 4: Create Systemd Service File # ============================================================================= log_info "Creating systemd service file: /etc/systemd/system/confluence-audit.service ..." cat > /etc/systemd/system/confluence-audit.service <<EOF [Unit] Description=Atlassian Confluence Audit Log Fetcher After=network.target Wants=network-online.target [Service] Type=oneshot ExecStart=/usr/local/bin/confluence_audit.sh # Run as your user User=${SERVICE_USER} WorkingDirectory=${CONFLUENCE_DIR} # Logging StandardOutput=journal StandardError=journal # Security (recommended) NoNewPrivileges=true [Install] WantedBy=multi-user.target EOF log_ok "Systemd service file created." # ============================================================================= # STEP 5: Create Systemd Timer File # ============================================================================= log_info "Creating systemd timer file: /etc/systemd/system/confluence-audit.timer ..." cat > /etc/systemd/system/confluence-audit.timer <<EOF [Unit] Description=Run Atlassian Confluence Audit every ${POLL_INTERVAL} seconds [Timer] OnBootSec=60 OnUnitActiveSec=${POLL_INTERVAL} Persistent=true Unit=confluence-audit.service [Install] WantedBy=timers.target EOF log_ok "Systemd timer file created (interval: ${POLL_INTERVAL}s)." # ============================================================================= # STEP 6: Configure Logrotate # ============================================================================= log_info "Configuring logrotate for $FLAT_FILE ..." cat > /etc/logrotate.d/confluence_audit <<EOF ${FLAT_FILE} { daily rotate 7 missingok notifempty copytruncate compress compressoptions -1 delaycompress dateext dateformat -%Y%m%d-%H%M%S create 0640 ${SERVICE_USER} ${SERVICE_GROUP} } EOF log_ok "Logrotate configuration created." # ============================================================================= # STEP 7: Enable and Start the Timer # ============================================================================= log_info "Reloading systemd and enabling the confluence-audit timer..." systemctl daemon-reload systemctl enable --now confluence-audit.timer log_ok "Timer enabled and started." # ============================================================================= # STEP 8: Verify Setup # ============================================================================= echo "" log_info "Verifying setup..." echo "" echo -e "${CYAN}--- Active Timers ---${NC}" systemctl list-timers --no-pager | grep confluence-audit || log_warn "Timer not found in list — check manually." echo "" echo -e "${CYAN}--- Service Status ---${NC}" systemctl status confluence-audit.service --no-pager || true # ============================================================================= # STEP 9: Summary # ============================================================================= echo "" echo -e "${GREEN}============================================================${NC}" echo -e "${GREEN} AQUILA Confluence Integration Setup Complete! ${NC}" echo -e "${GREEN}============================================================${NC}" echo "" echo -e " ${CYAN}Service User:${NC} $SERVICE_USER" echo -e " ${CYAN}Confluence Dir:${NC} $CONFLUENCE_DIR" echo -e " ${CYAN}Flat File Path:${NC} $FLAT_FILE" echo -e " ${CYAN}Poll Interval:${NC} ${POLL_INTERVAL}s" echo -e " ${CYAN}Script Location:${NC} /usr/local/bin/confluence_audit.sh" echo -e " ${CYAN}Service File:${NC} /etc/systemd/system/confluence-audit.service" echo -e " ${CYAN}Timer File:${NC} /etc/systemd/system/confluence-audit.timer" echo -e " ${CYAN}Logrotate Config:${NC} /etc/logrotate.d/confluence_audit" echo "" echo -e " ${CYAN}Provide to CyTech:${NC} $FLAT_FILE" echo -e " ${CYAN}Support:${NC} support@cytechint.com" echo "" echo -e " Monitor logs with: ${YELLOW}journalctl -u confluence-audit -f${NC}" echo ""
-
- Save the Script and change it to executable file.
-
chmod +x setup.sh
-
- Now execute the file in higher privileged.
-
sudo ./setup.sh
-
- Follow the on screen instruction to fully integrate the system.
If you need further assistance, kindly contact our support at support@cytechint.com for prompt assistance and guidance.