swtich from ELK to Loki!
All checks were successful
Test and Publish Templates / test-and-publish (push) Successful in 40s

This commit is contained in:
Your Name
2025-09-20 12:01:25 +12:00
parent d32042e42d
commit f114773d78
62 changed files with 1121 additions and 2899 deletions

View File

@@ -2,52 +2,39 @@
source "${AGENT_PATH}/common.sh"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Check required environment variables
_check_required_env_vars "CONTAINER_NAME" "IMAGE_REGISTRY" "IMAGE_REPO" "IMAGE_TAG" "LOGSERVER_HOST" "LOGSERVER_PORT" "API_KEY"
_check_required_env_vars "CONTAINER_NAME" "LOGSERVER_HOST" "LOGSERVER_PORT" "LOKI_PASSWORD"
# Validate API key
if [ -z "$API_KEY" ]; then
echo ""
echo "ERROR: API_KEY is not configured"
echo ""
echo "To get an API key:"
echo "1. On the logserver, run: ./generate-api-key.sh"
echo "2. Enter this client's hostname when prompted"
echo "3. Copy the generated API_KEY to this client's service.env"
echo ""
_die "Missing API_KEY configuration"
fi
# Check Docker is available
# Check Docker
_check_docker_installed || _die "Docker test failed"
# Test connectivity to logserver
echo "Testing connectivity to logserver at ${LOGSERVER_HOST}:${LOGSERVER_PORT}..."
nc -zv "$LOGSERVER_HOST" "$LOGSERVER_PORT" 2>/dev/null || echo "WARNING: Cannot connect to logserver. Will retry when container starts."
# Pull the Docker image
docker pull "$IMAGE_REGISTRY/$IMAGE_REPO:$IMAGE_TAG" || _die "Failed to pull Filebeat image"
echo "Testing connectivity to log server at ${LOGSERVER_HOST}:${LOGSERVER_PORT}..."
nc -zv "$LOGSERVER_HOST" "$LOGSERVER_PORT" 2>/dev/null || echo "WARNING: Cannot connect to log server. Will retry when container starts."
# Stop any existing container
bash ./stop.sh || true
bash ./stop.sh 2>/dev/null || true
# Remove old container
_remove_container "$CONTAINER_NAME" || true
# Generate Filebeat configuration (with actual hostname)
echo "Generating Filebeat configuration..."
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Generate configuration
echo "Generating configuration..."
export HOSTNAME=$(hostname)
bash "$SCRIPT_DIR/scripts/generate-config.sh" || _die "Failed to generate configuration"
# Create volumes using common function
source "$SCRIPT_DIR/_volumes.sh"
echo "Creating volumes..."
create_items $(get_logclient_volumes)
# Start the client
echo "Starting Log Client..."
docker compose up -d || _die "Failed to start"
# Start the new container
bash ./start.sh || _die "Failed to start Filebeat"
echo "Installation of ${CONTAINER_NAME} complete"
echo "Collecting logs from Docker API and shipping to ${LOGSERVER_HOST}:${LOGSERVER_PORT}"
echo "Using API key authentication"
echo ""
echo "========================================="
echo "Log Client Installed!"
echo "========================================="
echo ""
echo "Shipping logs to: ${LOGSERVER_HOST}:${LOGSERVER_PORT}"
echo "Using authentication: ${LOKI_USER:-logclient}"
echo "Hostname label: $(hostname)"
echo ""
echo "Collecting:"
echo " - All Docker container logs"
echo " - System logs (/var/log)"
echo ""
echo "View logs at: http://${LOGSERVER_HOST}:3000"
echo "========================================="