check_pollen 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/bin/sh
  2. #
  3. # check_pollen - verify the pollen server on localhost is operating correctly
  4. #
  5. # Copyright (C) 2013 Dustin Kirkland <dustin.kirkland@gmail.com>
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU Affero General Public License as published by
  9. # the Free Software Foundation, version 3 of the License.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU Affero General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU Affero General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. TMPDIR=$(mktemp -d -t "pollen.XXXXXXXXXXXX")
  19. trap "rm -rf ${TMPDIR} 2>/dev/null || true" EXIT HUP INT QUIT TERM
  20. md5sum1=$(grep pollen /var/log/syslog /var/log/pollen/pollen.log 2>/dev/null || true | md5sum)
  21. pollinate -t -i -s localhost -b -d - >"$TMPDIR/out" 2>"$TMPDIR/err" && RC=0 || RC=$?
  22. md5sum2=$(grep pollen /var/log/syslog /var/log/pollen/pollen.log 2>/dev/null || true | md5sum)
  23. bytes=$(wc -c "$TMPDIR/out" | awk '{print $1}')
  24. bpb=$(ent -t "$TMPDIR/out" | tail -n1 | awk -F, '{print $3}' | awk -F. '{print $1}')
  25. mean=$(ent -t "$TMPDIR/out" | tail -n1 | awk -F, '{print $5}' | awk -F. '{print $1}')
  26. if [ "$RC" != "0" ]; then
  27. echo "CRITICAL - pollen server did not properly respond to the test request [$RC]"
  28. cat "$TMPDIR/err" 1>&2
  29. exit 2
  30. fi
  31. if [ "$md5sum1" = "$md5sum2" ]; then
  32. echo "CRITICAL - pollen server did not properly log the test request [$RC]"
  33. grep pollen /var/log/syslog /var/log/pollen/pollen.log 2>/dev/null || true
  34. exit 2
  35. fi
  36. if [ -z "$bytes" ] || [ "$bytes" -lt 64 ]; then
  37. echo "WARNING - pollen server did not respond with at least 64 bytes [$bytes]"
  38. exit 1
  39. fi
  40. if [ -z "$bpb" ] || [ "$bpb" -lt 5 ]; then
  41. echo "WARNING - pollen server did not respond with sufficient entropy bits per byte [$bpb]"
  42. exit 1
  43. fi
  44. if [ -z "$mean" ] || [ "$mean" -lt 95 ] || [ "$mean" -gt 160 ]; then
  45. echo "WARNING - pollen server responded with poor entropy (bad arithmetic mean [$mean])"
  46. exit 1
  47. fi
  48. echo "OK - pollen server is online and responded correctly to the test request"
  49. exit 0