nagios-check-tor-authority-cert 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #!/bin/bash
  2. # nagios-check-tor-authority-cert - check certificate expiry time
  3. # A nagios check for Tor v3 directory authorities:
  4. # - Checks the current certificate expiry time
  5. #
  6. # Usage: nagios-check-tor-authority-cert <authority identity fingerprint>
  7. # e.g.: nagios-check-tor-authority-cert A9AC67E64B200BBF2FA26DF194AC0469E2A948C6
  8. # $Id$
  9. # Copyright (c) 2008 Peter Palfrader <peter@palfrader.org>
  10. #
  11. # Permission is hereby granted, free of charge, to any person obtaining
  12. # a copy of this software and associated documentation files (the
  13. # "Software"), to deal in the Software without restriction, including
  14. # without limitation the rights to use, copy, modify, merge, publish,
  15. # distribute, sublicense, and/or sell copies of the Software, and to
  16. # permit persons to whom the Software is furnished to do so, subject to
  17. # the following conditions:
  18. #
  19. # The above copyright notice and this permission notice shall be
  20. # included in all copies or substantial portions of the Software.
  21. #
  22. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  23. # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  24. # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  25. # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  26. # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  27. # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  28. # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  29. set -e
  30. set -u
  31. if [ -z "${1:-}" ]; then
  32. echo "Usage: $0 <authority identity fingerprint>" 2>&1
  33. exit 3
  34. fi
  35. identity="$1"
  36. DIRSERVERS=""
  37. DIRSERVERS="$DIRSERVERS 86.59.21.38:80" # tor26
  38. DIRSERVERS="$DIRSERVERS 128.31.0.34:9031" # moria1
  39. DIRSERVERS="$DIRSERVERS 216.224.124.114:9030" # ides
  40. DIRSERVERS="$DIRSERVERS 88.198.7.215:80" # gabelmoo
  41. DIRSERVERS="$DIRSERVERS 140.247.60.64:80" # lefkada
  42. TMPFILE="`tempfile`"
  43. trap 'rm -f "$TMPFILE"' 0
  44. for dirserver in $DIRSERVERS; do
  45. wget -q -O "$TMPFILE" "http://$dirserver/tor/keys/fp/$identity"
  46. if [ "$?" = 0 ]; then
  47. break
  48. else
  49. cat /dev/null > "$TMPFILE"
  50. continue
  51. fi
  52. done
  53. if ! [ -s "$TMPFILE" ] ; then
  54. echo "UNKNOWN: Downloading certificate for $identity failed."
  55. exit 3
  56. fi
  57. expirydate="$(awk '$1=="dir-key-expires" {printf "%s %s", $2, $3}' < "$TMPFILE")"
  58. expiryunix=$(date -d "$expirydate" +%s)
  59. now=$(date +%s)
  60. if [ "$now" -ge "$expiryunix" ]; then
  61. echo "CRITICAL: Certificate expired $expirydate (authority $identity)."
  62. exit 2
  63. elif [ "$(( $now + 7*24*60*60 ))" -ge "$expiryunix" ]; then
  64. echo "CRITICAL: Certificate expires $expirydate (authority $identity)."
  65. exit 2
  66. elif [ "$(( $now + 30*24*60*60 ))" -ge "$expiryunix" ]; then
  67. echo "WARNING: Certificate expires $expirydate (authority $identity)."
  68. exit 1
  69. else
  70. echo "OK: Certificate expires $expirydate (authority $identity)."
  71. exit 1
  72. fi