-
Notifications
You must be signed in to change notification settings - Fork 3
/
check_entropy.sh
executable file
·43 lines (40 loc) · 1.22 KB
/
check_entropy.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/sh
#
# (c)2014 Christian Kujau <[email protected]>
# Nagios plugin to check kernel.random.entropy_avail
#
# Similar plugins exist, but all seemed overly complicated and a bourne shell
# version is nice because it doesn't need Perl or Python installed.
#
# Perl: https://www.unixadm.org/software/nagios-stuff/checks/check_entropy
# Python: https://salsa.debian.org/dsa-team/mirror/dsa-nagios/blob/master/dsa-nagios-checks/checks/dsa-check-entropy
#
while getopts ":w:c:" opt; do
case $opt in
w) warn=$OPTARG ;;
c) crit=$OPTARG ;;
*) exit 3 ;;
esac
done
# Both warn and crit are needed
if [ -z "$warn" ] || [ -z "$crit" ]; then
echo "Usage: $(basename "$0") -w num -c num"
exit 3
fi
# warn should be greater than crit
if [ "$warn" -lt "$crit" ]; then
echo "UNKNOWN: warn ($warn) < crit ($crit)"
exit 3
fi
# TODO: how about other operating systems?
ENTROPY=$(/sbin/sysctl -n kernel.random.entropy_avail)
if [ "$ENTROPY" -lt "$crit" ]; then
echo "CRITICAL: Too little entropy ($ENTROPY) in the pool (warn: $warn, crit: $crit)"
exit 2
elif [ "$ENTROPY" -lt "$warn" ]; then
echo "WARNING: Too little entropy ($ENTROPY) in the pool (warn: $warn, crit: $crit)"
exit 2
else
echo "OK: $ENTROPY bytes in the pool."
exit 0
fi