Edit file File name : check_a2_salt_running.all Content :#!/bin/bash last_run=$(stat -c '%Y' /opt/includes/.saltrunning) uptime_seconds=$(awk '{print $1}' /proc/uptime | cut -d. -f1) now=$( date +%s ) ifdown="/opt/includes/.cfm_downtime" saltenv=$(grep ^saltenv /etc/salt/minion | awk '{print $NF}') if [[ -e "${ifdown}" ]]; then downtimed_since=$(date -d @"$(stat -c '%Y' "${ifdown}")" "+%b %d, %Y") downtimed_by=$(awk -F'|' '{print $1}' "${ifdown}") downtime_dur=$(awk -F'|' '{print $2}' "${ifdown}") reason=$(awk -F'|' '{print $NF}' "${ifdown}") fi check_status() { # see if downtimed if [ -f ${ifdown} ]; then if [[ $(awk -F'|' '{print NF; exit}' "${ifdown}") -eq 4 ]]; then echo -n "salt_running - Salt is downtimed for ${downtime_dur} by ${downtimed_by} - ${reason}" exit 1 else echo -n "salt_running - Salt is downtimed permanently since ${downtimed_since} by ${downtimed_by} - ${reason}" exit 1 fi echo "(in *${saltenv}* environment)" #Check if /opt/includes/.saltrunning exists or has not updated in more than 2 hours elif [[ ! -e /opt/includes/.saltrunning ]] || [[ $(( now - last_run )) -gt 7200 ]]; then echo "salt_running - Salt has not been updating 2 or more hours and in *${saltenv}* environment" exit 2 # otherwise okay else if [ "${saltenv}" == "production" ]; then echo "salt_running - Salt is running okay" exit 0 elif [ "${saltenv}" == "development" ]; then echo "salt_running - Salt is running in *${saltenv}* environment" exit 1 fi fi } if [ "${saltenv}" == "development" ] || [ "${saltenv}" == "production" ]; then # Check if uptime is greater than or equal to 2 hours (7200 seconds) if (( uptime_seconds >= 7200 )); then check_status else echo "salt_running - Uptime is less than 2 hours" exit 0 fi else echo "salt_running - Unknown Salt environment! Please check." exit 1 fi Save