check_salt 703 B

12345678910111213141516171819202122
  1. #!/bin/sh
  2. # Check if state-file exists, otherwise exit with unknown
  3. if [ ! -f /var/cache/salt/state_apply ] ; then echo "Statefile does not exist" ; exit 3 ; fi
  4. # Check age of statefile. If it's older than 2 hours, exit with unknown
  5. if [ $(($(date +%s) - $(date -r /var/cache/salt/state_apply +%s))) -gt 25200 ] ; then echo "Statefile too old" ; exit 3 ; fi
  6. if grep -o ' changed=\([0-9]\+\)' /var/cache/salt/state_apply > /dev/null ; then
  7. ANZ_CHANGED=$(grep -o ' changed=\([0-9]\+\)' /var/cache/salt/state_apply | cut -d= -f2)
  8. if [ $ANZ_CHANGED -gt 0 ] ; then
  9. echo "IDs with changes:"
  10. cat /var/cache/salt/state_apply | grep "ID:"
  11. exit 1 # warning
  12. fi
  13. fi
  14. echo "Nothing to do"
  15. exit 0 # ok