nagios-check-tor-authority-cert 2.9 KB

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