65 lines
2.0 KiB
Bash
65 lines
2.0 KiB
Bash
#!/bin/bash
|
|
|
|
# Function to process diffs and check ignores
|
|
process_container() {
|
|
local container_id=$1
|
|
local mode=$2
|
|
|
|
# Get the container labels
|
|
labels=$(docker inspect --format '{{json .Config.Labels}}' "$container_id")
|
|
cname=$(echo "$labels" | jq -r '.["oculus.cname"]')
|
|
ignores=$(echo "$labels" | jq -r '.["oculus.ignores"]')
|
|
|
|
# Get the diff
|
|
diff_output=$(docker diff "$container_id")
|
|
|
|
# Process ignores
|
|
if [ "$ignores" != "null" ]; then
|
|
IFS=',' read -ra ignore_array <<< "$ignores"
|
|
for ignore in "${ignore_array[@]}"; do
|
|
diff_output=$(echo "$diff_output" | grep -v "$ignore")
|
|
done
|
|
fi
|
|
|
|
# Write the diff output to a file
|
|
echo "$diff_output" > "${cname}.diff"
|
|
|
|
if [ "$mode" == "monitor" ]; then
|
|
# Check if there are any changes left after applying ignores
|
|
if [ -n "$diff_output" ]; then
|
|
# Send notification using go-glitch
|
|
echo "$diff_output" | go-glitch
|
|
fi
|
|
fi
|
|
}
|
|
|
|
export -f process_container
|
|
|
|
# Get the list of running containers
|
|
containers=$(docker ps -q)
|
|
|
|
# Check if there are no running containers
|
|
if [ -z "$containers" ]; then
|
|
echo "No running containers found."
|
|
exit 0
|
|
fi
|
|
|
|
# Iterate over each container and process based on labels
|
|
for container in $containers; do
|
|
labels=$(docker inspect --format '{{json .Config.Labels}}' "$container")
|
|
enable=$(echo "$labels" | jq -r '.["oculus.enable"]')
|
|
|
|
if [ "$enable" == "monitor" ]; then
|
|
frequency=$(echo "$labels" | jq -r '.["oculus.frequency"]')
|
|
if [ "$frequency" == "null" ]; then
|
|
frequency="300s" # Default frequency if not set
|
|
fi
|
|
# Run the process_container function with monitor mode
|
|
echo "$container monitor" | parallel process_container
|
|
sleep "${frequency}"
|
|
elif [ "$enable" == "profile" ]; then
|
|
# Run the process_container function with profile mode
|
|
echo "$container profile" | parallel process_container
|
|
fi
|
|
done
|