notify-prom-status.sh 489 B

123456789101112131415161718
  1. #!/bin/bash
  2. [ -z "$PROM_URL" ] && exit
  3. case $1 in
  4. start) state='1'; status='started' ;;
  5. stop|0) state='0'; status='stopped' ;;
  6. info|1) state='0'; status='stopped with info' ;;
  7. fail|2|*) state='-1'; status='failed' ;;
  8. esac
  9. cat <<EOF | curl --data-binary @- $PROM_URL
  10. # TYPE borg_hook_state gauge
  11. # HELP borg_hook_state 1=started 0=stopped -1=failed
  12. borg_hook_state $state
  13. # TYPE borg_hook_state_timestamp gauge
  14. borg_hook_state_timestamp{label="$status"} `date +%s`
  15. EOF