I am working on a pmm deploy script that includes promtail and having an issue parsing the mysql audit logs in json format… Hopefully someone can help me out here as I cant quite get it correctly… to build the yml file and append to the existing one I have a script that generates job entrys… can someone help me out here??
#!/bin/bash
# Prompt for user inputs
read -p "Enter hostname: " hostname
read -p "Enter applid: " applid
read -p "Enter environment: " environment
read -p "Enter log file path (__path__): " log_path
# Text file containing command classes (one per line)
command_classes_file="command_classes.txt"
# Output configuration file
output_file="promtail_config.yml"
# Clear or create the output file
> "$output_file"
# Loop through each command class in the text file
while IFS= read -r command_class; do
# Skip empty lines
if [[ -z "$command_class" ]]; then
continue
fi
cat >> "$output_file" << EOL
- job_name: ${command_class}
static_configs:
- targets:
- localhost
labels:
job: ${command_class}
hostname: ${hostname}
applid: ${applid}
environment: ${environment}
__path__: ${log_path}
pipeline_stages:
- json:
expressions:
audit_record: audit_record
- json:
expressions:
command_class: audit_record.command_class
name: audit_record.name
db: audit_record.db
ip: audit_record.ip
user: audit_record.user
status: audit_record.status
sqltext: audit_record.sqltext
- match:
selector: '{command_class="${command_class}"}'
stages:
- labels:
command_class: command_class
name: name
db: db
ip: ip
user: user
status: status
sqltext: sqltext
- match:
selector: '{command_class!="${command_class}"}'
stages:
- drop:
source: command_class
EOL
done < "$command_classes_file"
echo "Promtail configuration has been generated in $output_file"