You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

check_rainfall.sh 785B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/bin/bash
  2. while getopts “:w:c:” opt; do
  3. case $opt in
  4. w) warn=$OPTARG ;;
  5. c) crit=$OPTARG ;;
  6. esac
  7. done
  8. aweekago=$(date -d "7 days ago" +%Y-%m-%d)
  9. now=$(date +%Y-%m-%d)
  10. diff=$(mysql --defaults-extra-file=weather.ini -NBs -e "SELECT avg(Rainfall - ETo) FROM aggregated_weather WHERE Date BETWEEN \"${aweekago}\" AND \"${now}\"" ${db})
  11. OK=0
  12. WARNING=1
  13. CRITICAL=2
  14. UNKNOWN=3
  15. state=${OK}
  16. msg="OK:"
  17. if [[ "x${warn}" == "x" ]]; then
  18. warn=-0.5
  19. fi
  20. if [[ "x${crit}" == "x" ]]; then
  21. crit=-2
  22. fi
  23. if (( $(echo "${diff} < ${warn}" |bc -l) )); then
  24. state=${WARNING}
  25. msg="WARNING:"
  26. fi
  27. if (( $(echo "${diff} < ${crit}" |bc -l) )); then
  28. state=${CRITICAL}
  29. msg="CRITICAL:"
  30. fi
  31. echo "${msg} Rainfall - evapotransipration is ${diff}|diff=${diff};${warn};${crit}"
  32. exit ${state}