Adding salt-macros and fixes for sum.sh
This commit is contained in:
parent
0a347bde62
commit
5128947437
|
@ -0,0 +1,99 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Alias for listing scheduled jobs
|
||||||
|
alias salt-schedule-list='docker exec -it salt_master_1 salt-call schedule.list'
|
||||||
|
|
||||||
|
# Alias for adding a scheduled job
|
||||||
|
alias salt-schedule-add='docker exec -it salt_master_1 salt-call schedule.add'
|
||||||
|
|
||||||
|
# Alias for viewing job history
|
||||||
|
alias salt-job-history='docker exec -it salt_master_1 salt-run jobs.list_jobs'
|
||||||
|
|
||||||
|
# Alias for looking up a specific job
|
||||||
|
alias salt-job-lookup='docker exec -it salt_master_1 salt-run jobs.lookup_jid'
|
||||||
|
|
||||||
|
# Alias for real-time event monitoring
|
||||||
|
alias salt-event-monitor='docker exec -it salt_master_1 salt-run state.event pretty=True'
|
||||||
|
|
||||||
|
# Function to schedule an orchestration job
|
||||||
|
function salt-schedule-orchestration {
|
||||||
|
if [ "$#" -ne 5 ]; then
|
||||||
|
echo "Usage: salt-schedule-orchestration <job_name> <orchestration_sls> <start_time> <end_time> <interval_minutes>"
|
||||||
|
echo "Example: salt-schedule-orchestration apply_specific_states orchestrate.apply_specific_states '0 9 * * 6' '0 17 * * 6' 60"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
local job_name=$1
|
||||||
|
local orchestration_sls=$2
|
||||||
|
local start_time=$3
|
||||||
|
local end_time=$4
|
||||||
|
local interval_minutes=$5
|
||||||
|
|
||||||
|
docker exec -it salt_master_1 salt-call schedule.add $job_name \
|
||||||
|
function='state.orchestrate' \
|
||||||
|
job_args="[\"$orchestration_sls\"]" \
|
||||||
|
when="$start_time" \
|
||||||
|
until="$end_time" \
|
||||||
|
minutes=$interval_minutes
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to monitor the last job executed on minions
|
||||||
|
function salt-minion-last-job {
|
||||||
|
if [ "$#" -ne 1 ]; then
|
||||||
|
echo "Usage: salt-minion-last-job <minion_id>"
|
||||||
|
echo "Example: salt-minion-last-job minion_id"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
local minion_id=$1
|
||||||
|
docker exec -it salt_master_1 salt $minion_id saltutil.last_job
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to find a specific job on a minion
|
||||||
|
function salt-minion-find-job {
|
||||||
|
if [ "$#" -ne 2 ]; then
|
||||||
|
echo "Usage: salt-minion-find-job <minion_id> <job_id>"
|
||||||
|
echo "Example: salt-minion-find-job minion_id job_id"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
local minion_id=$1
|
||||||
|
local job_id=$2
|
||||||
|
docker exec -it salt_master_1 salt $minion_id saltutil.find_job $job_id
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to print usage and options
|
||||||
|
function salt-macros {
|
||||||
|
echo "Available Salt macros and their usage:"
|
||||||
|
echo
|
||||||
|
echo "Aliases:"
|
||||||
|
echo " salt-schedule-list - List scheduled jobs"
|
||||||
|
echo " salt-schedule-add - Add a scheduled job"
|
||||||
|
echo " salt-job-history - View job history"
|
||||||
|
echo " salt-job-lookup <job_id> - Look up a specific job"
|
||||||
|
echo " salt-event-monitor - Monitor Salt events in real-time"
|
||||||
|
echo
|
||||||
|
echo "Functions:"
|
||||||
|
echo " salt-schedule-orchestration <job_name> <orchestration_sls> <start_time> <end_time> <interval_minutes>"
|
||||||
|
echo " - Schedule an orchestration job"
|
||||||
|
echo " - Example: salt-schedule-orchestration apply_specific_states orchestrate.apply_specific_states '0 9 * * 6' '0 17 * * 6' 60"
|
||||||
|
echo
|
||||||
|
echo " salt-minion-last-job <minion_id>"
|
||||||
|
echo " - Monitor the last job executed on a minion"
|
||||||
|
echo " - Example: salt-minion-last-job minion_id"
|
||||||
|
echo
|
||||||
|
echo " salt-minion-find-job <minion_id> <job_id>"
|
||||||
|
echo " - Find a specific job on a minion"
|
||||||
|
echo " - Example: salt-minion-find-job minion_id job_id"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Example usage suggestions
|
||||||
|
# To schedule an orchestration:
|
||||||
|
# salt-schedule-orchestration "apply_specific_states" "orchestrate.apply_specific_states" "0 9 * * 6" "0 17 * * 6" 60
|
||||||
|
|
||||||
|
# To monitor the last job on a minion:
|
||||||
|
# salt-minion-last-job "minion_id"
|
||||||
|
|
||||||
|
# To find a specific job on a minion:
|
||||||
|
# salt-minion-find-job "minion_id" "job_id"
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
5027c07471f7a1413d5cc10da21f01bc167c6b69d1a3913cb739208483cce79b
|
15
src/sum.sh
15
src/sum.sh
|
@ -5,9 +5,9 @@ if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Function to generate SHA-256 hashes for .sh files in src or dist directories
|
# Function to generate SHA-256 hashes for .sh files in the src directory
|
||||||
calculate_hashes() {
|
calculate_hashes() {
|
||||||
local base_dir="$1"
|
local base_dir="./src"
|
||||||
|
|
||||||
# Check if the base directory exists
|
# Check if the base directory exists
|
||||||
if [ ! -d "$base_dir" ]; then
|
if [ ! -d "$base_dir" ]; then
|
||||||
|
@ -21,7 +21,7 @@ calculate_hashes() {
|
||||||
hash_cmd="sha256sum"
|
hash_cmd="sha256sum"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Function to process a directory
|
# Function to process the src directory
|
||||||
process_directory() {
|
process_directory() {
|
||||||
local dir="$1"
|
local dir="$1"
|
||||||
for file in "$dir"/*.sh; do
|
for file in "$dir"/*.sh; do
|
||||||
|
@ -33,13 +33,8 @@ calculate_hashes() {
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
# Process src and dist directories if they exist
|
# Process the src directory
|
||||||
for sub_dir in src dist; do
|
process_directory "$base_dir"
|
||||||
local full_dir="$base_dir/$sub_dir"
|
|
||||||
if [ -d "$full_dir" ]; then
|
|
||||||
process_directory "$full_dir"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
echo "SHA-256 hashes have been saved in .sha256 files."
|
echo "SHA-256 hashes have been saved in .sha256 files."
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
004ba4423c45dc5bbf57fe514ba44e07bc303e80e579911a58f265ab42365ba0
|
5d7646254d8f39bbd65b4473a3c8854eb088a566c0fc60ee9948a66ac8797e10
|
||||||
|
|
Loading…
Reference in New Issue