nagios-check-tor-authority-cert 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. DIRSERVERS="$DIRSERVERS 213.73.91.31:80" # dannenberg
  43. TMPFILE="`tempfile`"
  44. trap 'rm -f "$TMPFILE"' 0
  45. for dirserver in $DIRSERVERS; do
  46. wget -q -O "$TMPFILE" "http://$dirserver/tor/keys/fp/$identity"
  47. if [ "$?" = 0 ]; then
  48. break
  49. else
  50. cat /dev/null > "$TMPFILE"
  51. continue
  52. fi
  53. done
  54. if ! [ -s "$TMPFILE" ] ; then
  55. echo "UNKNOWN: Downloading certificate for $identity failed."
  56. exit 3
  57. fi
  58. expirydate="$(awk '$1=="dir-key-expires" {printf "%s %s", $2, $3}' < "$TMPFILE")"
  59. expiryunix=$(TZ=UTC date -d "$expirydate" +%s)
  60. now=$(date +%s)
  61. if [ "$now" -ge "$expiryunix" ]; then
  62. echo "CRITICAL: Certificate expired $expirydate (authority $identity)."
  63. exit 2
  64. elif [ "$(( $now + 7*24*60*60 ))" -ge "$expiryunix" ]; then
  65. echo "CRITICAL: Certificate expires $expirydate (authority $identity)."
  66. exit 2
  67. elif [ "$(( $now + 30*24*60*60 ))" -ge "$expiryunix" ]; then
  68. echo "WARNING: Certificate expires $expirydate (authority $identity)."
  69. exit 1
  70. else
  71. echo "OK: Certificate expires $expirydate (authority $identity)."
  72. exit 0
  73. fi