
All checks were successful
Test and Publish Templates / test-and-publish (push) Successful in 40s
111 lines
3.0 KiB
Bash
Executable File
111 lines
3.0 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Generate Promtail configuration for Log Client
|
|
|
|
# Check required variables
|
|
if [ -z "$LOGSERVER_HOST" ] || [ -z "$LOGSERVER_PORT" ] || [ -z "$LOKI_PASSWORD" ]; then
|
|
echo "ERROR: Required environment variables not set"
|
|
echo " LOGSERVER_HOST: ${LOGSERVER_HOST:-NOT SET}"
|
|
echo " LOGSERVER_PORT: ${LOGSERVER_PORT:-NOT SET}"
|
|
echo " LOKI_PASSWORD: ${LOKI_PASSWORD:-NOT SET}"
|
|
echo ""
|
|
echo "Please set these in config/service.env before running install"
|
|
exit 1
|
|
fi
|
|
|
|
# Get actual hostname
|
|
ACTUAL_HOSTNAME=${HOSTNAME_LABEL:-${HOSTNAME:-$(hostname 2>/dev/null || echo "unknown")}}
|
|
|
|
# Determine config directory
|
|
CONFIG_DIR="${CONFIG_PATH:-./config}"
|
|
mkdir -p "$CONFIG_DIR"
|
|
|
|
# Generate promtail.yaml configuration
|
|
cat > "$CONFIG_DIR/promtail.yaml" << EOF
|
|
server:
|
|
http_listen_port: 9080
|
|
grpc_listen_port: 0
|
|
|
|
positions:
|
|
filename: /tmp/positions/positions.yaml
|
|
|
|
clients:
|
|
- url: http://${LOKI_USER:-logclient}:${LOKI_PASSWORD}@${LOGSERVER_HOST}:${LOGSERVER_PORT}/loki/api/v1/push
|
|
# Authentication via URL (HTTP Basic Auth)
|
|
|
|
scrape_configs:
|
|
# Docker container logs via Docker API
|
|
- job_name: docker
|
|
docker_sd_configs:
|
|
- host: unix:///var/run/docker.sock
|
|
refresh_interval: 5s
|
|
relabel_configs:
|
|
- source_labels: ['__meta_docker_container_name']
|
|
regex: '/(.*)'
|
|
target_label: 'container_name'
|
|
- source_labels: ['__meta_docker_container_id']
|
|
target_label: 'container_id'
|
|
- source_labels: ['__meta_docker_container_image']
|
|
target_label: 'image'
|
|
- target_label: 'hostname'
|
|
replacement: '${ACTUAL_HOSTNAME}'
|
|
- target_label: 'job'
|
|
replacement: 'docker'
|
|
|
|
# System logs
|
|
- job_name: syslog
|
|
static_configs:
|
|
- targets:
|
|
- localhost
|
|
labels:
|
|
job: syslog
|
|
hostname: ${ACTUAL_HOSTNAME}
|
|
__path__: /var/log/syslog
|
|
|
|
- job_name: messages
|
|
static_configs:
|
|
- targets:
|
|
- localhost
|
|
labels:
|
|
job: messages
|
|
hostname: ${ACTUAL_HOSTNAME}
|
|
__path__: /var/log/messages
|
|
|
|
- job_name: auth
|
|
static_configs:
|
|
- targets:
|
|
- localhost
|
|
labels:
|
|
job: auth
|
|
hostname: ${ACTUAL_HOSTNAME}
|
|
__path__: /var/log/auth.log
|
|
|
|
# Docker container JSON logs (backup method)
|
|
- job_name: containers
|
|
static_configs:
|
|
- targets:
|
|
- localhost
|
|
labels:
|
|
job: containers
|
|
hostname: ${ACTUAL_HOSTNAME}
|
|
__path__: /var/lib/docker/containers/*/*-json.log
|
|
pipeline_stages:
|
|
- json:
|
|
expressions:
|
|
output: log
|
|
stream: stream
|
|
time: time
|
|
- timestamp:
|
|
source: time
|
|
format: RFC3339Nano
|
|
- labels:
|
|
stream:
|
|
- output:
|
|
source: output
|
|
EOF
|
|
|
|
echo "Promtail configuration generated at: $CONFIG_DIR/promtail.yaml"
|
|
echo "Configuration:"
|
|
echo " LOGSERVER_HOST: ${LOGSERVER_HOST}"
|
|
echo " LOGSERVER_PORT: ${LOGSERVER_PORT}"
|
|
echo " HOSTNAME: ${ACTUAL_HOSTNAME}" |